]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Fixed handling usernames with the same name as userdb extra fields.
authorTimo Sirainen <tss@iki.fi>
Fri, 4 Jan 2013 22:50:04 +0000 (00:50 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 4 Jan 2013 22:50:04 +0000 (00:50 +0200)
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
src/auth/auth-stream.c
src/auth/auth-stream.h

index 4181f2ef820039a0b065ce8489538889e498f387..5799aa5d508ec3d69c371519f34cbd1919b7d7e7 100644 (file)
@@ -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);
index c02e04fb47ae12c079e3cfa06342e932322c4a9b..72933c082637cb0fa427ebd9777927c22327f2ff 100644 (file)
@@ -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++) {
index 57e0da28128bfcf190444d83ae73fd7f7b82a3b4..7d73c91c1d75814bc23c81924449287cedca59e1 100644 (file)
@@ -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);