|
|
b2d430 |
From 9b0cda6876a5407b152bdeb51bb312aa52916172 Mon Sep 17 00:00:00 2001
|
|
|
b2d430 |
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
|
|
|
b2d430 |
Date: Tue, 28 Jun 2016 15:29:39 +0200
|
|
|
b2d430 |
Subject: [PATCH 092/102] sbus: add sbus_request_reply_error()
|
|
|
b2d430 |
MIME-Version: 1.0
|
|
|
b2d430 |
Content-Type: text/plain; charset=UTF-8
|
|
|
b2d430 |
Content-Transfer-Encoding: 8bit
|
|
|
b2d430 |
|
|
|
b2d430 |
This simplifies error handling in sbus requests since we avoid
|
|
|
b2d430 |
creating DBusError and checking for NULL manually. It removes
|
|
|
b2d430 |
few lines of code.
|
|
|
b2d430 |
|
|
|
b2d430 |
This patch does not replace all calls to sbus_request_fail_and_finish
|
|
|
b2d430 |
since sometimes it is desirable to create the error manualy. But
|
|
|
b2d430 |
it replaces it in most recent places.
|
|
|
b2d430 |
|
|
|
b2d430 |
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
|
|
|
b2d430 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
b2d430 |
(cherry picked from commit a06e23c0bcf0c8669a29b801876aca8aac422931)
|
|
|
b2d430 |
---
|
|
|
b2d430 |
src/providers/data_provider/dp_iface_backend.c | 11 ++--
|
|
|
b2d430 |
src/responder/ifp/ifp_domains.c | 12 ++---
|
|
|
b2d430 |
src/sbus/sssd_dbus.h | 9 +++-
|
|
|
b2d430 |
src/sbus/sssd_dbus_request.c | 73 ++++++++++++++++++++------
|
|
|
b2d430 |
4 files changed, 70 insertions(+), 35 deletions(-)
|
|
|
b2d430 |
|
|
|
b2d430 |
diff --git a/src/providers/data_provider/dp_iface_backend.c b/src/providers/data_provider/dp_iface_backend.c
|
|
|
b2d430 |
index f4af35ed6ec3858b7fff80cf2933926a653ba6f5..d9a84bfee4c5c11e46e0e8f7021f829825ad95c1 100644
|
|
|
b2d430 |
--- a/src/providers/data_provider/dp_iface_backend.c
|
|
|
b2d430 |
+++ b/src/providers/data_provider/dp_iface_backend.c
|
|
|
b2d430 |
@@ -34,7 +34,6 @@ errno_t dp_backend_is_online(struct sbus_request *sbus_req,
|
|
|
b2d430 |
{
|
|
|
b2d430 |
struct be_ctx *be_ctx;
|
|
|
b2d430 |
struct sss_domain_info *domain;
|
|
|
b2d430 |
- DBusError *error;
|
|
|
b2d430 |
bool online;
|
|
|
b2d430 |
|
|
|
b2d430 |
be_ctx = dp_client_be(dp_cli);
|
|
|
b2d430 |
@@ -44,13 +43,9 @@ errno_t dp_backend_is_online(struct sbus_request *sbus_req,
|
|
|
b2d430 |
} else {
|
|
|
b2d430 |
domain = find_domain_by_name(be_ctx->domain, domname, false);
|
|
|
b2d430 |
if (domain == NULL) {
|
|
|
b2d430 |
- error = sbus_error_new(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
|
|
|
b2d430 |
- "Unknown domain %s", domname);
|
|
|
b2d430 |
- if (error == NULL) {
|
|
|
b2d430 |
- return ENOMEM;
|
|
|
b2d430 |
- }
|
|
|
b2d430 |
-
|
|
|
b2d430 |
- return sbus_request_fail_and_finish(sbus_req, error);
|
|
|
b2d430 |
+ sbus_request_reply_error(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
|
|
|
b2d430 |
+ "Unknown domain %s", domname);
|
|
|
b2d430 |
+ return EOK;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
diff --git a/src/responder/ifp/ifp_domains.c b/src/responder/ifp/ifp_domains.c
|
|
|
b2d430 |
index 8bfd39feb39822921ea703d8a89ac372e0ad5410..ff690ed6a7d5519979d242a4d5dadd08aff50347 100644
|
|
|
b2d430 |
--- a/src/responder/ifp/ifp_domains.c
|
|
|
b2d430 |
+++ b/src/responder/ifp/ifp_domains.c
|
|
|
b2d430 |
@@ -543,15 +543,13 @@ int ifp_domains_domain_is_online(struct sbus_request *sbus_req,
|
|
|
b2d430 |
{
|
|
|
b2d430 |
struct ifp_ctx *ifp_ctx;
|
|
|
b2d430 |
struct sss_domain_info *dom;
|
|
|
b2d430 |
- DBusError *error;
|
|
|
b2d430 |
|
|
|
b2d430 |
ifp_ctx = talloc_get_type(data, struct ifp_ctx);
|
|
|
b2d430 |
|
|
|
b2d430 |
dom = get_domain_info_from_req(sbus_req, data);
|
|
|
b2d430 |
if (dom == NULL) {
|
|
|
b2d430 |
- error = sbus_error_new(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
|
|
|
b2d430 |
- "Unknown domain");
|
|
|
b2d430 |
- sbus_request_fail_and_finish(sbus_req, error);
|
|
|
b2d430 |
+ sbus_request_reply_error(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
|
|
|
b2d430 |
+ "Unknown domain");
|
|
|
b2d430 |
return EOK;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
@@ -567,15 +565,13 @@ int ifp_domains_domain_list_services(struct sbus_request *sbus_req,
|
|
|
b2d430 |
{
|
|
|
b2d430 |
struct ifp_ctx *ifp_ctx;
|
|
|
b2d430 |
struct sss_domain_info *dom;
|
|
|
b2d430 |
- DBusError *error;
|
|
|
b2d430 |
|
|
|
b2d430 |
ifp_ctx = talloc_get_type(data, struct ifp_ctx);
|
|
|
b2d430 |
|
|
|
b2d430 |
dom = get_domain_info_from_req(sbus_req, data);
|
|
|
b2d430 |
if (dom == NULL) {
|
|
|
b2d430 |
- error = sbus_error_new(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
|
|
|
b2d430 |
- "Unknown domain");
|
|
|
b2d430 |
- sbus_request_fail_and_finish(sbus_req, error);
|
|
|
b2d430 |
+ sbus_request_reply_error(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
|
|
|
b2d430 |
+ "Unknown domain");
|
|
|
b2d430 |
return EOK;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
diff --git a/src/sbus/sssd_dbus.h b/src/sbus/sssd_dbus.h
|
|
|
b2d430 |
index fe1c4a7e1730e088647744d9b49a68c3c71db57f..c0aedf36b496bfda05dcde921ea7060efb4cc91f 100644
|
|
|
b2d430 |
--- a/src/sbus/sssd_dbus.h
|
|
|
b2d430 |
+++ b/src/sbus/sssd_dbus.h
|
|
|
b2d430 |
@@ -357,6 +357,11 @@ int sbus_request_return_and_finish(struct sbus_request *dbus_req,
|
|
|
b2d430 |
int sbus_request_fail_and_finish(struct sbus_request *dbus_req,
|
|
|
b2d430 |
const DBusError *error);
|
|
|
b2d430 |
|
|
|
b2d430 |
+void sbus_request_reply_error(struct sbus_request *sbus_req,
|
|
|
b2d430 |
+ const char *error_name,
|
|
|
b2d430 |
+ const char *fmt,
|
|
|
b2d430 |
+ ...) SSS_ATTRIBUTE_PRINTF(3, 4);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
/*
|
|
|
b2d430 |
* Construct a new DBusError instance which can be consumed by functions such
|
|
|
b2d430 |
* as @sbus_request_fail_and_finish().
|
|
|
b2d430 |
@@ -368,9 +373,9 @@ int sbus_request_fail_and_finish(struct sbus_request *dbus_req,
|
|
|
b2d430 |
* is duplicated using the returned DBusError instance as a talloc parent.
|
|
|
b2d430 |
*/
|
|
|
b2d430 |
DBusError *sbus_error_new(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
- const char *dbus_err_name,
|
|
|
b2d430 |
+ const char *dbus_error_name,
|
|
|
b2d430 |
const char *fmt,
|
|
|
b2d430 |
- ...) SSS_ATTRIBUTE_PRINTF(3,4);
|
|
|
b2d430 |
+ ...) SSS_ATTRIBUTE_PRINTF(3, 4);
|
|
|
b2d430 |
|
|
|
b2d430 |
/*
|
|
|
b2d430 |
* Parse a DBus method call request.
|
|
|
b2d430 |
diff --git a/src/sbus/sssd_dbus_request.c b/src/sbus/sssd_dbus_request.c
|
|
|
b2d430 |
index f8647b5ecfb4a49d45a15733b22c6014f4bd084c..c5b08539ff85b5427e41f6e03991b40a0a43a7e3 100644
|
|
|
b2d430 |
--- a/src/sbus/sssd_dbus_request.c
|
|
|
b2d430 |
+++ b/src/sbus/sssd_dbus_request.c
|
|
|
b2d430 |
@@ -199,31 +199,70 @@ int sbus_request_fail_and_finish(struct sbus_request *dbus_req,
|
|
|
b2d430 |
return ret;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
+static DBusError *sbus_error_new_va(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
+ const char *error_name,
|
|
|
b2d430 |
+ const char *fmt,
|
|
|
b2d430 |
+ va_list ap)
|
|
|
b2d430 |
+{
|
|
|
b2d430 |
+ DBusError *error;
|
|
|
b2d430 |
+ const char *error_msg;
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ error = talloc_zero(mem_ctx, DBusError);
|
|
|
b2d430 |
+ if (error == NULL) {
|
|
|
b2d430 |
+ return NULL;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ if (fmt != NULL) {
|
|
|
b2d430 |
+ error_msg = talloc_vasprintf(error, fmt, ap);
|
|
|
b2d430 |
+ if (error_msg == NULL) {
|
|
|
b2d430 |
+ talloc_free(error);
|
|
|
b2d430 |
+ return NULL;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+ } else {
|
|
|
b2d430 |
+ error_msg = NULL;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ dbus_error_init(error);
|
|
|
b2d430 |
+ dbus_set_error_const(error, error_name, error_msg);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ return error;
|
|
|
b2d430 |
+}
|
|
|
b2d430 |
+
|
|
|
b2d430 |
DBusError *sbus_error_new(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
- const char *dbus_err_name,
|
|
|
b2d430 |
+ const char *dbus_error_name,
|
|
|
b2d430 |
const char *fmt,
|
|
|
b2d430 |
...)
|
|
|
b2d430 |
{
|
|
|
b2d430 |
- DBusError *dberr;
|
|
|
b2d430 |
- const char *err_msg_dup = NULL;
|
|
|
b2d430 |
+ DBusError *error;
|
|
|
b2d430 |
va_list ap;
|
|
|
b2d430 |
|
|
|
b2d430 |
- dberr = talloc(mem_ctx, DBusError);
|
|
|
b2d430 |
- if (dberr == NULL) return NULL;
|
|
|
b2d430 |
-
|
|
|
b2d430 |
- if (fmt) {
|
|
|
b2d430 |
- va_start(ap, fmt);
|
|
|
b2d430 |
- err_msg_dup = talloc_vasprintf(dberr, fmt, ap);
|
|
|
b2d430 |
- va_end(ap);
|
|
|
b2d430 |
- if (err_msg_dup == NULL) {
|
|
|
b2d430 |
- talloc_free(dberr);
|
|
|
b2d430 |
- return NULL;
|
|
|
b2d430 |
- }
|
|
|
b2d430 |
+ va_start(ap, fmt);
|
|
|
b2d430 |
+ error = sbus_error_new_va(mem_ctx, dbus_error_name, fmt, ap);
|
|
|
b2d430 |
+ va_end(ap);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ return error;
|
|
|
b2d430 |
+}
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+void sbus_request_reply_error(struct sbus_request *sbus_req,
|
|
|
b2d430 |
+ const char *error_name,
|
|
|
b2d430 |
+ const char *fmt,
|
|
|
b2d430 |
+ ...)
|
|
|
b2d430 |
+{
|
|
|
b2d430 |
+ DBusError *error;
|
|
|
b2d430 |
+ va_list ap;
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ va_start(ap, fmt);
|
|
|
b2d430 |
+ error = sbus_error_new_va(sbus_req, error_name, fmt, ap);
|
|
|
b2d430 |
+ va_end(ap);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ if (error == NULL) {
|
|
|
b2d430 |
+ DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
b2d430 |
+ "Unable to create D-Bus error, killing request!\n");
|
|
|
b2d430 |
+ talloc_free(sbus_req);
|
|
|
b2d430 |
+ return;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
- dbus_error_init(dberr);
|
|
|
b2d430 |
- dbus_set_error_const(dberr, dbus_err_name, err_msg_dup);
|
|
|
b2d430 |
- return dberr;
|
|
|
b2d430 |
+ sbus_request_fail_and_finish(sbus_req, error);
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
struct array_arg {
|
|
|
b2d430 |
--
|
|
|
b2d430 |
2.4.11
|
|
|
b2d430 |
|