summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Utils/xfuncs.cpp12
-rw-r--r--lib/Utils/xfuncs.h6
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/Utils/xfuncs.cpp b/lib/Utils/xfuncs.cpp
index 89273675..e2f9b4d3 100644
--- a/lib/Utils/xfuncs.cpp
+++ b/lib/Utils/xfuncs.cpp
@@ -390,6 +390,18 @@ bool string_to_bool(const char *s)
return false;
}
+void xseteuid(uid_t euid)
+{
+ if (seteuid(euid) != 0)
+ perror_msg_and_die("can't set %cid %lu", 'u', (long)euid);
+}
+
+void xsetegid(gid_t egid)
+{
+ if (setegid(egid) != 0)
+ perror_msg_and_die("can't set %cid %lu", 'g', (long)egid);
+}
+
void xsetreuid(uid_t ruid, uid_t euid)
{
if (setreuid(ruid, euid) != 0)
diff --git a/lib/Utils/xfuncs.h b/lib/Utils/xfuncs.h
index 93baa175..de785c8e 100644
--- a/lib/Utils/xfuncs.h
+++ b/lib/Utils/xfuncs.h
@@ -76,12 +76,12 @@ extern char *last_char_is(const char *s, int c);
extern bool string_to_bool(const char *s);
+extern void xseteuid(uid_t euid);
+extern void xsetegid(gid_t egid);
extern void xsetreuid(uid_t ruid, uid_t euid);
extern void xsetregid(gid_t rgid, gid_t egid);
-/* Do not pass the returned pointer to free().
- Do not modify the contents of the returned string.
- NULL is returned in the case of failure. */
+/* Returns getpwuid(uid)->pw_dir or NULL */
extern const char *get_home_dir(uid_t uid);
#ifdef __cplusplus