From b6cd3d6470f2d5a0f4c533865d8683489e17c1aa Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Mon, 11 Jan 2010 08:07:30 +0200 Subject: [PATCH] --- include/bouncer.h | 1 + include/system.h | 26 -------------------------- include/util.h | 1 - src/system.c | 44 -------------------------------------------- src/util.c | 45 +++++---------------------------------------- 5 files changed, 6 insertions(+), 111 deletions(-) diff --git a/include/bouncer.h b/include/bouncer.h index 441dee0..b415ced 100644 --- a/include/bouncer.h +++ b/include/bouncer.h @@ -30,6 +30,7 @@ #include #include #include +#include #include diff --git a/include/system.h b/include/system.h index beb7d0f..ced43b8 100644 --- a/include/system.h +++ b/include/system.h @@ -28,26 +28,6 @@ #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif -#ifdef HAVE_SYS_UN_H -#include -#endif -#ifdef HAVE_NETINET_IN_H -#include -#endif -#ifdef HAVE_NETINET_TCP_H -#include -#endif -#ifdef HAVE_ARPA_INET_H -#include -#endif -#ifdef HAVE_ARPA_INET_H -#include -#endif - -#include #include #include #include @@ -103,15 +83,9 @@ * libc compat functions. */ -#ifndef HAVE_GETPEEREID -int getpeereid(int fd, uid_t *uid_p, gid_t *gid_p) _MUSTCHECK; -#endif #ifndef HAVE_CRYPT static inline char *crypt(const char *p, const char *s) { return NULL; } #endif -#ifndef HAVE_INET_NTOP -const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); -#endif #ifndef HAVE_LSTAT static inline int lstat(const char *path, struct stat *st) { return stat(path, st); } #endif diff --git a/include/util.h b/include/util.h index 7f5f835..4bbc91c 100644 --- a/include/util.h +++ b/include/util.h @@ -60,7 +60,6 @@ int safe_accept(int fd, struct sockaddr *sa, socklen_t *sa_len) _MUSTCHECK; void pg_md5_encrypt(const char *part1, const char *part2, size_t p2len, char *dest); void get_random_bytes(uint8_t *dest, int len); -void socket_set_nonblocking(int fd, int val); void tune_socket(int sock, bool is_unix); bool strlist_contains(const char *liststr, const char *str); diff --git a/src/system.c b/src/system.c index abf92c2..8447495 100644 --- a/src/system.c +++ b/src/system.c @@ -38,38 +38,6 @@ #include #endif -/* - * Get other side's uid for UNIX socket. - * - * Standardise on getpeereid() from BSDs. - */ -#ifndef HAVE_GETPEEREID -int getpeereid(int fd, uid_t *uid_p, gid_t *gid_p) -{ -#ifdef SO_PEERCRED - struct ucred cred; - socklen_t len = sizeof(cred); - if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) >= 0) { - *uid_p = cred.uid; - *gid_p = cred.gid; - return 0; - } -#else /* !SO_PEERCRED */ -#ifdef HAVE_GETPEERUCRED - ucred_t *cred = NULL; - if (getpeerucred(fd, &cred) >= 0) { - *uid_p = ucred_geteuid(cred); - *gid_p = ucred_getegid(cred); - ucred_free(cred); - if (*uid_p >= 0 && *gid_p >= 0) - return 0; - } -#endif /* HAVE_GETPEERUCRED */ -#endif /* !SO_PEERCRED */ - return -1; -} -#endif /* !HAVE_GETPEEREID */ - void change_user(const char *user) { const struct passwd *pw; @@ -93,15 +61,3 @@ void change_user(const char *user) fatal("setuid() failed to work"); } -#ifndef HAVE_INET_NTOP -const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) -{ - const unsigned char *p = src; - if (af != AF_INET) - return NULL; - snprintf(dst, cnt, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); - return dst; -} -#endif - - diff --git a/src/util.c b/src/util.c index 1633456..3e3a588 100644 --- a/src/util.c +++ b/src/util.c @@ -164,39 +164,25 @@ loop: return res; } -static const char *sa2str(const struct sockaddr *sa) -{ - static char buf[256]; - - if (sa->sa_family == AF_INET) { - struct sockaddr_in *in = (struct sockaddr_in *)sa; - snprintf(buf, sizeof(buf), "%s:%d", inet_ntoa(in->sin_addr), ntohs(in->sin_port)); - } if (sa->sa_family == AF_UNIX) { - struct sockaddr_un *un = (struct sockaddr_un *)sa; - snprintf(buf, sizeof(buf), "unix:%s", un->sun_path); - } else { - snprintf(buf, sizeof(buf), "sa2str: unknown proto"); - } - return buf; -} - int safe_connect(int fd, const struct sockaddr *sa, socklen_t sa_len) { int res; + char buf[128]; loop: res = connect(fd, sa, sa_len); if (res < 0 && errno == EINTR) goto loop; if (res < 0 && (errno != EINPROGRESS || cf_verbose > 2)) - log_noise("connect(%d, %s) = %s", fd, sa2str(sa), strerror(errno)); + log_noise("connect(%d, %s) = %s", fd, sa2str(sa, buf, sizeof(buf)), strerror(errno)); else if (cf_verbose > 2) - log_noise("connect(%d, %s) = %d", fd, sa2str(sa), res); + log_noise("connect(%d, %s) = %d", fd, sa2str(sa, buf, sizeof(buf)), res); return res; } int safe_accept(int fd, struct sockaddr *sa, socklen_t *sa_len_p) { int res; + char buf[128]; loop: res = accept(fd, sa, sa_len_p); if (res < 0 && errno == EINTR) @@ -204,7 +190,7 @@ loop: if (res < 0) log_noise("safe_accept(%d) = %s", fd, strerror(errno)); else if (cf_verbose > 2) - log_noise("safe_accept(%d) = %d (%s)", fd, res, sa2str(sa)); + log_noise("safe_accept(%d) = %d (%s)", fd, res, sa2str(sa, buf, sizeof(buf))); return res; } @@ -290,27 +276,6 @@ void get_random_bytes(uint8_t *dest, int len) dest[i] = random() & 255; } -void socket_set_nonblocking(int fd, int val) -{ - int flags, res; - - /* get old flags */ - flags = fcntl(fd, F_GETFL, 0); - if (flags < 0) - fatal_perror("fcntl(F_GETFL)"); - - /* flip O_NONBLOCK */ - if (val) - flags |= O_NONBLOCK; - else - flags &= ~O_NONBLOCK; - - /* set new flags */ - res = fcntl(fd, F_SETFL, flags); - if (res < 0) - fatal_perror("fcntl(F_SETFL)"); -} - /* set needed socket options */ void tune_socket(int sock, bool is_unix) { -- 2.40.0