]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Allow auth extra-fields with empty strings, NULL values enforced to empty string ""
authorMarco Bettini <marco.bettini@open-xchange.com>
Fri, 27 Jan 2023 13:37:15 +0000 (13:37 +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

index 2bd63dd9c63c96df3494e371859a1fb5992612b7..da1208c9f138a3411e1cf9d8296254ed6e458cde 100644 (file)
@@ -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";
        }
 }
 
index 100372b6194b4bcc79fc4a4f995b4f49b46506ae..119689b3113342fdd3dbbc13d0a041570052340f 100644 (file)
@@ -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. */