summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c17
-rw-r--r--src/shared/util.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 49b58444c7..a87828d451 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4444,6 +4444,23 @@ int get_user_creds(
return 0;
}
+char* uid_to_name(uid_t uid) {
+ struct passwd *p;
+ char *r;
+
+ if (uid == 0)
+ return strdup("root");
+
+ p = getpwuid(uid);
+ if (p)
+ return strdup(p->pw_name);
+
+ if (asprintf(&r, "%lu", (unsigned long) uid) < 0)
+ return NULL;
+
+ return r;
+}
+
int get_group_creds(const char **groupname, gid_t *gid) {
struct group *g;
gid_t id;
diff --git a/src/shared/util.h b/src/shared/util.h
index bb6602fb24..bbf744e900 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -433,6 +433,8 @@ int get_group_creds(const char **groupname, gid_t *gid);
int in_group(const char *name);
+char* uid_to_name(uid_t uid);
+
int glob_exists(const char *path);
int dirent_ensure_type(DIR *d, struct dirent *de);