drop_privileges_or_die(): Check return value of setuid().
authorAndre Noll <maan@systemlinux.org>
Thu, 22 Oct 2009 20:42:36 +0000 (22:42 +0200)
committerAndre Noll <maan@systemlinux.org>
Thu, 22 Oct 2009 20:42:36 +0000 (22:42 +0200)
The call to setuid() may fail, e.g. because it brings the process over its RLIMIT_NPROC
resource limit. So print an error message and exit in this case.

daemon.c

index 3bcb6e019a442ddf7a8709759937a7d2bd603bf6..ae183d8edad65b0d20fdd7cc2fa4c332d8401564 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -269,7 +269,11 @@ void drop_privileges_or_die(const char *username, const char *groupname)
                exit(EXIT_FAILURE);
        }
        PARA_INFO_LOG("dropping root privileges\n");
                exit(EXIT_FAILURE);
        }
        PARA_INFO_LOG("dropping root privileges\n");
-       setuid(p->pw_uid);
+       if (setuid(p->pw_uid) < 0) {
+               PARA_EMERG_LOG("failed to set effective user ID (%s)",
+                       strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        PARA_DEBUG_LOG("uid: %d, euid: %d\n", (int)getuid(), (int)geteuid());
 }
 
        PARA_DEBUG_LOG("uid: %d, euid: %d\n", (int)getuid(), (int)geteuid());
 }