X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=opie.c;h=26f3c93cc561e610120b2eb21538b066fb9dfbec;hb=91644ff0b2e6eb3b26c5544a4a769ca4aaf08a14;hp=ef8173acfff4d88203c904d6da4180491a5c1baa;hpb=15c492a8f8227ff79f76f23df7e448b8ef4dd6b3;p=~andy%2Ffetchmail diff --git a/opie.c b/opie.c index ef8173ac..26f3c93c 100644 --- a/opie.c +++ b/opie.c @@ -15,39 +15,50 @@ #include "socket.h" #include "i18n.h" -#include "md5.h" +#include "fm_md5.h" -#if OPIE_ENABLE +#ifdef OPIE_ENABLE +#ifdef __cplusplus +extern "C" { +#endif #include +#ifdef __cplusplus +} +#endif -int do_otp(int sock, char *command, struct query *ctl) +int do_otp(int sock, const char *command, struct query *ctl) { int i, rval; - int result; char buffer[128]; - char challenge[OPIE_CHALLENGE_MAX+1]; + char challenge[OPIE_CHALLENGE_MAX+1+8]; char response[OPIE_RESPONSE_MAX+1]; - gen_send(sock, "%s X-OTP"); + gen_send(sock, "%s X-OTP", command); - if (rval = gen_recv(sock, buffer, sizeof(buffer))) + if ((rval = gen_recv(sock, buffer, sizeof(buffer)))) return rval; - if ((i = from64tobits(challenge, buffer, sizeof(challenge))) < 0) { - report(stderr, GT_("Could not decode initial BASE64 challenge\n")); + if (strncmp(buffer, "+", 1)) { + report(stderr, GT_("server recv fatal\n")); return PS_AUTHFAIL; - }; + } to64frombits(buffer, ctl->remotename, strlen(ctl->remotename)); - if (rval = gen_transact(sock, buffer, sizeof(buffer))) + suppress_tags = TRUE; + gen_send(sock, "%s", buffer); + suppress_tags = FALSE; + + if ((rval = gen_recv(sock, buffer, sizeof(buffer)))) return rval; - if ((i = from64tobits(challenge, buffer, sizeof(challenge))) < 0) { + memset(challenge, '\0', sizeof(challenge)); + if ((i = from64tobits(challenge, buffer+2, sizeof(challenge))) < 0) { report(stderr, GT_("Could not decode OTP challenge\n")); return PS_AUTHFAIL; }; - rval = opiegenerator(challenge, !strcmp(ctl->password, "opie") ? "" : ctl->password, response); + memset(response, '\0', sizeof(response)); + rval = opiegenerator(challenge, ctl->password, response); if ((rval == -2) && !run.poll_interval) { char secret[OPIE_SECRET_MAX+1]; fprintf(stderr, GT_("Secret pass phrase: ")); @@ -61,14 +72,14 @@ int do_otp(int sock, char *command, struct query *ctl) to64frombits(buffer, response, strlen(response)); suppress_tags = TRUE; - result = gen_transact(sock, buffer, strlen(buffer)); + gen_send(sock, "%s", buffer); suppress_tags = FALSE; - if (result) - return PS_SUCCESS; - else - return PS_AUTHFAIL; -}; + if ((rval = gen_recv(sock, buffer, sizeof(buffer)))) + return rval; + + return PS_SUCCESS; +} #endif /* OPIE_ENABLE */ /* opie.c ends here */