challenge.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. void
  13. usage(void)
  14. {
  15. fprint(2, "usage: auth/challenge 'params'\n");
  16. exits("usage");
  17. }
  18. void
  19. main(int argc, char **argv)
  20. {
  21. char buf[128], bufu[128];
  22. int afd, n;
  23. AuthInfo *ai;
  24. AuthRpc *rpc;
  25. Chalstate *c;
  26. ARGBEGIN{
  27. default:
  28. usage();
  29. }ARGEND
  30. if(argc != 1)
  31. usage();
  32. if((afd = open("/mnt/factotum/rpc", ORDWR)) < 0)
  33. sysfatal("open /mnt/factotum/rpc: %r");
  34. rpc = auth_allocrpc(afd);
  35. if(rpc == nil)
  36. sysfatal("auth_allocrpc: %r");
  37. if((c = auth_challenge("%s", argv[0])) == nil)
  38. sysfatal("auth_challenge: %r");
  39. print("challenge: %s\n", c->chal);
  40. print("user:");
  41. n = read(0, bufu, sizeof bufu);
  42. if(n > 0){
  43. bufu[n-1] = '\0';
  44. c->user = bufu;
  45. }
  46. print("response: ");
  47. n = read(0, buf, sizeof buf);
  48. if(n < 0)
  49. sysfatal("read: %r");
  50. if(n == 0)
  51. exits(nil);
  52. c->nresp = n-1;
  53. c->resp = buf;
  54. if((ai = auth_response(c)) == nil)
  55. sysfatal("auth_response: %r");
  56. print("%s %s\n", ai->cuid, ai->suid);
  57. }