From b649ad438108ea1865c05a155cd4b47a9eb7efe4 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Thu, 3 Jul 2014 15:12:28 -0500 Subject: [PATCH] startup program improvements --- Makefile | 3 +++ chids.c | 9 +++++++-- exec.c | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index acf459c..664dc27 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,9 @@ all: $(PRG) clean: rm -f *.o $(PRG) +daemon.o: daemon.c exec.c +chids.o: chids.c exec.c + install: install-scripts install-scripts: diff --git a/chids.c b/chids.c index 61e7226..fbe742f 100644 --- a/chids.c +++ b/chids.c @@ -1,5 +1,5 @@ /* - * daemonize and exec + * set id */ #include @@ -8,16 +8,21 @@ #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); } - seteuid(pw->pw_uid); + if (seteuid(pw->pw_uid) == -1) { + errordie("seteuid"); + exit(EXIT_FAILURE); + }; do_exec(2, ac, av); diff --git a/exec.c b/exec.c index b8378ce..bd07905 100644 --- a/exec.c +++ b/exec.c @@ -15,6 +15,11 @@ static void do_exec(int skip, int ac, char *av[]) { int i; + if (skip >= ac) { + fprintf(stderr, "nothing to exec\n"); + exit(EXIT_FAILURE); + } + for (i=0;i