]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Remove extra tabs inserted using auth_fields_append()
authorMarco Bettini <marco.bettini@open-xchange.com>
Thu, 2 Feb 2023 09:26:12 +0000 (09:26 +0000)
committerMarco Bettini <marco.bettini@open-xchange.com>
Thu, 2 Feb 2023 14:13:03 +0000 (14:13 +0000)
src/auth/auth-fields.c
src/auth/auth-fields.h
src/auth/auth-master-connection.c
src/auth/auth-request-handler.c
src/auth/auth-request.c
src/auth/auth-worker-server.c

index 49193ae8b295f681be56b093241f036f501e07f8..8b92836588302717d5d25a9b1bc50b113d4526ce 100644 (file)
@@ -162,11 +162,11 @@ const ARRAY_TYPE(auth_field) *auth_fields_export(struct auth_fields *fields)
 
 void auth_fields_append(struct auth_fields *fields, string_t *dest,
                        enum auth_field_flags flags_mask,
-                       enum auth_field_flags flags_result)
+                       enum auth_field_flags flags_result,
+                       bool prefix_with_tab)
 {
        const struct auth_field *f;
        unsigned int i, count;
-       bool first = TRUE;
 
        if (!array_is_created(&fields->fields))
                return;
@@ -176,10 +176,10 @@ void auth_fields_append(struct auth_fields *fields, string_t *dest,
                if ((f[i].flags & flags_mask) != flags_result)
                        continue;
 
-               if (first)
-                       first = FALSE;
-               else
+               if (prefix_with_tab)
                        str_append_c(dest, '\t');
+               else
+                       prefix_with_tab = TRUE;
                str_append(dest, f[i].key);
                str_append_c(dest, '=');
                str_append_tabescaped(dest, f[i].value);
index adf50c5be2d2e1fabb93ee565210667d5f5776b1..855f0ac47589240ba0f9ceadf6bb606dedb25e69 100644 (file)
@@ -35,7 +35,8 @@ const ARRAY_TYPE(auth_field) *auth_fields_export(struct auth_fields *fields);
 /* Append fields where (flag & flags_mask) == flags_result. */
 void auth_fields_append(struct auth_fields *fields, string_t *dest,
                        enum auth_field_flags flags_mask,
-                       enum auth_field_flags flags_result);
+                       enum auth_field_flags flags_result,
+                       bool prefix_with_tab);
 bool auth_fields_is_empty(struct auth_fields *fields);
 
 /* Remember the current fields. */
index ea54d0a793881cbfe1bfc27cd312665a9f82982d..476515449e89447d20801e6eb658a7d4b549b574 100644 (file)
@@ -297,9 +297,8 @@ user_callback(enum userdb_result result,
        case USERDB_RESULT_OK:
                str_printfa(str, "USER\t%u\t", auth_request->id);
                str_append_tabescaped(str, auth_request->fields.user);
-               str_append_c(str, '\t');
                auth_fields_append(auth_request->fields.userdb_reply, str,
-                                  AUTH_FIELD_FLAG_HIDDEN, 0);
+                                  AUTH_FIELD_FLAG_HIDDEN, 0, TRUE);
                break;
        }
 
@@ -349,11 +348,8 @@ static void pass_callback_finish(struct auth_request *auth_request,
                }
                str_printfa(str, "PASS\t%u\tuser=", auth_request->id);
                str_append_tabescaped(str, auth_request->fields.user);
-               if (!auth_fields_is_empty(auth_request->fields.extra_fields)) {
-                       str_append_c(str, '\t');
-                       auth_fields_append(auth_request->fields.extra_fields,
-                                          str, AUTH_FIELD_FLAG_HIDDEN, 0);
-               }
+               auth_fields_append(auth_request->fields.extra_fields, str,
+                                  AUTH_FIELD_FLAG_HIDDEN, 0, TRUE);
                break;
        case PASSDB_RESULT_USER_UNKNOWN:
        case PASSDB_RESULT_USER_DISABLED:
