From 30b5370d56c3eff7649fc63691fadc00e553d1a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Thu, 24 Apr 2014 11:36:18 +0200
Subject: [PATCH 2/2] IFP: report error from ifp_req_create()

This patch makes d-bus error reporting more meaningful.

Instead of:
Error org.freedesktop.DBus.Error.Failed: Could not create ifp_req

You get:
Error org.freedesktop.DBus.Error.Failed: Permission denied
---
 src/responder/ifp/ifp_private.h |  5 +++--
 src/responder/ifp/ifpsrv_cmd.c  |  6 +++---
 src/responder/ifp/ifpsrv_util.c | 23 +++++++++++++----------
 3 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/src/responder/ifp/ifp_private.h b/src/responder/ifp/ifp_private.h
index b5d4d6cf9539faf45e0420e897e9493d60e3b0bf..d540edb84cba8ba837cead1bca71396cf34d6a03 100644
--- a/src/responder/ifp/ifp_private.h
+++ b/src/responder/ifp/ifp_private.h
@@ -58,8 +58,9 @@ struct ifp_req {
     uid_t caller;
 };
 
-struct ifp_req *ifp_req_create(struct sbus_request *dbus_req,
-                               struct ifp_ctx *ifp_ctx);
+errno_t ifp_req_create(struct sbus_request *dbus_req,
+                       struct ifp_ctx *ifp_ctx,
+                       struct ifp_req **_ifp_req);
 
 int ifp_enomem(struct ifp_req *ireq);
 int ifp_return_failure(struct ifp_req *ireq, const char *err_msg);
diff --git a/src/responder/ifp/ifpsrv_cmd.c b/src/responder/ifp/ifpsrv_cmd.c
index 4ac0f0bd273700e14966108da9a3ff49dfd7d92d..2de0f7fbea1054af60732c9a026ff066aaf4e91d 100644
--- a/src/responder/ifp/ifpsrv_cmd.c
+++ b/src/responder/ifp/ifpsrv_cmd.c
@@ -62,11 +62,11 @@ int ifp_user_get_attr(struct sbus_request *dbus_req, void *data)
         return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
     }
 
-    ireq = ifp_req_create(dbus_req, ifp_ctx);
-    if (ireq == NULL) {
+    ret = ifp_req_create(dbus_req, ifp_ctx, &ireq);
+    if (ret != EOK) {
         return sbus_request_fail_and_finish_str(dbus_req,
                                                 DBUS_ERROR_FAILED,
-                                                "Could not create ifp_req\n");
+                                                strerror(ret));
     }
 
     attr_req = talloc_zero(ireq, struct ifp_attr_req);
diff --git a/src/responder/ifp/ifpsrv_util.c b/src/responder/ifp/ifpsrv_util.c
index b9251dc6f444088ccc9962d3e25968f9bfb7d66b..79dd5e1a16b5c65b136867ddecf790bc426bb3c8 100644
--- a/src/responder/ifp/ifpsrv_util.c
+++ b/src/responder/ifp/ifpsrv_util.c
@@ -55,20 +55,21 @@ static errno_t sysbus_get_caller(struct sbus_connection *conn,
     return EOK;
 }
 
-struct ifp_req *ifp_req_create(struct sbus_request *dbus_req,
-                               struct ifp_ctx *ifp_ctx)
+errno_t ifp_req_create(struct sbus_request *dbus_req,
+                       struct ifp_ctx *ifp_ctx,
+                       struct ifp_req **_ifp_req)
 {
     struct ifp_req *req;
     errno_t ret;
 
     if (ifp_ctx->sysbus == NULL) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Responder not connected to sysbus!\n");
-        return NULL;
+        return EINVAL;
     }
 
     req = talloc_zero(dbus_req, struct ifp_req);
     if (req == NULL) {
-        return NULL;
+        return ENOMEM;
     }
 
     req->ifp_ctx = ifp_ctx;
@@ -77,7 +78,7 @@ struct ifp_req *ifp_req_create(struct sbus_request *dbus_req,
     ret = sysbus_get_caller(dbus_req->conn, dbus_req->message, &req->caller);
     if (ret != EOK) {
         DEBUG(SSSDBG_OP_FAILURE, "Could not identify caller, access denied\n");
-        goto fail;
+        goto done;
     }
 
     ret = check_allowed_uids(req->caller, ifp_ctx->rctx->allowed_uids_count,
@@ -85,19 +86,21 @@ struct ifp_req *ifp_req_create(struct sbus_request *dbus_req,
     if (ret == EACCES) {
         DEBUG(SSSDBG_MINOR_FAILURE,
               "User %"SPRIuid" not in ACL\n", req->caller);
-        goto fail;
+        goto done;
     } else if (ret != EOK) {
         DEBUG(SSSDBG_OP_FAILURE,
               "Cannot check if user %"SPRIuid" is present in ACL\n",
               req->caller);
-        goto fail;
+        goto done;
     }
 
-    return req;
+    *_ifp_req = req;
 
-fail:
+    ret = EOK;
+
+done:
     talloc_free(req);
-    return NULL;
+    return ret;
 }
 
 static inline int ifp_req_fail_and_finish(struct ifp_req *ireq,
-- 
1.7.11.7

