Blob Blame History Raw
diff -up ./src/mappers/mail_mapper.c.strip-email-domain ./src/mappers/mail_mapper.c
--- ./src/mappers/mail_mapper.c.strip-email-domain	2008-12-31 04:13:39.000000000 -0800
+++ ./src/mappers/mail_mapper.c	2017-03-10 18:09:01.608738541 -0800
@@ -49,6 +49,7 @@ static int ignorecase = 1;
 
 /* also check the domain part on email field */
 static int ignoredomain = 1;
+static int stripdomain = 0;
 static char *hostname = NULL;
 
 static int debug=0;
@@ -81,6 +82,22 @@ static int check_domain(char *domain) {
 	return 0;
 }
 
+static char *mail_strip_email_user(char *email)
+{
+	char *at;
+	char *user = clone_str(email);
+
+	if (user == NULL) {
+	    return user;
+	}
+	at = strchr(email, '@');
+
+	if (at != NULL) {
+	    user[at - email] = 0;
+	}
+	return user;
+}
+
 /**
 * compare previously mapped email against user name
 */
@@ -112,6 +129,10 @@ static char * mail_mapper_find_user(X509
                 DBG("get_email() failed");
                 return NULL;
         }
+	if (stripdomain) {
+		/* strip domain implies we aren't using a map file */
+		return mail_strip_email_user(entries[0]);
+	}
 	/* TODO: What's on ignoredomain flag ?*/
 	return mapfile_find(mapfile,entries[0],ignorecase);
 }
@@ -176,11 +197,17 @@ mapper_module * mail_mapper_module_init(
 		debug = scconf_get_bool(blk,"debug",0);
 	ignorecase = scconf_get_bool(blk,"ignorecase",ignorecase);
 	ignoredomain = scconf_get_bool(blk,"ignoredomain",ignoredomain);
+	stripdomain = scconf_get_bool(blk,"stripdomain",stripdomain);
 	mapfile = scconf_get_str(blk,"mapfile",mapfile);
 	} else {
 		DBG1("No block declaration for mapper '%s'",mapper_name);
 	}
 	set_debug_level(debug);
+
+	if (stripdomain) {
+	    /* stripdomain implies ignore domain */
+	    ignoredomain = 1;
+	}
 	/* obtain and store hostname */
 	/* Note: in some systems without nis/yp, getdomainname() call
 	   returns NULL. So instead we use gethostname() an match