summaryrefslogtreecommitdiff
path: root/sys/src/libauth/auth_userpasswd.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libauth/auth_userpasswd.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libauth/auth_userpasswd.c')
-rwxr-xr-xsys/src/libauth/auth_userpasswd.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/sys/src/libauth/auth_userpasswd.c b/sys/src/libauth/auth_userpasswd.c
new file mode 100755
index 000000000..292899281
--- /dev/null
+++ b/sys/src/libauth/auth_userpasswd.c
@@ -0,0 +1,49 @@
+#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, sizeof buf);
+ snprint((char *)buf, sizeof buf, "%lud", chal);
+ if(encrypt(key, buf, 8) < 0)
+ abort();
+ sprint(answer, "%.8ux", buf[0]<<24 | buf[1]<<16 | buf[2]<<8 | buf[3]);
+}
+
+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;
+}