On Mon, 2012-05-14 at 11:48 +0200, Alexander 'Leo' Bergolth wrote:
> > Any hints on how to change the order of userdb settings?
> 
> OK, got it.
> 
> userdb settings are parsed in the same order as set in USERDB_KEYS.
> The key NAMESPACES has to be defined before the namespace-specific keys.
> 
> My post-login script was setting this variable dynamically from a hash
> so the order was undefined. That's why it did actually work sometimes... :-)

Could you try if the attached patch also fixes the ordering? If yes, I
could add it to v2.2.

diff -r fac49069993a src/lib-storage/mail-storage-service.c
--- a/src/lib-storage/mail-storage-service.c	Mon May 14 18:09:10 2012 +0300
+++ b/src/lib-storage/mail-storage-service.c	Mon May 14 18:28:56 2012 +0300
@@ -909,6 +909,21 @@
 					user_set->mail_plugins, &mod_set);
 }
 
+static int extra_field_key_cmp_p(const char *const *s1, const char *const *s2)
+{
+	const char *p1 = *s1, *p2 = *s2;
+
+	for (; *p1 == *p2; p1++, p2++) {
+		if (*p1 == '\0')
+			return 0;
+	}
+	if (*p1 == '=')
+		return -1;
+	if (*p2 == '=')
+		return 1;
+	return *p1 - *p2;
+}
+
 int mail_storage_service_lookup(struct mail_storage_service_ctx *ctx,
 				const struct mail_storage_service_input *input,
 				struct mail_storage_service_user **user_r,
@@ -994,6 +1009,7 @@
 
 	if (userdb_fields != NULL) {
 		auth_user_fields_parse(userdb_fields, temp_pool, &reply);
+		array_sort(&reply.extra_fields, extra_field_key_cmp_p);
 		if (user_reply_handle(ctx, user, &reply, &error) < 0) {
 			i_error("user %s: Invalid settings in userdb: %s",
 				username, error);

Reply via email to