[dovecot-cvs] dovecot/src/auth mech-apop.c, 1.2, 1.3 mech-cram-md5.c, 1.8, 1.9 mech-digest-md5.c, 1.22, 1.23 mech-login.c, 1.1, 1.2 mech-ntlm.c, 1.2, 1.3 mech-plain.c, 1.19, 1.20 mech-rpa.c, 1.1, 1.2 mech.c, 1.31, 1.32 mech.h, 1.19, 1.20

cras at dovecot.org cras at dovecot.org
Sat Aug 28 16:25:45 EEST 2004


Update of /home/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv24992/src/auth

Modified Files:
	mech-apop.c mech-cram-md5.c mech-digest-md5.c mech-login.c 
	mech-ntlm.c mech-plain.c mech-rpa.c mech.c mech.h 
Log Message:
Added auth_username_translation setting.



Index: mech-apop.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/mech-apop.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mech-apop.c	6 Jul 2004 06:35:30 -0000	1.2
+++ mech-apop.c	28 Aug 2004 13:25:42 -0000	1.3
@@ -115,7 +115,7 @@
 	tmp++;
 
 	auth_request->user = p_strdup(auth->pool, username);
-	if (!mech_is_valid_username(auth_request->user)) {
+	if (!mech_fix_username(auth_request->user)) {
 		if (verbose) {
 			i_info("apop(%s): invalid username",
 			       get_log_prefix(auth_request));

Index: mech-cram-md5.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/mech-cram-md5.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mech-cram-md5.c	30 Jul 2004 07:53:26 -0000	1.8
+++ mech-cram-md5.c	28 Aug 2004 13:25:42 -0000	1.9
@@ -138,7 +138,7 @@
 		auth_request->user =
 			p_strdup(auth_request->pool, auth->username);
 
-		if (mech_is_valid_username(auth_request->user)) {
+		if (mech_fix_username(auth_request->user)) {
 			passdb->lookup_credentials(&auth->auth_request,
 						   PASSDB_CREDENTIALS_CRAM_MD5,
 						   credentials_callback);

Index: mech-digest-md5.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/mech-digest-md5.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- mech-digest-md5.c	31 May 2004 20:10:02 -0000	1.22
+++ mech-digest-md5.c	28 Aug 2004 13:25:42 -0000	1.23
@@ -559,7 +559,7 @@
 							 realm, NULL);
 		}
 
-		if (mech_is_valid_username(auth_request->user)) {
+		if (mech_fix_username(auth_request->user)) {
 			passdb->lookup_credentials(&auth->auth_request,
 						PASSDB_CREDENTIALS_DIGEST_MD5,
 						credentials_callback);

Index: mech-login.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/mech-login.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mech-login.c	22 Jul 2004 13:42:02 -0000	1.1
+++ mech-login.c	28 Aug 2004 13:25:42 -0000	1.2
@@ -34,7 +34,7 @@
 		auth_request->user =
 			p_strndup(auth_request->pool, data, data_size);
 
-		if (!mech_is_valid_username(auth_request->user)) {
+		if (!mech_fix_username(auth_request->user)) {
 			if (verbose) {
 				i_info("login(%s): invalid username",
 				       get_log_prefix(auth_request));

Index: mech-ntlm.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/mech-ntlm.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mech-ntlm.c	30 Jul 2004 01:43:21 -0000	1.2
+++ mech-ntlm.c	28 Aug 2004 13:25:42 -0000	1.3
@@ -175,7 +175,7 @@
 		username = p_strdup(auth_request->pool,
 				    ntlmssp_t_str(auth->response, user));
 
-		if (!mech_is_valid_username(username)) {
+		if (!mech_fix_username(username)) {
 			if (verbose) {
 				i_info("ntlm(%s): invalid username",
 				       get_log_prefix(auth_request));

Index: mech-plain.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/mech-plain.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- mech-plain.c	9 Jul 2004 10:57:32 -0000	1.19
+++ mech-plain.c	28 Aug 2004 13:25:42 -0000	1.20
@@ -60,7 +60,7 @@
 						      authenid);
 		}
 
-		if (!mech_is_valid_username(auth_request->user)) {
+		if (!mech_fix_username(auth_request->user)) {
 			/* invalid username */
 			if (verbose) {
 				i_info("plain(%s): invalid username",

Index: mech-rpa.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/mech-rpa.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mech-rpa.c	19 Aug 2004 03:56:02 -0000	1.1
+++ mech-rpa.c	28 Aug 2004 13:25:42 -0000	1.2
@@ -483,7 +483,7 @@
 		return TRUE;
 	}
 
-	if (!mech_is_valid_username(auth_request->user)) {
+	if (!mech_fix_username(auth_request->user)) {
 		if (verbose) {
 			i_info("rpa(%s): invalid username",
 			       get_log_prefix(auth_request));

Index: mech.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/mech.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- mech.c	19 Aug 2004 03:56:02 -0000	1.31
+++ mech.c	28 Aug 2004 13:25:42 -0000	1.32
@@ -16,7 +16,7 @@
 const char *const *auth_realms;
 const char *default_realm;
 const char *anonymous_username;
-char username_chars[256];
+char username_chars[256], username_translation[256];
 
 static int set_use_cyrus_sasl;
 static int ssl_require_client_cert;
@@ -253,11 +253,13 @@
 	}
 }
 
-int mech_is_valid_username(const char *username)
+int mech_fix_username(char *username)
 {
-	const unsigned char *p;
+	unsigned char *p;
 
-	for (p = (const unsigned char *)username; *p != '\0'; p++) {
+	for (p = (unsigned char *)username; *p != '\0'; p++) {
+		if (username_translation[*p & 0xff] != 0)
+			*p = username_translation[*p & 0xff];
 		if (username_chars[*p & 0xff] == 0)
 			return FALSE;
 	}
@@ -470,6 +472,15 @@
 			username_chars[((unsigned char)*env) & 0xff] = 0xff;
 	}
 
+	env = getenv("USERNAME_TRANSLATION");
+	memset(username_translation, 0, sizeof(username_translation));
+	if (env != NULL) {
+		for (; *env != '\0' && env[1] != '\0'; env += 2) {
+			username_translation[((unsigned char)*env) & 0xff] =
+				env[1];
+		}
+	}
+
 	set_use_cyrus_sasl = getenv("USE_CYRUS_SASL") != NULL;
 #ifdef USE_CYRUS_SASL2
 	if (set_use_cyrus_sasl)

Index: mech.h
===================================================================
RCS file: /home/cvs/dovecot/src/auth/mech.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- mech.h	31 May 2004 20:10:02 -0000	1.19
+++ mech.h	28 Aug 2004 13:25:42 -0000	1.20
@@ -81,7 +81,7 @@
 void mech_auth_finish(struct auth_request *auth_request,
 		      const void *data, size_t data_size, int success);
 
-int mech_is_valid_username(const char *username);
+int mech_fix_username(char *username);
 
 void mech_cyrus_sasl_init_lib(void);
 struct auth_request *



More information about the dovecot-cvs mailing list