]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
acl: More code cleanups.
authorTimo Sirainen <tss@iki.fi>
Fri, 17 Jan 2014 21:23:49 +0000 (16:23 -0500)
committerTimo Sirainen <tss@iki.fi>
Fri, 17 Jan 2014 21:23:49 +0000 (16:23 -0500)
src/plugins/acl/acl-api-private.h
src/plugins/acl/acl-api.c
src/plugins/acl/acl-backend-vfile-update.c
src/plugins/acl/acl-backend-vfile.c

index 45d39499e3a883aaa4614f1e34bd6ebdcbc65045..3e84141302d85171068ef1c861356cded49e34a0 100644 (file)
@@ -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 *
index 78f1ba5c875d06f7cd2e4a8af4977d4b41a06df6..c3c5229213e2685f95491ba6738ee2bdaa92d8aa 100644 (file)
@@ -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;
+
+       /* <id> [<imap acls>] [:<named acls>] */
+       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;
index 306a7bf5ee44c535551b62bde78a1bc8cc8ac3fa..9be468d10f3bb9f4cab8ab1e44c039d2ff466fd1 100644 (file)
@@ -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 <utime.h>
+#include <sys/stat.h>
 
 static struct dotlock_settings dotlock_set = {
        .timeout = 30,
index cc1512823518e02a0bc6a6d2e4ac8bb8160a0769..2396a2e524c134c4896c639d749fbb0034596376 100644 (file)
@@ -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 <stdlib.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/stat.h>
@@ -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;
-
-       /* <id> [<imap acls>] [:<named acls>] */
-       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) {