aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-08-29 13:37:09 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-08-29 13:37:09 +0000
commitdf50ddf545c92692b108258f3e091533b26e3f94 (patch)
tree30a86515db2bea93d513e80ab848f7d1b8a9f514
parent2a1fa4fd253d6e8fc50a6ee4bd9ccb6230da7145 (diff)
downloadmpd-df50ddf545c92692b108258f3e091533b26e3f94.tar.gz
mpd-df50ddf545c92692b108258f3e091533b26e3f94.tar.xz
mpd-df50ddf545c92692b108258f3e091533b26e3f94.zip
some slight cleanup in setuid code
git-svn-id: https://svn.musicpd.org/mpd/trunk@2078 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/main.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index 00f630722..ddde281a7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -229,18 +229,14 @@ void establishListen(Options * options) {
void changeToUser(Options * options) {
if (options->usr && strlen(options->usr)) {
- int uid, gid;
-
/* get uid */
struct passwd * userpwd;
if ((userpwd = getpwnam(options->usr)) == NULL) {
ERROR("no such user: %s\n", options->usr);
exit(EXIT_FAILURE);
}
- uid = userpwd->pw_uid;
- gid = userpwd->pw_gid;
- if(setgid(gid) == -1) {
+ if(setgid(userpwd->pw_gid) == -1) {
ERROR("cannot setgid of user %s: %s\n", options->usr,
strerror(errno));
exit(EXIT_FAILURE);
@@ -250,7 +246,7 @@ void changeToUser(Options * options) {
/* init suplementary groups
* (must be done before we change our uid)
*/
- if (initgroups(options->usr, gid) == -1) {
+ if (initgroups(options->usr, userpwd->pw_gid) == -1) {
WARNING("cannot init suplementary groups "
"of user %s: %s\n", options->usr,
strerror(errno));
@@ -258,7 +254,7 @@ void changeToUser(Options * options) {
#endif
/* set uid */
- if (setuid(uid) == -1) {
+ if (setuid(userpwd->pw_uid) == -1) {
ERROR("cannot change to uid of user "
"%s: %s\n", options->usr,
strerror(errno));