httpauth.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <auth.h>
  12. #include <authsrv.h>
  13. /* deprecated.
  14. This is the mechanism that put entries in /sys/lib/httpd.rewrite
  15. and passwords on the authserver in /sys/lib/httppasswords, which
  16. was awkward to administer. Instead, use local .httplogin files,
  17. which are implemented in sys/src/cmd/ip/httpd/authorize.c */
  18. int
  19. httpauth(char *name, char *password)
  20. {
  21. int afd;
  22. Ticketreq tr;
  23. Ticket t;
  24. char key[DESKEYLEN];
  25. char buf[512];
  26. afd = authdial(nil, nil);
  27. if(afd < 0)
  28. return -1;
  29. /* send ticket request to AS */
  30. memset(&tr, 0, sizeof(tr));
  31. strcpy(tr.uid, name);
  32. tr.type = AuthHttp;
  33. convTR2M(&tr, buf);
  34. if(write(afd, buf, TICKREQLEN) != TICKREQLEN){
  35. close(afd);
  36. return -1;
  37. }
  38. if(_asrdresp(afd, buf, TICKETLEN) < 0){
  39. close(afd);
  40. return -1;
  41. }
  42. close(afd);
  43. /*
  44. * use password and try to decrypt the
  45. * ticket. If it doesn't work we've got a bad password,
  46. * give up.
  47. */
  48. passtokey(key, password);
  49. convM2T(buf, &t, key);
  50. if(t.num != AuthHr || strcmp(t.cuid, tr.uid))
  51. return -1;
  52. return 0;
  53. }