diff options
author | Matt Johnston <matt@ucc.asn.au> | 2006-12-06 13:11:41 +0000 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2006-12-06 13:11:41 +0000 |
commit | d5897b9a5d461c91cd525e5b2212125cf53ad268 (patch) | |
tree | cec78b43140a2610175f8e918ae22bfff0bbdf1f /dbutil.c | |
parent | 7b780efb42e3d9b369b4f00421fba1fc21ec2a22 (diff) | |
parent | 35bcc463e5ffe2f630c71962ca12d69a84952568 (diff) |
merge of '182c2d8dbd5321ef4d1df8758936f4dc7127015f'
and '31dcd7a22983ef19d6c63248e415e71d292dd0ec'
--HG--
extra : convert_revision : e84f66826c7ee6ebe99ef92cc0f6c22ecf638d01
Diffstat (limited to 'dbutil.c')
-rw-r--r-- | dbutil.c | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -400,7 +400,10 @@ unsigned char * getaddrstring(struct sockaddr_storage* addr, int withport) { len = sizeof(struct sockaddr_storage); /* Some platforms such as Solaris 8 require that len is the length - * of the specific structure. */ + * of the specific structure. Some older linux systems (glibc 2.1.3 + * such as debian potato) have sockaddr_storage.__ss_family instead + * but we'll ignore them */ +#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY if (addr->ss_family == AF_INET) { len = sizeof(struct sockaddr_in); } @@ -409,6 +412,7 @@ unsigned char * getaddrstring(struct sockaddr_storage* addr, int withport) { len = sizeof(struct sockaddr_in6); } #endif +#endif ret = getnameinfo((struct sockaddr*)addr, len, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICSERV | NI_NUMERICHOST); @@ -448,6 +452,7 @@ char* getaddrhostname(struct sockaddr_storage * addr) { len = sizeof(struct sockaddr_storage); /* Some platforms such as Solaris 8 require that len is the length * of the specific structure. */ +#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY if (addr->ss_family == AF_INET) { len = sizeof(struct sockaddr_in); } @@ -456,6 +461,7 @@ char* getaddrhostname(struct sockaddr_storage * addr) { len = sizeof(struct sockaddr_in6); } #endif +#endif ret = getnameinfo((struct sockaddr*)addr, len, hbuf, sizeof(hbuf), @@ -521,26 +527,36 @@ char * stripcontrol(const char * text) { * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ int buf_readfile(buffer* buf, const char* filename) { - int fd; + int fd = -1; int len; int maxlen; + int ret = DROPBEAR_FAILURE; fd = open(filename, O_RDONLY); if (fd < 0) { - close(fd); - return DROPBEAR_FAILURE; + goto out; } do { maxlen = buf->size - buf->pos; - len = read(fd, buf_getwriteptr(buf, maxlen), - maxlen); + len = read(fd, buf_getwriteptr(buf, maxlen), maxlen); + if (len < 0) { + if (errno == EINTR || errno == EAGAIN) { + continue; + } + goto out; + } buf_incrwritepos(buf, len); } while (len < maxlen && len > 0); - close(fd); - return DROPBEAR_SUCCESS; + ret = DROPBEAR_SUCCESS; + +out: + if (fd >= 0) { + m_close(fd); + } + return ret; } /* get a line from the file into buffer in the style expected for an |