Mercurial > dropbear
annotate cli-auth.c @ 41:18eccbfb9641
added window-size change handling
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 01 Aug 2004 09:41:37 +0000 |
parents | b4874d772210 |
children | 942b22d7dd1c |
rev | line source |
---|---|
33 | 1 #include "includes.h" |
2 #include "session.h" | |
3 #include "auth.h" | |
4 #include "dbutil.h" | |
5 #include "buffer.h" | |
6 #include "ssh.h" | |
7 #include "packet.h" | |
8 #include "runopts.h" | |
9 | |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
37
diff
changeset
|
10 #undef DROPBEAR_PUBKEY_AUTH |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
37
diff
changeset
|
11 |
33 | 12 void cli_authinitialise() { |
13 | |
14 memset(&ses.authstate, 0, sizeof(ses.authstate)); | |
15 } | |
16 | |
17 | |
18 /* Send a "none" auth request to get available methods */ | |
19 void cli_auth_getmethods() { | |
20 | |
21 TRACE(("enter cli_auth_getmethods")); | |
22 | |
23 CHECKCLEARTOWRITE(); | |
24 | |
25 buf_putbyte(ses.writepayload, SSH_MSG_USERAUTH_REQUEST); | |
35
0ad5fb979f42
set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents:
34
diff
changeset
|
26 buf_putstring(ses.writepayload, cli_opts.username, |
0ad5fb979f42
set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents:
34
diff
changeset
|
27 strlen(cli_opts.username)); |
33 | 28 buf_putstring(ses.writepayload, SSH_SERVICE_CONNECTION, |
29 SSH_SERVICE_CONNECTION_LEN); | |
30 buf_putstring(ses.writepayload, "none", 4); /* 'none' method */ | |
31 | |
32 encrypt_packet(); | |
33 cli_ses.state = USERAUTH_METHODS_SENT; | |
34 TRACE(("leave cli_auth_getmethods")); | |
35 | |
36 } | |
37 | |
38 void recv_msg_userauth_failure() { | |
39 | |
40 unsigned char * methods = NULL; | |
41 unsigned char * tok = NULL; | |
42 unsigned int methlen = 0; | |
43 unsigned int partial = 0; | |
44 unsigned int i = 0; | |
45 | |
46 TRACE(("<- MSG_USERAUTH_FAILURE")); | |
47 TRACE(("enter recv_msg_userauth_failure")); | |
48 | |
49 methods = buf_getstring(ses.payload, &methlen); | |
50 | |
51 partial = buf_getbyte(ses.payload); | |
52 | |
53 if (partial) { | |
54 dropbear_log(LOG_INFO, "Authentication partially succeeded, more attempts required"); | |
55 } else { | |
56 ses.authstate.failcount++; | |
57 } | |
58 | |
59 TRACE(("Methods (len %d): '%s'", methlen, methods)); | |
60 | |
61 ses.authstate.authdone=0; | |
62 ses.authstate.authtypes=0; | |
63 | |
64 /* Split with nulls rather than commas */ | |
65 for (i = 0; i < methlen; i++) { | |
66 if (methods[i] == ',') { | |
67 methods[i] = '\0'; | |
68 } | |
69 } | |
70 | |
71 tok = methods; /* tok stores the next method we'll compare */ | |
72 for (i = 0; i <= methlen; i++) { | |
73 if (methods[i] == '\0') { | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
74 TRACE(("auth method '%s'", tok)); |
33 | 75 #ifdef DROPBEAR_PUBKEY_AUTH |
76 if (strncmp(AUTH_METHOD_PUBKEY, tok, | |
77 AUTH_METHOD_PUBKEY_LEN) == 0) { | |
78 ses.authstate.authtypes |= AUTH_TYPE_PUBKEY; | |
79 } | |
80 #endif | |
81 #ifdef DROPBEAR_PASSWORD_AUTH | |
82 if (strncmp(AUTH_METHOD_PASSWORD, tok, | |
83 AUTH_METHOD_PASSWORD_LEN) == 0) { | |
84 ses.authstate.authtypes |= AUTH_TYPE_PASSWORD; | |
85 } | |
86 #endif | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
87 tok = &methods[i+1]; /* Must make sure we don't use it after the |
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
88 last loop, since it'll point to something |
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
89 undefined */ |
33 | 90 } |
91 } | |
92 | |
93 cli_ses.state = USERAUTH_FAIL_RCVD; | |
94 | |
95 TRACE(("leave recv_msg_userauth_failure")); | |
96 } | |
97 | |
98 void recv_msg_userauth_success() { | |
99 TRACE(("received msg_userauth_success")); | |
100 ses.authstate.authdone = 1; | |
37 | 101 cli_ses.state = USERAUTH_SUCCESS_RCVD; |
33 | 102 } |
103 | |
104 void cli_auth_try() { | |
105 | |
106 TRACE(("enter cli_auth_try")); | |
107 int finished = 0; | |
108 | |
109 CHECKCLEARTOWRITE(); | |
110 | |
111 /* XXX We hardcode that we try a pubkey first */ | |
112 #ifdef DROPBEAR_PUBKEY_AUTH | |
113 if (ses.authstate.authtypes & AUTH_TYPE_PUBKEY) { | |
114 finished = cli_auth_pubkey(); | |
115 } | |
116 #endif | |
117 | |
118 #ifdef DROPBEAR_PASSWORD_AUTH | |
119 if (!finished && ses.authstate.authtypes & AUTH_TYPE_PASSWORD) { | |
120 finished = cli_auth_password(); | |
121 } | |
122 #endif | |
123 | |
124 if (!finished) { | |
125 dropbear_exit("No auth methods could be used."); | |
126 } | |
127 | |
128 cli_ses.state = USERAUTH_REQ_SENT; | |
129 TRACE(("leave cli_auth_try")); | |
130 } |