authpasswd.c 758 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "ssh.h"
  2. static int
  3. authpasswordfn(Conn *c)
  4. {
  5. Msg *m;
  6. UserPasswd *up;
  7. up = auth_getuserpasswd(c->interactive ? auth_getkey : nil, "proto=pass service=ssh server=%q user=%q", c->host, c->user);
  8. if(up == nil){
  9. debug(DBG_AUTH, "getuserpasswd returned nothing (interactive=%d)\n", c->interactive);
  10. return -1;
  11. }
  12. debug(DBG_AUTH, "try using password from factotum\n");
  13. m = allocmsg(c, SSH_CMSG_AUTH_PASSWORD, 4+strlen(up->passwd));
  14. putstring(m, up->passwd);
  15. sendmsg(m);
  16. m = recvmsg(c, 0);
  17. if(m == nil)
  18. badmsg(m, 0);
  19. switch(m->type){
  20. default:
  21. badmsg(m, 0);
  22. case SSH_SMSG_SUCCESS:
  23. free(m);
  24. return 0;
  25. case SSH_SMSG_FAILURE:
  26. free(m);
  27. return -1;
  28. }
  29. }
  30. Auth authpassword =
  31. {
  32. SSH_AUTH_PASSWORD,
  33. "password",
  34. authpasswordfn,
  35. };