summary refs log tree commit diff
path: root/src/chpst.c
diff options
context:
space:
mode:
authorGerrit Pape <pape@smarden.org>2007-04-17 07:49:09 +0000
committerGerrit Pape <pape@innominate.com>2007-04-17 07:49:09 +0000
commitcf45c27c0b81d495e961ac83a8bbd9b6569047a7 (patch)
tree423d0f22e8ec954db6c1060d50463ac64bc5921b /src/chpst.c
parent157727221652084a17037478826af086127a6956 (diff)
downloadrunit-cf45c27c0b81d495e961ac83a8bbd9b6569047a7.tar.gz
runit-cf45c27c0b81d495e961ac83a8bbd9b6569047a7.tar.xz
runit-cf45c27c0b81d495e961ac83a8bbd9b6569047a7.zip
chpst.c, uidgid.c: improve error reporting if getpwnam() or getgrnam() fails
...cleanup.
Diffstat (limited to 'src/chpst.c')
-rw-r--r--src/chpst.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/chpst.c b/src/chpst.c
index 9df2fb6..8f84928 100644
--- a/src/chpst.c
+++ b/src/chpst.c
@@ -64,17 +64,17 @@ unsigned int lockdelay;
 void suidgid(char *user, unsigned int ext) {
   struct uidgid ugid;
 
-  if (ext) {
+  if (ext)
     if (! uidgids_get(&ugid, user)) {
-      if (*user == ':')
-        fatalx("invalid uid/gids", user +1);
-      else
+      if (*user == ':') fatalx("invalid uid/gids", user +1);
+      if (errno) fatal("unable to get password/group file entry");
       fatalx("unknown user/group", user);
     }
-  }
-    else
-    if (! uidgid_get(&ugid, user))
+  else
+    if (! uidgid_get(&ugid, user)) {
+      if (errno) fatal("unable to get password file entry");
       fatalx("unknown account", user);
+    }
   if (setgroups(ugid.gids, ugid.gid) == -1) fatal("unable to setgroups");
   if (setgid(*ugid.gid) == -1) fatal("unable to setgid");
   if (prot_uid(ugid.uid) == -1) fatal("unable to setuid");
@@ -84,17 +84,17 @@ void euidgid(char *user, unsigned int ext) {
   struct uidgid ugid;
   char bufnum[FMT_ULONG];
 
-  if (ext) {
+  if (ext)
     if (! uidgids_get(&ugid, user)) {
-      if (*user == ':')
-        fatalx("invalid uid/gids", user +1);
-      else
+      if (*user == ':') fatalx("invalid uid/gids", user +1);
+      if (errno) fatal("unable to get password/group file entry");
       fatalx("unknown user/group", user);
     }
-  }
-    else
-    if (! uidgid_get(&ugid, user))
+  else
+    if (! uidgid_get(&ugid, user)) {
+      if (errno) fatal("unable to get password file entry");
       fatalx("unknown account", user);
+    }
   bufnum[fmt_ulong(bufnum, *ugid.gid)] =0;
   if (! pathexec_env("GID", bufnum)) die_nomem();
   bufnum[fmt_ulong(bufnum, ugid.uid)] =0;
@@ -332,7 +332,6 @@ int main(int argc, const char *const *argv) {
     if (chdir(root) == -1) fatal2("unable to change directory", root);
     if (chroot(".") == -1) fatal("unable to change root directory");
   }
-  slimit();
   if (nicelvl) {
     errno =0;
     if (nice(nicelvl) == -1) if (errno) fatal("unable to set nice level");
@@ -343,6 +342,7 @@ int main(int argc, const char *const *argv) {
   if (nostdin) if (close(0) == -1) fatal("unable to close stdin");
   if (nostdout) if (close(1) == -1) fatal("unable to close stdout");
   if (nostderr) if (close(2) == -1) fatal("unable to close stderr");
+  slimit();
   pathexec(argv);
   fatal2("unable to run", *argv);
   return(0);