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