From: Wilfried Goesgens Date: Mon, 22 Dec 2014 19:15:48 +0000 (+0100) Subject: more places to fix the new linebreak behaviour of the base64 encoder. X-Git-Tag: v9.01~72 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=b26e3e79fcb15dc1b46f4c7710a6bafdc6472950 more places to fix the new linebreak behaviour of the base64 encoder. --- diff --git a/citadel/modules/dspam/serv_dspam.c b/citadel/modules/dspam/serv_dspam.c index 28a9a8d74..7454634f7 100644 --- a/citadel/modules/dspam/serv_dspam.c +++ b/citadel/modules/dspam/serv_dspam.c @@ -167,9 +167,13 @@ void dspam_do_msg(long msgnum, void *userdata) else { /* Copy to a safe place */ - + // TODO: len -> cm_fields? msg->cm_fields[eErrorMsg] = malloc (CTX->signature->length * 2); - CtdlEncodeBase64(msg->cm_fields[eErrorMsg], CTX->signature->data, CTX->signature->length, 0); + size_t len = CtdlEncodeBase64(msg->cm_fields[eErrorMsg], CTX->signature->data, CTX->signature->length, 0); + + if (msg->cm_fields[eErrorMsg][len - 1] == '\n') { + msg->cm_fields[eErrorMsg][len - 1] = '\0'; + } } free(msgtext); diff --git a/citadel/modules/imap/serv_imap.c b/citadel/modules/imap/serv_imap.c index d49b8d854..278cc7332 100644 --- a/citadel/modules/imap/serv_imap.c +++ b/citadel/modules/imap/serv_imap.c @@ -677,7 +677,11 @@ void imap_authenticate(int num_parms, ConstStr *Params) } if (!strcasecmp(Params[2].Key, "LOGIN")) { - CtdlEncodeBase64(UsrBuf, "Username:", 9, 0); + size_t len = CtdlEncodeBase64(UsrBuf, "Username:", 9, 0); + if (UsrBuf[len - 1] == '\n') { + UsrBuf[len - 1] = '\0'; + } + IAPrintf("+ %s\r\n", UsrBuf); IMAP->authstate = imap_as_expecting_username; strcpy(IMAP->authseq, Params[0].Key); @@ -685,7 +689,10 @@ void imap_authenticate(int num_parms, ConstStr *Params) } if (!strcasecmp(Params[2].Key, "PLAIN")) { - // CtdlEncodeBase64(UsrBuf, "Username:", 9, 0); + // size_t len = CtdlEncodeBase64(UsrBuf, "Username:", 9, 0); + // if (UsrBuf[len - 1] == '\n') { + // UsrBuf[len - 1] = '\0'; + // } // IAPuts("+ %s\r\n", UsrBuf); IAPuts("+ \r\n"); IMAP->authstate = imap_as_expecting_plainauth; @@ -768,7 +775,11 @@ void imap_auth_login_user(long state) case imap_as_expecting_username: StrBufDecodeBase64(Imap->Cmd.CmdBuf); CtdlLoginExistingUser(NULL, ChrPtr(Imap->Cmd.CmdBuf)); - CtdlEncodeBase64(PWBuf, "Password:", 9, 0); + size_t len = CtdlEncodeBase64(PWBuf, "Password:", 9, 0); + if (PWBuf[len - 1] == '\n') { + PWBuf[len - 1] = '\0'; + } + IAPrintf("+ %s\r\n", PWBuf); Imap->authstate = imap_as_expecting_password; diff --git a/citadel/modules/managesieve/serv_managesieve.c b/citadel/modules/managesieve/serv_managesieve.c index 7158f4c00..23f5f263c 100644 --- a/citadel/modules/managesieve/serv_managesieve.c +++ b/citadel/modules/managesieve/serv_managesieve.c @@ -507,7 +507,10 @@ void mgsve_auth(char *argbuf) { if (strlen(argbuf) >= 7) { } else { - CtdlEncodeBase64(username_prompt, "Username:", 9, 0); + size_t len = CtdlEncodeBase64(username_prompt, "Username:", 9, 0); + if (username_prompt[len - 1] == '\n') { + username_prompt[len - 1] = '\0'; + } cprintf("334 %s\r\n", username_prompt); } return; diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index 4abb0a3fe..a93bb438e 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -400,7 +400,11 @@ void smtp_get_user(long offset) /* syslog(LOG_DEBUG, "Trying <%s>\n", username); */ if (CtdlLoginExistingUser(NULL, ChrPtr(sSMTP->Cmd)) == login_ok) { - CtdlEncodeBase64(buf, "Password:", 9, 0); + size_t len = CtdlEncodeBase64(buf, "Password:", 9, 0); + + if (buf[len - 1] == '\n') { + buf[len - 1] = '\0'; + } cprintf("334 %s\r\n", buf); sSMTP->command_state = smtp_password; } @@ -519,7 +523,10 @@ void smtp_auth(long offset, long Flags) smtp_get_user(6); } else { - CtdlEncodeBase64(username_prompt, "Username:", 9, 0); + size_t len = CtdlEncodeBase64(username_prompt, "Username:", 9, 0); + if (username_prompt[len - 1] == '\n') { + username_prompt[len - 1] = '\0'; + } cprintf("334 %s\r\n", username_prompt); sSMTP->command_state = smtp_user; } diff --git a/citadel/modules/smtp/smtp_clienthandlers.c b/citadel/modules/smtp/smtp_clienthandlers.c index bbdbc4684..198649e1f 100644 --- a/citadel/modules/smtp/smtp_clienthandlers.c +++ b/citadel/modules/smtp/smtp_clienthandlers.c @@ -234,10 +234,14 @@ eNextState SMTPC_send_auth(SmtpOutMsg *Msg) Msg->pCurrRelay->User, '\0', Msg->pCurrRelay->Pass); - CtdlEncodeBase64(encoded, buf, - strlen(Msg->pCurrRelay->User) * 2 + - strlen(Msg->pCurrRelay->Pass) + 2, 0); - + size_t len = CtdlEncodeBase64(encoded, buf, + strlen(Msg->pCurrRelay->User) * 2 + + strlen(Msg->pCurrRelay->Pass) + 2, 0); + + if (buf[len - 1] == '\n') { + buf[len - 1] = '\0'; + } + StrBufPrintf(Msg->IO.SendBuf.Buf, "AUTH PLAIN %s\r\n", encoded); @@ -289,6 +293,10 @@ eNextState SMTPC_send_authplain_1(SmtpOutMsg *Msg) Msg->pCurrRelay->User, strlen(Msg->pCurrRelay->User), 0); + if (encoded[encodedlen - 1] == '\n') { + encodedlen --; + encoded[encodedlen] = '\0'; + } StrBufPlain(Msg->IO.SendBuf.Buf, encoded, @@ -330,6 +338,11 @@ eNextState SMTPC_send_authplain_2(SmtpOutMsg *Msg) strlen(Msg->pCurrRelay->Pass), 0); + if (encoded[encodedlen - 1] == '\n') { + encodedlen --; + encoded[encodedlen] = '\0'; + } + StrBufPlain(Msg->IO.SendBuf.Buf, encoded, encodedlen); diff --git a/webcit/sieve.c b/webcit/sieve.c index ee6bcec9e..cce70574a 100644 --- a/webcit/sieve.c +++ b/webcit/sieve.c @@ -337,7 +337,10 @@ void parse_fields_from_rule_editor(void) { redirect, automsg, final ); - CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0); + size_t len = CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0); + if (encoded_rule[len - 1] == '\n') { + encoded_rule[len - 1] = '\0'; + } serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule); output_sieve_rule(hfield, compare, htext, sizecomp, sizeval, action, fileinto, redirect, automsg, final, my_addresses);