From 225c6899635f5556e8220e39b047c52e414cbf3f 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/14] 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 7cfc73d2b8a9dd61c796fcc14d69c778dc2a0227..bb485633595cb60859936717290db1a7fc927f05 100644
--- a/src/confdb/confdb.h
+++ b/src/confdb/confdb.h
@@ -105,6 +105,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 a26c42534c553167ab5d5fc5068fc82fc2e059b2..f6395679807aaba35a0385005d4858b2ef778ff5 100644
--- a/src/config/SSSDConfig.py
+++ b/src/config/SSSDConfig.py
@@ -78,6 +78,7 @@ option_strings = {
     'auth_provider' : _('Authentication provider'),
     'access_provider' : _('Access control provider'),
     'chpass_provider' : _('Password change 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 afc207c096cc0d79bdffd9eb7b9d8af7adf4c137..4704aff71bd74b8e4a9809456924a1c85dc63942 100755
--- a/src/config/SSSDConfigTest.py
+++ b/src/config/SSSDConfigTest.py
@@ -490,7 +490,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")
@@ -809,7 +810,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 34b67dec32ad56f1d22813de01f9ecd0db6346a1..31894208671f31ca4728304588d0b564c18f8c86 100644
--- a/src/config/etc/sssd.api.conf
+++ b/src/config/etc/sssd.api.conf
@@ -50,6 +50,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..796b28c64f62f3fdc8003dedd53409f86446996e 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(0, ("fatal error initializing data providers\n"));
+            return ret;
+        }
+        DEBUG(1, ("No SUDO module provided for [%s] !!\n",
+                  be_domain));
+    } else {
+        DEBUG(9, ("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

