From 9eea0bf9dbd14851355be0056bfae753bf0a6ae4 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 5 Oct 2023 06:43:02 -0700 Subject: [PATCH] loop: add support for FLUX_OPT_TESTING cred access Problem: rpc unit tests test relies on connector level accessors for credentials but loop:// doesn't implement them. Add support for FLUX_OPT_TESTING_USERID and FLUX_OPT_TESTING_ROLEMASK options, as implemented in loopback_create(). --- src/common/libflux/connector_loop.c | 56 +++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/src/common/libflux/connector_loop.c b/src/common/libflux/connector_loop.c index a54e03bf8f36..cb5953ff6eaa 100644 --- a/src/common/libflux/connector_loop.c +++ b/src/common/libflux/connector_loop.c @@ -18,6 +18,8 @@ #include +#include "ccan/str/str.h" + typedef struct { flux_t *h; @@ -87,6 +89,56 @@ static flux_msg_t *op_recv (void *impl, int flags) return msg; } +static int op_getopt (void *impl, const char *option, void *val, size_t size) +{ + loop_ctx_t *c = impl; + + if (option && streq (option, FLUX_OPT_TESTING_USERID)) { + if (size != sizeof (c->cred.userid)) + goto error; + memcpy (val, &c->cred.userid, size); + } + else if (option && streq (option, FLUX_OPT_TESTING_ROLEMASK)) { + if (size != sizeof (c->cred.rolemask)) + goto error; + memcpy (val, &c->cred.rolemask, size); + } + else + goto error; + return 0; +error: + errno = EINVAL; + return -1; +} + +static int op_setopt (void *impl, + const char *option, + const void *val, + size_t size) +{ + loop_ctx_t *c = impl; + size_t val_size; + + if (option && streq (option, FLUX_OPT_TESTING_USERID)) { + val_size = sizeof (c->cred.userid); + if (size != val_size) + goto error; + memcpy (&c->cred.userid, val, val_size); + } + else if (option && streq (option, FLUX_OPT_TESTING_ROLEMASK)) { + val_size = sizeof (c->cred.rolemask); + if (size != val_size) + goto error; + memcpy (&c->cred.rolemask, val, val_size); + } + else + goto error; + return 0; +error: + errno = EINVAL; + return -1; +} + static void op_fini (void *impl) { loop_ctx_t *c = impl; @@ -129,8 +181,8 @@ static const struct flux_handle_ops handle_ops = { .pollevents = op_pollevents, .send = op_send, .recv = op_recv, - .getopt = NULL, - .setopt = NULL, + .getopt = op_getopt, + .setopt = op_setopt, .impl_destroy = op_fini, };