Mercurial > dropbear
comparison dbutil.c @ 478:d4f32c3443ac dbclient-netcat-alike
propagate from branch 'au.asn.ucc.matt.dropbear' (head f21045c791002d81fc6b8dde6537ea481e513eb2)
to branch 'au.asn.ucc.matt.dropbear.dbclient-netcat-alike' (head d1f69334581dc4c35f9ca16aa5355074c9dd315d)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 14 Sep 2008 06:47:51 +0000 |
parents | c216212001fc |
children | c1e9c81d1d27 357a2e2e9bcc 12d845ab7b5f |
comparison
equal
deleted
inserted
replaced
296:6b41e2cbf071 | 478:d4f32c3443ac |
---|---|
197 | 197 |
198 memset(&hints, 0, sizeof(hints)); | 198 memset(&hints, 0, sizeof(hints)); |
199 hints.ai_family = AF_UNSPEC; /* TODO: let them flag v4 only etc */ | 199 hints.ai_family = AF_UNSPEC; /* TODO: let them flag v4 only etc */ |
200 hints.ai_socktype = SOCK_STREAM; | 200 hints.ai_socktype = SOCK_STREAM; |
201 | 201 |
202 // for calling getaddrinfo: | 202 /* for calling getaddrinfo: |
203 // address == NULL and !AI_PASSIVE: local loopback | 203 address == NULL and !AI_PASSIVE: local loopback |
204 // address == NULL and AI_PASSIVE: all interfaces | 204 address == NULL and AI_PASSIVE: all interfaces |
205 // address != NULL: whatever the address says | 205 address != NULL: whatever the address says */ |
206 if (!address) { | 206 if (!address) { |
207 TRACE(("dropbear_listen: local loopback")) | 207 TRACE(("dropbear_listen: local loopback")) |
208 } else { | 208 } else { |
209 if (address[0] == '\0') { | 209 if (address[0] == '\0') { |
210 TRACE(("dropbear_listen: all interfaces")) | 210 TRACE(("dropbear_listen: all interfaces")) |
284 if (errstring != NULL && *errstring == NULL) { | 284 if (errstring != NULL && *errstring == NULL) { |
285 int len; | 285 int len; |
286 len = 20 + strlen(strerror(err)); | 286 len = 20 + strlen(strerror(err)); |
287 *errstring = (char*)m_malloc(len); | 287 *errstring = (char*)m_malloc(len); |
288 snprintf(*errstring, len, "Error listening: %s", strerror(err)); | 288 snprintf(*errstring, len, "Error listening: %s", strerror(err)); |
289 TRACE(("leave dropbear_listen: failure, %s", strerror(err))) | 289 } |
290 return -1; | 290 TRACE(("leave dropbear_listen: failure, %s", strerror(err))) |
291 } | 291 return -1; |
292 } | 292 } |
293 | 293 |
294 TRACE(("leave dropbear_listen: success, %d socks bound", nsock)) | 294 TRACE(("leave dropbear_listen: success, %d socks bound", nsock)) |
295 return nsock; | 295 return nsock; |
296 } | 296 } |
398 int ret; | 398 int ret; |
399 unsigned int len; | 399 unsigned int len; |
400 | 400 |
401 len = sizeof(struct sockaddr_storage); | 401 len = sizeof(struct sockaddr_storage); |
402 /* Some platforms such as Solaris 8 require that len is the length | 402 /* Some platforms such as Solaris 8 require that len is the length |
403 * of the specific structure. */ | 403 * of the specific structure. Some older linux systems (glibc 2.1.3 |
404 * such as debian potato) have sockaddr_storage.__ss_family instead | |
405 * but we'll ignore them */ | |
406 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY | |
404 if (addr->ss_family == AF_INET) { | 407 if (addr->ss_family == AF_INET) { |
405 len = sizeof(struct sockaddr_in); | 408 len = sizeof(struct sockaddr_in); |
406 } | 409 } |
407 #ifdef AF_INET6 | 410 #ifdef AF_INET6 |
408 if (addr->ss_family == AF_INET6) { | 411 if (addr->ss_family == AF_INET6) { |
409 len = sizeof(struct sockaddr_in6); | 412 len = sizeof(struct sockaddr_in6); |
410 } | 413 } |
414 #endif | |
411 #endif | 415 #endif |
412 | 416 |
413 ret = getnameinfo((struct sockaddr*)addr, len, hbuf, sizeof(hbuf), | 417 ret = getnameinfo((struct sockaddr*)addr, len, hbuf, sizeof(hbuf), |
414 sbuf, sizeof(sbuf), NI_NUMERICSERV | NI_NUMERICHOST); | 418 sbuf, sizeof(sbuf), NI_NUMERICSERV | NI_NUMERICHOST); |
415 | 419 |
446 #endif | 450 #endif |
447 | 451 |
448 len = sizeof(struct sockaddr_storage); | 452 len = sizeof(struct sockaddr_storage); |
449 /* Some platforms such as Solaris 8 require that len is the length | 453 /* Some platforms such as Solaris 8 require that len is the length |
450 * of the specific structure. */ | 454 * of the specific structure. */ |
455 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY | |
451 if (addr->ss_family == AF_INET) { | 456 if (addr->ss_family == AF_INET) { |
452 len = sizeof(struct sockaddr_in); | 457 len = sizeof(struct sockaddr_in); |
453 } | 458 } |
454 #ifdef AF_INET6 | 459 #ifdef AF_INET6 |
455 if (addr->ss_family == AF_INET6) { | 460 if (addr->ss_family == AF_INET6) { |
456 len = sizeof(struct sockaddr_in6); | 461 len = sizeof(struct sockaddr_in6); |
457 } | 462 } |
463 #endif | |
458 #endif | 464 #endif |
459 | 465 |
460 | 466 |
461 ret = getnameinfo((struct sockaddr*)addr, len, hbuf, sizeof(hbuf), | 467 ret = getnameinfo((struct sockaddr*)addr, len, hbuf, sizeof(hbuf), |
462 sbuf, sizeof(sbuf), flags); | 468 sbuf, sizeof(sbuf), flags); |
519 /* reads the contents of filename into the buffer buf, from the current | 525 /* reads the contents of filename into the buffer buf, from the current |
520 * position, either to the end of the file, or the buffer being full. | 526 * position, either to the end of the file, or the buffer being full. |
521 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ | 527 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ |
522 int buf_readfile(buffer* buf, const char* filename) { | 528 int buf_readfile(buffer* buf, const char* filename) { |
523 | 529 |
524 int fd; | 530 int fd = -1; |
525 int len; | 531 int len; |
526 int maxlen; | 532 int maxlen; |
533 int ret = DROPBEAR_FAILURE; | |
527 | 534 |
528 fd = open(filename, O_RDONLY); | 535 fd = open(filename, O_RDONLY); |
529 | 536 |
530 if (fd < 0) { | 537 if (fd < 0) { |
531 close(fd); | 538 goto out; |
532 return DROPBEAR_FAILURE; | |
533 } | 539 } |
534 | 540 |
535 do { | 541 do { |
536 maxlen = buf->size - buf->pos; | 542 maxlen = buf->size - buf->pos; |
537 len = read(fd, buf_getwriteptr(buf, maxlen), | 543 len = read(fd, buf_getwriteptr(buf, maxlen), maxlen); |
538 maxlen); | 544 if (len < 0) { |
545 if (errno == EINTR || errno == EAGAIN) { | |
546 continue; | |
547 } | |
548 goto out; | |
549 } | |
539 buf_incrwritepos(buf, len); | 550 buf_incrwritepos(buf, len); |
540 } while (len < maxlen && len > 0); | 551 } while (len < maxlen && len > 0); |
541 | 552 |
542 close(fd); | 553 ret = DROPBEAR_SUCCESS; |
543 return DROPBEAR_SUCCESS; | 554 |
555 out: | |
556 if (fd >= 0) { | |
557 m_close(fd); | |
558 } | |
559 return ret; | |
544 } | 560 } |
545 | 561 |
546 /* get a line from the file into buffer in the style expected for an | 562 /* get a line from the file into buffer in the style expected for an |
547 * authkeys file. | 563 * authkeys file. |
548 * Will return DROPBEAR_SUCCESS if data is read, or DROPBEAR_FAILURE on EOF.*/ | 564 * Will return DROPBEAR_SUCCESS if data is read, or DROPBEAR_FAILURE on EOF.*/ |
675 dropbear_exit("Couldn't set nonblocking"); | 691 dropbear_exit("Couldn't set nonblocking"); |
676 } | 692 } |
677 } | 693 } |
678 TRACE(("leave setnonblocking")) | 694 TRACE(("leave setnonblocking")) |
679 } | 695 } |
696 | |
697 void disallow_core() { | |
698 struct rlimit lim; | |
699 lim.rlim_cur = lim.rlim_max = 0; | |
700 setrlimit(RLIMIT_CORE, &lim); | |
701 } |