Mercurial > dropbear
annotate cli-auth.c @ 43:942b22d7dd1c
Banner printing
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 02 Aug 2004 04:25:05 +0000 |
parents | b4874d772210 |
children | 9ee8996a375f |
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 | |
43 | 38 void recv_msg_userauth_banner() { |
39 | |
40 unsigned char* banner = NULL; | |
41 unsigned int bannerlen; | |
42 unsigned int i, linecount; | |
43 | |
44 TRACE(("enter recv_msg_userauth_banner")); | |
45 if (ses.authstate.authdone) { | |
46 TRACE(("leave recv_msg_userauth_banner: banner after auth done")); | |
47 return; | |
48 } | |
49 | |
50 banner = buf_getstring(ses.payload, &bannerlen); | |
51 buf_eatstring(ses.payload); /* The language string */ | |
52 | |
53 if (bannerlen > MAX_BANNER_SIZE) { | |
54 TRACE(("recv_msg_userauth_banner: bannerlen too long: %d", bannerlen)); | |
55 goto out; | |
56 } | |
57 | |
58 cleantext(banner); | |
59 | |
60 /* Limit to 25 lines */ | |
61 linecount = 1; | |
62 for (i = 0; i < bannerlen; i++) { | |
63 if (banner[i] == '\n') { | |
64 if (linecount >= MAX_BANNER_LINES) { | |
65 banner[i] = '\0'; | |
66 break; | |
67 } | |
68 linecount++; | |
69 } | |
70 } | |
71 | |
72 printf("%s\n", banner); | |
73 | |
74 out: | |
75 m_free(banner); | |
76 TRACE(("leave recv_msg_userauth_banner")); | |
77 } | |
78 | |
79 | |
33 | 80 void recv_msg_userauth_failure() { |
81 | |
82 unsigned char * methods = NULL; | |
83 unsigned char * tok = NULL; | |
84 unsigned int methlen = 0; | |
85 unsigned int partial = 0; | |
86 unsigned int i = 0; | |
87 | |
88 TRACE(("<- MSG_USERAUTH_FAILURE")); | |
89 TRACE(("enter recv_msg_userauth_failure")); | |
90 | |
91 methods = buf_getstring(ses.payload, &methlen); | |
92 | |
93 partial = buf_getbyte(ses.payload); | |
94 | |
95 if (partial) { | |
96 dropbear_log(LOG_INFO, "Authentication partially succeeded, more attempts required"); | |
97 } else { | |
98 ses.authstate.failcount++; | |
99 } | |
100 | |
101 TRACE(("Methods (len %d): '%s'", methlen, methods)); | |
102 | |
103 ses.authstate.authdone=0; | |
104 ses.authstate.authtypes=0; | |
105 | |
106 /* Split with nulls rather than commas */ | |
107 for (i = 0; i < methlen; i++) { | |
108 if (methods[i] == ',') { | |
109 methods[i] = '\0'; | |
110 } | |
111 } | |
112 | |
113 tok = methods; /* tok stores the next method we'll compare */ | |
114 for (i = 0; i <= methlen; i++) { | |
115 if (methods[i] == '\0') { | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
116 TRACE(("auth method '%s'", tok)); |
33 | 117 #ifdef DROPBEAR_PUBKEY_AUTH |
118 if (strncmp(AUTH_METHOD_PUBKEY, tok, | |
119 AUTH_METHOD_PUBKEY_LEN) == 0) { | |
120 ses.authstate.authtypes |= AUTH_TYPE_PUBKEY; | |
121 } | |
122 #endif | |
123 #ifdef DROPBEAR_PASSWORD_AUTH | |
124 if (strncmp(AUTH_METHOD_PASSWORD, tok, | |
125 AUTH_METHOD_PASSWORD_LEN) == 0) { | |
126 ses.authstate.authtypes |= AUTH_TYPE_PASSWORD; | |
127 } | |
128 #endif | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
129 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
|
130 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
|
131 undefined */ |
33 | 132 } |
133 } | |
134 | |
135 cli_ses.state = USERAUTH_FAIL_RCVD; | |
136 | |
137 TRACE(("leave recv_msg_userauth_failure")); | |
138 } | |
139 | |
140 void recv_msg_userauth_success() { | |
141 TRACE(("received msg_userauth_success")); | |
142 ses.authstate.authdone = 1; | |
37 | 143 cli_ses.state = USERAUTH_SUCCESS_RCVD; |
33 | 144 } |
145 | |
146 void cli_auth_try() { | |
147 | |
148 TRACE(("enter cli_auth_try")); | |
149 int finished = 0; | |
150 | |
151 CHECKCLEARTOWRITE(); | |
152 | |
153 /* XXX We hardcode that we try a pubkey first */ | |
154 #ifdef DROPBEAR_PUBKEY_AUTH | |
155 if (ses.authstate.authtypes & AUTH_TYPE_PUBKEY) { | |
156 finished = cli_auth_pubkey(); | |
157 } | |
158 #endif | |
159 | |
160 #ifdef DROPBEAR_PASSWORD_AUTH | |
161 if (!finished && ses.authstate.authtypes & AUTH_TYPE_PASSWORD) { | |
162 finished = cli_auth_password(); | |
163 } | |
164 #endif | |
165 | |
166 if (!finished) { | |
167 dropbear_exit("No auth methods could be used."); | |
168 } | |
169 | |
170 cli_ses.state = USERAUTH_REQ_SENT; | |
171 TRACE(("leave cli_auth_try")); | |
172 } |