challenge.c 980 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <auth.h>
  4. void
  5. usage(void)
  6. {
  7. fprint(2, "usage: auth/challenge 'params'\n");
  8. exits("usage");
  9. }
  10. void
  11. main(int argc, char **argv)
  12. {
  13. char buf[128], bufu[128];
  14. int afd, n;
  15. AuthInfo *ai;
  16. AuthRpc *rpc;
  17. Chalstate *c;
  18. ARGBEGIN{
  19. default:
  20. usage();
  21. }ARGEND
  22. if(argc != 1)
  23. usage();
  24. if((afd = open("/mnt/factotum/rpc", ORDWR)) < 0)
  25. sysfatal("open /mnt/factotum/rpc: %r");
  26. rpc = auth_allocrpc(afd);
  27. if(rpc == nil)
  28. sysfatal("auth_allocrpc: %r");
  29. if((c = auth_challenge("%s", argv[0])) == nil)
  30. sysfatal("auth_challenge: %r");
  31. print("challenge: %s\n", c->chal);
  32. print("user:");
  33. n = read(0, bufu, sizeof bufu);
  34. if(n > 0){
  35. bufu[n-1] = '\0';
  36. c->user = bufu;
  37. }
  38. print("response: ");
  39. n = read(0, buf, sizeof buf);
  40. if(n < 0)
  41. sysfatal("read: %r");
  42. if(n == 0)
  43. exits(nil);
  44. c->nresp = n-1;
  45. c->resp = buf;
  46. if((ai = auth_response(c)) == nil)
  47. sysfatal("auth_response: %r");
  48. print("%s %s\n", ai->cuid, ai->suid);
  49. }