X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=cram.c;h=f7559e6d9668792ef42c30ebd6dc1327c1e5a5cb;hb=24ab4a608c8ee1613698a1a312a7b30d138a241e;hp=e2002eeabfdcab9f5f1dcec86baf00cc63723093;hpb=2e21bad416b831a5702ff230b30e1a71f4223119;p=~andy%2Ffetchmail diff --git a/cram.c b/cram.c index e2002eea..f7559e6d 100644 --- a/cram.c +++ b/cram.c @@ -8,18 +8,16 @@ #include #include #include -#if defined(STDC_HEADERS) #include -#endif #include "fetchmail.h" #include "socket.h" -#include "i18n.h" -#include "md5.h" +#include "gettext.h" +#include "fm_md5.h" -static void hmac_md5 (unsigned char *password, size_t pass_len, - unsigned char *challenge, size_t chal_len, - unsigned char *response, size_t resp_len) +void hmac_md5 (const unsigned char *password, size_t pass_len, + const unsigned char *challenge, size_t chal_len, + unsigned char *response, size_t resp_len) { int i; unsigned char ipad[64]; @@ -60,16 +58,16 @@ static void hmac_md5 (unsigned char *password, size_t pass_len, MD5Final (response, &ctx); } -int do_cram_md5 (int sock, char *command, struct query *ctl, char *strip) +int do_cram_md5 (int sock, const char *command, struct query *ctl, const char *strip) /* authenticate as per RFC2195 */ { int result; int len; - unsigned char buf1[1024]; - unsigned char msg_id[768]; + char buf1[1024]; + char msg_id[768]; unsigned char response[16]; - unsigned char reply[1024]; - unsigned char *respdata; + char reply[1024]; + char *respdata; gen_send (sock, "%s CRAM-MD5", command); @@ -89,18 +87,18 @@ int do_cram_md5 (int sock, char *command, struct query *ctl, char *strip) respdata = buf1; if (strip && strncmp(buf1, strip, strlen(strip)) == 0) respdata += strlen(strip); - len = from64tobits (msg_id, respdata); + len = from64tobits (msg_id, respdata, sizeof(msg_id)); if (len < 0) { - report (stderr, _("could not decode BASE64 challenge\n")); + report (stderr, GT_("could not decode BASE64 challenge\n")); return PS_AUTHFAIL; - } else if (len < sizeof (msg_id)) { + } else if ((size_t)len < sizeof (msg_id)) { msg_id[len] = 0; } else { msg_id[sizeof (msg_id)-1] = 0; } if (outlevel >= O_DEBUG) { - report (stdout, _("decoded as %s\n"), msg_id); + report (stdout, GT_("decoded as %s\n"), msg_id); } /* The client makes note of the data and then responds with a string @@ -110,15 +108,11 @@ int do_cram_md5 (int sock, char *command, struct query *ctl, char *strip) * (including angle-brackets). */ - hmac_md5(ctl->password, strlen(ctl->password), - msg_id, strlen (msg_id), + hmac_md5((unsigned char *)ctl->password, strlen(ctl->password), + (unsigned char *)msg_id, strlen (msg_id), response, sizeof (response)); -#ifdef HAVE_SNPRINTF snprintf (reply, sizeof(reply), -#else - sprintf(reply, -#endif "%s %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", ctl->remotename, response[0], response[1], response[2], response[3], @@ -131,7 +125,7 @@ int do_cram_md5 (int sock, char *command, struct query *ctl, char *strip) /* ship the authentication back, accept the server's responses */ /* PMDF5.2 IMAP has a bug that requires this to be a single write */ suppress_tags = TRUE; - result = gen_transact(sock, buf1, sizeof(buf1)); + result = gen_transact(sock, "%s", buf1); suppress_tags = FALSE; if (result) return(result);