]> Pileus Git - ~andy/fetchmail/blobdiff - opie.c
Update website for 6.3.24.
[~andy/fetchmail] / opie.c
diff --git a/opie.c b/opie.c
index ef8173acfff4d88203c904d6da4180491a5c1baa..26f3c93cc561e610120b2eb21538b066fb9dfbec 100644 (file)
--- a/opie.c
+++ b/opie.c
 #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 <opie.h>
+#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 */