summaryrefslogtreecommitdiff
path: root/lib/identity.c
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-05-14 21:43:02 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-05-14 21:43:02 -0400
commite735ad6710a82604a206ad29f6cbcdd7dc4b024c (patch)
tree5fe8eebbb7a2bff20bb71bd2368955356979e0a2 /lib/identity.c
parentsync (diff)
downloadlazysphere-e735ad6710a82604a206ad29f6cbcdd7dc4b024c.tar.gz
lazysphere-e735ad6710a82604a206ad29f6cbcdd7dc4b024c.tar.bz2
lazysphere-e735ad6710a82604a206ad29f6cbcdd7dc4b024c.zip
refactor and add su
Diffstat (limited to 'lib/identity.c')
-rw-r--r--lib/identity.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/identity.c b/lib/identity.c
new file mode 100644
index 0000000..58dcf52
--- /dev/null
+++ b/lib/identity.c
@@ -0,0 +1,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);
+}