bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2014-2018 Dovecot authors, see the included COPYING file */
e2e6f40d58b85041ca77338026a17d6708f324efTimo Sirainenacl_global_file_init(const char *path, unsigned int refresh_interval_secs,
4c158400b046fefefce0194603951a6587f51867Timo Sirainen file->refresh_interval_secs = refresh_interval_secs;
4c158400b046fefefce0194603951a6587f51867Timo Sirainen file->rights_pool = pool_alloconly_create("acl global file rights", 1024);
4c158400b046fefefce0194603951a6587f51867Timo Sirainenvoid acl_global_file_deinit(struct acl_global_file **_file)
4c158400b046fefefce0194603951a6587f51867Timo Sirainenstatic int acl_global_parse_rights_cmp(const struct acl_global_parse_rights *r1,
fa96f616b3e940b8835d923a7544acb1e6d7669fTimo Sirainen ARRAY(struct acl_global_parse_rights) parse_rights;
fa96f616b3e940b8835d923a7544acb1e6d7669fTimo Sirainenacl_global_file_parse_line(struct acl_global_file_parse_ctx *ctx,
fa96f616b3e940b8835d923a7544acb1e6d7669fTimo Sirainen if (str_unescape_next(&line, &vpattern) < 0) {
fa96f616b3e940b8835d923a7544acb1e6d7669fTimo Sirainen pright = array_append_space(&ctx->parse_rights);
fa96f616b3e940b8835d923a7544acb1e6d7669fTimo Sirainen pright->vpattern = p_strdup(ctx->file->rights_pool, vpattern);
ad9a6d27cd065a502d165e4929e7227abd19063dTimo Sirainen if (acl_rights_parse_line(line, ctx->file->rights_pool,
4c158400b046fefefce0194603951a6587f51867Timo Sirainenstatic int acl_global_file_read(struct acl_global_file *file)
4c158400b046fefefce0194603951a6587f51867Timo Sirainen input = i_stream_create_file(file->path, (size_t)-1);
4c158400b046fefefce0194603951a6587f51867Timo Sirainen while ((line = i_stream_read_next_line(input)) != NULL) {
fa96f616b3e940b8835d923a7544acb1e6d7669fTimo Sirainen ret = acl_global_file_parse_line(&ctx, line, &error);
4c158400b046fefefce0194603951a6587f51867Timo Sirainen i_error("Couldn't read global ACL file %s: %s",
587cca00ff7ec4980bfa7c069cc65e0e409d2a5fTimo Sirainen i_error("Couldn't stat global ACL file %s: %s",
4c158400b046fefefce0194603951a6587f51867Timo Sirainen /* sort all parsed rights */
fa96f616b3e940b8835d923a7544acb1e6d7669fTimo Sirainen array_sort(&ctx.parse_rights, acl_global_parse_rights_cmp);
4c158400b046fefefce0194603951a6587f51867Timo Sirainen /* combine identical patterns into same structs */
fa96f616b3e940b8835d923a7544acb1e6d7669fTimo Sirainen array_foreach_modifiable(&ctx.parse_rights, pright) {
4c158400b046fefefce0194603951a6587f51867Timo Sirainen strcmp(prev_vpattern, pright->vpattern) != 0) {
4c158400b046fefefce0194603951a6587f51867Timo Sirainen p_array_init(&right->rights, file->rights_pool, 4);
4c158400b046fefefce0194603951a6587f51867Timo Sirainen array_append(&right->rights, &pright->rights, 1);
4c158400b046fefefce0194603951a6587f51867Timo Sirainenint acl_global_file_refresh(struct acl_global_file *file)
4c158400b046fefefce0194603951a6587f51867Timo Sirainen if (file->last_refresh_time + (time_t)file->refresh_interval_secs > ioloop_time)
4c158400b046fefefce0194603951a6587f51867Timo Sirainen /* no change to the file */
af134287071b6d8a9e12c3f11a50fe9ad824d89aTimo Sirainenvoid acl_global_file_last_stat(struct acl_global_file *file, struct stat *st_r)
4c158400b046fefefce0194603951a6587f51867Timo Sirainenvoid acl_global_file_get(struct acl_global_file *file, const char *vname,
4c158400b046fefefce0194603951a6587f51867Timo Sirainen pool_t pool, ARRAY_TYPE(acl_rights) *rights_r)
3b65d5b306f25bb80660bcb4f9eda9e22d38ab52Timo Sirainen array_foreach_modifiable(&file->rights, global_rights) {
3b65d5b306f25bb80660bcb4f9eda9e22d38ab52Timo Sirainen if (!wildcard_match(vname, global_rights->vpattern))
e2e6f40d58b85041ca77338026a17d6708f324efTimo Sirainen i_debug("Mailbox '%s' matches global ACL pattern '%s'",
3b65d5b306f25bb80660bcb4f9eda9e22d38ab52Timo Sirainen array_foreach(&global_rights->rights, rights) {
4c158400b046fefefce0194603951a6587f51867Timo Sirainenbool acl_global_file_have_any(struct acl_global_file *file, const char *vname)