From df50ddf545c92692b108258f3e091533b26e3f94 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Sun, 29 Aug 2004 13:37:09 +0000 Subject: some slight cleanup in setuid code git-svn-id: https://svn.musicpd.org/mpd/trunk@2078 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/main.c | 10 +++------- 1 file 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)); -- cgit v1.2.3