changeset 6575:d573bc2a967d HEAD

Added "username" and "domain" fields for modifying the username.
author Timo Sirainen <tss@iki.fi>
date Sun, 21 Oct 2007 00:02:13 +0300
parents ab3a1a8ade55
children 66e6311e22b3
files src/auth/auth-request.c
diffstat 1 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/auth-request.c	Sat Oct 20 23:47:30 2007 +0300
+++ b/src/auth/auth-request.c	Sun Oct 21 00:02:13 2007 +0300
@@ -944,6 +944,8 @@
 			    const char *name, const char *value,
 			    const char *default_scheme)
 {
+	const char *p;
+
 	i_assert(*name != '\0');
 	i_assert(value != NULL);
 
@@ -967,8 +969,27 @@
 		return;
 	}
 
-	if (strcmp(name, "user") == 0) {
-		/* update username to be exactly as it's in database */
+	if (strcmp(name, "user") == 0 ||
+	    strcmp(name, "username") == 0 || strcmp(name, "domain") == 0) {
+		/* update username */
+		if (strcmp(name, "username") == 0 &&
+		    strchr(value, '@') == NULL &&
+		    (p = strchr(request->user, '@')) != NULL) {
+			/* preserve the current @domain */
+			value = t_strconcat(value, p, NULL);
+		} else if (strcmp(name, "domain") == 0) {
+			p = strchr(request->user, '@');
+			if (p == NULL) {
+				/* add the domain */
+				value = t_strconcat(request->user, "@",
+						    value, NULL);
+			} else {
+				/* replace the existing domain */
+				p = t_strdup_until(request->user, p + 1);
+				value = t_strconcat(p, value, NULL);
+			}
+		}
+
 		if (strcmp(request->user, value) != 0) {
 			/* remember the original username for cache */
 			if (request->original_username == NULL) {