From 1de29c9ff602f208605d11a69bcbed388c67afff Mon Sep 17 00:00:00 2001
From: Jan Zeleny <jzeleny@redhat.com>
Date: Mon, 21 Nov 2011 06:26:44 -0500
Subject: [PATCH] Add ldap_sasl_minssf option

https://fedorahosted.org/sssd/ticket/1075
---
 src/config/SSSDConfig.py                   |    1 +
 src/config/etc/sssd.api.d/sssd-ipa.conf    |    1 +
 src/config/etc/sssd.api.d/sssd-ldap.conf   |    1 +
 src/providers/ipa/ipa_common.c             |    1 +
 src/providers/ipa/ipa_common.h             |    2 +-
 src/providers/ldap/ldap_common.c           |    1 +
 src/providers/ldap/sdap.h                  |    1 +
 src/providers/ldap/sdap_async_connection.c |   17 +++++++++++++++++
 8 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/src/config/SSSDConfig.py b/src/config/SSSDConfig.py
index 6858ce49c84625b10df571d07f30f9fd650b976a..b9ead7ddddd879f7efb91c51d143834ed97e7d5a 100644
--- a/src/config/SSSDConfig.py
+++ b/src/config/SSSDConfig.py
@@ -145,6 +145,7 @@ option_strings = {
     'ldap_sasl_mech' : _('Specify the sasl mechanism to use'),
     'ldap_sasl_authid' : _('Specify the sasl authorization id to use'),
     'ldap_sasl_realm' : _('Specify the sasl authorization realm to use'),
+    'ldap_sasl_minssf' : _('Specify the minimal SSF for LDAP sasl authorization'),
     'ldap_krb5_keytab' : _('Kerberos service keytab'),
     'ldap_krb5_init_creds' : _('Use Kerberos auth for LDAP connection'),
     'ldap_referrals' : _('Follow LDAP referrals'),
diff --git a/src/config/etc/sssd.api.d/sssd-ipa.conf b/src/config/etc/sssd.api.d/sssd-ipa.conf
index 9ea45285ec93c4afe0ea2210c5a27a68de894b3f..0103adfa6e59bcf728bfca3e61f6ea93a2a15ed0 100644
--- a/src/config/etc/sssd.api.d/sssd-ipa.conf
+++ b/src/config/etc/sssd.api.d/sssd-ipa.conf
@@ -22,6 +22,7 @@ ldap_tls_cipher_suite = str, None, false
 ldap_tls_reqcert = str, None, false
 ldap_sasl_mech = str, None, false
 ldap_sasl_authid = str, None, false
+ldap_sasl_minssf = int, None, false
 krb5_kdcip = str, None, false
 krb5_server = str, None, false
 krb5_realm = str, None, false
diff --git a/src/config/etc/sssd.api.d/sssd-ldap.conf b/src/config/etc/sssd.api.d/sssd-ldap.conf
index f76ce19a158f1f78f626aed75b178b292e61dc16..dcd1586c1b4eca55a0b58f8315a8806b818bc41c 100644
--- a/src/config/etc/sssd.api.d/sssd-ldap.conf
+++ b/src/config/etc/sssd.api.d/sssd-ldap.conf
@@ -31,6 +31,7 @@ ldap_deref = str, None, false
 ldap_page_size = int, None, false
 ldap_deref_threshold = int, None, false
 ldap_sasl_canonicalize = bool, None, false
+ldap_sasl_minssf = int, None, false
 
 [provider/ldap/id]
 ldap_search_timeout = int, None, false
diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c
index 8f9d5d77955cb7b01bfac69fc4ba00b136f866f2..861099fba1ad464f8d33025a4c973b452f3ecc4d 100644
--- a/src/providers/ipa/ipa_common.c
+++ b/src/providers/ipa/ipa_common.c
@@ -73,6 +73,7 @@ struct dp_option ipa_def_ldap_opts[] = {
     { "ldap_sasl_mech", DP_OPT_STRING, { "GSSAPI" } , NULL_STRING },
     { "ldap_sasl_authid", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_sasl_realm", DP_OPT_STRING, NULL_STRING, NULL_STRING },
+    { "ldap_sasl_minssf", DP_OPT_NUMBER, { .number = 56 }, NULL_NUMBER },
     { "ldap_krb5_keytab", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_krb5_init_creds", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
     /* use the same parm name as the krb5 module so we set it only once */
diff --git a/src/providers/ipa/ipa_common.h b/src/providers/ipa/ipa_common.h
index 40c5e53205285d761a43f6f0a77764006a5d79ca..cb579245ee2b93bccd16d1ae728ded4c2e16ec3c 100644
--- a/src/providers/ipa/ipa_common.h
+++ b/src/providers/ipa/ipa_common.h
@@ -35,7 +35,7 @@ struct ipa_service {
 /* the following defines are used to keep track of the options in the ldap
  * module, so that if they change and ipa is not updated correspondingly
  * this will trigger a runtime abort error */
-#define IPA_OPTS_BASIC_TEST 53
+#define IPA_OPTS_BASIC_TEST 54
 
 /* the following define is used to keep track of the options in the krb5
  * module, so that if they change and ipa is not updated correspondingly
diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c
index 9e2c2a4ae5de390ee1d4825a4c2b0d3738adff29..5dc6b7431cc6393033cd6a2fdd7b1a877d0197cc 100644
--- a/src/providers/ldap/ldap_common.c
+++ b/src/providers/ldap/ldap_common.c
@@ -64,6 +64,7 @@ struct dp_option default_basic_opts[] = {
     { "ldap_sasl_mech", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_sasl_authid", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_sasl_realm", DP_OPT_STRING, NULL_STRING, NULL_STRING },
+    { "ldap_sasl_minssf", DP_OPT_NUMBER, { .number = -1 }, NULL_NUMBER },
     { "ldap_krb5_keytab", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_krb5_init_creds", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
     /* use the same parm name as the krb5 module so we set it only once */
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
index b32560a8ffef3b55913aa1a4e6e82f27e5b3642e..3cebc1a7b673cfd22eaa1b51948038c1a9812407 100644
--- a/src/providers/ldap/sdap.h
+++ b/src/providers/ldap/sdap.h
@@ -179,6 +179,7 @@ enum sdap_basic_opt {
     SDAP_SASL_MECH,
     SDAP_SASL_AUTHID,
     SDAP_SASL_REALM,
+    SDAP_SASL_MINSSF,
     SDAP_KRB5_KEYTAB,
     SDAP_KRB5_KINIT,
     SDAP_KRB5_KDC,
diff --git a/src/providers/ldap/sdap_async_connection.c b/src/providers/ldap/sdap_async_connection.c
index 076e7ee3708d97341bd3cd2a0269331557ff19f1..6ccf4136ebb691ea22c090bd11a527e7685517f9 100644
--- a/src/providers/ldap/sdap_async_connection.c
+++ b/src/providers/ldap/sdap_async_connection.c
@@ -150,6 +150,8 @@ static void sdap_sys_connect_done(struct tevent_req *subreq)
     struct sdap_rebind_proc_params *rebind_proc_params;
     int sd;
     bool sasl_nocanon;
+    const char *sasl_mech;
+    int sasl_minssf;
 
     ret = sss_ldap_init_recv(subreq, &state->sh->ldap, &sd);
     talloc_zfree(subreq);
@@ -269,6 +271,21 @@ static void sdap_sys_connect_done(struct tevent_req *subreq)
         goto fail;
     }
 
+    sasl_mech = dp_opt_get_string(state->opts->basic, SDAP_SASL_MECH);
+    if (sasl_mech != NULL) {
+        sasl_minssf = dp_opt_get_int(state->opts->basic, SDAP_SASL_MINSSF);
+        if (sasl_minssf >= 0) {
+            lret = ldap_set_option(state->sh->ldap, LDAP_OPT_X_SASL_SSF_MIN,
+                                   &sasl_minssf);
+            if (lret != LDAP_OPT_SUCCESS) {
+                DEBUG(SSSDBG_CRIT_FAILURE,
+                      ("Failed to set LDAP MIN SSF option to %d\n",
+                       sasl_minssf));
+                goto fail;
+            }
+        }
+    }
+
     /* if we do not use start_tls the connection is not really connected yet
      * just fake an async procedure and leave connection to the bind call */
     if (!state->use_start_tls) {
-- 
1.7.6.4

