summaryrefslogtreecommitdiff
path: root/shlibs
diff options
context:
space:
mode:
Diffstat (limited to 'shlibs')
-rw-r--r--shlibs/mount/src/mountP.h3
-rw-r--r--shlibs/mount/src/utils.c43
2 files changed, 46 insertions, 0 deletions
diff --git a/shlibs/mount/src/mountP.h b/shlibs/mount/src/mountP.h
index f5958957..230f51cb 100644
--- a/shlibs/mount/src/mountP.h
+++ b/shlibs/mount/src/mountP.h
@@ -107,6 +107,9 @@ extern int endswith(const char *s, const char *sx);
extern int startswith(const char *s, const char *sx);
extern char *mnt_get_username(const uid_t uid);
+extern int mnt_get_uid(const char *username, uid_t *uid);
+extern int mnt_get_gid(const char *groupname, gid_t *gid);
+
extern int mnt_has_regular_mtab(void);
extern char *mnt_get_mountpoint(const char *path);
diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c
index f48e533d..108bb2eb 100644
--- a/shlibs/mount/src/utils.c
+++ b/shlibs/mount/src/utils.c
@@ -27,6 +27,7 @@
#include <sys/types.h>
#include <fcntl.h>
#include <pwd.h>
+#include <grp.h>
#include "strutils.h"
#include "pathnames.h"
@@ -316,6 +317,48 @@ char *mnt_get_username(const uid_t uid)
return username;
}
+int mnt_get_uid(const char *username, uid_t *uid)
+{
+ struct passwd pwd;
+ struct passwd *pw;
+ size_t sz = sysconf(_SC_GETPW_R_SIZE_MAX);
+ char *buf;
+
+ if (sz <= 0)
+ sz = 16384; /* Should be more than enough */
+
+ buf = malloc(sz);
+ if (!buf)
+ return -ENOMEM;
+
+ if (!getpwnam_r(username, &pwd, buf, sz, &pw) && pw)
+ *uid= pw->pw_uid;
+
+ free(buf);
+ return 0;
+}
+
+int mnt_get_gid(const char *groupname, gid_t *gid)
+{
+ struct group grp;
+ struct group *gr;
+ size_t sz = sysconf(_SC_GETGR_R_SIZE_MAX);
+ char *buf;
+
+ if (sz <= 0)
+ sz = 16384; /* Should be more than enough */
+
+ buf = malloc(sz);
+ if (!buf)
+ return -ENOMEM;
+
+ if (!getgrnam_r(groupname, &grp, buf, sz, &gr) && gr)
+ *gid= gr->gr_gid;
+
+ free(buf);
+ return 0;
+}
+
/*
* Returns 1 if /etc/mtab is a reqular file.
*/