From: Timo Sirainen Date: Fri, 17 Jan 2014 21:23:49 +0000 (-0500) Subject: acl: More code cleanups. X-Git-Tag: 2.2.11~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15f43b172d2c626aa03c921979c49821a55c7e5e;p=thirdparty%2Fdovecot%2Fcore.git acl: More code cleanups. --- diff --git a/src/plugins/acl/acl-api-private.h b/src/plugins/acl/acl-api-private.h index 45d39499e3..3e84141302 100644 --- a/src/plugins/acl/acl-api-private.h +++ b/src/plugins/acl/acl-api-private.h @@ -92,6 +92,8 @@ int acl_rights_update_import(struct acl_rights_update *update, const char *id, const char *const *rights, const char **error_r); const char *acl_rights_export(const struct acl_rights *rights); +int acl_rights_parse_line(const char *line, pool_t pool, + struct acl_rights *rights_r, const char **error_r); int acl_rights_cmp(const struct acl_rights *r1, const struct acl_rights *r2); const char *const * diff --git a/src/plugins/acl/acl-api.c b/src/plugins/acl/acl-api.c index 78f1ba5c87..c3c5229213 100644 --- a/src/plugins/acl/acl-api.c +++ b/src/plugins/acl/acl-api.c @@ -3,6 +3,7 @@ #include "lib.h" #include "array.h" #include "str.h" +#include "strescape.h" #include "hash.h" #include "mail-user.h" #include "mailbox-list.h" @@ -333,6 +334,55 @@ const char *acl_rights_export(const struct acl_rights *rights) return str_c(str); } +int acl_rights_parse_line(const char *line, pool_t pool, + struct acl_rights *rights_r, const char **error_r) +{ + const char *id_str, *const *right_names, *error = NULL; + + if (*line == '\0' || *line == '#') + return 0; + + /* [] [:] */ + if (*line == '"') { + line++; + if (str_unescape_next(&line, &id_str) < 0 || + (line[0] != ' ' && line[0] != '\0')) { + *error_r = "Invalid quoted ID"; + return -1; + } + if (line[0] == ' ') + line++; + } else { + id_str = line; + line = strchr(id_str, ' '); + if (line == NULL) + line = ""; + else + id_str = t_strdup_until(id_str, line++); + } + + memset(rights_r, 0, sizeof(*rights_r)); + + right_names = acl_right_names_parse(pool, line, &error); + if (*id_str != '-') + rights_r->rights = right_names; + else { + id_str++; + rights_r->neg_rights = right_names; + } + + if (acl_identifier_parse(id_str, rights_r) < 0) + error = t_strdup_printf("Unknown ID '%s'", id_str); + + if (error != NULL) { + *error_r = error; + return -1; + } + + rights_r->identifier = p_strdup(pool, rights_r->identifier); + return 0; +} + int acl_rights_cmp(const struct acl_rights *r1, const struct acl_rights *r2) { int ret; diff --git a/src/plugins/acl/acl-backend-vfile-update.c b/src/plugins/acl/acl-backend-vfile-update.c index 306a7bf5ee..9be468d10f 100644 --- a/src/plugins/acl/acl-backend-vfile-update.c +++ b/src/plugins/acl/acl-backend-vfile-update.c @@ -8,12 +8,12 @@ #include "strescape.h" #include "file-dotlock.h" #include "ostream.h" -#include "mailbox-list.h" -#include "mail-storage-private.h" +#include "mail-storage.h" #include "acl-cache.h" #include "acl-backend-vfile.h" #include +#include static struct dotlock_settings dotlock_set = { .timeout = 30, diff --git a/src/plugins/acl/acl-backend-vfile.c b/src/plugins/acl/acl-backend-vfile.c index cc15128235..2396a2e524 100644 --- a/src/plugins/acl/acl-backend-vfile.c +++ b/src/plugins/acl/acl-backend-vfile.c @@ -3,18 +3,12 @@ #include "lib.h" #include "ioloop.h" #include "array.h" -#include "str.h" -#include "strescape.h" #include "istream.h" -#include "ostream.h" #include "nfs-workarounds.h" #include "mail-storage-private.h" -#include "mailbox-list-private.h" -#include "mail-namespace.h" #include "acl-cache.h" #include "acl-backend-vfile.h" -#include #include #include #include @@ -270,61 +264,6 @@ static void acl_backend_vfile_object_deinit(struct acl_object *_aclobj) i_free(aclobj); } -static int -acl_object_vfile_parse_line(struct acl_object_vfile *aclobj, bool global, - const char *path, const char *line, - unsigned int linenum) -{ - struct acl_rights rights; - const char *id_str, *const *right_names, *error = NULL; - - if (*line == '\0' || *line == '#') - return 0; - - /* [] [:] */ - if (*line == '"') { - line++; - if (str_unescape_next(&line, &id_str) < 0 || - (line[0] != ' ' && line[0] != '\0')) { - i_error("ACL file %s line %u: Invalid quoted ID", - path, linenum); - return -1; - } - if (line[0] == ' ') - line++; - } else { - id_str = line; - line = strchr(id_str, ' '); - if (line == NULL) - line = ""; - else - id_str = t_strdup_until(id_str, line++); - } - - memset(&rights, 0, sizeof(rights)); - rights.global = global; - - right_names = acl_right_names_parse(aclobj->rights_pool, line, &error); - if (*id_str != '-') - rights.rights = right_names; - else { - id_str++; - rights.neg_rights = right_names; - } - - if (acl_identifier_parse(id_str, &rights) < 0) - error = t_strdup_printf("Unknown ID '%s'", id_str); - - if (error != NULL) { - i_error("ACL file %s line %u: %s", path, linenum, error); - return -1; - } - - rights.identifier = p_strdup(aclobj->rights_pool, rights.identifier); - array_append(&aclobj->rights, &rights, 1); - return 0; -} - static void acl_backend_remove_all_access(struct acl_object_vfile *aclobj) { static const char *null = NULL; @@ -348,7 +287,8 @@ acl_backend_vfile_read(struct acl_object_vfile *aclobj, { struct istream *input; struct stat st; - const char *line; + struct acl_rights rights; + const char *line, *error; unsigned int linenum; int fd, ret = 0; @@ -402,12 +342,19 @@ acl_backend_vfile_read(struct acl_object_vfile *aclobj, linenum = 1; while ((line = i_stream_read_next_line(input)) != NULL) { T_BEGIN { - ret = acl_object_vfile_parse_line(aclobj, global, - path, line, - linenum++); + ret = acl_rights_parse_line(line, aclobj->rights_pool, + &rights, &error); + rights.global = global; + if (ret < 0) { + i_error("ACL file %s line %u: %s", + path, linenum, error); + } else { + array_append(&aclobj->rights, &rights, 1); + } } T_END; if (ret < 0) break; + linenum++; } if (ret < 0) {