1 be8b315d 2004-06-17 devnull #include <u.h>
2 be8b315d 2004-06-17 devnull #include <libc.h>
3 be8b315d 2004-06-17 devnull #include <auth.h>
4 be8b315d 2004-06-17 devnull #include <authsrv.h>
6 be8b315d 2004-06-17 devnull /* deprecated.
7 be8b315d 2004-06-17 devnull This is the mechanism that put entries in /sys/lib/httpd.rewrite
8 be8b315d 2004-06-17 devnull and passwords on the authserver in /sys/lib/httppasswords, which
9 be8b315d 2004-06-17 devnull was awkward to administer. Instead, use local .httplogin files,
10 be8b315d 2004-06-17 devnull which are implemented in sys/src/cmd/ip/httpd/authorize.c */
13 be8b315d 2004-06-17 devnull httpauth(char *name, char *password)
16 be8b315d 2004-06-17 devnull Ticketreq tr;
17 be8b315d 2004-06-17 devnull Ticket t;
18 be8b315d 2004-06-17 devnull char key[DESKEYLEN];
19 be8b315d 2004-06-17 devnull char buf[512];
21 be8b315d 2004-06-17 devnull afd = authdial(nil, nil);
22 be8b315d 2004-06-17 devnull if(afd < 0)
23 be8b315d 2004-06-17 devnull return -1;
25 be8b315d 2004-06-17 devnull /* send ticket request to AS */
26 be8b315d 2004-06-17 devnull memset(&tr, 0, sizeof(tr));
27 be8b315d 2004-06-17 devnull strcpy(tr.uid, name);
28 be8b315d 2004-06-17 devnull tr.type = AuthHttp;
29 be8b315d 2004-06-17 devnull convTR2M(&tr, buf);
30 be8b315d 2004-06-17 devnull if(write(afd, buf, TICKREQLEN) != TICKREQLEN){
31 be8b315d 2004-06-17 devnull close(afd);
32 be8b315d 2004-06-17 devnull return -1;
34 be8b315d 2004-06-17 devnull if(_asrdresp(afd, buf, TICKETLEN) < 0){
35 be8b315d 2004-06-17 devnull close(afd);
36 be8b315d 2004-06-17 devnull return -1;
38 be8b315d 2004-06-17 devnull close(afd);
41 be8b315d 2004-06-17 devnull * use password and try to decrypt the
42 be8b315d 2004-06-17 devnull * ticket. If it doesn't work we've got a bad password,
43 be8b315d 2004-06-17 devnull * give up.
45 be8b315d 2004-06-17 devnull passtokey(key, password);
46 be8b315d 2004-06-17 devnull convM2T(buf, &t, key);
47 be8b315d 2004-06-17 devnull if(t.num != AuthHr || strcmp(t.cuid, tr.uid))
48 be8b315d 2004-06-17 devnull return -1;
50 be8b315d 2004-06-17 devnull return 0;