[Midnightbsd-cvs] src [6793] trunk/lib/libmport: add mport_get_uid/mport_get_gid
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Wed Oct 1 21:16:08 EDT 2014
Revision: 6793
http://svnweb.midnightbsd.org/src/?rev=6793
Author: laffer1
Date: 2014-10-01 21:16:08 -0400 (Wed, 01 Oct 2014)
Log Message:
-----------
add mport_get_uid/mport_get_gid
Modified Paths:
--------------
trunk/lib/libmport/mport_private.h
trunk/lib/libmport/util.c
Modified: trunk/lib/libmport/mport_private.h
===================================================================
--- trunk/lib/libmport/mport_private.h 2014-10-02 01:09:47 UTC (rev 6792)
+++ trunk/lib/libmport/mport_private.h 2014-10-02 01:16:08 UTC (rev 6793)
@@ -81,6 +81,8 @@
/* Utils */
char* mport_hash_file(const char *);
int mport_copy_file(const char *, const char *);
+uid_t mport_get_uid(const char *);
+gid_t mport_get_gid(const char *);
int mport_rmtree(const char *);
int mport_mkdir(const char *);
int mport_rmdir(const char *, int);
Modified: trunk/lib/libmport/util.c
===================================================================
--- trunk/lib/libmport/util.c 2014-10-02 01:09:47 UTC (rev 6792)
+++ trunk/lib/libmport/util.c 2014-10-02 01:16:08 UTC (rev 6793)
@@ -30,6 +30,8 @@
#include <sys/types.h>
#include <sys/sysctl.h>
+#include <pwd.h>
+#include <grp.h>
#include <sha256.h>
#include <errno.h>
#include <stdlib.h>
@@ -122,6 +124,34 @@
return SHA256_File(filename, NULL);
}
+uid_t mport_get_uid(const char *username)
+{
+ struct passwd *pw;
+
+ if (username == NULL || *username == '\0')
+ return 0; /* root */
+
+ pw = getpwnam(username);
+ if (pw == NULL)
+ return 0; /* if we cant figure it out be safe */
+
+ return pw->pw_uid;
+}
+
+gid_t mport_get_gid(const char *group)
+{
+ struct group *gr;
+
+ if (group == NULL || *group == '\0')
+ return 0; /* wheel */
+
+ gr = getgrnam(group);
+ if (gr == NULL)
+ return 0; /* wheel, could not look up */
+
+ return gr->gr_gid;
+}
+
/* a wrapper around chdir, to work with our error system */
int mport_chdir(mportInstance *mport, const char *dir)
{
More information about the Midnightbsd-cvs
mailing list