From 422f4f2b41e9623af73f2ab69e4ab2ed8098551c Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 8 Mar 2006 12:41:27 +0000 Subject: * Per-IP connection unauthed connection limits * m_close() exits fatally on failure * other cleanups --HG-- extra : convert_revision : bed6155e95a293c9fce7e889d283b5958f3035dc --- dbutil.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'dbutil.c') diff --git a/dbutil.c b/dbutil.c index 696bac3..15f51ba 100644 --- a/dbutil.c +++ b/dbutil.c @@ -588,20 +588,17 @@ out: } #endif -/* loop until the socket is closed (in case of EINTR) or - * we get and error. - * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ -int m_close(int fd) { +/* make sure that the socket closes */ +void m_close(int fd) { int val; do { val = close(fd); } while (val < 0 && errno == EINTR); - if (val == 0 || errno == EBADF) { - return DROPBEAR_SUCCESS; - } else { - return DROPBEAR_FAILURE; + if (val < 0 && errno != EBADF) { + /* Linux says EIO can happen */ + dropbear_exit("Error closing fd %d, %s", fd, strerror(errno)); } } -- cgit v1.2.3 From ac2b546a13a466218d56245ee4b26931b00ad258 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Mon, 12 Jun 2006 15:57:14 +0000 Subject: Another stab at getting ss_family happy on older glibc --HG-- extra : convert_revision : 7a1e9b08a576d794c28275e1bf54cb603372a4a6 --- configure.in | 4 +++- dbutil.c | 8 +++++++- includes.h | 7 ------- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'dbutil.c') diff --git a/configure.in b/configure.in index 571c457..5c5a455 100644 --- a/configure.in +++ b/configure.in @@ -342,7 +342,7 @@ AC_CHECK_MEMBERS([struct utmp.ut_host, struct utmp.ut_pid, struct utmp.ut_type, #endif ]) -AC_CHECK_MEMBERS([struct utmpx.ut_host, struct utmpx.ut_syslen, struct utmpx.ut_type, struct utmpx.ut_id, struct utmpx.ut_addr, struct utmpx.ut_addr_v6, struct utmpx.ut_time, struct utmpx.ut_tv, struct sockaddr_storage.ss_family, struct sockadd_storage.__family],,,[ +AC_CHECK_MEMBERS([struct utmpx.ut_host, struct utmpx.ut_syslen, struct utmpx.ut_type, struct utmpx.ut_id, struct utmpx.ut_addr, struct utmpx.ut_addr_v6, struct utmpx.ut_time, struct utmpx.ut_tv],,,[ #include #include #if HAVE_UTMPX_H @@ -350,6 +350,8 @@ AC_CHECK_MEMBERS([struct utmpx.ut_host, struct utmpx.ut_syslen, struct utmpx.ut_ #endif ]) +AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],,,[]) + AC_CHECK_FUNCS(endutent getutent getutid getutline pututline setutent) AC_CHECK_FUNCS(utmpname) AC_CHECK_FUNCS(endutxent getutxent getutxid getutxline pututxline ) diff --git a/dbutil.c b/dbutil.c index 15f51ba..9f4e8b7 100644 --- a/dbutil.c +++ b/dbutil.c @@ -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); } @@ -408,6 +411,7 @@ unsigned char * getaddrstring(struct sockaddr_storage* addr, int withport) { if (addr->ss_family == AF_INET6) { len = sizeof(struct sockaddr_in6); } +#endif #endif ret = getnameinfo((struct sockaddr*)addr, len, hbuf, sizeof(hbuf), @@ -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), diff --git a/includes.h b/includes.h index 06c9692..02e8877 100644 --- a/includes.h +++ b/includes.h @@ -135,13 +135,6 @@ typedef u_int16_t uint16_t; #define LOG_AUTHPRIV LOG_AUTH #endif -/* glibc 2.1.3 systems have sockaddr_storage.__ss_family rather than - * sockaddr_storage.ss_family */ -#if !defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY) \ - && defined(HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY) -#define ss_family __ss_family -#endif - /* so we can avoid warnings about unused params (ie in signal handlers etc) */ #ifdef UNUSED #elif defined(__GNUC__) -- cgit v1.2.3 From 14a790891fe6179e1577213978264f84cd428c75 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sun, 20 Aug 2006 12:16:13 +0000 Subject: Handle failure reading a file (such as a key file) --HG-- extra : convert_revision : 3219ab5642c86615c6ffb30eb93f573a73415d2f --- dbutil.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'dbutil.c') diff --git a/dbutil.c b/dbutil.c index 9f4e8b7..52d9008 100644 --- a/dbutil.c +++ b/dbutil.c @@ -527,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; + 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 -- cgit v1.2.3 From 33a182674a8c8735c17e627984bf49562aeb1370 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Mon, 11 Sep 2006 11:22:52 +0000 Subject: Forgot variable declaration. --HG-- extra : convert_revision : 08a0ab6d3e7efefaa07f3d428e9fe8a503f670ac --- dbutil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dbutil.c') diff --git a/dbutil.c b/dbutil.c index 52d9008..9445f0e 100644 --- a/dbutil.c +++ b/dbutil.c @@ -530,7 +530,7 @@ int buf_readfile(buffer* buf, const char* filename) { int fd = -1; int len; int maxlen; - ret = DROPBEAR_FAILURE; + int ret = DROPBEAR_FAILURE; fd = open(filename, O_RDONLY); -- cgit v1.2.3