From d1a27d8dd525c8720f0a30cb49136c4030e435ed Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 5 Jan 2013 00:50:04 +0200 Subject: [PATCH] auth: Fixed handling usernames with the same name as userdb extra fields. This is a bit kludgy fix, but pretty much guaranteed not to break anything. v2.2 has a cleaner fix, but it's a bit more invasive. --- src/auth/auth-request.c | 4 ++-- src/auth/auth-stream.c | 22 +++++++++++++++++++--- src/auth/auth-stream.h | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/auth/auth-request.c b/src/auth/auth-request.c index 4181f2ef82..5799aa5d50 100644 --- a/src/auth/auth-request.c +++ b/src/auth/auth-request.c @@ -863,7 +863,7 @@ static bool auth_request_lookup_user_cache(struct auth_request *request, } *result_r = USERDB_RESULT_OK; - *reply_r = auth_stream_reply_init(request->pool); + *reply_r = auth_stream_reply_init_userdb(request->pool); auth_stream_reply_import(*reply_r, value); return TRUE; } @@ -1342,7 +1342,7 @@ void auth_request_init_userdb_reply(struct auth_request *request) { struct userdb_module *module = request->userdb->userdb; - request->userdb_reply = auth_stream_reply_init(request->pool); + request->userdb_reply = auth_stream_reply_init_userdb(request->pool); auth_stream_reply_add(request->userdb_reply, NULL, request->user); userdb_template_export(module->default_fields_tmpl, request); diff --git a/src/auth/auth-stream.c b/src/auth/auth-stream.c index c02e04fb47..72933c0826 100644 --- a/src/auth/auth-stream.c +++ b/src/auth/auth-stream.c @@ -9,6 +9,7 @@ struct auth_stream_reply { string_t *str; + bool userdb; }; struct auth_stream_reply *auth_stream_reply_init(pool_t pool) @@ -20,6 +21,15 @@ struct auth_stream_reply *auth_stream_reply_init(pool_t pool) return reply; } +struct auth_stream_reply *auth_stream_reply_init_userdb(pool_t pool) +{ + struct auth_stream_reply *reply; + + reply = auth_stream_reply_init(pool); + reply->userdb = TRUE; + return reply; +} + void auth_stream_reply_add(struct auth_stream_reply *reply, const char *key, const char *value) { @@ -44,10 +54,16 @@ static bool auth_stream_reply_find_area(struct auth_stream_reply *reply, const char *key, unsigned int *idx_r, unsigned int *len_r) { - const char *str = str_c(reply->str); - unsigned int i, start, key_len = strlen(key); + const char *p, *str = str_c(reply->str); + unsigned int i = 0, start, key_len = strlen(key); + + if (reply->userdb) { + p = strchr(str, '\t'); + if (p == NULL) + return FALSE; + i = p-str+1; + } - i = 0; while (str[i] != '\0') { start = i; for (; str[i] != '\0'; i++) { diff --git a/src/auth/auth-stream.h b/src/auth/auth-stream.h index 57e0da2812..7d73c91c1d 100644 --- a/src/auth/auth-stream.h +++ b/src/auth/auth-stream.h @@ -4,6 +4,7 @@ struct auth_request; struct auth_stream_reply *auth_stream_reply_init(pool_t pool); +struct auth_stream_reply *auth_stream_reply_init_userdb(pool_t pool); void auth_stream_reply_add(struct auth_stream_reply *reply, const char *key, const char *value); void auth_stream_reply_reset(struct auth_stream_reply *reply); -- 2.47.3