Recently we changed Postfix to use Dovecot for our SASL authentication
and we ran into trouble with some of our clients having extraneous
spaces at the end of their usernames. The quick fix was to add a space
to username_chars. The slightly longer fix was a pretty simple patch to
Dovecot. I put the trimming in auth_request_fix_username. I didn't think
it warranted a full strfuncs function.
If there is a better way to do this I'm all ears. I don't really like
patching with my own code, even if I did essentially steal if from the
kernel's strstrip().
diff -u dovecot-1.1.rc5/src/auth/auth-request.c
dovecot-1.1.rc5-patched/src/auth/auth-request.c
--- dovecot-1.1.rc5/src/auth/auth-request.c 2008-05-04
15:01:52.000000000 -0700
+++ dovecot-1.1.rc5-patched/src/auth/auth-request.c 2008-05-16
00:44:15.000000000 -0700
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <sys/stat.h>
+#include <ctype.h>
struct auth_request *
auth_request_new(struct auth *auth, const struct mech_module *mech,
@@ -750,6 +751,7 @@
{
unsigned char *p;
char *user;
+ size_t size;
if (strchr(username, '@') == NULL &&
request->auth->default_realm != NULL) {
@@ -759,6 +761,16 @@
user = p_strdup(request->pool, username);
}
+ /* Trim trailing whitespace from the username */
+ size = strlen((unsigned char*)user);
+ if(size) {
+ p = user + size - 1;
+ while (p != user && isspace(*p))
+ p--;
+ *(p + 1) = '\0';
+ p = NULL;
+ }
+
for (p = (unsigned char *)user; *p != '\0'; p++) {
if (request->auth->username_translation[*p & 0xff] != 0)
*p = request->auth->username_translation[*p &
0xff];