summaryrefslogtreecommitdiff
path: root/lib/identity.c
blob: 58dcf521329d668ec7bb60d11b5f839f0dc2500e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "lslib.h"

#include <grp.h>
#include <pwd.h>
#include <unistd.h>
#include <errno.h>

void change_identity(const struct passwd* pw) {
	int res;

	res = initgroups(pw->pw_name, pw->pw_gid);
	endgrent();

	if (res != 0) {
		if (errno == ENOSYS && pw->pw_uid == getuid()) {
			return;
		}

		error("can't set groups");
	}

	xsetgid(pw->pw_gid);
	xsetuid(pw->pw_uid);
}