some slight cleanup in setuid code
git-svn-id: https://svn.musicpd.org/mpd/trunk@2078 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
2a1fa4fd25
commit
df50ddf545
10
src/main.c
10
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));
|
||||
|
|
Loading…
Reference in New Issue