Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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