1 #include <u.h> 2 #include <libc.h> 3 #include <auth.h> 4 #include "authlocal.h" 5 6 int 7 httpauth(char *name, char *password) 8 { 9 int afd; 10 Ticketreq tr; 11 Ticket t; 12 char key[DESKEYLEN]; 13 char buf[512]; 14 15 afd = authdial(); 16 if(afd < 0) 17 return -1; 18 19 /* send ticket request to AS */ 20 memset(&tr, 0, sizeof(tr)); 21 strcpy(tr.uid, name); 22 tr.type = AuthHttp; 23 convTR2M(&tr, buf); 24 if(write(afd, buf, TICKREQLEN) != TICKREQLEN){ 25 close(afd); 26 return -1; 27 } 28 if(_asrdresp(afd, buf, TICKETLEN) < 0){ 29 close(afd); 30 return -1; 31 } 32 close(afd); 33 34 /* 35 * use password and try to decrypt the 36 * ticket. If it doesn't work we've got a bad password, 37 * give up. 38 */ 39 passtokey(key, password); 40 convM2T(buf, &t, key); 41 if(t.num != AuthHr || strcmp(t.cuid, tr.uid)) 42 return -1; 43 44 return 0; 45 } 46