From 028de13e0d9438e93a7df2c1445194e0348024a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?= Date: Wed, 26 Oct 2011 18:06:14 +0200 Subject: [PATCH 06/13] SUDO integration - Responder <-> Data provider communication functions --- Makefile.am | 1 + src/responder/sudo/sudosrv.h | 2 + src/responder/sudo/sudosrv_dp.c | 76 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 0 deletions(-) create mode 100644 src/responder/sudo/sudosrv_dp.c diff --git a/Makefile.am b/Makefile.am index 9dff335..ee0b1d5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -431,6 +431,7 @@ sssd_pam_LDADD = \ sssd_sudo_SOURCES = \ src/responder/sudo/sudosrv.c \ src/responder/sudo/sudosrv_cmd.c \ + src/responder/sudo/sudosrv_dp.c \ $(SSSD_RESPONDER_OBJ) sssd_sudo_LDADD = \ $(SSSD_LIBS) \ diff --git a/src/responder/sudo/sudosrv.h b/src/responder/sudo/sudosrv.h index 5abdb80..314fddd 100644 --- a/src/responder/sudo/sudosrv.h +++ b/src/responder/sudo/sudosrv.h @@ -30,6 +30,8 @@ struct sudo_ctx { int sudo_cmd_execute(struct cli_ctx *cctx); +int sudo_dp_refresh_send(struct cli_ctx *cctx, const char *domain, int timeout); + struct sss_cmd_table *get_sudo_cmds(void); #endif /* SUDOSRV_H_ */ diff --git a/src/responder/sudo/sudosrv_dp.c b/src/responder/sudo/sudosrv_dp.c new file mode 100644 index 0000000..0fc6635 --- /dev/null +++ b/src/responder/sudo/sudosrv_dp.c @@ -0,0 +1,76 @@ +/* + Authors: + Pavel Březina + + Copyright (C) 2011 Red Hat + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include + +#include "util/util.h" +#include "sbus/sbus_client.h" +#include "providers/data_provider.h" +#include "responder/common/responder.h" +#include "responder/sudo/sudosrv.h" + +static void sudo_dp_process_reply(DBusPendingCall *pending, void *ptr) +{ + DEBUG(0, ("=== received SUDO reply===\n")); +} + +int sudo_dp_refresh_send(struct cli_ctx *cctx, const char *domain, int timeout) +{ + struct be_conn *be_conn; + DBusMessage *msg; + int ret; + + /* double check dp_ctx has actually been initialized. + * in some pathological cases it may happen that sudo starts up before + * dp connection code is actually able to establish a connection. + */ + ret = sss_dp_get_domain_conn(cctx->rctx, + domain, &be_conn); + if (ret != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, + ("The Data Provider connection for %s is not available! " + "This maybe a bug, it shouldn't happen!\n", + domain)); + return EIO; + } + + msg = dbus_message_new_method_call(NULL, + DP_PATH, + DP_INTERFACE, + DP_METHOD_SUDOHANDLER); + if (msg == NULL) { + DEBUG(SSSDBG_FATAL_FAILURE, ("Out of memory?!\n")); + return ENOMEM; + } + + DEBUG(SSSDBG_TRACE_FUNC, ("Sending SUDOers refresh request\n")); + + ret = sbus_conn_send(be_conn->conn, msg, + timeout, sudo_dp_process_reply, + cctx, NULL); + dbus_message_unref(msg); + + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, ("Unable to contact data provider " + "for domain %s", domain)); + } + + return ret; +} -- 1.7.6.4