Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ 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);
}
}

int main(int argc, const char *const *argv) {
uid_t uid;
uid_t uid, euid;
char fnbuf[100];
char *ep;
const char *np;
Expand All @@ -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;
Expand Down