File authid_normalize.patch of Package cyrus-imapd
Index: lib/auth_unix.c
===================================================================
--- lib/auth_unix.c.orig
+++ lib/auth_unix.c
@@ -157,10 +157,12 @@ const char *identifier;
size_t len;
{
static char retbuf[81];
+ char backup[81];
struct group *grp;
char sawalpha;
char *p;
int username_tolower = 0;
+ int ic,rbc;
if(!len) len = strlen(identifier);
if(len >= sizeof(retbuf)) return NULL;
@@ -210,6 +212,22 @@ size_t len;
/* now we don't */
/* if (!sawalpha) return NULL; */
+ if( (libcyrus_config_getswitch(CYRUSOPT_NORMALIZEUID) == 1) ) {
+ strcpy(backup,retbuf);
+ /* remove leading blanks */
+ for(ic=0; isblank(backup[ic]); ic++);
+ for(rbc=0; backup[ic]; ic++) {
+ retbuf[rbc] = ( isalpha(backup[ic]) ?
+ tolower(backup[ic]) : backup[ic] );
+ rbc++;
+ }
+ retbuf[rbc] = '\0';
+ /* remove trailing blanks */
+ for(--rbc; isblank(retbuf[rbc]); rbc--) {
+ retbuf[rbc] = '\0';
+ }
+ }
+
return retbuf;
}
Index: lib/imapoptions
===================================================================
--- lib/imapoptions.orig
+++ lib/imapoptions
@@ -927,6 +927,11 @@ are listed with ``<none>''.
interface, otherwise the user is assumed to be in the default
domain (if set). */
+{ "normalizeuid", 1, SWITCH }
+/* Lowercase uid and strip leading and trailing blanks. It is recommended
+ to set this to yes, especially if OpenLDAP is used as authentication
+ source. */
+
/*
.SH SEE ALSO
.PP
Index: lib/libcyr_cfg.c
===================================================================
--- lib/libcyr_cfg.c.orig
+++ lib/libcyr_cfg.c
@@ -123,6 +123,11 @@ struct cyrusopt_s cyrus_options[] = {
CFGVAL(long, 100),
CYRUS_OPT_INT },
+ { CYRUSOPT_NORMALIZEUID,
+ CFGVAL(long, 1),
+ CYRUS_OPT_SWITCH },
+
+
{ CYRUSOPT_LAST, { NULL }, CYRUS_OPT_NOTOPT }
};
Index: lib/libcyr_cfg.h
===================================================================
--- lib/libcyr_cfg.h.orig
+++ lib/libcyr_cfg.h
@@ -99,6 +99,8 @@ enum cyrus_opt {
CYRUSOPT_SQL_PASSWD,
/* Secure SQL connection (OFF) */
CYRUSOPT_SQL_USESSL,
+ /* Lowercase uid and strip leading and trailing blanks (ON) */
+ CYRUSOPT_NORMALIZEUID,
CYRUSOPT_LAST