Mercurial > dropbear
comparison dbutil.c @ 378:a124aff0cbf1
merge of '182c2d8dbd5321ef4d1df8758936f4dc7127015f'
and '31dcd7a22983ef19d6c63248e415e71d292dd0ec'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 06 Dec 2006 13:11:41 +0000 |
parents | e81d3bc1dc78 |
children | b895f91c2ee6 |
comparison
equal
deleted
inserted
replaced
377:1bfa65fed772 | 378:a124aff0cbf1 |
---|---|
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.*/ |