diff options
author | Evan Prodromou <evan@prodromou.name> | 2008-09-04 15:10:31 -0400 |
---|---|---|
committer | Evan Prodromou <evan@prodromou.name> | 2008-09-04 15:10:31 -0400 |
commit | 32a189220c1e7422dff591c8c8d5e8db04fcca83 (patch) | |
tree | 52b94f6a7c391d7879df6aec3d1130ea5c67479c | |
parent | 65efe17c4e4b960ada6a46e28557aec18b9364c0 (diff) |
more robust code for setting daemon uid/gid
darcs-hash:20080904191031-84dde-bb457c429c76eedb9bd4ea838b7ccad28844effd.gz
-rw-r--r-- | lib/daemon.php | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/daemon.php b/lib/daemon.php index 0bda0272f..a7a49ce94 100644 --- a/lib/daemon.php +++ b/lib/daemon.php @@ -85,16 +85,28 @@ class Daemon { function changeUser() { - if (common_config('daemon', 'user')) { - $user_info = posix_getpwnam(common_config('daemon', 'user')); - common_log(LOG_INFO, "Setting user to " . common_config('daemon', 'user')); - posix_setuid($user_info['uid']); + $username = common_config('daemon', 'user'); + + if ($username) { + $user_info = posix_getpwnam($username); + if (!$user_info) { + common_log(LOG_WARNING, 'Ignoring unknown user for daemon: ' . $username); + } else { + common_log(LOG_INFO, "Setting user to " . $username); + posix_setuid($user_info['uid']); + } } + + $groupname = common_config('daemon', 'group'); - if (common_config('daemon', 'group')) { - $group_info = posix_getgrnam(common_config('daemon', 'group')); - common_log(LOG_INFO, "Setting group to " . common_config('daemon', 'group')); - posix_setgid($group_info['gid']); + if ($groupname) { + $group_info = posix_getgrnam($groupname); + if (!$group_info) { + common_log(LOG_WARNING, 'Ignoring unknown group for daemon: ' . $groupname); + } else { + common_log(LOG_INFO, "Setting group to " . $groupname); + posix_setgid($group_info['gid']); + } } } |