c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef ACL_API_PRIVATE_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define ACL_API_PRIVATE_H
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen#include "acl-api.h"
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen#define ACL_ID_NAME_ANYONE "anyone"
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen#define ACL_ID_NAME_AUTHENTICATED "authenticated"
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen#define ACL_ID_NAME_OWNER "owner"
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen#define ACL_ID_NAME_USER_PREFIX "user="
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen#define ACL_ID_NAME_GROUP_PREFIX "group="
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen#define ACL_ID_NAME_GROUP_OVERRIDE_PREFIX "group-override="
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainenstruct acl_backend_vfuncs {
3809b9691c46926aa54968ac8e418d04361e1efaTimo Sirainen struct acl_backend *(*alloc)(void);
3809b9691c46926aa54968ac8e418d04361e1efaTimo Sirainen int (*init)(struct acl_backend *backend, const char *data);
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen void (*deinit)(struct acl_backend *backend);
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen struct acl_mailbox_list_context *
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen (*nonowner_lookups_iter_init)(struct acl_backend *backend);
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi bool (*nonowner_lookups_iter_next)(struct acl_mailbox_list_context *ctx,
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen const char **name_r);
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi int (*nonowner_lookups_iter_deinit)
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen (struct acl_mailbox_list_context *ctx);
579e70631b8474d20fd3829f477c62950e5f9635Timo Sirainen int (*nonowner_lookups_rebuild)(struct acl_backend *backend);
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen struct acl_object *(*object_init)(struct acl_backend *backend,
3809b9691c46926aa54968ac8e418d04361e1efaTimo Sirainen const char *name);
da9f6acdcb303d0fe5160b669668aedf39c8f45aTimo Sirainen struct acl_object *(*object_init_parent)(struct acl_backend *backend,
da9f6acdcb303d0fe5160b669668aedf39c8f45aTimo Sirainen const char *child_name);
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen void (*object_deinit)(struct acl_object *aclobj);
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen int (*object_refresh_cache)(struct acl_object *aclobj);
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen int (*object_update)(struct acl_object *aclobj,
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen const struct acl_rights_update *update);
eb4d4f557fa75aa2a47639e9deb75a21f44eb42aTimo Sirainen int (*last_changed)(struct acl_object *aclobj, time_t *last_changed_r);
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen struct acl_object_list_iter *
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen (*object_list_init)(struct acl_object *aclobj);
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi bool (*object_list_next)(struct acl_object_list_iter *iter,
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen struct acl_rights *rights_r);
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi int (*object_list_deinit)(struct acl_object_list_iter *iter);
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen};
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainenstruct acl_backend {
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen pool_t pool;
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen const char *username;
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen const char **groups;
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen unsigned int group_count;
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
e7ca5f820d6a1a8fe549a2966ac707a60e055ef4Timo Sirainen struct mailbox_list *list;
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen struct acl_cache *cache;
4c158400b046fefefce0194603951a6587f51867Timo Sirainen struct acl_global_file *global_file;
8ab69d02c689fbdad2a1c83a5cd27e6adf21ca6cTimo Sirainen
8ab69d02c689fbdad2a1c83a5cd27e6adf21ca6cTimo Sirainen struct acl_object *default_aclobj;
8ab69d02c689fbdad2a1c83a5cd27e6adf21ca6cTimo Sirainen struct acl_mask *default_aclmask;
7705148680904051b573a9125ecee765032a5809Timo Sirainen const char *const *default_rights;
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen struct acl_backend_vfuncs v;
3809b9691c46926aa54968ac8e418d04361e1efaTimo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool owner:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool debug:1;
5714c480bb705939ef33de2ec7e8fb501809aa49Timo Sirainen bool globals_only:1;
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen};
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainenstruct acl_mailbox_list_context {
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen struct acl_backend *backend;
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi bool empty:1;
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi bool failed:1;
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi const char *error;
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen};
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainenstruct acl_object {
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen struct acl_backend *backend;
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen char *name;
086c52e4bcdc950e47ee331e1e07c9c10982a670Timo Sirainen
086c52e4bcdc950e47ee331e1e07c9c10982a670Timo Sirainen pool_t rights_pool;
4c158400b046fefefce0194603951a6587f51867Timo Sirainen ARRAY_TYPE(acl_rights) rights;
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen};
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainenstruct acl_object_list_iter {
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen struct acl_object *aclobj;
e293d46ffe09252ae50704b2a53be6e5b9bdc778Timo Sirainen pool_t pool;
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen
e293d46ffe09252ae50704b2a53be6e5b9bdc778Timo Sirainen struct acl_rights *rights;
e293d46ffe09252ae50704b2a53be6e5b9bdc778Timo Sirainen unsigned int idx, count;
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi bool empty:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool failed:1;
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi const char *error;
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen};
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen
7d8afd1e15bdf23b5fd13aa9ac9606aca2797125Timo Sirainenextern const char *const all_mailbox_rights[];
7d8afd1e15bdf23b5fd13aa9ac9606aca2797125Timo Sirainen
086c52e4bcdc950e47ee331e1e07c9c10982a670Timo Sirainenstruct acl_object_list_iter *
086c52e4bcdc950e47ee331e1e07c9c10982a670Timo Sirainenacl_default_object_list_init(struct acl_object *aclobj);
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomibool acl_default_object_list_next(struct acl_object_list_iter *iter,
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomi struct acl_rights *rights_r);
37c72fa0cd3f1d74d79b64afb3fb6da5ffd4fe3aAki Tuomiint acl_default_object_list_deinit(struct acl_object_list_iter *iter);
086c52e4bcdc950e47ee331e1e07c9c10982a670Timo Sirainen
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainenconst char *const *
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainenacl_backend_mask_get_names(struct acl_backend *backend,
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen const struct acl_mask *mask, pool_t pool);
515d649c1802beb48433b90125518c00d0a1fbb4Timo Sirainenstruct acl_object *acl_backend_get_default_object(struct acl_backend *backend);
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainenint acl_backend_get_default_rights(struct acl_backend *backend,
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen const struct acl_mask **mask_r);
81e6e1ef0feef60644a4c4b745d82a4c98223affTimo Sirainenvoid acl_rights_write_id(string_t *dest, const struct acl_rights *right);
3cd0463d17cf9ecbc3d826d60b36800d09f0633cTimo Sirainenbool acl_rights_has_nonowner_lookup_changes(const struct acl_rights *rights);
2f122b4db3f0d4eeb59ff9d306e54b2009d72cf9Timo Sirainen
7d8afd1e15bdf23b5fd13aa9ac9606aca2797125Timo Sirainenint acl_identifier_parse(const char *line, struct acl_rights *rights);
eb4d4f557fa75aa2a47639e9deb75a21f44eb42aTimo Sirainenint acl_rights_update_import(struct acl_rights_update *update,
eb4d4f557fa75aa2a47639e9deb75a21f44eb42aTimo Sirainen const char *id, const char *const *rights,
eb4d4f557fa75aa2a47639e9deb75a21f44eb42aTimo Sirainen const char **error_r);
eb4d4f557fa75aa2a47639e9deb75a21f44eb42aTimo Sirainenconst char *acl_rights_export(const struct acl_rights *rights);
15f43b172d2c626aa03c921979c49821a55c7e5eTimo Sirainenint acl_rights_parse_line(const char *line, pool_t pool,
15f43b172d2c626aa03c921979c49821a55c7e5eTimo Sirainen struct acl_rights *rights_r, const char **error_r);
4c158400b046fefefce0194603951a6587f51867Timo Sirainenvoid acl_rights_dup(const struct acl_rights *src,
4c158400b046fefefce0194603951a6587f51867Timo Sirainen pool_t pool, struct acl_rights *dest_r);
cc287b822b175619a853686b738ba673e370117bTimo Sirainenint acl_rights_cmp(const struct acl_rights *r1, const struct acl_rights *r2);
086c52e4bcdc950e47ee331e1e07c9c10982a670Timo Sirainenvoid acl_rights_sort(struct acl_object *aclobj);
cc287b822b175619a853686b738ba673e370117bTimo Sirainen
cc287b822b175619a853686b738ba673e370117bTimo Sirainenconst char *const *
cc287b822b175619a853686b738ba673e370117bTimo Sirainenacl_right_names_parse(pool_t pool, const char *acl, const char **error_r);
cc287b822b175619a853686b738ba673e370117bTimo Sirainenvoid acl_right_names_write(string_t *dest, const char *const *rights);
cc287b822b175619a853686b738ba673e370117bTimo Sirainenvoid acl_right_names_merge(pool_t pool, const char *const **destp,
cc287b822b175619a853686b738ba673e370117bTimo Sirainen const char *const *src, bool dup_strings);
cc287b822b175619a853686b738ba673e370117bTimo Sirainenbool acl_right_names_modify(pool_t pool,
cc287b822b175619a853686b738ba673e370117bTimo Sirainen const char *const **rightsp,
cc287b822b175619a853686b738ba673e370117bTimo Sirainen const char *const *modify_rights,
cc287b822b175619a853686b738ba673e370117bTimo Sirainen enum acl_modify_mode modify_mode);
086c52e4bcdc950e47ee331e1e07c9c10982a670Timo Sirainenvoid acl_object_rebuild_cache(struct acl_object *aclobj);
086c52e4bcdc950e47ee331e1e07c9c10982a670Timo Sirainenvoid acl_object_remove_all_access(struct acl_object *aclobj);
4c158400b046fefefce0194603951a6587f51867Timo Sirainenvoid acl_object_add_global_acls(struct acl_object *aclobj);
7d8afd1e15bdf23b5fd13aa9ac9606aca2797125Timo Sirainen
7fb70daba4e571eab5b64f496d20b9e37e31141bTimo Sirainen#endif