diff options
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | imap.c | 40 |
2 files changed, 39 insertions, 4 deletions
@@ -20,6 +20,9 @@ fetchmail-4.4.0 (): under Red Hat 5.0. * Kerberos V support from Jon Dugan <jdugan@ncsa.uiuc.edu> and Von Welch <vwelch@ncsa.uiuc.edu>. +* Ron Kaminsky <kam@Orbotech.Co.IL> sent a patch to RFC1730-encode passwords + sent to IMAP servers. This allows them to contain doublequotes and + backslashes. There are 269 people on fetchmail-friends and 144 on fetchmail-announce. @@ -562,6 +562,28 @@ static int do_gssauth(int sock, char *hostname, char *username) } #endif /* GSSAPI */ +static char *canonify_imap_password(char *passwd) +/* encode an IMAP password as per RFC1730's quoting conventions */ +{ + char *result; + int i, j; + + result = malloc(2*strlen(passwd)); + if (!result) + return 0; + + j=0; + for (i=0; i<strlen(passwd); ++i) + { + if ((passwd[i] == '\\') || (passwd[i] == '"')) + result[j++] = '\\'; + result[j++] = passwd[i]; + } + result[j] = '\0'; + + return(result); +} + int imap_getauth(int sock, struct query *ctl, char *greeting) /* apply for connection authorization */ { @@ -655,10 +677,20 @@ int imap_getauth(int sock, struct query *ctl, char *greeting) }; /* try to get authorized in the ordinary (AUTH=LOGIN) way */ - ok = gen_transact(sock, "LOGIN %s \"%s\"", ctl->remotename, ctl->password); - if (ok) - return(ok); - + { + char *newpass = canonify_imap_password(ctl->password); + + if (!newpass) + return(PS_AUTHFAIL); /* should report error better!!!! */ + + ok = gen_transact(sock, "LOGIN %s \"%s\"", ctl->remotename, newpass); + + free(newpass); + + if (ok) + return(ok); + } + return(PS_SUCCESS); } |