[SSSD] [PATCH] SUDO: Provide a sudo DP request based on the internal_req
Jakub Hrozek
jhrozek at redhat.com
Mon Jan 23 14:36:57 UTC 2012
On Sun, Jan 22, 2012 at 08:24:42PM -0500, Stephen Gallagher wrote:
> On Sun, 2012-01-22 at 22:14 +0100, Jakub Hrozek wrote:
> > The attached patch requires the DP refactoring patch. It contains a
> > sudo-specific DP request.
> >
> > A patch that actually uses the request in the sudo responder is being
> > tested now, but I wanted to get an early response on the approach.
>
>
> Nack.
>
> Based on my review of the sss_dp_issue_request() patch, this will need
> updating to account for the hash key changes.
>
The key is now a string local to the _send() function, hash_key is now
created in sss_dp_issue_request()
> I'd rather see us start separating the different responder DP processing
> into their own source files. I think this belongs in responder/sudo/. We
> should reserve common for truly independent features (like the
> sss_dp_issue_request()).
OK, done. This patch puts the new request into sudosrv_dp.c and a later
one that actually uses this new request is going to remove the old
implementation.
Would you like to move the _account_send() request as well? I think
that "getting user info" is quite common among all the responders, so
the account request can stay in responders/common/ rather than
responders/nss.
>
> Also, when you call sss_dp_issue_request(), you're passing 'state' as
> the pvt data for sss_dp_get_sudoers_msg(), but you meant to pass 'info',
> I think.
Right, I had this fixed but squashed into another patch (otherwise I
wouldn't be able to test the new code). Sorry, it's fixed in the patch
now.
>
> Otherwise, this patch looks straightforward.
Thank you, a new patch is attached.
-------------- next part --------------
From fcd4e907f8fb313ac03200f96da3900cbebaf3e5 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Thu, 19 Jan 2012 10:00:47 +0100
Subject: [PATCH] SUDO: Provide a sudo DP request based on the internal_req
---
src/providers/data_provider.h | 1 +
src/responder/common/responder.h | 3 +-
src/responder/sudo/sudosrv_dp.c | 125 ++++++++++++++++++++++++++++++++++
src/responder/sudo/sudosrv_private.h | 15 ++++
4 files changed, 143 insertions(+), 1 deletions(-)
diff --git a/src/providers/data_provider.h b/src/providers/data_provider.h
index fb61c730a2daca28b76a6f50fed5019a17d8a6d6..eb4f98cf3a62a6356b31758c0ebbd028ae0fff21 100644
--- a/src/providers/data_provider.h
+++ b/src/providers/data_provider.h
@@ -137,6 +137,7 @@
#define BE_REQ_INITGROUPS 0x0003
#define BE_REQ_NETGROUP 0x0004
#define BE_REQ_SERVICES 0x0005
+#define BE_REQ_SUDO 0x0006
#define BE_REQ_FAST 0x1000
/* AUTH related common data and functions */
diff --git a/src/responder/common/responder.h b/src/responder/common/responder.h
index dc0bdc307e94c36b498382b0cdef455ba3f3b83a..a1020afbe85e5bba06df9e51ceb01e4dc1f14de1 100644
--- a/src/responder/common/responder.h
+++ b/src/responder/common/responder.h
@@ -162,7 +162,8 @@ enum sss_dp_type {
SSS_DP_GROUP,
SSS_DP_INITGROUPS,
SSS_DP_NETGR,
- SSS_DP_SERVICES
+ SSS_DP_SERVICES,
+ SSS_DP_SUDO
};
typedef void (*sss_dp_callback_t)(uint16_t err_maj, uint32_t err_min,
diff --git a/src/responder/sudo/sudosrv_dp.c b/src/responder/sudo/sudosrv_dp.c
index 27f01f92b160d9805b69815fb789d5176c356f8b..1c0e21d4d4445b00bd32dc8f80be6ebc70a3c920 100644
--- a/src/responder/sudo/sudosrv_dp.c
+++ b/src/responder/sudo/sudosrv_dp.c
@@ -220,3 +220,128 @@ errno_t sudosrv_dp_refresh_recv(struct tevent_req *req,
TEVENT_REQ_RETURN_ON_ERROR(req);
return EOK;
}
+
+struct sss_dp_get_sudoers_info {
+ struct sss_domain_info *dom;
+
+ bool fast_reply;
+ int type;
+ const char *name;
+};
+
+static DBusMessage *
+sss_dp_get_sudoers_msg(void *pvt);
+
+struct tevent_req *
+sss_dp_get_sudoers_send(TALLOC_CTX *mem_ctx,
+ struct resp_ctx *rctx,
+ struct sss_domain_info *dom,
+ bool fast_reply,
+ int type,
+ const char *name)
+{
+ struct tevent_req *req;
+ struct sss_dp_req_state *state;
+ struct sss_dp_get_sudoers_info *info;
+ errno_t ret;
+ char *key;
+
+ req = tevent_req_create(mem_ctx, &state, struct sss_dp_req_state);
+ if (!req) {
+ ret = ENOMEM;
+ goto error;
+ }
+
+ if (!dom) {
+ ret = EINVAL;
+ goto error;
+ }
+
+ info = talloc_zero(state, struct sss_dp_get_sudoers_info);
+ info->fast_reply = fast_reply;
+ info->type = type;
+ info->name = name;
+ info->dom = dom;
+
+ key = talloc_asprintf(state, "%d:%s@%s", type, name, dom->name);
+ if (!key) {
+ ret = ENOMEM;
+ goto error;
+ }
+
+ ret = sss_dp_issue_request(state, rctx, key, dom, sss_dp_get_sudoers_msg,
+ info, req);
+ talloc_free(key);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE,
+ ("Could not issue DP request [%d]: %s\n",
+ ret, strerror(ret)));
+ goto error;
+ }
+
+ return req;
+
+error:
+ tevent_req_error(req, ret);
+ tevent_req_post(req, rctx->ev);
+ return req;
+}
+
+static DBusMessage *
+sss_dp_get_sudoers_msg(void *pvt)
+{
+ DBusMessage *msg;
+ dbus_bool_t dbret;
+ struct sss_dp_get_sudoers_info *info;
+ uint32_t be_type = BE_REQ_SUDO;
+ char *filter;
+
+ info = talloc_get_type(pvt, struct sss_dp_get_sudoers_info);
+
+ if (info->fast_reply) {
+ be_type |= BE_REQ_FAST;
+ }
+
+ filter = talloc_asprintf(info, "name=%s", info->name);
+ if (!filter) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory?!\n"));
+ return NULL;
+ }
+
+ msg = dbus_message_new_method_call(NULL,
+ DP_PATH,
+ DP_INTERFACE,
+ DP_METHOD_SUDOHANDLER);
+ if (msg == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory?!\n"));
+ return NULL;
+ }
+
+ /* create the message */
+ DEBUG(SSSDBG_TRACE_FUNC,
+ ("Creating SUDOers request for [%s][%u][%s]\n",
+ info->dom->name, be_type, filter));
+
+ dbret = dbus_message_append_args(msg,
+ DBUS_TYPE_UINT32, &be_type,
+ DBUS_TYPE_STRING, &filter,
+ DBUS_TYPE_INVALID);
+ talloc_free(filter);
+ if (!dbret) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to build message\n"));
+ dbus_message_unref(msg);
+ return NULL;
+ }
+
+ return msg;
+}
+
+errno_t
+sss_dp_get_sudoers_recv(TALLOC_CTX *mem_ctx,
+ struct tevent_req *req,
+ dbus_uint16_t *dp_err,
+ dbus_uint32_t *dp_ret,
+ char **err_msg)
+{
+ return sss_dp_req_recv(mem_ctx, req, dp_err, dp_ret, err_msg);
+}
diff --git a/src/responder/sudo/sudosrv_private.h b/src/responder/sudo/sudosrv_private.h
index 7401570cc548ed22be5ec64e0c0d5c2fb00490c1..82915931c4f9cf1f7d6e3d0ae756c185ea1470fa 100644
--- a/src/responder/sudo/sudosrv_private.h
+++ b/src/responder/sudo/sudosrv_private.h
@@ -106,4 +106,19 @@ int sudosrv_response_append_attr(TALLOC_CTX *mem_ctx,
uint8_t **_response_body,
size_t *_response_len);
+struct tevent_req *
+sss_dp_get_sudoers_send(TALLOC_CTX *mem_ctx,
+ struct resp_ctx *rctx,
+ struct sss_domain_info *dom,
+ bool fast_reply,
+ int type,
+ const char *name);
+
+errno_t
+sss_dp_get_sudoers_recv(TALLOC_CTX *mem_ctx,
+ struct tevent_req *req,
+ dbus_uint16_t *err_maj,
+ dbus_uint32_t *err_min,
+ char **err_msg);
+
#endif /* _SUDOSRV_PRIVATE_H_ */
--
1.7.7.5
More information about the sssd-devel
mailing list