]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix segfault on user not found at startup (from Maciej Soltysiak).
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 23 Mar 2015 20:20:15 +0000 (20:20 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 23 Mar 2015 20:20:15 +0000 (20:20 +0000)
git-svn-id: file:///svn/unbound/trunk@3375 be551aaa-1e26-0410-a405-d3ace91eadb9

daemon/remote.c
daemon/unbound.c
doc/Changelog
util/config_file.c

index f88e0e58030162ff78131142b92987bc36ebc027..894b63fee32d4bd8a650d4a7186ada0cc527dbcd 100644 (file)
@@ -328,7 +328,8 @@ add_open(const char* ip, int nr, struct listen_port** list, int noproto_is_err,
                 */
                if(fd != -1) {
 #ifdef HAVE_CHOWN
-                       if (cfg->username && cfg->username[0])
+                       if (cfg->username && cfg->username[0] &&
+                               cfg_uid != (uid_t)-1)
                                chown(ip, cfg_uid, cfg_gid);
                        chmod(ip, (mode_t)(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
 #else
index b70e39686d4c2c927ebe58882f4d04a3a8b7fc05..8e07c38956501b2072ed79d8e1e9599fb5c7d63d 100644 (file)
@@ -503,7 +503,7 @@ perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
 #ifdef HAVE_KILL
        if(cfg->pidfile && cfg->pidfile[0]) {
                writepid(daemon->pidfile, getpid());
-               if(cfg->username && cfg->username[0]) {
+               if(cfg->username && cfg->username[0] && cfg_uid != (uid_t)-1) {
 #  ifdef HAVE_CHOWN
                        if(chown(daemon->pidfile, cfg_uid, cfg_gid) == -1) {
                                log_err("cannot chown %u.%u %s: %s",
@@ -519,7 +519,7 @@ perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
 
        /* Set user context */
 #ifdef HAVE_GETPWNAM
-       if(cfg->username && cfg->username[0]) {
+       if(cfg->username && cfg->username[0] && cfg_uid != (uid_t)-1) {
 #ifdef HAVE_SETUSERCONTEXT
                /* setusercontext does initgroups, setuid, setgid, and
                 * also resource limits from login config, but we
@@ -586,7 +586,7 @@ perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
 
        /* drop permissions after chroot, getpwnam, pidfile, syslog done*/
 #ifdef HAVE_GETPWNAM
-       if(cfg->username && cfg->username[0]) {
+       if(cfg->username && cfg->username[0] && cfg_uid != (uid_t)-1) {
 #  ifdef HAVE_INITGROUPS
                if(initgroups(cfg->username, cfg_gid) != 0)
                        log_warn("unable to initgroups %s: %s",
index 54ddcf9f437a83eb6083e1500ba67d825ef74373..6efb8552b47e16154da729d5bb44f0c4ae8cc600 100644 (file)
@@ -1,3 +1,6 @@
+23 March 2015: Wouter
+       - Fix segfault on user not found at startup (from Maciej Soltysiak).
+
 20 March 2015: Wouter
        - Fixed to add integer overflow checks on allocation (defense in depth).
 
index a212d1787299864a76feba4ee59bd04dbbf34a68..45a48880a52e6e6f96345b50376121b9fff53f7f 100644 (file)
@@ -1220,8 +1220,10 @@ void config_lookup_uid(struct config_file* cfg)
                struct passwd *pwd;
                if((pwd = getpwnam(cfg->username)) == NULL)
                        log_err("user '%s' does not exist.", cfg->username);
-               cfg_uid = pwd->pw_uid;
-               cfg_gid = pwd->pw_gid;
+               else {
+                       cfg_uid = pwd->pw_uid;
+                       cfg_gid = pwd->pw_gid;
+               }
        }
 #else
        (void)cfg;