[dovecot-cvs] dovecot/src/auth auth-request.c, 1.57, 1.58 auth.c, 1.30, 1.31 auth.h, 1.21, 1.22

cras at dovecot.org cras at dovecot.org
Wed Apr 12 17:37:04 EEST 2006


Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv6724/src/auth

Modified Files:
	auth-request.c auth.c auth.h 
Log Message:
Added auth_username_format setting.



Index: auth-request.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-request.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- auth-request.c	12 Apr 2006 11:27:17 -0000	1.57
+++ auth-request.c	12 Apr 2006 14:36:58 -0000	1.58
@@ -7,6 +7,7 @@
 #include "str.h"
 #include "safe-memset.h"
 #include "str-sanitize.h"
+#include "strescape.h"
 #include "var-expand.h"
 #include "auth-request.h"
 #include "auth-client-connection.h"
@@ -554,7 +555,29 @@
 			*error_r = "Username contains disallowed characters";
 			return NULL;
 		}
-        }
+	}
+
+	if (request->auth->username_format != NULL) {
+		/* username format given, put it through variable expansion.
+		   we'll have to temporarily replace request->user to get
+		   %u to be the wanted username */
+		const struct var_expand_table *table;
+		char *old_username;
+		string_t *dest;
+
+		old_username = request->user;
+		request->user = user;
+
+		t_push();
+		dest = t_str_new(256);
+		table = auth_request_get_var_expand_table(request, str_escape);
+		var_expand(dest, request->auth->username_format, table);
+		user = p_strdup(request->pool, str_c(dest));
+		t_pop();
+
+		request->user = old_username;
+	}
+
         return user;
 }
 

Index: auth.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- auth.c	7 Apr 2006 07:23:04 -0000	1.30
+++ auth.c	12 Apr 2006 14:36:58 -0000	1.31
@@ -225,9 +225,9 @@
 		env = "";
 	auth->auth_realms = t_strsplit_spaces(env, " ");
 
-	auth->default_realm = getenv("DEFAULT_REALM");
-	if (auth->default_realm != NULL && *auth->default_realm == '\0')
-		auth->default_realm = NULL;
+	env = getenv("DEFAULT_REALM");
+	if (env != NULL && *env != '\0')
+		auth->default_realm = env;
 
 	env = getenv("USERNAME_CHARS");
 	if (env == NULL || *env == '\0') {
@@ -244,6 +244,10 @@
 			auth->username_translation[(int)(uint8_t)*env] = env[1];
 	}
 
+	env = getenv("USERNAME_FORMAT");
+	if (env != NULL && *env != '\0')
+		auth->username_format = env;
+
 	env = getenv("MASTER_USER_SEPARATOR");
 	if (env != NULL)
 		auth->master_user_separator = env[0];

Index: auth.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- auth.h	27 Mar 2006 12:54:24 -0000	1.21
+++ auth.h	12 Apr 2006 14:37:02 -0000	1.22
@@ -43,6 +43,7 @@
 	const char *const *auth_realms;
 	const char *default_realm;
 	const char *anonymous_username;
+	const char *username_format;
 	char username_chars[256];
 	char username_translation[256];
 	char master_user_separator;



More information about the dovecot-cvs mailing list