From 34858f28d68b63316f3bc69c27a62b0ea0ada34b Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Fri, 1 Jul 2011 16:12:58 -0400
Subject: [PATCH 7/8] Add ipa_hbac_treat_deny_as option

By default, we will treat the presence of any DENY rule as denying
all users. This option will allow the admin to explicitly ignore
DENY rules during a transitional period.
---
 src/config/SSSDConfig.py                |    1 +
 src/config/etc/sssd.api.d/sssd-ipa.conf |    1 +
 src/man/sssd-ipa.5.xml                  |   26 ++++++++++++++++++++++++++
 src/providers/ipa/ipa_access.c          |   11 ++++++++++-
 src/providers/ipa/ipa_common.c          |    3 ++-
 src/providers/ipa/ipa_common.h          |    1 +
 6 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/src/config/SSSDConfig.py b/src/config/SSSDConfig.py
index 21a4d16c396faf98d9972e452b4d046da4eb0372..2af4892b4fb1f80e0613ee621acb0c7297c3581d 100644
--- a/src/config/SSSDConfig.py
+++ b/src/config/SSSDConfig.py
@@ -98,6 +98,7 @@ option_strings = {
     'ipa_dyndns_iface' : _("The interface whose IP should be used for dynamic DNS updates"),
     'ipa_hbac_search_base' : _("Search base for HBAC related objects"),
     'ipa_hbac_refresh' : _("The amount of time between lookups of the HBAC rules against the IPA server"),
+    'ipa_hbac_treat_deny_as' : _("If DENY rules are present, either DENY_ALL or IGNORE"),
 
     # [provider/krb5]
     'krb5_kdcip' : _('Kerberos server address'),
diff --git a/src/config/etc/sssd.api.d/sssd-ipa.conf b/src/config/etc/sssd.api.d/sssd-ipa.conf
index b1ca5027be61934cb37cfff9238544c22fa3c928..b366b6bcbbb78206b1138967aa056c3910142aba 100644
--- a/src/config/etc/sssd.api.d/sssd-ipa.conf
+++ b/src/config/etc/sssd.api.d/sssd-ipa.conf
@@ -103,6 +103,7 @@ krb5_use_fast = str, None, false
 
 [provider/ipa/access]
 ipa_hbac_refresh = int, None, false
+ipa_hbac_treat_deny_as = str, None, false
 
 [provider/ipa/chpass]
 
diff --git a/src/man/sssd-ipa.5.xml b/src/man/sssd-ipa.5.xml
index f728e9ccf86df3e8a4f0ad6bc93c161747ea27f0..fbbab2a6ff1579f4a7c4b15001ee4c79f9d576c3 100644
--- a/src/man/sssd-ipa.5.xml
+++ b/src/man/sssd-ipa.5.xml
@@ -190,6 +190,32 @@
                         </para>
                     </listitem>
                 </varlistentry>
+                <varlistentry>
+                    <term>ipa_hbac_treat_deny_as (string)</term>
+                    <listitem>
+                        <para>
+                            This option specifies how to treat the deprecated
+                            DENY-type HBAC rules. As of FreeIPA v2.1, DENY
+                            rules are no longer supported on the server. All
+                            users of FreeIPA will need to migrate their rules
+                            to use only the ALLOW rules. The client will
+                            support two modes of operation during this
+                            transition period:
+                        </para>
+                        <para>
+                            <emphasis>DENY_ALL</emphasis>: If any HBAC rules
+                            are detected, all users will be denied access.
+                        </para>
+                        <para>
+                            <emphasis>IGNORE</emphasis>: SSSD will ignore any
+                            DENY rules. Be very careful with this option, as
+                            it may result in opening unintended access.
+                        </para>
+                        <para>
+                            Default: DENY_ALL
+                        </para>
+                    </listitem>
+                </varlistentry>
 
             </variablelist>
         </para>
diff --git a/src/providers/ipa/ipa_access.c b/src/providers/ipa/ipa_access.c
index db15835c9b01ac0b8d09f1e1811a3ed89e146f9b..29d56e52dba2f5d915bd0d5876dcba85525b6b0e 100644
--- a/src/providers/ipa/ipa_access.c
+++ b/src/providers/ipa/ipa_access.c
@@ -97,6 +97,7 @@ void ipa_access_handler(struct be_req *be_req)
 {
     struct pam_data *pd;
     struct hbac_ctx *hbac_ctx;
+    const char *deny_method;
     int pam_status = PAM_SYSTEM_ERR;
     struct ipa_access_ctx *ipa_access_ctx;
     int ret;
@@ -108,7 +109,7 @@ void ipa_access_handler(struct be_req *be_req)
         DEBUG(1, ("talloc failed.\n"));
         goto fail;
     }
-    hbac_ctx->get_deny_rules = true; /* make this a config option */
+
     hbac_ctx->be_req = be_req;
     hbac_ctx->pd = pd;
     ipa_access_ctx = talloc_get_type(
@@ -124,6 +125,14 @@ void ipa_access_handler(struct be_req *be_req)
         goto fail;
     }
 
+    deny_method = dp_opt_get_string(hbac_ctx->ipa_options,
+                                    IPA_HBAC_DENY_METHOD);
+    if (strcasecmp(deny_method, "IGNORE") == 0) {
+        hbac_ctx->get_deny_rules = false;
+    } else {
+        hbac_ctx->get_deny_rules = true;
+    }
+
     ret = hbac_retry(hbac_ctx);
     if (ret != EOK) {
         goto fail;
diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c
index 0995e0f1a02fb3e985d821d1a7cc87c78b3dbb4d..55a197244c1d94e37682e839c520b36767949562 100644
--- a/src/providers/ipa/ipa_common.c
+++ b/src/providers/ipa/ipa_common.c
@@ -38,7 +38,8 @@ struct dp_option ipa_basic_opts[] = {
     { "ipa_dyndns_iface", DP_OPT_STRING, NULL_STRING, NULL_STRING},
     { "ipa_hbac_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING},
     { "krb5_realm", DP_OPT_STRING, NULL_STRING, NULL_STRING},
-    { "ipa_hbac_refresh", DP_OPT_NUMBER, { .number = 5 }, NULL_NUMBER }
+    { "ipa_hbac_refresh", DP_OPT_NUMBER, { .number = 5 }, NULL_NUMBER },
+    { "ipa_hbac_treat_deny_as", DP_OPT_STRING, { "DENY_ALL" }, NULL_STRING }
 };
 
 struct dp_option ipa_def_ldap_opts[] = {
diff --git a/src/providers/ipa/ipa_common.h b/src/providers/ipa/ipa_common.h
index 1c1f722152de48a35d0ecbde2647a1df97d018cf..7fba7330cdbc5650d20ebf63a7cbab9b607c6745 100644
--- a/src/providers/ipa/ipa_common.h
+++ b/src/providers/ipa/ipa_common.h
@@ -51,6 +51,7 @@ enum ipa_basic_opt {
     IPA_HBAC_SEARCH_BASE,
     IPA_KRB5_REALM,
     IPA_HBAC_REFRESH,
+    IPA_HBAC_DENY_METHOD,
 
     IPA_OPTS_BASIC /* opts counter */
 };
-- 
1.7.5.4

