diff --git a/Makefile b/Makefile index 9df28d9..9ac6daa 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ STRIP ?= strip # from loading the libauthbind.dylib library if that library is only built # for e.g. the x86_64 arch. ARCH=-arch i386 -arch x86_64 -OSX_CFLAGS=-flat_namespace +OSX_CFLAGS= OSX_LDFLAGS=$(ARCH) -dynamiclib -dynamic -flat_namespace OPTIMISE=-O2 diff --git a/helper.c b/helper.c index c4c3d16..948d048 100644 --- a/helper.c +++ b/helper.c @@ -55,7 +55,7 @@ static struct sockaddr_in saddr; static void authorised(void) { if (bind(0, (struct sockaddr *) &saddr, sizeof(saddr))) { - perrorfail("libauthbind's helper: bind() failed"); + perrorfail("bind() failed"); } else { _exit(0); @@ -63,7 +63,7 @@ static void authorised(void) { } int main(int argc, const char *const *argv) { - uid_t uid; + uid_t uid, euid; char fnbuf[100]; char *ep; const char *np; @@ -85,6 +85,18 @@ int main(int argc, const char *const *argv) { perrorfail("chdir " CONFIGDIR); } + euid = geteuid(); + if (euid == (uid_t)-1) { + perrorfail("geteuid"); + } + + if (euid != (uid_t)0) { + fprintf(stderr, "Error: libauthbind's helper needs root privileges. Please run:\n"); + fprintf(stderr, " $ chmod u+s %s\n", argv[0]); + fprintf(stderr, " $ sudo chown root %s\n\n", argv[0]); + exiterrno(EPERM); + } + fnbuf[sizeof(fnbuf)-1] = 0; memset(&saddr, 0, sizeof(saddr)); saddr.sin_family = AF_INET;