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

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