authpasswd.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. authpasswordfn(Conn *c)
  12. {
  13. Msg *m;
  14. UserPasswd *up;
  15. up = auth_getuserpasswd(c->interactive ? auth_getkey : nil, "proto=pass service=ssh server=%q user=%q", c->host, c->user);
  16. if(up == nil){
  17. debug(DBG_AUTH, "getuserpasswd returned nothing (interactive=%d)\n", c->interactive);
  18. return -1;
  19. }
  20. debug(DBG_AUTH, "try using password from factotum\n");
  21. m = allocmsg(c, SSH_CMSG_AUTH_PASSWORD, 4+strlen(up->passwd));
  22. putstring(m, up->passwd);
  23. sendmsg(m);
  24. m = recvmsg(c, -1);
  25. switch(m->type){
  26. default:
  27. badmsg(m, 0);
  28. case SSH_SMSG_SUCCESS:
  29. free(m);
  30. return 0;
  31. case SSH_SMSG_FAILURE:
  32. free(m);
  33. return -1;
  34. }
  35. }
  36. Auth authpassword =
  37. {
  38. SSH_AUTH_PASSWORD,
  39. "password",
  40. authpasswordfn,
  41. };