httpauth.c 1.0 KB

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