Blame SOURCES/0053-sssctl-call-dbus-instead-of-pam-to-refresh-HBAC-rule.patch

ced1f5
From cbe1f1f8fa207eded53260a0fb288c5b31b18c96 Mon Sep 17 00:00:00 2001
ced1f5
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
ced1f5
Date: Thu, 2 Nov 2017 15:00:17 +0100
ced1f5
Subject: [PATCH 53/57] sssctl: call dbus instead of pam to refresh HBAC rules
ced1f5
MIME-Version: 1.0
ced1f5
Content-Type: text/plain; charset=UTF-8
ced1f5
Content-Transfer-Encoding: 8bit
ced1f5
ced1f5
Related:
ced1f5
https://pagure.io/SSSD/sssd/issue/2840
ced1f5
ced1f5
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
ced1f5
Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
ced1f5
(cherry picked from commit be804178d5e5fee64be2b080e73f4ce7b0074f76)
ced1f5
---
ced1f5
 src/tools/sssctl/sssctl_access_report.c | 127 +++++++++++++++-----------------
ced1f5
 1 file changed, 58 insertions(+), 69 deletions(-)
ced1f5
ced1f5
diff --git a/src/tools/sssctl/sssctl_access_report.c b/src/tools/sssctl/sssctl_access_report.c
ced1f5
index 11172329817b4dedaca480ab8a4537149853c330..8cf1a8a871b27827c317d658c0f93f34773c4841 100644
ced1f5
--- a/src/tools/sssctl/sssctl_access_report.c
ced1f5
+++ b/src/tools/sssctl/sssctl_access_report.c
ced1f5
@@ -15,11 +15,11 @@
ced1f5
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
ced1f5
 */
ced1f5
 
ced1f5
-#include <security/pam_appl.h>
ced1f5
-
ced1f5
 #include "util/util.h"
ced1f5
 #include "tools/common/sss_tools.h"
ced1f5
 #include "tools/sssctl/sssctl.h"
ced1f5
+#include "sbus/sssd_dbus.h"
ced1f5
+#include "responder/ifp/ifp_iface.h"
ced1f5
 
ced1f5
 /*
ced1f5
  * We're searching the cache directly..
ced1f5
@@ -27,58 +27,9 @@
ced1f5
 #include "providers/ipa/ipa_hbac_private.h"
ced1f5
 #include "providers/ipa/ipa_rules_common.h"
ced1f5
 
ced1f5
-#ifdef HAVE_SECURITY_PAM_MISC_H
ced1f5
-# include <security/pam_misc.h>
ced1f5
-#elif defined(HAVE_SECURITY_OPENPAM_H)
ced1f5
-# include <security/openpam.h>
ced1f5
-#endif
ced1f5
-
ced1f5
-#ifdef HAVE_SECURITY_PAM_MISC_H
ced1f5
-static struct pam_conv conv = {
ced1f5
-    misc_conv,
ced1f5
-    NULL
ced1f5
-};
ced1f5
-#elif defined(HAVE_SECURITY_OPENPAM_H)
ced1f5
-static struct pam_conv conv = {
ced1f5
-    openpam_ttyconv,
ced1f5
-    NULL
ced1f5
-};
ced1f5
-#else
ced1f5
-# error "Missing text based pam conversation function"
ced1f5
-#endif
ced1f5
-
ced1f5
-#ifndef DEFAULT_SERVICE
ced1f5
-#define DEFAULT_SERVICE "system-auth"
ced1f5
-#endif /* DEFAULT_SERVICE */
ced1f5
-
ced1f5
-#ifndef DEFAULT_USER
ced1f5
-#define DEFAULT_USER "admin"
ced1f5
-#endif /* DEFAULT_USER */
ced1f5
-
ced1f5
 typedef errno_t (*sssctl_dom_access_reporter_fn)(struct sss_tool_ctx *tool_ctx,
ced1f5
-                                                 const char *user,
ced1f5
-                                                 const char *service,
ced1f5
                                                  struct sss_domain_info *domain);
ced1f5
 
