]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Use t_split_key_value_eq()
authorMarco Bettini <marco.bettini@open-xchange.com>
Fri, 27 Jan 2023 13:43:34 +0000 (13:43 +0000)
committerMarco Bettini <marco.bettini@open-xchange.com>
Thu, 2 Feb 2023 14:13:03 +0000 (14:13 +0000)
src/lib-storage/mail-storage-service.c
src/lib-storage/mail-user.c

index 5e831ad6484117a16baff22f7cd34e541884c029..cccb420f54297126a0f99206dc352e6149b95d7e 100644 (file)
@@ -225,7 +225,7 @@ user_reply_handle(struct mail_storage_service_ctx *ctx,
 {
        const char *home = reply->home;
        const char *chroot = reply->chroot;
-       const char *const *str, *line, *p, *value;
+       const char *const *str, *p;
        unsigned int i, count;
        int ret = 0;
 
@@ -270,13 +270,14 @@ user_reply_handle(struct mail_storage_service_ctx *ctx,
 
        str = array_get(&reply->extra_fields, &count);
        for (i = 0; i < count; i++) {
-               line = str[i];
-               if (str_begins(line, "system_groups_user=", &value)) {
-                       user->system_groups_user =
-                               p_strdup(user->pool, value);
-               } else if (str_begins(line, "chdir=", &value)) {
+               const char *key, *value, *line = str[i];
+               t_split_key_value_eq(line, &key, &value);
+
+               if (strcmp(key, "system_groups_user") == 0) {
+                       user->system_groups_user = p_strdup(user->pool, value);
+               } else if (strcmp(key, "chdir") == 0) {
                        user->chdir_path = p_strdup(user->pool, value);
-               } else if (str_begins(line, "nice=", &value)) {
+               } else if (strcmp(key, "nice") == 0) {
 #ifdef HAVE_SETPRIORITY
                        int n;
                        if (str_to_int(value, &n) < 0) {
@@ -289,15 +290,14 @@ user_reply_handle(struct mail_storage_service_ctx *ctx,
                                                "setpriority(%d) failed: %m", n);
                        }
 #endif
-               } else if (str_begins(line, "auth_mech=", &value)) {
+               } else if (strcmp(key, "auth_mech") == 0) {
                        user->auth_mech = p_strdup(user->pool, value);
-               } else if (str_begins(line, "auth_token=", &value)) {
+               } else if (strcmp(key, "auth_token") == 0) {
                        user->auth_token = p_strdup(user->pool, value);
-               } else if (str_begins(line, "auth_user=", &value)) {
+               } else if (strcmp(key, "auth_user") == 0) {
                        user->auth_user = p_strdup(user->pool, value);
-               } else if (str_begins(line, "admin=", &value)) {
-                       user->admin = value[0] == 'y' || value[0] == 'Y' ||
-                               value[0] == '1';
+               } else if (strcmp(key, "admin") == 0) {
+                       user->admin = strchr("1Yy", value[0]) != NULL;
                } else T_BEGIN {
                        ret = set_line(ctx, user, line);
                } T_END;
index 505d4130d03308fe87823c4484fbe370d07895af..06944a2156d75856eaa0d6e6423d04c92b807bf3 100644 (file)
@@ -691,14 +691,9 @@ const char *const *mail_user_get_alt_usernames(struct mail_user *user)
        ARRAY_TYPE(const_string) alt_usernames;
        t_array_init(&alt_usernames, 4);
        for (unsigned int i = 0; user->userdb_fields[i] != NULL; i++) {
-               const char *field = user->userdb_fields[i];
-               if (strncmp(field, "user_", 5) != 0)
-                       continue;
-
-               const char *value = strchr(field, '=');
-               if (value != NULL) {
-                       const char *key =
-                               p_strdup_until(user->pool, field, value++);
+               const char *key, *value;
+               if (t_split_key_value_eq(user->userdb_fields[i], &key, &value) &&
+                   str_begins_with(key, "user_")) {
                        array_append(&alt_usernames, &key, 1);
                        array_append(&alt_usernames, &value, 1);
                }