From: Marco Bettini Date: Fri, 27 Jan 2023 13:37:15 +0000 (+0000) Subject: auth: Allow auth extra-fields with empty strings, NULL values enforced to empty string "" X-Git-Tag: 2.4.0~3004 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da23cc9ed698d387dc9a95844068c7f9c67eaa18;p=thirdparty%2Fdovecot%2Fcore.git auth: Allow auth extra-fields with empty strings, NULL values enforced to empty string "" --- diff --git a/src/auth/auth-fields.c b/src/auth/auth-fields.c index 2bd63dd9c6..da1208c9f1 100644 --- a/src/auth/auth-fields.c +++ b/src/auth/auth-fields.c @@ -75,7 +75,7 @@ void auth_fields_add(struct auth_fields *fields, auth_fields_snapshot_preserve(fields); field = array_idx_modifiable(&fields->fields, idx); } - field->value = p_strdup_empty(fields->pool, value); + field->value = value == NULL ? "yes" : p_strdup(fields->pool, value); field->flags = flags | AUTH_FIELD_FLAG_CHANGED; } @@ -98,7 +98,8 @@ const char *auth_fields_find(struct auth_fields *fields, const char *key) return NULL; field = array_idx(&fields->fields, idx); - return field->value == NULL ? "" : field->value; + i_assert(field->value != NULL); + return field->value; } bool auth_fields_exists(struct auth_fields *fields, const char *key) @@ -180,10 +181,8 @@ void auth_fields_append(struct auth_fields *fields, string_t *dest, else str_append_c(dest, '\t'); str_append(dest, f[i].key); - if (f[i].value != NULL) { - str_append_c(dest, '='); - str_append_tabescaped(dest, f[i].value); - } + str_append_c(dest, '='); + str_append_tabescaped(dest, f[i].value); } } @@ -200,7 +199,7 @@ void auth_fields_booleanize(struct auth_fields *fields, const char *key) if (auth_fields_find_idx(fields, key, &idx)) { field = array_idx_modifiable(&fields->fields, idx); - field->value = NULL; + field->value = "yes"; } } diff --git a/src/auth/auth-fields.h b/src/auth/auth-fields.h index 100372b619..119689b311 100644 --- a/src/auth/auth-fields.h +++ b/src/auth/auth-fields.h @@ -37,8 +37,8 @@ void auth_fields_append(struct auth_fields *fields, string_t *dest, enum auth_field_flags flags_mask, enum auth_field_flags flags_result); bool auth_fields_is_empty(struct auth_fields *fields); -/* If the field exists, clear its value (so the exported string will be "key" - instead of e.g. "key=y"). */ +/* If the field exists, set its value to "yes", + so the exported string will be "key=yes" */ void auth_fields_booleanize(struct auth_fields *fields, const char *key); /* Remember the current fields. */