ced1f5
-static errno_t run_pam_acct(struct sss_tool_ctx *tool_ctx,
ced1f5
-                            const char *user,
ced1f5
-                            const char *service,
ced1f5
-                            struct sss_domain_info *domain)
ced1f5
-{
ced1f5
-    errno_t ret;
ced1f5
-    pam_handle_t *pamh;
ced1f5
-
ced1f5
-    ret = pam_start(service, user, &conv, &pamh);
ced1f5
-    if (ret != PAM_SUCCESS) {
ced1f5
-        ERROR("pam_start failed: %s\n", pam_strerror(pamh, ret));
ced1f5
-        return EIO;
ced1f5
-    }
ced1f5
-
ced1f5
-    ret = pam_acct_mgmt(pamh, 0);
ced1f5
-    pam_end(pamh, ret);
ced1f5
-    return ret;
ced1f5
-}
ced1f5
-
ced1f5
 static errno_t get_rdn_value(TALLOC_CTX *mem_ctx,
ced1f5
                              struct sss_domain_info *dom,
ced1f5
                              const char *dn_attr,
ced1f5
@@ -315,9 +266,58 @@ static void print_ipa_hbac_rule(struct sss_domain_info *domain,
ced1f5
     PRINT("\n");
ced1f5
 }
ced1f5
 
ced1f5
+static errno_t refresh_hbac_rules(struct sss_tool_ctx *tool_ctx,
ced1f5
+                                  struct sss_domain_info *domain)
ced1f5
+{
ced1f5
+    TALLOC_CTX *tmp_ctx;
ced1f5
+    sss_sifp_error error;
ced1f5
+    sss_sifp_ctx *sifp;
ced1f5
+    DBusMessage *reply;
ced1f5
+    const char *path;
ced1f5
+    errno_t ret;
ced1f5
+
ced1f5
+    tmp_ctx = talloc_new(NULL);
ced1f5
+    if (tmp_ctx == NULL) {
ced1f5
+        DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
ced1f5
+        return ENOMEM;
ced1f5
+    }
ced1f5
+
ced1f5
+    path = sbus_opath_compose(tmp_ctx, IFP_PATH_DOMAINS, domain->name);
ced1f5
+    if (path == NULL) {
ced1f5
+        printf(_("Out of memory!\n"));
ced1f5
+        ret = ENOMEM;
ced1f5
+        goto done;
ced1f5
+    }
ced1f5
+
ced1f5
+    error = sssctl_sifp_init(tool_ctx, &sifp);
ced1f5
+    if (error != SSS_SIFP_OK) {
ced1f5
+        sssctl_sifp_error(sifp, error, "Unable to connect to the InfoPipe");
ced1f5
+        ret = EIO;
ced1f5
+        goto done;
ced1f5
+    }
ced1f5
+
ced1f5
+    error = sssctl_sifp_send(tmp_ctx, sifp, &reply, path,
ced1f5
+                             IFACE_IFP_DOMAINS_DOMAIN,
ced1f5
+                             IFACE_IFP_DOMAINS_DOMAIN_REFRESHACCESSRULES);
ced1f5
+    if (error != SSS_SIFP_OK) {
ced1f5
+        sssctl_sifp_error(sifp, error, "Unable to refresh HBAC rules");
ced1f5
+        ret = EIO;
ced1f5
+        goto done;
ced1f5
+    }
ced1f5
+
ced1f5
+    ret = sbus_parse_reply(reply);
ced1f5
+    if (ret != EOK) {
ced1f5
+        goto done;
ced1f5
+    }
ced1f5
+
ced1f5
+    ret = EOK;
ced1f5
+
ced1f5
+done:
ced1f5
+    talloc_free(tmp_ctx);
ced1f5
+    return ret;
ced1f5
+}
ced1f5
+
ced1f5
 static errno_t sssctl_ipa_access_report(struct sss_tool_ctx *tool_ctx,
ced1f5
-                                        const char *user,
ced1f5
-                                        const char *service,
ced1f5
                                         struct sss_domain_info *domain)
ced1f5
 {
ced1f5
     TALLOC_CTX *tmp_ctx = NULL;
ced1f5
@@ -338,9 +338,9 @@ static errno_t sssctl_ipa_access_report(struct sss_tool_ctx *tool_ctx,
ced1f5
     struct ldb_message **msgs = NULL;
ced1f5
 
ced1f5
     /* Run the pam account phase to make sure the rules are fetched by SSSD */
ced1f5
-    ret = run_pam_acct(tool_ctx, user, service, domain);
ced1f5
-    if (ret != PAM_SUCCESS && ret != PAM_PERM_DENIED) {
ced1f5
-        ERROR("Cannot run the PAM account phase, reporting stale rules\n");
ced1f5
+    ret = refresh_hbac_rules(tool_ctx, domain);
ced1f5
+    if (ret != EOK) {
ced1f5
+        ERROR("Unable to refresh HBAC rules, using cached content\n");
ced1f5
         /* Non-fatal */
ced1f5
     }
ced1f5
 
ced1f5
@@ -398,19 +398,8 @@ errno_t sssctl_access_report(struct sss_cmdline *cmdline,
ced1f5
     const char *domname = NULL;
ced1f5
     sssctl_dom_access_reporter_fn reporter;
ced1f5
     struct sss_domain_info *dom;
ced1f5
-    const char *user = DEFAULT_USER;
ced1f5
-    const char *service = DEFAULT_SERVICE;
ced1f5
 
ced1f5
-    /* Parse command line. */
ced1f5
-    struct poptOption options[] = {
ced1f5
-        { "user", 'u', POPT_ARG_STRING, &user, 0,
ced1f5
-          _("PAM user, default: " DEFAULT_USER), NULL },
ced1f5
-        { "service", 's', POPT_ARG_STRING, &service, 0,
ced1f5
-          _("PAM service, default: " DEFAULT_SERVICE), NULL },
ced1f5
-        POPT_TABLEEND
ced1f5
-    };
ced1f5
-
ced1f5
-    ret = sss_tool_popt_ex(cmdline, options, SSS_TOOL_OPT_OPTIONAL,
ced1f5
+    ret = sss_tool_popt_ex(cmdline, NULL, SSS_TOOL_OPT_OPTIONAL,
ced1f5
                            NULL, NULL, "DOMAIN", _("Specify domain name."),
ced1f5
                            &domname, NULL);
ced1f5
     if (ret != EOK) {
ced1f5
@@ -431,5 +420,5 @@ errno_t sssctl_access_report(struct sss_cmdline *cmdline,
ced1f5
         return ret;
ced1f5
     }
ced1f5
 
ced1f5
-    return reporter(tool_ctx, user, service, dom);
ced1f5
+    return reporter(tool_ctx, dom);
ced1f5
 }
ced1f5
-- 
ced1f5
2.14.3
ced1f5