From 97c1bc1b3cb16224315db59268f64025cc00d172 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 2 Jun 2012 01:23:02 +0100 Subject: [PATCH] wip about to undo --- authbind.h | 10 ++++++++++ helper.c | 14 +++++++++----- libauthbind.c | 4 +--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/authbind.h b/authbind.h index 3911c08..94abaa0 100644 --- a/authbind.h +++ b/authbind.h @@ -30,8 +30,18 @@ # define HELPER "/usr/local/lib/authbind/helper" #endif +#ifndef CONFIGDIR +# define CONFIGDIR "/etc/authbind" +#endif + #define PRELOAD_VAR "LD_PRELOAD" #define AUTHBINDLIB_VAR "AUTHBIND_LIB" #define AUTHBIND_LEVELS_VAR "AUTHBIND_LEVELS" +static inline void bytes2hex(const unsigned char *in, char *out, size_t len) { + size_t i; + for (i=0; i<16; i++) + sprintf(out+i*2,"%02x", in[i]); +} + #endif diff --git a/helper.c b/helper.c index cc4efe2..9e8ab86 100644 --- a/helper.c +++ b/helper.c @@ -30,9 +30,7 @@ #include #include -#ifndef CONFIGDIR -# define CONFIGDIR "/etc/authbind" -#endif +#include "authbind.h" static void exiterrno(int e) { exit(e>0 && e<128 ? e : ENOSYS); @@ -138,15 +136,21 @@ int main(int argc, const char *const *argv) { assert(np); if (af == AF_INET) { - snprintf(fnbuf,sizeof(fnbuf)-1,"byaddr/%s%s:%u",np,tophalfchar,hport); + snprintf(fnbuf,sizeof(fnbuf)-1,"byaddr/%s%s:%u",tophalfchar,np,hport); if (!access(fnbuf,X_OK)) authorised(); if (errno != ENOENT) exiterrno(errno); } - snprintf(fnbuf,sizeof(fnbuf)-1,"byaddr/%s%s,%u",np,tophalfchar,hport); + snprintf(fnbuf,sizeof(fnbuf)-1,"byaddr/%s%s,%u",tophalfchar,np,hport); if (!access(fnbuf,X_OK)) authorised(); if (errno != ENOENT) exiterrno(errno); + if (af == AF_INET6) { + char sbuf[addrlen_any*2+1]; + bytes2hex(addr_any,sbuf,addrlen_any); + snprintf(fnbuf,sizeof(fnbuf)-1,"byaddr/%s%s,%u",tophalfchar,sbuf,hport); + } + uid= getuid(); if (uid==(uid_t)-1) perrorfail("getuid"); snprintf(fnbuf,sizeof(fnbuf)-1,"byuid/%s%lu",tophalfchar,(unsigned long)uid); diff --git a/libauthbind.c b/libauthbind.c index a685ce3..03905e4 100644 --- a/libauthbind.c +++ b/libauthbind.c @@ -185,9 +185,7 @@ int bind(int fd, const struct sockaddr *addr, socklen_t addrlen) { break; case AF_INET6: afarg = "6"; - for (i=0; i<16; i++) - sprintf(addrarg+i*2,"%02x", - ((struct sockaddr_in6*)addr)->sin6_addr.s6_addr[i]); + bytes2hex(((struct sockaddr_in6*)addr)->sin6_addr.s6_addr, addrarg, 16); break; default: abort(); -- 2.30.2