[SSSD] [PATCH] send a message if a backend target is not configured

Sumit Bose sbose at redhat.com
Wed Oct 14 13:31:33 UTC 2009


Hi,

this should fix the second part of #220. Now a more specific error code
(PAM_MODULE_UNKNOWN) together with an error message is sent back to the
client if a backend target is not configured.

bye,
Sumit
-------------- next part --------------
>From 0a91d0efa95d8451582ad7c91069ee477dcc7c56 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Wed, 14 Oct 2009 15:22:10 +0200
Subject: [PATCH] send a message if a backend target is not configured

If a backend target is not configured the return code is changed
from PAM_SYSTEM_ERR to PAM_MODULE_UNKNOWN and an error message is
sent back to the client.
---
 server/providers/data_provider_be.c |   42 +++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/server/providers/data_provider_be.c b/server/providers/data_provider_be.c
index 1a3e2d2..e146687 100644
--- a/server/providers/data_provider_be.c
+++ b/server/providers/data_provider_be.c
@@ -46,6 +46,8 @@
 #define ACCESS_PERMIT "permit"
 #define NO_PROVIDER "none"
 
+#define MSG_TARGET_NO_CONFIGURED "sssd_be: The requested target is not configured"
+
 struct sbus_method monitor_be_methods[] = {
     { MON_CLI_METHOD_PING, monitor_common_pong },
     { MON_CLI_METHOD_RES_INIT, monitor_common_res_init },
@@ -421,7 +423,6 @@ static int be_pam_handler(DBusMessage *message, struct sbus_connection *conn)
     void *user_data;
     struct pam_data *pd = NULL;
     struct be_req *be_req = NULL;
-    uint32_t pam_status = PAM_SYSTEM_ERR;
     enum bet_type target = BET_NULL;
 
     user_data = sbus_conn_get_private_data(conn);
@@ -432,7 +433,6 @@ static int be_pam_handler(DBusMessage *message, struct sbus_connection *conn)
     reply = dbus_message_new_method_return(message);
     if (!reply) {
         DEBUG(1, ("dbus_message_new_method_return failed, cannot send reply.\n"));
-        talloc_free(pd);
         return ENOMEM;
     }
 
@@ -448,14 +448,24 @@ static int be_pam_handler(DBusMessage *message, struct sbus_connection *conn)
     be_req->pvt = reply;
 
     pd = talloc_zero(be_req, struct pam_data);
-    if (!pd) return ENOMEM;
+    if (!pd) {
+        talloc_free(be_req);
+        return ENOMEM;
+    }
+
+    pd->pam_status = PAM_SYSTEM_ERR;
+    pd->domain = talloc_strdup(pd, becli->bectx->domain->name);
+    if (pd->domain == NULL) {
+        talloc_free(be_req);
+        return ENOMEM;
+    }
 
     dbus_error_init(&dbus_error);
 
     ret = dp_unpack_pam_request(message, pd, &dbus_error);
     if (!ret) {
         DEBUG(1,("Failed, to parse message!\n"));
-        talloc_free(pd);
+        talloc_free(be_req);
         return EIO;
     }
 
@@ -474,14 +484,21 @@ static int be_pam_handler(DBusMessage *message, struct sbus_connection *conn)
             break;
         default:
             DEBUG(7, ("Unsupported PAM command [%d].\n", pd->cmd));
-            pam_status = PAM_SUCCESS;
+            pd->pam_status = PAM_SUCCESS;
             ret = EOK;
             goto done;
     }
 
-    /* return an error if corresponding backend target is configured */
+    /* return an error if corresponding backend target is not configured */
     if (!becli->bectx->bet_info[target].bet_ops) {
         DEBUG(7, ("Undefined backend target.\n"));
+        pd->pam_status = PAM_MODULE_UNKNOWN;
+        ret = pam_add_response(pd, PAM_USER_INFO,
+                               sizeof(MSG_TARGET_NO_CONFIGURED),
+                               (const uint8_t *) MSG_TARGET_NO_CONFIGURED);
+        if (ret != EOK) {
+            DEBUG(1, ("pam_add_response failed.\n"));
+        }
         goto done;
     }
 
@@ -498,15 +515,14 @@ static int be_pam_handler(DBusMessage *message, struct sbus_connection *conn)
     return EOK;
 
 done:
-    talloc_free(be_req);
 
     DEBUG(4, ("Sending result [%d][%s]\n",
-              pam_status, becli->bectx->domain->name));
-    ret = dbus_message_append_args(reply,
-                                   DBUS_TYPE_UINT32, &pam_status,
-                                   DBUS_TYPE_STRING, &becli->bectx->domain->name,
-                                   DBUS_TYPE_INVALID);
+              pd->pam_status, pd->domain));
+
+    ret = dp_pack_pam_response(reply, pd);
     if (!ret) {
+        DEBUG(1, ("Failed to generate dbus reply\n"));
+        talloc_free(be_req);
         return EIO;
     }
 
@@ -514,6 +530,8 @@ done:
     sbus_conn_send_reply(conn, reply);
     dbus_message_unref(reply);
 
+    talloc_free(be_req);
+
     return EOK;
 }
 
-- 
1.6.2.5



More information about the sssd-devel mailing list