dovecot-2.2: acl: More code cleanups.
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jan 17 23:24:03 EET 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/498fcb82fcb6
changeset: 17114:498fcb82fcb6
user: Timo Sirainen <tss at iki.fi>
date: Fri Jan 17 16:23:49 2014 -0500
description:
acl: More code cleanups.
diffstat:
src/plugins/acl/acl-api-private.h | 2 +
src/plugins/acl/acl-api.c | 50 +++++++++++++++++++
src/plugins/acl/acl-backend-vfile-update.c | 4 +-
src/plugins/acl/acl-backend-vfile.c | 77 ++++-------------------------
4 files changed, 66 insertions(+), 67 deletions(-)
diffs (214 lines):
diff -r a217a938f9ae -r 498fcb82fcb6 src/plugins/acl/acl-api-private.h
--- a/src/plugins/acl/acl-api-private.h Fri Jan 17 16:10:56 2014 -0500
+++ b/src/plugins/acl/acl-api-private.h Fri Jan 17 16:23:49 2014 -0500
@@ -92,6 +92,8 @@
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 -r a217a938f9ae -r 498fcb82fcb6 src/plugins/acl/acl-api.c
--- a/src/plugins/acl/acl-api.c Fri Jan 17 16:10:56 2014 -0500
+++ b/src/plugins/acl/acl-api.c Fri Jan 17 16:23:49 2014 -0500
@@ -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 @@
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;
diff -r a217a938f9ae -r 498fcb82fcb6 src/plugins/acl/acl-backend-vfile-update.c
--- a/src/plugins/acl/acl-backend-vfile-update.c Fri Jan 17 16:10:56 2014 -0500
+++ b/src/plugins/acl/acl-backend-vfile-update.c Fri Jan 17 16:23:49 2014 -0500
@@ -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,
diff -r a217a938f9ae -r 498fcb82fcb6 src/plugins/acl/acl-backend-vfile.c
--- a/src/plugins/acl/acl-backend-vfile.c Fri Jan 17 16:10:56 2014 -0500
+++ b/src/plugins/acl/acl-backend-vfile.c Fri Jan 17 16:23:49 2014 -0500
@@ -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 @@
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 @@
{
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 @@
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) {
More information about the dovecot-cvs
mailing list