From: Marco Bettini Date: Thu, 2 Feb 2023 09:26:12 +0000 (+0000) Subject: auth: Remove extra tabs inserted using auth_fields_append() X-Git-Tag: 2.4.0~3002 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=812baec1b2dce7f3ab987cf8f1b4f57c0e5cae91;p=thirdparty%2Fdovecot%2Fcore.git auth: Remove extra tabs inserted using auth_fields_append() --- diff --git a/src/auth/auth-fields.c b/src/auth/auth-fields.c index 49193ae8b2..8b92836588 100644 --- a/src/auth/auth-fields.c +++ b/src/auth/auth-fields.c @@ -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); diff --git a/src/auth/auth-fields.h b/src/auth/auth-fields.h index adf50c5be2..855f0ac475 100644 --- a/src/auth/auth-fields.h +++ b/src/auth/auth-fields.h @@ -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. */ diff --git a/src/auth/auth-master-connection.c b/src/auth/auth-master-connection.c index ea54d0a793..476515449e 100644 --- a/src/auth/auth-master-connection.c +++ b/src/auth/auth-master-connection.c @@ -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: diff --git a/src/auth/auth-request-handler.c b/src/auth/auth-request-handler.c index eeeda06af5..1001d34856 100644 --- a/src/auth/auth-request-handler.c +++ b/src/auth/auth-request-handler.c @@ -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")) { diff --git a/src/auth/auth-request.c b/src/auth/auth-request.c index 86963bde12..6d732656cb 100644 --- a/src/auth/auth-request.c +++ b/src/auth/auth-request.c @@ -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) diff --git a/src/auth/auth-worker-server.c b/src/auth/auth-worker-server.c index 15b8202298..d0c154345f 100644 --- a/src/auth/auth-worker-server.c +++ b/src/auth/auth-worker-server.c @@ -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;