authtis.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "ssh.h"
  10. static int
  11. authtisfn(Conn *c)
  12. {
  13. int fd, n;
  14. int8_t *chal, resp[256];
  15. Msg *m;
  16. if(!c->interactive)
  17. return -1;
  18. debug(DBG_AUTH, "try TIS\n");
  19. sendmsg(allocmsg(c, SSH_CMSG_AUTH_TIS, 0));
  20. m = recvmsg(c, -1);
  21. switch(m->type){
  22. default:
  23. badmsg(m, SSH_SMSG_AUTH_TIS_CHALLENGE);
  24. case SSH_SMSG_FAILURE:
  25. free(m);
  26. return -1;
  27. case SSH_SMSG_AUTH_TIS_CHALLENGE:
  28. break;
  29. }
  30. chal = getstring(m);
  31. free(m);
  32. if((fd = open("/dev/cons", ORDWR)) < 0)
  33. error("can't open console");
  34. fprint(fd, "TIS Authentication\n%s", chal);
  35. n = read(fd, resp, sizeof resp-1);
  36. if(n < 0)
  37. resp[0] = '\0';
  38. else
  39. resp[n] = '\0';
  40. if(resp[0] == 0 || resp[0] == '\n')
  41. return -1;
  42. m = allocmsg(c, SSH_CMSG_AUTH_TIS_RESPONSE, 4+strlen(resp));
  43. putstring(m, resp);
  44. sendmsg(m);
  45. m = recvmsg(c, -1);
  46. switch(m->type){
  47. default:
  48. badmsg(m, 0);
  49. case SSH_SMSG_SUCCESS:
  50. free(m);
  51. return 0;
  52. case SSH_SMSG_FAILURE:
  53. free(m);
  54. return -1;
  55. }
  56. }
  57. Auth authtis =
  58. {
  59. SSH_AUTH_TIS,
  60. "tis",
  61. authtisfn,
  62. };