aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2001-12-04 08:40:21 +0000
committerEric S. Raymond <esr@thyrsus.com>2001-12-04 08:40:21 +0000
commit15c492a8f8227ff79f76f23df7e448b8ef4dd6b3 (patch)
tree3ff021ec4d6304b9848445005545203847557e67
parent8e62e51a6c4b87c9991dce390f3d13a8f23f379b (diff)
downloadfetchmail-15c492a8f8227ff79f76f23df7e448b8ef4dd6b3.tar.gz
fetchmail-15c492a8f8227ff79f76f23df7e448b8ef4dd6b3.tar.bz2
fetchmail-15c492a8f8227ff79f76f23df7e448b8ef4dd6b3.zip
Initial revision
svn path=/trunk/; revision=3551
-rw-r--r--opie.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/opie.c b/opie.c
new file mode 100644
index 00000000..ef8173ac
--- /dev/null
+++ b/opie.c
@@ -0,0 +1,74 @@
+/*
+ * opie.c -- One-Time Password authentication.
+ *
+ * For license terms, see the file COPYING in this directory.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#if defined(STDC_HEADERS)
+#include <stdlib.h>
+#endif
+#include "fetchmail.h"
+#include "socket.h"
+
+#include "i18n.h"
+#include "md5.h"
+
+#if OPIE_ENABLE
+#include <opie.h>
+
+int do_otp(int sock, char *command, struct query *ctl)
+{
+ int i, rval;
+ int result;
+ char buffer[128];
+ char challenge[OPIE_CHALLENGE_MAX+1];
+ char response[OPIE_RESPONSE_MAX+1];
+
+ gen_send(sock, "%s X-OTP");
+
+ 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"));
+ return PS_AUTHFAIL;
+ };
+
+ to64frombits(buffer, ctl->remotename, strlen(ctl->remotename));
+ if (rval = gen_transact(sock, buffer, sizeof(buffer)))
+ return rval;
+
+ if ((i = from64tobits(challenge, buffer, 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);
+ if ((rval == -2) && !run.poll_interval) {
+ char secret[OPIE_SECRET_MAX+1];
+ fprintf(stderr, GT_("Secret pass phrase: "));
+ if (opiereadpass(secret, sizeof(secret), 0))
+ rval = opiegenerator(challenge, secret, response);
+ memset(secret, 0, sizeof(secret));
+ };
+
+ if (rval)
+ return(PS_AUTHFAIL);
+
+ to64frombits(buffer, response, strlen(response));
+ suppress_tags = TRUE;
+ result = gen_transact(sock, buffer, strlen(buffer));
+ suppress_tags = FALSE;
+
+ if (result)
+ return PS_SUCCESS;
+ else
+ return PS_AUTHFAIL;
+};
+#endif /* OPIE_ENABLE */
+
+/* opie.c ends here */