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;
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);
/* 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. */
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;
}
}
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:
{
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 &&
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")) {
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);
}
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)
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
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;