From 54dc25a25f760fb2800120f905e338f9f6d5e502 Mon Sep 17 00:00:00 2001
From: Jan Zeleny <jzeleny@redhat.com>
Date: Thu, 2 Feb 2012 09:05:40 -0500
Subject: [PATCH 12/13] Add session target in data provider

---
 src/confdb/confdb.h              |    1 +
 src/config/SSSDConfig.py         |    1 +
 src/config/SSSDConfigTest.py     |    6 ++++--
 src/config/etc/sssd.api.conf     |    1 +
 src/providers/data_provider_be.c |   20 +++++++++++++++++++-
 src/providers/dp_backend.h       |    1 +
 6 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h
index 2bfe3b272913efacf9c21d1b407d78078696b7e2..75e983c5acd901145b9c948fa1f99cdec1f1c2fb 100644
--- a/src/confdb/confdb.h
+++ b/src/confdb/confdb.h
@@ -109,6 +109,7 @@
 #define CONFDB_DOMAIN_ACCESS_PROVIDER "access_provider"
 #define CONFDB_DOMAIN_CHPASS_PROVIDER "chpass_provider"
 #define CONFDB_DOMAIN_SUDO_PROVIDER "sudo_provider"
+#define CONFDB_DOMAIN_SESSION_PROVIDER "session_provider"
 #define CONFDB_DOMAIN_COMMAND "command"
 #define CONFDB_DOMAIN_TIMEOUT "timeout"
 #define CONFDB_DOMAIN_ATTR "cn"
diff --git a/src/config/SSSDConfig.py b/src/config/SSSDConfig.py
index 1a241430d8a4e072ae5470d4bff79896ea45e796..c03970cef68616a4aa286e6e3f66a422a9c8339b 100644
--- a/src/config/SSSDConfig.py
+++ b/src/config/SSSDConfig.py
@@ -83,6 +83,7 @@ option_strings = {
     'access_provider' : _('Access control provider'),
     'chpass_provider' : _('Password change provider'),
     'sudo_provider' : _('SUDO provider'),
+    'session_provider' : _('Session-loading provider'),
 
     # [domain]
     'min_id' : _('Minimum user ID'),
diff --git a/src/config/SSSDConfigTest.py b/src/config/SSSDConfigTest.py
index 66b3f9c7abbaa566e411a525e2ee8fd27701ea46..ad0afce8c9ab92443a29325ff2e10d143623126a 100755
--- a/src/config/SSSDConfigTest.py
+++ b/src/config/SSSDConfigTest.py
@@ -494,7 +494,8 @@ class SSSDConfigTestSSSDDomain(unittest.TestCase):
             'auth_provider',
             'access_provider',
             'chpass_provider',
-            'sudo_provider']
+            'sudo_provider',
+            'session_provider']
 
         self.assertTrue(type(options) == dict,
                         "Options should be a dictionary")
@@ -817,7 +818,8 @@ class SSSDConfigTestSSSDDomain(unittest.TestCase):
             'auth_provider',
             'access_provider',
             'chpass_provider',
-            'sudo_provider']
+            'sudo_provider',
+            'session_provider']
 
         self.assertTrue(type(options) == dict,
                         "Options should be a dictionary")
diff --git a/src/config/etc/sssd.api.conf b/src/config/etc/sssd.api.conf
index 6eb08a5d9cd1bb20b35c771885e0b1f6c882c2bb..b1fa70c8330eb9e725bb3825df052cdf83d2a613 100644
--- a/src/config/etc/sssd.api.conf
+++ b/src/config/etc/sssd.api.conf
@@ -55,6 +55,7 @@ auth_provider = str, None, false
 access_provider = str, None, false
 chpass_provider = str, None, false
 sudo_provider = str, None, false
+session_provider = str, None, false
 
 [domain]
 # Options available to all domains
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index 9965e52f6b9176d6bda60996cc88b4f08edba5bc..37cbb2f516c1afb57c1f791e47b418ee8ef66ebb 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -106,6 +106,7 @@ static struct bet_data bet_data[] = {
     {BET_ACCESS, CONFDB_DOMAIN_ACCESS_PROVIDER, "sssm_%s_access_init"},
     {BET_CHPASS, CONFDB_DOMAIN_CHPASS_PROVIDER, "sssm_%s_chpass_init"},
     {BET_SUDO, CONFDB_DOMAIN_SUDO_PROVIDER, "sssm_%s_sudo_init"},
+    {BET_SESSION, CONFDB_DOMAIN_SESSION_PROVIDER, "sssm_%s_session_init"},
     {BET_MAX, NULL, NULL}
 };
 
@@ -574,8 +575,10 @@ static int be_pam_handler(DBusMessage *message, struct sbus_connection *conn)
         case SSS_PAM_CHAUTHTOK_PRELIM:
             target = BET_CHPASS;
             break;
-        case SSS_PAM_SETCRED:
         case SSS_PAM_OPEN_SESSION:
+            target = BET_SESSION;
+            break;
+        case SSS_PAM_SETCRED:
         case SSS_PAM_CLOSE_SESSION:
             pd->pam_status = PAM_SUCCESS;
             goto done;
@@ -1419,6 +1422,21 @@ int be_process_init(TALLOC_CTX *mem_ctx,
                   "from provider [%s].\n", ctx->bet_info[BET_SUDO].mod_name));
     }
 
+    ret = load_backend_module(ctx, BET_SESSION,
+                              &ctx->bet_info[BET_SESSION],
+                              ctx->bet_info[BET_ID].mod_name);
+    if (ret != EOK) {
+        if (ret != ENOENT) {
+            DEBUG(SSSDBG_FATAL_FAILURE, ("fatal error initializing data providers\n"));
+            return ret;
+        }
+        DEBUG(SSSDBG_CRIT_FAILURE, ("No SUDO module provided for [%s] !!\n",
+                  be_domain));
+    } else {
+        DEBUG(SSSDBG_TRACE_ALL, ("SUDO backend target successfully loaded "
+                  "from provider [%s].\n", ctx->bet_info[BET_SUDO].mod_name));
+    }
+
     /* Handle SIGUSR1 to force offline behavior */
     BlockSignals(false, SIGUSR1);
     tes = tevent_add_signal(ctx->ev, ctx, SIGUSR1, 0,
diff --git a/src/providers/dp_backend.h b/src/providers/dp_backend.h
index 0964110ab850afc9ae338215633a7f656add1a8f..a580bbba8093f8659372e629a3c70a2a32b93bb2 100644
--- a/src/providers/dp_backend.h
+++ b/src/providers/dp_backend.h
@@ -50,6 +50,7 @@ enum bet_type {
     BET_ACCESS,
     BET_CHPASS,
     BET_SUDO,
+    BET_SESSION,
     BET_MAX
 };
 
-- 
1.7.6.4

