aboutsummaryrefslogtreecommitdiff
path: root/src/libauth/auth_userpasswd.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-06-17 03:27:35 +0000
committerrsc <devnull@localhost>2004-06-17 03:27:35 +0000
commitbe8b315d1522fa1c109a49435c1638bafd838b91 (patch)
tree4d8e2a0799ab463160b0a80feb0a008940d11230 /src/libauth/auth_userpasswd.c
parentd9c8a7c5366aea63aa45b4afc6a75d133192786d (diff)
downloadplan9port-be8b315d1522fa1c109a49435c1638bafd838b91.tar.gz
plan9port-be8b315d1522fa1c109a49435c1638bafd838b91.tar.bz2
plan9port-be8b315d1522fa1c109a49435c1638bafd838b91.zip
basically none of these build
Diffstat (limited to 'src/libauth/auth_userpasswd.c')
-rw-r--r--src/libauth/auth_userpasswd.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/libauth/auth_userpasswd.c b/src/libauth/auth_userpasswd.c
new file mode 100644
index 00000000..34a38c26
--- /dev/null
+++ b/src/libauth/auth_userpasswd.c
@@ -0,0 +1,50 @@
+#include <u.h>
+#include <libc.h>
+#include <auth.h>
+#include <authsrv.h>
+#include "authlocal.h"
+
+/*
+ * compute the proper response. We encrypt the ascii of
+ * challenge number, with trailing binary zero fill.
+ * This process was derived empirically.
+ * this was copied from inet's guard.
+ */
+static void
+netresp(char *key, long chal, char *answer)
+{
+ uchar buf[8];
+
+ memset(buf, 0, 8);
+ sprint((char *)buf, "%lud", chal);
+ if(encrypt(key, buf, 8) < 0)
+ abort();
+ chal = (buf[0]<<24)+(buf[1]<<16)+(buf[2]<<8)+buf[3];
+ sprint(answer, "%.8lux", chal);
+}
+
+AuthInfo*
+auth_userpasswd(char *user, char *passwd)
+{
+ char key[DESKEYLEN], resp[16];
+ AuthInfo *ai;
+ Chalstate *ch;
+
+ /*
+ * Probably we should have a factotum protocol
+ * to check a raw password. For now, we use
+ * p9cr, which is simplest to speak.
+ */
+ if((ch = auth_challenge("user=%q proto=p9cr role=server", user)) == nil)
+ return nil;
+
+ passtokey(key, passwd);
+ netresp(key, atol(ch->chal), resp);
+ memset(key, 0, sizeof key);
+
+ ch->resp = resp;
+ ch->nresp = strlen(resp);
+ ai = auth_response(ch);
+ auth_freechal(ch);
+ return ai;
+}