summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Luke <chrisy@flirble.org>2016-06-01 19:25:49 -0400
committerChris Luke <chrisy@flirble.org>2016-06-01 19:50:09 -0400
commita0e1f31b3d1886746bdb37ec7236f2b791cb4c9f (patch)
tree340b613f4941a4b43928c1d1c245cdf10649d0c8
parent966bef4ad1d8dec81299758eec70b69cc2030c2c (diff)
VPP-105 Map API SHM uid/gid name to number
When providing uid or gid for the API SHM, if non-numeric values are given look them up in the local system user database and if found use the values discovered. Change-Id: I95152f58646643bc44d2af4cbad6338901935c69 Signed-off-by: Chris Luke <chrisy@flirble.org>
-rw-r--r--vpp/api/api.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/vpp/api/api.c b/vpp/api/api.c
index 0d27d582bca..9c3f4ee3fc8 100644
--- a/vpp/api/api.c
+++ b/vpp/api/api.c
@@ -30,6 +30,9 @@
#include <time.h>
#include <fcntl.h>
#include <string.h>
+#include <pwd.h>
+#include <grp.h>
+
#include <vppinfra/clib.h>
#include <vppinfra/vec.h>
#include <vppinfra/hash.h>
@@ -6086,11 +6089,16 @@ vpe_api_init (vlib_main_t *vm)
VLIB_INIT_FUNCTION(vpe_api_init);
+
static clib_error_t *
api_segment_config (vlib_main_t * vm, unformat_input_t * input)
{
u8 * chroot_path;
- int uid, gid;
+ int uid, gid, rv;
+ char *s, buf[128];
+ struct passwd _pw, *pw;
+ struct group _grp, *grp;
+ clib_error_t *e;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
@@ -6103,6 +6111,50 @@ api_segment_config (vlib_main_t * vm, unformat_input_t * input)
vl_set_memory_uid (uid);
else if (unformat (input, "gid %d", &gid))
vl_set_memory_gid (gid);
+ else if (unformat (input, "uid %s", &s))
+ {
+ /* lookup the username */
+ pw = NULL;
+ rv = getpwnam_r(s, &_pw, buf, sizeof(buf), &pw);
+ if (rv < 0)
+ {
+ e = clib_error_return_code(0, rv,
+ CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
+ "cannot fetch username %s", s);
+ vec_free (s);
+ return e;
+ }
+ if (pw == NULL)
+ {
+ e = clib_error_return_fatal(0, "username %s does not exist", s);
+ vec_free (s);
+ return e;
+ }
+ vec_free (s);
+ vl_set_memory_uid (pw->pw_uid);
+ }
+ else if (unformat (input, "gid %s", &s))
+ {
+ /* lookup the group name */
+ grp = NULL;
+ rv = getgrnam_r(s, &_grp, buf, sizeof(buf), &grp);
+ if (rv != 0)
+ {
+ e = clib_error_return_code(0, rv,
+ CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
+ "cannot fetch group %s", s);
+ vec_free (s);
+ return e;
+ }
+ if (grp == NULL)
+ {
+ e = clib_error_return_fatal(0, "group %s does not exist", s);
+ vec_free (s);
+ return e;
+ }
+ vec_free (s);
+ vl_set_memory_gid (grp->gr_gid);
+ }
else
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);