From a99b3128aa7428fe93a85e48bc9169a2fe8c9746 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Sun, 28 May 2017 06:10:12 +0000 Subject: [PATCH] renamed chids to setid --- Makefile | 8 +++++--- chids.c | 31 ---------------------------- setid.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 34 deletions(-) delete mode 100644 chids.c create mode 100644 setid.c diff --git a/Makefile b/Makefile index 664dc27..0c1b740 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PRG=daemon chdir chids +PRG=daemon chdir setid CFLAGS=-Wall -Wno-parentheses RCSCRIPTS=example.rc functions.rc network ETC=rc.conf rc.local rc.multi rc.shutdown rc.single rc.sysinit @@ -9,9 +9,11 @@ clean: rm -f *.o $(PRG) daemon.o: daemon.c exec.c -chids.o: chids.c exec.c +setid.o: setid.c exec.c -install: install-scripts +install: all install-scripts + install -d -m755 $(DESTDIR)/sbin + install setid $(DESTDIR)/sbin install-scripts: install -d -m755 $(DESTDIR)/etc/rc.d diff --git a/chids.c b/chids.c deleted file mode 100644 index fbe742f..0000000 --- a/chids.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * set id - */ - -#include -#include -#include -#include - -#include "exec.c" -#include "die.c" - -int main(int ac, char *av[]) { - struct passwd *pw; - - pw = getpwnam(av[1]); - if (!pw) { - errordie("getpwnam"); - exit(EXIT_FAILURE); - } - - if (seteuid(pw->pw_uid) == -1) { - errordie("seteuid"); - exit(EXIT_FAILURE); - }; - - do_exec(2, ac, av); - - /* shouldn't get here... */ - return EXIT_FAILURE; -} diff --git a/setid.c b/setid.c new file mode 100644 index 0000000..d37c405 --- /dev/null +++ b/setid.c @@ -0,0 +1,61 @@ +/* + * set id + */ + +#include +#include +#include + +#include +#include +#include + +#include + + int getgrouplist(const char *user, gid_t group, + gid_t *groups, int *ngroups); + + + +#include "exec.c" +#if 0 +#include "die.c" +#endif + +/* + * chids cmd... run command as uid, gid from passwd + * chids cmd run command as uid, gid + * chids cmd run command as uid, gid from passwd,groups + */ +int main(int ac, char *av[]) { + struct passwd *pw; + uid_t uid; + + uid = geteuid(); + + pw = getpwnam(av[1]); + if (!pw) { + perror("getpwnam"); + exit(EXIT_FAILURE); + } + + if (uid == 0 && setgroups(0,0) == -1) { + perror("setgroups"); + exit(EXIT_FAILURE); + }; + + if (setgid(pw->pw_gid) == -1) { + perror("setgid"); + exit(EXIT_FAILURE); + }; + + if (setuid(pw->pw_uid) == -1) { + perror("setuid"); + exit(EXIT_FAILURE); + }; + + do_exec(2, ac, av); + + /* shouldn't get here... */ + return EXIT_FAILURE; +} -- 2.40.0