|
|
b2d430 |
From bb8653ba6ba4eddb7faeddd9ceb3349107f77fd9 Mon Sep 17 00:00:00 2001
|
|
|
b2d430 |
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
|
|
|
b2d430 |
Date: Wed, 29 Jun 2016 14:03:38 +0200
|
|
|
b2d430 |
Subject: [PATCH 094/102] sssctl: use talloc with sifp
|
|
|
b2d430 |
MIME-Version: 1.0
|
|
|
b2d430 |
Content-Type: text/plain; charset=UTF-8
|
|
|
b2d430 |
Content-Transfer-Encoding: 8bit
|
|
|
b2d430 |
|
|
|
b2d430 |
This way we completely move D-Bus memory management to talloc and
|
|
|
b2d430 |
we reduce number of code lines needed to send and receive reply.
|
|
|
b2d430 |
|
|
|
b2d430 |
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
|
|
|
b2d430 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
b2d430 |
(cherry picked from commit 9b74009c1260e6f3b1031a6ae110bf1d957cba81)
|
|
|
b2d430 |
---
|
|
|
b2d430 |
src/tools/sssctl/sssctl.h | 14 +++++++++
|
|
|
b2d430 |
src/tools/sssctl/sssctl_domains.c | 62 ++++++++++++++++++---------------------
|
|
|
b2d430 |
src/tools/sssctl/sssctl_sifp.c | 46 +++++++++++++++++++++++++++++
|
|
|
b2d430 |
3 files changed, 88 insertions(+), 34 deletions(-)
|
|
|
b2d430 |
|
|
|
b2d430 |
diff --git a/src/tools/sssctl/sssctl.h b/src/tools/sssctl/sssctl.h
|
|
|
b2d430 |
index 72930ee5c3a1195e90c6e35768f715cbf6a1c4e1..d4e3359b0b160d12a0c2699f754989a24b2b336a 100644
|
|
|
b2d430 |
--- a/src/tools/sssctl/sssctl.h
|
|
|
b2d430 |
+++ b/src/tools/sssctl/sssctl.h
|
|
|
b2d430 |
@@ -24,6 +24,7 @@
|
|
|
b2d430 |
#include "lib/sifp/sss_sifp.h"
|
|
|
b2d430 |
#include "lib/sifp/sss_sifp_dbus.h"
|
|
|
b2d430 |
#include "tools/common/sss_tools.h"
|
|
|
b2d430 |
+#include "sbus/sssd_dbus.h"
|
|
|
b2d430 |
|
|
|
b2d430 |
enum sssctl_prompt_result {
|
|
|
b2d430 |
SSSCTL_PROMPT_YES,
|
|
|
b2d430 |
@@ -56,6 +57,19 @@ void _sssctl_sifp_error(sss_sifp_ctx *sifp,
|
|
|
b2d430 |
#define sssctl_sifp_error(sifp, error, message) \
|
|
|
b2d430 |
_sssctl_sifp_error(sifp, error, _(message))
|
|
|
b2d430 |
|
|
|
b2d430 |
+sss_sifp_error _sssctl_sifp_send(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
+ sss_sifp_ctx *sifp,
|
|
|
b2d430 |
+ DBusMessage **_reply,
|
|
|
b2d430 |
+ const char *path,
|
|
|
b2d430 |
+ const char *iface,
|
|
|
b2d430 |
+ const char *method,
|
|
|
b2d430 |
+ int first_arg_type,
|
|
|
b2d430 |
+ ...);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+#define sssctl_sifp_send(mem_ctx, sifp, reply, path, iface, method, ...) \
|
|
|
b2d430 |
+ _sssctl_sifp_send(mem_ctx, sifp, reply, path, iface, method, \
|
|
|
b2d430 |
+ ##__VA_ARGS__, DBUS_TYPE_INVALID);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
errno_t sssctl_domain_list(struct sss_cmdline *cmdline,
|
|
|
b2d430 |
struct sss_tool_ctx *tool_ctx,
|
|
|
b2d430 |
void *pvt);
|
|
|
b2d430 |
diff --git a/src/tools/sssctl/sssctl_domains.c b/src/tools/sssctl/sssctl_domains.c
|
|
|
b2d430 |
index 17ad670f39dfc045ba090210ffcfa77df713c306..40962792b84eabeb2c142f158184b17180a01669 100644
|
|
|
b2d430 |
--- a/src/tools/sssctl/sssctl_domains.c
|
|
|
b2d430 |
+++ b/src/tools/sssctl/sssctl_domains.c
|
|
|
b2d430 |
@@ -74,47 +74,32 @@ errno_t sssctl_domain_list(struct sss_cmdline *cmdline,
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
static errno_t sssctl_domain_status_online(struct sss_tool_ctx *tool_ctx,
|
|
|
b2d430 |
- const char *domain_path,
|
|
|
b2d430 |
- bool force_start)
|
|
|
b2d430 |
+ sss_sifp_ctx *sifp,
|
|
|
b2d430 |
+ const char *domain_path)
|
|
|
b2d430 |
{
|
|
|
b2d430 |
- sss_sifp_ctx *sifp;
|
|
|
b2d430 |
- sss_sifp_error sifp_error;
|
|
|
b2d430 |
- DBusMessage *reply = NULL;
|
|
|
b2d430 |
- DBusMessage *msg;
|
|
|
b2d430 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
b2d430 |
+ sss_sifp_error error;
|
|
|
b2d430 |
+ DBusMessage *reply;
|
|
|
b2d430 |
bool is_online;
|
|
|
b2d430 |
errno_t ret;
|
|
|
b2d430 |
|
|
|
b2d430 |
- if (!sssctl_start_sssd(force_start)) {
|
|
|
b2d430 |
- ret = ERR_SSSD_NOT_RUNNING;
|
|
|
b2d430 |
- goto done;
|
|
|
b2d430 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
b2d430 |
+ if (tmp_ctx == NULL) {
|
|
|
b2d430 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
|
|
|
b2d430 |
+ return ENOMEM;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
- sifp_error = sssctl_sifp_init(tool_ctx, &sifp);
|
|
|
b2d430 |
- if (sifp_error != SSS_SIFP_OK) {
|
|
|
b2d430 |
- sssctl_sifp_error(sifp, sifp_error, "Unable to connect to the InfoPipe");
|
|
|
b2d430 |
- ret = EFAULT;
|
|
|
b2d430 |
- goto done;
|
|
|
b2d430 |
- }
|
|
|
b2d430 |
-
|
|
|
b2d430 |
- msg = sbus_create_message(tool_ctx, SSS_SIFP_ADDRESS, domain_path,
|
|
|
b2d430 |
- IFACE_IFP_DOMAINS_DOMAIN,
|
|
|
b2d430 |
- IFACE_IFP_DOMAINS_DOMAIN_ISONLINE);
|
|
|
b2d430 |
- if (msg == NULL) {
|
|
|
b2d430 |
- DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create D-Bus message\n");
|
|
|
b2d430 |
- ret = ENOMEM;
|
|
|
b2d430 |
- goto done;
|
|
|
b2d430 |
- }
|
|
|
b2d430 |
-
|
|
|
b2d430 |
- sifp_error = sss_sifp_send_message(sifp, msg, &reply);
|
|
|
b2d430 |
- if (sifp_error != SSS_SIFP_OK) {
|
|
|
b2d430 |
- sssctl_sifp_error(sifp, sifp_error, "Unable to get online status");
|
|
|
b2d430 |
+ error = sssctl_sifp_send(tmp_ctx, sifp, &reply, domain_path,
|
|
|
b2d430 |
+ IFACE_IFP_DOMAINS_DOMAIN,
|
|
|
b2d430 |
+ IFACE_IFP_DOMAINS_DOMAIN_ISONLINE);
|
|
|
b2d430 |
+ if (error != SSS_SIFP_OK) {
|
|
|
b2d430 |
+ sssctl_sifp_error(sifp, error, "Unable to get online status");
|
|
|
b2d430 |
ret = EIO;
|
|
|
b2d430 |
goto done;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
ret = sbus_parse_reply(reply, DBUS_TYPE_BOOLEAN, &is_online);
|
|
|
b2d430 |
if (ret != EOK) {
|
|
|
b2d430 |
- fprintf(stderr, _("Unable to get information from SSSD\n"));
|
|
|
b2d430 |
goto done;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
@@ -123,10 +108,7 @@ static errno_t sssctl_domain_status_online(struct sss_tool_ctx *tool_ctx,
|
|
|
b2d430 |
ret = EOK;
|
|
|
b2d430 |
|
|
|
b2d430 |
done:
|
|
|
b2d430 |
- if (reply != NULL) {
|
|
|
b2d430 |
- dbus_message_unref(reply);
|
|
|
b2d430 |
- }
|
|
|
b2d430 |
-
|
|
|
b2d430 |
+ talloc_free(tmp_ctx);
|
|
|
b2d430 |
return ret;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
@@ -144,6 +126,8 @@ errno_t sssctl_domain_status(struct sss_cmdline *cmdline,
|
|
|
b2d430 |
void *pvt)
|
|
|
b2d430 |
{
|
|
|
b2d430 |
struct sssctl_domain_status_opts opts = {0};
|
|
|
b2d430 |
+ sss_sifp_ctx *sifp;
|
|
|
b2d430 |
+ sss_sifp_error error;
|
|
|
b2d430 |
const char *path;
|
|
|
b2d430 |
bool opt_set;
|
|
|
b2d430 |
errno_t ret;
|
|
|
b2d430 |
@@ -181,7 +165,17 @@ errno_t sssctl_domain_status(struct sss_cmdline *cmdline,
|
|
|
b2d430 |
return ENOMEM;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
- ret = sssctl_domain_status_online(tool_ctx, path, opts.force_start);
|
|
|
b2d430 |
+ if (!sssctl_start_sssd(opts.force_start)) {
|
|
|
b2d430 |
+ return ERR_SSSD_NOT_RUNNING;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ error = sssctl_sifp_init(tool_ctx, &sifp);
|
|
|
b2d430 |
+ if (error != SSS_SIFP_OK) {
|
|
|
b2d430 |
+ sssctl_sifp_error(sifp, error, "Unable to connect to the InfoPipe");
|
|
|
b2d430 |
+ return EFAULT;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ ret = sssctl_domain_status_online(tool_ctx, sifp, path);
|
|
|
b2d430 |
if (ret != EOK) {
|
|
|
b2d430 |
fprintf(stderr, _("Unable to get online status\n"));
|
|
|
b2d430 |
return ret;
|
|
|
b2d430 |
diff --git a/src/tools/sssctl/sssctl_sifp.c b/src/tools/sssctl/sssctl_sifp.c
|
|
|
b2d430 |
index e541c4b27ba38e50b209b0957c8b38f03afc891a..782a72d7ce8bbf1080c6d6ac988ffac2f432955f 100644
|
|
|
b2d430 |
--- a/src/tools/sssctl/sssctl_sifp.c
|
|
|
b2d430 |
+++ b/src/tools/sssctl/sssctl_sifp.c
|
|
|
b2d430 |
@@ -116,3 +116,49 @@ void _sssctl_sifp_error(sss_sifp_ctx *sifp,
|
|
|
b2d430 |
break;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
}
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+sss_sifp_error _sssctl_sifp_send(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
+ sss_sifp_ctx *sifp,
|
|
|
b2d430 |
+ DBusMessage **_reply,
|
|
|
b2d430 |
+ const char *path,
|
|
|
b2d430 |
+ const char *iface,
|
|
|
b2d430 |
+ const char *method,
|
|
|
b2d430 |
+ int first_arg_type,
|
|
|
b2d430 |
+ ...)
|
|
|
b2d430 |
+{
|
|
|
b2d430 |
+ sss_sifp_error error;
|
|
|
b2d430 |
+ DBusMessage *msg;
|
|
|
b2d430 |
+ dbus_bool_t bret;
|
|
|
b2d430 |
+ errno_t ret;
|
|
|
b2d430 |
+ va_list va;
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ msg = sss_sifp_create_message(path, iface, method);
|
|
|
b2d430 |
+ if (msg == NULL) {
|
|
|
b2d430 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create D-Bus message\n");
|
|
|
b2d430 |
+ return SSS_SIFP_OUT_OF_MEMORY;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ va_start(va, first_arg_type);
|
|
|
b2d430 |
+ bret = dbus_message_append_args_valist(msg, first_arg_type, va);
|
|
|
b2d430 |
+ va_end(va);
|
|
|
b2d430 |
+ if (!bret) {
|
|
|
b2d430 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Failed to build message\n");
|
|
|
b2d430 |
+ error = SSS_SIFP_OUT_OF_MEMORY;
|
|
|
b2d430 |
+ goto done;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ error = sss_sifp_send_message(sifp, msg, _reply);
|
|
|
b2d430 |
+ if (error != SSS_SIFP_OK) {
|
|
|
b2d430 |
+ goto done;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ ret = sbus_talloc_bound_message(mem_ctx, *_reply);
|
|
|
b2d430 |
+ if (ret != EOK) {
|
|
|
b2d430 |
+ error = SSS_SIFP_OUT_OF_MEMORY;
|
|
|
b2d430 |
+ goto done;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+done:
|
|
|
b2d430 |
+ dbus_message_unref(msg);
|
|
|
b2d430 |
+ return error;
|
|
|
b2d430 |
+}
|
|
|
b2d430 |
--
|
|
|
b2d430 |
2.4.11
|
|
|
b2d430 |
|