lazysphere/lib/identity.c

25 lines
374 B
C
Raw Permalink Normal View History

2023-05-15 01:43:02 +00:00
#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);
}