index eeeda06af56f8f993251d550e6b681309829ed70..1001d348564277abed26a722764b2759fdf8ddac 100644 (file)
@@ -171,11 +171,8 @@ auth_str_append_extra_fields(struct auth_request *request, string_t *dest)
 {
        const struct auth_request_fields *fields = &request->fields;
 
-       if (!auth_fields_is_empty(fields->extra_fields)) {
-               str_append_c(dest, '\t');
-               auth_fields_append(fields->extra_fields, dest,
-                                  AUTH_FIELD_FLAG_HIDDEN, 0);
-       }
+       auth_fields_append(fields->extra_fields, dest,
+                          AUTH_FIELD_FLAG_HIDDEN, 0, TRUE);
 
        if (fields->original_username != NULL &&
            null_strcmp(fields->original_username, fields->user) != 0 &&
@@ -732,9 +729,8 @@ bool auth_request_handler_auth_continue(struct auth_request_handler *handler,
 static void auth_str_append_userdb_extra_fields(struct auth_request *request,
                                                string_t *dest)
 {
-       str_append_c(dest, '\t');
        auth_fields_append(request->fields.userdb_reply, dest,
-                          AUTH_FIELD_FLAG_HIDDEN, 0);
+                          AUTH_FIELD_FLAG_HIDDEN, 0, TRUE);
 
        if (request->fields.master_user != NULL &&
            !auth_fields_exists(request->fields.userdb_reply, "master_user")) {
index 86963bde12ebf91f8734a190543876cfc2a3a37d..6d732656cbbe99211904919b37dbdc5d210358e6 100644 (file)
@@ -471,16 +471,12 @@ static void auth_request_save_cache(struct auth_request *request,
                str_append_tabescaped(str, request->passdb_password);
        }
 
-       if (!auth_fields_is_empty(request->fields.extra_fields)) {
-               str_append_c(str, '\t');
-               /* add only those extra fields to cache that were set by this
-                  passdb lookup. the CHANGED flag does this, because we
-                  snapshotted the extra_fields before the current passdb
-                  lookup. */
-               auth_fields_append(request->fields.extra_fields, str,
-                                  AUTH_FIELD_FLAG_CHANGED,
-                                  AUTH_FIELD_FLAG_CHANGED);
-       }
+       /* add only those extra fields to cache that were set by this passdb
+          lookup. the CHANGED flag does this, because we snapshotted the
+          extra_fields before the current passdb lookup. */
+       auth_fields_append(request->fields.extra_fields, str,
+                          AUTH_FIELD_FLAG_CHANGED, AUTH_FIELD_FLAG_CHANGED,
+                          TRUE);
        auth_cache_insert(passdb_cache, request, passdb->cache_key, str_c(str),
                          result == PASSDB_RESULT_OK);
 }
@@ -1332,8 +1328,8 @@ static void auth_request_userdb_save_cache(struct auth_request *request,
        else {
                str = t_str_new(128);
                auth_fields_append(request->fields.userdb_reply, str,
-                                  AUTH_FIELD_FLAG_CHANGED,
-                                  AUTH_FIELD_FLAG_CHANGED);
+                                  AUTH_FIELD_FLAG_CHANGED, AUTH_FIELD_FLAG_CHANGED,
+                                  FALSE);
                if (request->user_changed_by_lookup) {
                        /* username was changed by passdb or userdb */
                        if (str_len(str) > 0)
index 15b8202298243915350f34048d98b175130b81a6..d0c154345f9b64315a78086e572ee46482f10ac5 100644 (file)
@@ -192,15 +192,11 @@ static void auth_worker_send_reply(struct auth_worker_server *server,
 static void
 reply_append_extra_fields(string_t *str, struct auth_request *request)
 {
-       if (!auth_fields_is_empty(request->fields.extra_fields)) {
-               str_append_c(str, '\t');
-               /* export only the fields changed by this lookup, so the
-                  changed-flag gets preserved correctly on the master side as
-                  well. */
-               auth_fields_append(request->fields.extra_fields, str,
-                                  AUTH_FIELD_FLAG_CHANGED,
-                                  AUTH_FIELD_FLAG_CHANGED);
-       }
+       /* export only the fields changed by this lookup, so the changed-flag
+          gets preserved correctly on the master side as well. */
+       auth_fields_append(request->fields.extra_fields, str,
+                          AUTH_FIELD_FLAG_CHANGED, AUTH_FIELD_FLAG_CHANGED,
+                          TRUE);
        if (request->fields.userdb_reply != NULL &&
            auth_fields_is_empty(request->fields.userdb_reply)) {
                /* all userdb_* fields had NULL values. we'll still
@@ -513,11 +509,10 @@ lookup_user_callback(enum userdb_result result,
                str_append(str, "OK\t");
                if (auth_request->user_changed_by_lookup)
                        str_append_tabescaped(str, auth_request->fields.user);
-               str_append_c(str, '\t');
                /* export only the fields changed by this lookup */
                auth_fields_append(auth_request->fields.userdb_reply, str,
-                                  AUTH_FIELD_FLAG_CHANGED,
-                                  AUTH_FIELD_FLAG_CHANGED);
+                                  AUTH_FIELD_FLAG_CHANGED, AUTH_FIELD_FLAG_CHANGED,
+                                  TRUE);
                if (auth_request->userdb_lookup_tempfailed)
                        str_append(str, "\ttempfail");
                break;