]> pd.if.org Git - startuptools/commitdiff
renamed chids to setid
authorNathan Wagner <nw@hydaspes.if.org>
Sun, 28 May 2017 06:10:12 +0000 (06:10 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sun, 28 May 2017 06:10:12 +0000 (06:10 +0000)
Makefile
chids.c [deleted file]
setid.c [new file with mode: 0644]

index 664dc271149bfb1efeefcf2bffe799189953875d..0c1b74094d6b8784244e17996171799c403d99e1 100644 (file)
--- 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 (file)
index fbe742f..0000000
--- a/chids.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * set id
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <pwd.h>
-
-#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 (file)
index 0000000..d37c405
--- /dev/null
+++ b/setid.c
@@ -0,0 +1,61 @@
+/*
+ * set id
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
+
+#include <grp.h>
+
+       int getgrouplist(const char *user, gid_t group,
+                        gid_t *groups, int *ngroups);
+
+
+
+#include "exec.c"
+#if 0
+#include "die.c"
+#endif
+
+/*
+ * chids <uid> cmd... run command as uid, gid from passwd
+ * chids <uid:gid> cmd run command as uid, gid
+ * chids <uid:> 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;
+}