aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-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));