Mercurial > dropbear
comparison common-session.c @ 165:0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 02 Jan 2005 20:25:56 +0000 |
parents | d663445c1533 |
children | 581f81e8c50c c5d3ef11155f |
comparison
equal
deleted
inserted
replaced
161:b9d3f725e00b | 165:0cfba3034be5 |
---|---|
50 | 50 |
51 | 51 |
52 /* called only at the start of a session, set up initial state */ | 52 /* called only at the start of a session, set up initial state */ |
53 void common_session_init(int sock, char* remotehost) { | 53 void common_session_init(int sock, char* remotehost) { |
54 | 54 |
55 TRACE(("enter session_init")); | 55 TRACE(("enter session_init")) |
56 | 56 |
57 ses.remotehost = remotehost; | 57 ses.remotehost = remotehost; |
58 | 58 |
59 ses.sock = sock; | 59 ses.sock = sock; |
60 ses.maxfd = sock; | 60 ses.maxfd = sock; |
108 ses.chantypes = NULL; | 108 ses.chantypes = NULL; |
109 | 109 |
110 ses.allowprivport = 0; | 110 ses.allowprivport = 0; |
111 | 111 |
112 | 112 |
113 TRACE(("leave session_init")); | 113 TRACE(("leave session_init")) |
114 } | 114 } |
115 | 115 |
116 void session_loop(void(*loophandler)()) { | 116 void session_loop(void(*loophandler)()) { |
117 | 117 |
118 fd_set readfd, writefd; | 118 fd_set readfd, writefd; |
160 /* check for auth timeout, rekeying required etc */ | 160 /* check for auth timeout, rekeying required etc */ |
161 checktimeouts(); | 161 checktimeouts(); |
162 | 162 |
163 if (val == 0) { | 163 if (val == 0) { |
164 /* timeout */ | 164 /* timeout */ |
165 TRACE(("select timeout")); | 165 TRACE(("select timeout")) |
166 continue; | 166 continue; |
167 } | 167 } |
168 | 168 |
169 /* process session socket's incoming/outgoing data */ | 169 /* process session socket's incoming/outgoing data */ |
170 if (ses.sock != -1) { | 170 if (ses.sock != -1) { |
199 } | 199 } |
200 | 200 |
201 /* clean up a session on exit */ | 201 /* clean up a session on exit */ |
202 void common_session_cleanup() { | 202 void common_session_cleanup() { |
203 | 203 |
204 TRACE(("enter session_cleanup")); | 204 TRACE(("enter session_cleanup")) |
205 | 205 |
206 /* we can't cleanup if we don't know the session state */ | 206 /* we can't cleanup if we don't know the session state */ |
207 if (!sessinitdone) { | 207 if (!sessinitdone) { |
208 TRACE(("leave session_cleanup: !sessinitdone")); | 208 TRACE(("leave session_cleanup: !sessinitdone")) |
209 return; | 209 return; |
210 } | 210 } |
211 | 211 |
212 m_free(ses.session_id); | 212 m_free(ses.session_id); |
213 m_burn(ses.keys, sizeof(struct key_context)); | 213 m_burn(ses.keys, sizeof(struct key_context)); |
214 m_free(ses.keys); | 214 m_free(ses.keys); |
215 | 215 |
216 chancleanup(); | 216 chancleanup(); |
217 | 217 |
218 TRACE(("leave session_cleanup")); | 218 TRACE(("leave session_cleanup")) |
219 } | 219 } |
220 | 220 |
221 | 221 |
222 void session_identification() { | 222 void session_identification() { |
223 | 223 |
250 break; | 250 break; |
251 } | 251 } |
252 } | 252 } |
253 | 253 |
254 if (!done) { | 254 if (!done) { |
255 TRACE(("err: %s for '%s'\n", strerror(errno), linebuf)); | 255 TRACE(("err: %s for '%s'\n", strerror(errno), linebuf)) |
256 dropbear_exit("Failed to get remote version"); | 256 dropbear_exit("Failed to get remote version"); |
257 } else { | 257 } else { |
258 /* linebuf is already null terminated */ | 258 /* linebuf is already null terminated */ |
259 ses.remoteident = m_malloc(len); | 259 ses.remoteident = m_malloc(len); |
260 memcpy(ses.remoteident, linebuf, len); | 260 memcpy(ses.remoteident, linebuf, len); |
261 } | 261 } |
262 | 262 |
263 TRACE(("remoteident: %s", ses.remoteident)); | 263 TRACE(("remoteident: %s", ses.remoteident)) |
264 | 264 |
265 } | 265 } |
266 | 266 |
267 /* returns the length including null-terminating zero on success, | 267 /* returns the length including null-terminating zero on success, |
268 * or -1 on failure */ | 268 * or -1 on failure */ |
272 int pos = 0; | 272 int pos = 0; |
273 int num = 0; | 273 int num = 0; |
274 fd_set fds; | 274 fd_set fds; |
275 struct timeval timeout; | 275 struct timeval timeout; |
276 | 276 |
277 TRACE(("enter ident_readln")); | 277 TRACE(("enter ident_readln")) |
278 | 278 |
279 if (count < 1) { | 279 if (count < 1) { |
280 return -1; | 280 return -1; |
281 } | 281 } |
282 | 282 |
293 timeout.tv_usec = 0; | 293 timeout.tv_usec = 0; |
294 if (select(fd+1, &fds, NULL, NULL, &timeout) < 0) { | 294 if (select(fd+1, &fds, NULL, NULL, &timeout) < 0) { |
295 if (errno == EINTR) { | 295 if (errno == EINTR) { |
296 continue; | 296 continue; |
297 } | 297 } |
298 TRACE(("leave ident_readln: select error")); | 298 TRACE(("leave ident_readln: select error")) |
299 return -1; | 299 return -1; |
300 } | 300 } |
301 | 301 |
302 checktimeouts(); | 302 checktimeouts(); |
303 | 303 |
311 if (num < 0) { | 311 if (num < 0) { |
312 /* error */ | 312 /* error */ |
313 if (errno == EINTR) { | 313 if (errno == EINTR) { |
314 continue; /* not a real error */ | 314 continue; /* not a real error */ |
315 } | 315 } |
316 TRACE(("leave ident_readln: read error")); | 316 TRACE(("leave ident_readln: read error")) |
317 return -1; | 317 return -1; |
318 } | 318 } |
319 if (num == 0) { | 319 if (num == 0) { |
320 /* EOF */ | 320 /* EOF */ |
321 TRACE(("leave ident_readln: EOF")); | 321 TRACE(("leave ident_readln: EOF")) |
322 return -1; | 322 return -1; |
323 } | 323 } |
324 if (in == '\n') { | 324 if (in == '\n') { |
325 /* end of ident string */ | 325 /* end of ident string */ |
326 break; | 326 break; |
332 } | 332 } |
333 } | 333 } |
334 } | 334 } |
335 | 335 |
336 buf[pos] = '\0'; | 336 buf[pos] = '\0'; |
337 TRACE(("leave ident_readln: return %d", pos+1)); | 337 TRACE(("leave ident_readln: return %d", pos+1)) |
338 return pos+1; | 338 return pos+1; |
339 } | 339 } |
340 | 340 |
341 /* Check all timeouts which are required. Currently these are the time for | 341 /* Check all timeouts which are required. Currently these are the time for |
342 * user authentication, and the automatic rekeying. */ | 342 * user authentication, and the automatic rekeying. */ |
361 } | 361 } |
362 | 362 |
363 if (!ses.kexstate.sentkexinit | 363 if (!ses.kexstate.sentkexinit |
364 && (secs - ses.kexstate.lastkextime >= KEX_REKEY_TIMEOUT | 364 && (secs - ses.kexstate.lastkextime >= KEX_REKEY_TIMEOUT |
365 || ses.kexstate.datarecv+ses.kexstate.datatrans >= KEX_REKEY_DATA)){ | 365 || ses.kexstate.datarecv+ses.kexstate.datatrans >= KEX_REKEY_DATA)){ |
366 TRACE(("rekeying after timeout or max data reached")); | 366 TRACE(("rekeying after timeout or max data reached")) |
367 send_msg_kexinit(); | 367 send_msg_kexinit(); |
368 } | 368 } |
369 } | 369 } |
370 | 370 |