summary refs log tree commit diff
path: root/src/setuidgid.c
diff options
context:
space:
mode:
authorGerrit Pape <pape@smarden.org>2003-06-05 11:39:34 +0000
committerGerrit Pape <pape@smarden.org>2003-06-05 11:39:34 +0000
commit25bc8855142a55bff08cd0a2dbdc37f81036cd04 (patch)
tree380e5c3aea41c269f31a5e2af76e6c2256b4d296 /src/setuidgid.c
parentbca5d80102ca893c60a5c5d0906a4cd8816d6a13 (diff)
downloadrunit-25bc8855142a55bff08cd0a2dbdc37f81036cd04.tar.gz
runit-25bc8855142a55bff08cd0a2dbdc37f81036cd04.tar.xz
runit-25bc8855142a55bff08cd0a2dbdc37f81036cd04.zip
debianized.
Diffstat (limited to 'src/setuidgid.c')
-rw-r--r--src/setuidgid.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/setuidgid.c b/src/setuidgid.c
new file mode 100644
index 0000000..e5a3db3
--- /dev/null
+++ b/src/setuidgid.c
@@ -0,0 +1,33 @@
+#include <sys/types.h>
+#include <pwd.h>
+#include "prot.h"
+#include "strerr.h"
+#include "pathexec.h"
+
+#define USAGE " account child"
+#define FATAL "setuidgid: fatal: "
+
+const char *progname;
+
+void fatal(char *m) { strerr_die3sys(111, FATAL, m, ": "); }
+void usage() { strerr_die4x(100, "usage: ", progname, USAGE, "\n"); }
+
+int main(int argc, const char *const *argv, const char *const *envp) {
+  const char *account;
+  struct passwd *pw;
+
+  progname =argv[0];
+
+  if (! (account =*++argv)) usage();
+  if (! *++argv) usage();
+
+  if (! (pw =getpwnam(account)))
+    strerr_die3x(111, FATAL, "unknown account ", account);
+
+  if (prot_gid(pw->pw_gid) == -1) fatal("unable to setgid");
+  if (prot_uid(pw->pw_uid) == -1) fatal("unable to setuid");
+
+  pathexec_run(*argv, argv, envp);
+  strerr_die4sys(111, FATAL, "unable to run ", *argv, ": ");
+  return(1);
+}