06067d
From 1d5dc35b3c5d793f75cd6572bdda2a1ab0df99cc Mon Sep 17 00:00:00 2001
06067d
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
06067d
Date: Fri, 10 Dec 2021 16:08:04 +0100
06067d
Subject: [PATCH 01/10] s3:utils: set ads->auth.flags using krb5_state
06067d
MIME-Version: 1.0
06067d
Content-Type: text/plain; charset=UTF-8
06067d
Content-Transfer-Encoding: 8bit
06067d
06067d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14955
06067d
06067d
Pair-Programmed-With: Andreas Schneider <asn@samba.org>
06067d
06067d
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
06067d
Signed-off-by: Andreas Schneider <asn@samba.org>
06067d
Reviewed-by: Stefan Metzmacher <metze@samba.org>
06067d
(cherry picked from commit afcdb090769f6f0f66428cd29f88b0283c6bd527)
06067d
---
06067d
 source3/utils/net_ads.c | 22 +++++++++++++++++++++-
06067d
 1 file changed, 21 insertions(+), 1 deletion(-)
06067d
06067d
diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c
06067d
index 6ab4a0096b1..8f993f9ba4c 100644
06067d
--- a/source3/utils/net_ads.c
06067d
+++ b/source3/utils/net_ads.c
06067d
@@ -607,6 +607,8 @@ static ADS_STATUS ads_startup_int(struct net_context *c, bool only_own_domain,
06067d
 	char *cp;
06067d
 	const char *realm = NULL;
06067d
 	bool tried_closest_dc = false;
06067d
+	enum credentials_use_kerberos krb5_state =
06067d
+		CRED_USE_KERBEROS_DISABLED;
06067d
 
06067d
 	/* lp_realm() should be handled by a command line param,
06067d
 	   However, the join requires that realm be set in smb.conf
06067d
@@ -650,10 +652,28 @@ retry:
06067d
 		ads->auth.password = smb_xstrdup(c->opt_password);
06067d
 	}
06067d
 
06067d
-	ads->auth.flags |= auth_flags;
06067d
 	SAFE_FREE(ads->auth.user_name);
06067d
 	ads->auth.user_name = smb_xstrdup(c->opt_user_name);
06067d
 
06067d
+	ads->auth.flags |= auth_flags;
06067d
+
06067d
+	/* The ADS code will handle FIPS mode */
06067d
+	krb5_state = cli_credentials_get_kerberos_state(c->creds);
06067d
+	switch (krb5_state) {
06067d
+	case CRED_USE_KERBEROS_REQUIRED:
06067d
+		ads->auth.flags &= ~ADS_AUTH_DISABLE_KERBEROS;
06067d
+		ads->auth.flags &= ~ADS_AUTH_ALLOW_NTLMSSP;
06067d
+		break;
06067d
+	case CRED_USE_KERBEROS_DESIRED:
06067d
+		ads->auth.flags &= ~ADS_AUTH_DISABLE_KERBEROS;
06067d
+		ads->auth.flags |= ADS_AUTH_ALLOW_NTLMSSP;
06067d
+		break;
06067d
+	case CRED_USE_KERBEROS_DISABLED:
06067d
+		ads->auth.flags |= ADS_AUTH_DISABLE_KERBEROS;
06067d
+		ads->auth.flags |= ADS_AUTH_ALLOW_NTLMSSP;
06067d
+		break;
06067d
+	}
06067d
+
06067d
        /*
06067d
         * If the username is of the form "name@realm",
06067d
         * extract the realm and convert to upper case.
06067d
-- 
06067d
2.33.1
06067d
06067d
06067d
From 8f5c1246fdf03ae4d4abba50ef41e2a5cded61d3 Mon Sep 17 00:00:00 2001
06067d
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
06067d
Date: Wed, 8 Dec 2021 16:05:17 +0100
06067d
Subject: [PATCH 02/10] s3:libads: Remove trailing spaces from sasl.c
06067d
MIME-Version: 1.0
06067d
Content-Type: text/plain; charset=UTF-8
06067d
Content-Transfer-Encoding: 8bit
06067d
06067d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14955
06067d
06067d
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
06067d
Signed-off-by: Andreas Schneider <asn@samba.org>
06067d
Reviewed-by: Stefan Metzmacher <metze@samba.org>
06067d
(cherry picked from commit 49d18f2d6e8872c2b0cbe2bf3324e7057c8438f4)
06067d
---
06067d
 source3/libads/sasl.c | 22 +++++++++++-----------
06067d
 1 file changed, 11 insertions(+), 11 deletions(-)
06067d
06067d
diff --git a/source3/libads/sasl.c b/source3/libads/sasl.c
06067d
index 60fa2bf80cb..b91e2d15bcf 100644
06067d
--- a/source3/libads/sasl.c
06067d
+++ b/source3/libads/sasl.c
06067d
@@ -1,18 +1,18 @@
06067d
-/* 
06067d
+/*
06067d
    Unix SMB/CIFS implementation.
06067d
    ads sasl code
06067d
    Copyright (C) Andrew Tridgell 2001
06067d
-   
06067d
+
06067d
    This program is free software; you can redistribute it and/or modify
06067d
    it under the terms of the GNU General Public License as published by
06067d
    the Free Software Foundation; either version 3 of the License, or
06067d
    (at your option) any later version.
06067d
-   
06067d
+
06067d
    This program is distributed in the hope that it will be useful,
06067d
    but WITHOUT ANY WARRANTY; without even the implied warranty of
06067d
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
06067d
    GNU General Public License for more details.
06067d
-   
06067d
+
06067d
    You should have received a copy of the GNU General Public License
06067d
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
06067d
 */
06067d
@@ -117,7 +117,7 @@ static const struct ads_saslwrap_ops ads_sasl_gensec_ops = {
06067d
 	.disconnect	= ads_sasl_gensec_disconnect
06067d
 };
06067d
 
06067d
-/* 
06067d
+/*
06067d
    perform a LDAP/SASL/SPNEGO/{NTLMSSP,KRB5} bind (just how many layers can
06067d
    we fit on one socket??)
06067d
 */
06067d
@@ -496,7 +496,7 @@ static ADS_STATUS ads_generate_service_principal(ADS_STRUCT *ads,
06067d
 
06067d
 #endif /* HAVE_KRB5 */
06067d
 
06067d
-/* 
06067d
+/*
06067d
    this performs a SASL/SPNEGO bind
06067d
 */
06067d
 static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
06067d
@@ -529,7 +529,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
06067d
 	file_save("sasl_spnego.dat", blob.data, blob.length);
06067d
 #endif
06067d
 
06067d
-	/* the server sent us the first part of the SPNEGO exchange in the negprot 
06067d
+	/* the server sent us the first part of the SPNEGO exchange in the negprot
06067d
 	   reply */
06067d
 	if (!spnego_parse_negTokenInit(talloc_tos(), blob, OIDs, &given_principal, NULL) ||
06067d
 			OIDs[0] == NULL) {
06067d
@@ -557,7 +557,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
06067d
 
06067d
 #ifdef HAVE_KRB5
06067d
 	if (!(ads->auth.flags & ADS_AUTH_DISABLE_KERBEROS) &&
06067d
-	    got_kerberos_mechanism) 
06067d
+	    got_kerberos_mechanism)
06067d
 	{
06067d
 		mech = "KRB5";
06067d
 
06067d
@@ -578,7 +578,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
06067d
 				  "calling kinit\n", ads_errstr(status)));
06067d
 		}
06067d
 
06067d
-		status = ADS_ERROR_KRB5(ads_kinit_password(ads)); 
06067d
+		status = ADS_ERROR_KRB5(ads_kinit_password(ads));
06067d
 
06067d
 		if (ADS_ERR_OK(status)) {
06067d
 			status = ads_sasl_spnego_gensec_bind(ads, "GSS-SPNEGO",
06067d
@@ -597,7 +597,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
06067d
 		}
06067d
 
06067d
 		/* only fallback to NTLMSSP if allowed */
06067d
-		if (ADS_ERR_OK(status) || 
06067d
+		if (ADS_ERR_OK(status) ||
06067d
 		    !(ads->auth.flags & ADS_AUTH_ALLOW_NTLMSSP)) {
06067d
 			goto done;
06067d
 		}
06067d
@@ -613,7 +613,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
06067d
 #endif
06067d
 
06067d
 	/* lets do NTLMSSP ... this has the big advantage that we don't need
06067d
-	   to sync clocks, and we don't rely on special versions of the krb5 
06067d
+	   to sync clocks, and we don't rely on special versions of the krb5
06067d
 	   library for HMAC_MD4 encryption */
06067d
 	mech = "NTLMSSP";
06067d
 	status = ads_sasl_spnego_gensec_bind(ads, "GSS-SPNEGO",
06067d
-- 
06067d
2.33.1
06067d
06067d
06067d
From 2885c2186fd2d1d8e2fc5f90e58f54b0c72a72df Mon Sep 17 00:00:00 2001
06067d
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
06067d
Date: Thu, 9 Dec 2021 13:43:08 +0100
06067d
Subject: [PATCH 03/10] s3:libads: Disable NTLMSSP for FIPS
06067d
MIME-Version: 1.0
06067d
Content-Type: text/plain; charset=UTF-8
06067d
Content-Transfer-Encoding: 8bit
06067d
06067d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14955
06067d
06067d
Pair-Programmed-With: Andreas Schneider <asn@samba.org>
06067d
06067d
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
06067d
Signed-off-by: Andreas Schneider <asn@samba.org>
06067d
Reviewed-by: Stefan Metzmacher <metze@samba.org>
06067d
(cherry picked from commit 7785eb9b78066f6f7ee2541cf72d80fcf7411329)
06067d
---
06067d
 source3/libads/sasl.c | 10 +++++++++-
06067d
 1 file changed, 9 insertions(+), 1 deletion(-)
06067d
06067d
diff --git a/source3/libads/sasl.c b/source3/libads/sasl.c
06067d
index b91e2d15bcf..992f7022a69 100644
06067d
--- a/source3/libads/sasl.c
06067d
+++ b/source3/libads/sasl.c
06067d
@@ -604,7 +604,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
06067d
 
06067d
 		DEBUG(1,("ads_sasl_spnego_gensec_bind(KRB5) failed "
06067d
 			 "for %s/%s with user[%s] realm[%s]: %s, "
06067d
-			 "fallback to NTLMSSP\n",
06067d
+			 "try to fallback to NTLMSSP\n",
06067d
 			 p.service, p.hostname,
06067d
 			 ads->auth.user_name,
06067d
 			 ads->auth.realm,
06067d
@@ -616,6 +616,14 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
06067d
 	   to sync clocks, and we don't rely on special versions of the krb5
06067d
 	   library for HMAC_MD4 encryption */
06067d
 	mech = "NTLMSSP";
06067d
+
06067d
+	if (lp_weak_crypto() == SAMBA_WEAK_CRYPTO_DISALLOWED) {
06067d
+		DBG_WARNING("We can't fallback to NTLMSSP, weak crypto is"
06067d
+			    " disallowed.\n");
06067d
+		status = ADS_ERROR_NT(NT_STATUS_NETWORK_CREDENTIAL_CONFLICT);
06067d
+		goto done;
06067d
+	}
06067d
+
06067d
 	status = ads_sasl_spnego_gensec_bind(ads, "GSS-SPNEGO",
06067d
 					     CRED_USE_KERBEROS_DISABLED,
06067d
 					     p.service, p.hostname,
06067d
-- 
06067d
2.33.1
06067d
06067d
06067d
From 636281a0b09f20e4c91f649a950a8c9ca53d1e3c Mon Sep 17 00:00:00 2001
06067d
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
06067d
Date: Fri, 7 Jan 2022 10:31:19 +0100
06067d
Subject: [PATCH 04/10] s3:libads: Improve debug messages for SASL bind
06067d
MIME-Version: 1.0
06067d
Content-Type: text/plain; charset=UTF-8
06067d
Content-Transfer-Encoding: 8bit
06067d
06067d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14955
06067d
06067d
Pair-Programmed-With: Andreas Schneider <asn@samba.org>
06067d
06067d
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
06067d
Signed-off-by: Andreas Schneider <asn@samba.org>
06067d
Reviewed-by: Stefan Metzmacher <metze@samba.org>
06067d
(cherry picked from commit 5f6251abf2f468b3744a96376b0e1c3bc317c738)
06067d
---
06067d
 source3/libads/sasl.c | 22 +++++++++++-----------
06067d
 1 file changed, 11 insertions(+), 11 deletions(-)
06067d
06067d
diff --git a/source3/libads/sasl.c b/source3/libads/sasl.c
06067d
index 992f7022a69..ea98aa47ecd 100644
06067d
--- a/source3/libads/sasl.c
06067d
+++ b/source3/libads/sasl.c
06067d
@@ -586,13 +586,13 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
06067d
 							p.service, p.hostname,
06067d
 							blob);
06067d
 			if (!ADS_ERR_OK(status)) {
06067d
-				DEBUG(0,("kinit succeeded but "
06067d
-					"ads_sasl_spnego_gensec_bind(KRB5) failed "
06067d
-					"for %s/%s with user[%s] realm[%s]: %s\n",
06067d
+				DBG_ERR("kinit succeeded but "
06067d
+					"SPNEGO bind with Kerberos failed "
06067d
+					"for %s/%s - user[%s], realm[%s]: %s\n",
06067d
 					p.service, p.hostname,
06067d
 					ads->auth.user_name,
06067d
 					ads->auth.realm,
06067d
-					ads_errstr(status)));
06067d
+					ads_errstr(status));
06067d
 			}
06067d
 		}
06067d
 
06067d
@@ -602,13 +602,13 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
06067d
 			goto done;
06067d
 		}
06067d
 
06067d
-		DEBUG(1,("ads_sasl_spnego_gensec_bind(KRB5) failed "
06067d
-			 "for %s/%s with user[%s] realm[%s]: %s, "
06067d
-			 "try to fallback to NTLMSSP\n",
06067d
-			 p.service, p.hostname,
06067d
-			 ads->auth.user_name,
06067d
-			 ads->auth.realm,
06067d
-			 ads_errstr(status)));
06067d
+		DBG_WARNING("SASL bind with Kerberos failed "
06067d
+			    "for %s/%s - user[%s], realm[%s]: %s, "
06067d
+			    "try to fallback to NTLMSSP\n",
06067d
+			    p.service, p.hostname,
06067d
+			    ads->auth.user_name,
06067d
+			    ads->auth.realm,
06067d
+			    ads_errstr(status));
06067d
 	}
06067d
 #endif
06067d
 
06067d
-- 
06067d
2.33.1
06067d
06067d
06067d
From db4df8c4ebc9a10d14174878c3303c5f7a9e3d2f Mon Sep 17 00:00:00 2001
06067d
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
06067d
Date: Mon, 3 Jan 2022 11:13:06 +0100
06067d
Subject: [PATCH 05/10] s3:libads: Disable NTLMSSP if not allowed (for builds
06067d
 without kerberos)
06067d
MIME-Version: 1.0
06067d
Content-Type: text/plain; charset=UTF-8
06067d
Content-Transfer-Encoding: 8bit
06067d
06067d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14955
06067d
06067d
Pair-Programmed-With: Andreas Schneider <asn@samba.org>
06067d
06067d
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
06067d
Signed-off-by: Andreas Schneider <asn@samba.org>
06067d
Reviewed-by: Stefan Metzmacher <metze@samba.org>
06067d
(cherry picked from commit 17ea2ccdabbe935ef571e1227908d51b755707bc)
06067d
---
06067d
 source3/libads/sasl.c | 6 ++++++
06067d
 1 file changed, 6 insertions(+)
06067d
06067d
diff --git a/source3/libads/sasl.c b/source3/libads/sasl.c
06067d
index ea98aa47ecd..1bcfe0490a8 100644
06067d
--- a/source3/libads/sasl.c
06067d
+++ b/source3/libads/sasl.c
06067d
@@ -617,6 +617,12 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
06067d
 	   library for HMAC_MD4 encryption */
06067d
 	mech = "NTLMSSP";
06067d
 
06067d
+	if (!(ads->auth.flags & ADS_AUTH_ALLOW_NTLMSSP)) {
06067d
+		DBG_WARNING("We can't use NTLMSSP, it is not allowed.\n");
06067d
+		status = ADS_ERROR_NT(NT_STATUS_NETWORK_CREDENTIAL_CONFLICT);
06067d
+		goto done;
06067d
+	}
06067d
+
06067d
 	if (lp_weak_crypto() == SAMBA_WEAK_CRYPTO_DISALLOWED) {
06067d
 		DBG_WARNING("We can't fallback to NTLMSSP, weak crypto is"
06067d
 			    " disallowed.\n");
06067d
-- 
06067d
2.33.1
06067d
06067d
06067d
From 86e4b3649f001e162328b1b89ea2d068056514e7 Mon Sep 17 00:00:00 2001
06067d
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
06067d
Date: Mon, 3 Jan 2022 15:33:46 +0100
06067d
Subject: [PATCH 06/10] tests: Add test for disabling NTLMSSP for ldap client
06067d
 connections
06067d
MIME-Version: 1.0
06067d
Content-Type: text/plain; charset=UTF-8
06067d
Content-Transfer-Encoding: 8bit
06067d
06067d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14955
06067d
06067d
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
06067d
Signed-off-by: Andreas Schneider <asn@samba.org>
06067d
Reviewed-by: Stefan Metzmacher <metze@samba.org>
06067d
(cherry picked from commit eb0fa26dce77829995505f542af02e32df088cd6)
06067d
---
06067d
 .../test_weak_disable_ntlmssp_ldap.sh         | 41 +++++++++++++++++++
06067d
 1 file changed, 41 insertions(+)
06067d
 create mode 100755 testprogs/blackbox/test_weak_disable_ntlmssp_ldap.sh
06067d
06067d
diff --git a/testprogs/blackbox/test_weak_disable_ntlmssp_ldap.sh b/testprogs/blackbox/test_weak_disable_ntlmssp_ldap.sh
06067d
new file mode 100755
06067d
index 00000000000..2822ab29d14
06067d
--- /dev/null
06067d
+++ b/testprogs/blackbox/test_weak_disable_ntlmssp_ldap.sh
06067d
@@ -0,0 +1,41 @@
06067d
+#!/bin/sh
06067d
+# Blackbox tests for diabing NTLMSSP for ldap clinet connections
06067d
+# Copyright (c) 2022      Pavel Filipenský <pfilipen@redhat.com>
06067d
+
06067d
+if [ $# -lt 2 ]; then
06067d
+cat <
06067d
+Usage: $0 USERNAME PASSWORD
06067d
+EOF
06067d
+exit 1;
06067d
+fi
06067d
+
06067d
+USERNAME=$1
06067d
+PASSWORD=$2
06067d
+shift 2
06067d
+
06067d
+failed=0
06067d
+. `dirname $0`/subunit.sh
06067d
+
06067d
+samba_testparm="$BINDIR/testparm"
06067d
+samba_net="$BINDIR/net"
06067d
+
06067d
+unset GNUTLS_FORCE_FIPS_MODE
06067d
+
06067d
+# Checks that testparm reports: Weak crypto is allowed
06067d
+testit_grep "testparm" "Weak crypto is allowed" $samba_testparm --suppress-prompt $SMB_CONF_PATH 2>&1 || failed=`expr $failed + 1`
06067d
+
06067d
+# We should be allowed to use NTLM for connecting
06067d
+testit "net_ads_search.ntlm" $samba_net ads search --use-kerberos=off '(objectCategory=group)' sAMAccountName -U${USERNAME}%${PASSWORD} || failed=`expr $failed + 1`
06067d
+
06067d
+GNUTLS_FORCE_FIPS_MODE=1
06067d
+export GNUTLS_FORCE_FIPS_MODE
06067d
+
06067d
+# Checks that testparm reports: Weak crypto is disallowed
06067d
+testit_grep "testparm" "Weak crypto is disallowed" $samba_testparm --suppress-prompt $SMB_CONF_PATH 2>&1 || failed=`expr $failed + 1`
06067d
+
06067d
+# We should not be allowed to use NTLM for connecting
06067d
+testit_expect_failure_grep "net_ads_search.ntlm" "We can't fallback to NTLMSSP, weak crypto is disallowed." $samba_net ads search --use-kerberos=off -d10 '(objectCategory=group)' sAMAccountName -U${USERNAME}%${PASSWORD} || failed=`expr $failed + 1`
06067d
+
06067d
+unset GNUTLS_FORCE_FIPS_MODE
06067d
+
06067d
+exit $failed
06067d
-- 
06067d
2.33.1
06067d
06067d
06067d
From bd39e9418da9dee81d5872037aa5834deba2b40b Mon Sep 17 00:00:00 2001
06067d
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
06067d
Date: Tue, 4 Jan 2022 12:00:20 +0100
06067d
Subject: [PATCH 07/10] s4:selftest: plan test suite
06067d
 samba4.blackbox.test_weak_disable_ntlmssp_ldap
06067d
MIME-Version: 1.0
06067d
Content-Type: text/plain; charset=UTF-8
06067d
Content-Transfer-Encoding: 8bit
06067d
06067d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14955
06067d
06067d
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
06067d
Signed-off-by: Andreas Schneider <asn@samba.org>
06067d
Reviewed-by: Stefan Metzmacher <metze@samba.org>
06067d
(cherry picked from commit 9624e60e8c32de695661ae8f0fb5f8f9d836ab95)
06067d
---
06067d
 source4/selftest/tests.py | 1 +
06067d
 1 file changed, 1 insertion(+)
06067d
06067d
diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py
06067d
index 1e4b2ae6dd3..3a6a716f061 100755
06067d
--- a/source4/selftest/tests.py
06067d
+++ b/source4/selftest/tests.py
06067d
@@ -636,6 +636,7 @@ plantestsuite("samba4.blackbox.samba-tool_ntacl(ad_member:local)", "ad_member:lo
06067d
 
06067d
 if have_gnutls_fips_mode_support:
06067d
     plantestsuite("samba4.blackbox.weak_crypto.client", "ad_dc", [os.path.join(bbdir, "test_weak_crypto.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$REALM', '$DOMAIN', "$PREFIX/ad_dc"])
06067d
+    plantestsuite("samba4.blackbox.test_weak_disable_ntlmssp_ldap", "ad_member:local", [os.path.join(bbdir, "test_weak_disable_ntlmssp_ldap.sh"),'$DC_USERNAME', '$DC_PASSWORD'])
06067d
 
06067d
     for env in ["ad_dc_fips", "ad_member_fips"]:
06067d
         plantestsuite("samba4.blackbox.weak_crypto.server", env, [os.path.join(bbdir, "test_weak_crypto_server.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$REALM', '$DOMAIN', "$PREFIX/ad_dc_fips", configuration])
06067d
-- 
06067d
2.33.1
06067d
06067d
06067d
From bde5c51a9eef39a165dad7aadf23ecaa5921f520 Mon Sep 17 00:00:00 2001
06067d
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
06067d
Date: Tue, 18 Jan 2022 19:47:38 +0100
06067d
Subject: [PATCH 08/10] s3:winbindd: Remove trailing spaces from winbindd_ads.c
06067d
MIME-Version: 1.0
06067d
Content-Type: text/plain; charset=UTF-8
06067d
Content-Transfer-Encoding: 8bit
06067d
06067d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14955
06067d
06067d
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
06067d
Signed-off-by: Andreas Schneider <asn@samba.org>
06067d
Reviewed-by: Stefan Metzmacher <metze@samba.org>
06067d
(cherry picked from commit fcf225a356abb06d1205f66eb79f707c85803cb5)
06067d
---
06067d
 source3/winbindd/winbindd_ads.c | 38 ++++++++++++++++-----------------
06067d
 1 file changed, 19 insertions(+), 19 deletions(-)
06067d
06067d
diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c
06067d
index 948c903f165..e415df347e6 100644
06067d
--- a/source3/winbindd/winbindd_ads.c
06067d
+++ b/source3/winbindd/winbindd_ads.c
06067d
@@ -326,7 +326,7 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain,
06067d
 
06067d
 	if ( !winbindd_can_contact_domain( domain ) ) {
06067d
 		DEBUG(10,("query_user_list: No incoming trust for domain %s\n",
06067d
-			  domain->name));		
06067d
+			  domain->name));
06067d
 		return NT_STATUS_OK;
06067d
 	}
06067d
 
06067d
@@ -432,7 +432,7 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
06067d
 
06067d
 	if ( !winbindd_can_contact_domain( domain ) ) {
06067d
 		DEBUG(10,("enum_dom_groups: No incoming trust for domain %s\n",
06067d
-			  domain->name));		
06067d
+			  domain->name));
06067d
 		return NT_STATUS_OK;
06067d
 	}
06067d
 
06067d
@@ -447,7 +447,7 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
06067d
 	 * According to Section 5.1(4) of RFC 2251 if a value of a type is it's
06067d
 	 * default value, it MUST be absent. In case of extensible matching the
06067d
 	 * "dnattr" boolean defaults to FALSE and so it must be only be present
06067d
-	 * when set to TRUE. 
06067d
+	 * when set to TRUE.
06067d
 	 *
06067d
 	 * When it is set to FALSE and the OpenLDAP lib (correctly) encodes a
06067d
 	 * filter using bitwise matching rule then the buggy AD fails to decode
06067d
@@ -458,9 +458,9 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
06067d
 	 *
06067d
 	 * Thanks to Ralf Haferkamp for input and testing - Guenther */
06067d
 
06067d
-	filter = talloc_asprintf(mem_ctx, "(&(objectCategory=group)(&(groupType:dn:%s:=%d)(!(groupType:dn:%s:=%d))))", 
06067d
+	filter = talloc_asprintf(mem_ctx, "(&(objectCategory=group)(&(groupType:dn:%s:=%d)(!(groupType:dn:%s:=%d))))",
06067d
 				 ADS_LDAP_MATCHING_RULE_BIT_AND, GROUP_TYPE_SECURITY_ENABLED,
06067d
-				 ADS_LDAP_MATCHING_RULE_BIT_AND, 
06067d
+				 ADS_LDAP_MATCHING_RULE_BIT_AND,
06067d
 				 enum_dom_local_groups ? GROUP_TYPE_BUILTIN_LOCAL_GROUP : GROUP_TYPE_RESOURCE_GROUP);
06067d
 
06067d
 	if (filter == NULL) {
06067d
@@ -529,7 +529,7 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
06067d
 	DEBUG(3,("ads enum_dom_groups gave %d entries\n", (*num_entries)));
06067d
 
06067d
 done:
06067d
-	if (res) 
06067d
+	if (res)
06067d
 		ads_msgfree(ads, res);
06067d
 
06067d
 	return status;
06067d
@@ -542,12 +542,12 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
06067d
 				struct wb_acct_info **info)
06067d
 {
06067d
 	/*
06067d
-	 * This is a stub function only as we returned the domain 
06067d
+	 * This is a stub function only as we returned the domain
06067d
 	 * local groups in enum_dom_groups() if the domain->native field
06067d
 	 * was true.  This is a simple performance optimization when
06067d
 	 * using LDAP.
06067d
 	 *
06067d
-	 * if we ever need to enumerate domain local groups separately, 
06067d
+	 * if we ever need to enumerate domain local groups separately,
06067d
 	 * then this optimization in enum_dom_groups() will need
06067d
 	 * to be split out
06067d
 	 */
06067d
@@ -601,7 +601,7 @@ static NTSTATUS rids_to_names(struct winbindd_domain *domain,
06067d
    tokenGroups are not available. */
06067d
 static NTSTATUS lookup_usergroups_member(struct winbindd_domain *domain,
06067d
 					 TALLOC_CTX *mem_ctx,
06067d
-					 const char *user_dn, 
06067d
+					 const char *user_dn,
06067d
 					 struct dom_sid *primary_group,
06067d
 					 uint32_t *p_num_groups, struct dom_sid **user_sids)
06067d
 {
06067d
@@ -620,7 +620,7 @@ static NTSTATUS lookup_usergroups_member(struct winbindd_domain *domain,
06067d
 
06067d
 	if ( !winbindd_can_contact_domain( domain ) ) {
06067d
 		DEBUG(10,("lookup_usergroups_members: No incoming trust for domain %s\n",
06067d
-			  domain->name));		
06067d
+			  domain->name));
06067d
 		return NT_STATUS_OK;
06067d
 	}
06067d
 
06067d
@@ -702,7 +702,7 @@ static NTSTATUS lookup_usergroups_member(struct winbindd_domain *domain,
06067d
 
06067d
 	DEBUG(3,("ads lookup_usergroups (member) succeeded for dn=%s\n", user_dn));
06067d
 done:
06067d
-	if (res) 
06067d
+	if (res)
06067d
 		ads_msgfree(ads, res);
06067d
 
06067d
 	return status;
06067d
@@ -883,14 +883,14 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
06067d
 	if (count != 1) {
06067d
 		status = NT_STATUS_UNSUCCESSFUL;
06067d
 		DEBUG(1,("lookup_usergroups(sid=%s) ads_search tokenGroups: "
06067d
-			 "invalid number of results (count=%d)\n", 
06067d
+			 "invalid number of results (count=%d)\n",
06067d
 			 dom_sid_str_buf(sid, &buf),
06067d
 			 count));
06067d
 		goto done;
06067d
 	}
06067d
 
06067d
 	if (!msg) {
06067d
-		DEBUG(1,("lookup_usergroups(sid=%s) ads_search tokenGroups: NULL msg\n", 
06067d
+		DEBUG(1,("lookup_usergroups(sid=%s) ads_search tokenGroups: NULL msg\n",
06067d
 			 dom_sid_str_buf(sid, &buf)));
06067d
 		status = NT_STATUS_UNSUCCESSFUL;
06067d
 		goto done;
06067d
@@ -903,7 +903,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
06067d
 	}
06067d
 
06067d
 	if (!ads_pull_uint32(ads, msg, "primaryGroupID", &primary_group_rid)) {
06067d
-		DEBUG(1,("%s: No primary group for sid=%s !?\n", 
06067d
+		DEBUG(1,("%s: No primary group for sid=%s !?\n",
06067d
 			 domain->name,
06067d
 			 dom_sid_str_buf(sid, &buf)));
06067d
 		goto done;
06067d
@@ -913,7 +913,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
06067d
 
06067d
 	count = ads_pull_sids(ads, mem_ctx, msg, "tokenGroups", &sids);
06067d
 
06067d
-	/* there must always be at least one group in the token, 
06067d
+	/* there must always be at least one group in the token,
06067d
 	   unless we are talking to a buggy Win2k server */
06067d
 
06067d
 	/* actually this only happens when the machine account has no read
06067d
@@ -937,7 +937,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
06067d
 		/* lookup what groups this user is a member of by DN search on
06067d
 		 * "member" */
06067d
 
06067d
-		status = lookup_usergroups_member(domain, mem_ctx, user_dn, 
06067d
+		status = lookup_usergroups_member(domain, mem_ctx, user_dn,
06067d
 						  &primary_group,
06067d
 						  &num_groups, user_sids);
06067d
 		*p_num_groups = num_groups;
06067d
@@ -1302,7 +1302,7 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
06067d
 			DEBUG(10, ("lookup_groupmem: lsa_lookup_sids could "
06067d
 				   "not map any SIDs at all.\n"));
06067d
 			/* Don't handle this as an error here.
06067d
-			 * There is nothing left to do with respect to the 
06067d
+			 * There is nothing left to do with respect to the
06067d
 			 * overall result... */
06067d
 		}
06067d
 		else if (!NT_STATUS_IS_OK(status)) {
06067d
@@ -1367,13 +1367,13 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain,
06067d
 			NETR_TRUST_FLAG_IN_FOREST;
06067d
 	} else {
06067d
 		flags = NETR_TRUST_FLAG_IN_FOREST;
06067d
-	}	
06067d
+	}
06067d
 
06067d
 	result = cm_connect_netlogon(domain, &cli;;
06067d
 
06067d
 	if (!NT_STATUS_IS_OK(result)) {
06067d
 		DEBUG(5, ("trusted_domains: Could not open a connection to %s "
06067d
-			  "for PIPE_NETLOGON (%s)\n", 
06067d
+			  "for PIPE_NETLOGON (%s)\n",
06067d
 			  domain->name, nt_errstr(result)));
06067d
 		return NT_STATUS_UNSUCCESSFUL;
06067d
 	}
06067d
-- 
06067d
2.33.1
06067d
06067d
06067d
From db840cc208542a52a8e8a226b452c4df921fe9e6 Mon Sep 17 00:00:00 2001
06067d
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
06067d
Date: Tue, 18 Jan 2022 19:44:54 +0100
06067d
Subject: [PATCH 09/10] s3:winbindd: Do not set ADS_AUTH_ALLOW_NTLMSSP in FIPS
06067d
 mode
06067d
MIME-Version: 1.0
06067d
Content-Type: text/plain; charset=UTF-8
06067d
Content-Transfer-Encoding: 8bit
06067d
06067d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14955
06067d
06067d
Pair-Programmed-With: Andreas Schneider <asn@samba.org>
06067d
06067d
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
06067d
Signed-off-by: Andreas Schneider <asn@samba.org>
06067d
Reviewed-by: Stefan Metzmacher <metze@samba.org>
06067d
(cherry picked from commit f03abaec2abbd22b9dc83ce4a103b1b3a2912d96)
06067d
---
06067d
 source3/winbindd/winbindd_ads.c | 19 ++++++++++++++++++-
06067d
 1 file changed, 18 insertions(+), 1 deletion(-)
06067d
06067d
diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c
06067d
index e415df347e6..6f01ef6e334 100644
06067d
--- a/source3/winbindd/winbindd_ads.c
06067d
+++ b/source3/winbindd/winbindd_ads.c
06067d
@@ -34,6 +34,7 @@
06067d
 #include "../libds/common/flag_mapping.h"
06067d
 #include "libsmb/samlogon_cache.h"
06067d
 #include "passdb.h"
06067d
+#include "auth/credentials/credentials.h"
06067d
 
06067d
 #ifdef HAVE_ADS
06067d
 
06067d
@@ -102,6 +103,7 @@ static ADS_STATUS ads_cached_connection_connect(ADS_STRUCT **adsp,
06067d
 	ADS_STATUS status;
06067d
 	struct sockaddr_storage dc_ss;
06067d
 	fstring dc_name;
06067d
+	enum credentials_use_kerberos krb5_state;
06067d
 
06067d
 	if (auth_realm == NULL) {
06067d
 		return ADS_ERROR_NT(NT_STATUS_UNSUCCESSFUL);
06067d
@@ -125,7 +127,22 @@ static ADS_STATUS ads_cached_connection_connect(ADS_STRUCT **adsp,
06067d
 	ads->auth.renewable = renewable;
06067d
 	ads->auth.password = password;
06067d
 
06067d
-	ads->auth.flags |= ADS_AUTH_ALLOW_NTLMSSP;
06067d
+	/* In FIPS mode, client use kerberos is forced to required. */
06067d
+	krb5_state = lp_client_use_kerberos();
06067d
+	switch (krb5_state) {
06067d
+	case CRED_USE_KERBEROS_REQUIRED:
06067d
+		ads->auth.flags &= ~ADS_AUTH_DISABLE_KERBEROS;
06067d
+		ads->auth.flags &= ~ADS_AUTH_ALLOW_NTLMSSP;
06067d
+		break;
06067d
+	case CRED_USE_KERBEROS_DESIRED:
06067d
+		ads->auth.flags &= ~ADS_AUTH_DISABLE_KERBEROS;
06067d
+		ads->auth.flags |= ADS_AUTH_ALLOW_NTLMSSP;
06067d
+		break;
06067d
+	case CRED_USE_KERBEROS_DISABLED:
06067d
+		ads->auth.flags |= ADS_AUTH_DISABLE_KERBEROS;
06067d
+		ads->auth.flags |= ADS_AUTH_ALLOW_NTLMSSP;
06067d
+		break;
06067d
+	}
06067d
 
06067d
 	ads->auth.realm = SMB_STRDUP(auth_realm);
06067d
 	if (!strupper_m(ads->auth.realm)) {
06067d
-- 
06067d
2.33.1
06067d
06067d
06067d
From ead4f4c0a908f22ee2edf7510033345700e2efd9 Mon Sep 17 00:00:00 2001
06067d
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
06067d
Date: Fri, 21 Jan 2022 12:01:33 +0100
06067d
Subject: [PATCH 10/10] s3:libnet: Do not set ADS_AUTH_ALLOW_NTLMSSP in FIPS
06067d
 mode
06067d
MIME-Version: 1.0
06067d
Content-Type: text/plain; charset=UTF-8
06067d
Content-Transfer-Encoding: 8bit
06067d
06067d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14955
06067d
06067d
Pair-Programmed-With: Andreas Schneider <asn@samba.org>
06067d
06067d
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
06067d
Signed-off-by: Andreas Schneider <asn@samba.org>
06067d
Reviewed-by: Stefan Metzmacher <metze@samba.org>
06067d
06067d
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
06067d
Autobuild-Date(master): Sat Jan 22 00:27:52 UTC 2022 on sn-devel-184
06067d
06067d
(cherry picked from commit fa5413b63c8f4a20ab5b803f5cc523e0658eefc9)
06067d
---
06067d
 source3/libnet/libnet_join.c | 18 +++++++++++++++++-
06067d
 1 file changed, 17 insertions(+), 1 deletion(-)
06067d
06067d
diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c
06067d
index 02705f1c70c..4c67e9af5c4 100644
06067d
--- a/source3/libnet/libnet_join.c
06067d
+++ b/source3/libnet/libnet_join.c
06067d
@@ -139,6 +139,7 @@ static ADS_STATUS libnet_connect_ads(const char *dns_domain_name,
06067d
 	ADS_STATUS status;
06067d
 	ADS_STRUCT *my_ads = NULL;
06067d
 	char *cp;
06067d
+	enum credentials_use_kerberos krb5_state;
06067d
 
06067d
 	my_ads = ads_init(dns_domain_name,
06067d
 			  netbios_domain_name,
06067d
@@ -148,7 +149,22 @@ static ADS_STATUS libnet_connect_ads(const char *dns_domain_name,
06067d
 		return ADS_ERROR_LDAP(LDAP_NO_MEMORY);
06067d
 	}
06067d
 
06067d
-	my_ads->auth.flags |= ADS_AUTH_ALLOW_NTLMSSP;
06067d
+	/* In FIPS mode, client use kerberos is forced to required. */
06067d
+	krb5_state = lp_client_use_kerberos();
06067d
+	switch (krb5_state) {
06067d
+	case CRED_USE_KERBEROS_REQUIRED:
06067d
+		my_ads->auth.flags &= ~ADS_AUTH_DISABLE_KERBEROS;
06067d
+		my_ads->auth.flags &= ~ADS_AUTH_ALLOW_NTLMSSP;
06067d
+		break;
06067d
+	case CRED_USE_KERBEROS_DESIRED:
06067d
+		my_ads->auth.flags &= ~ADS_AUTH_DISABLE_KERBEROS;
06067d
+		my_ads->auth.flags |= ADS_AUTH_ALLOW_NTLMSSP;
06067d
+		break;
06067d
+	case CRED_USE_KERBEROS_DISABLED:
06067d
+		my_ads->auth.flags |= ADS_AUTH_DISABLE_KERBEROS;
06067d
+		my_ads->auth.flags |= ADS_AUTH_ALLOW_NTLMSSP;
06067d
+		break;
06067d
+	}
06067d
 
06067d
 	if (user_name) {
06067d
 		SAFE_FREE(my_ads->auth.user_name);
06067d
-- 
06067d
2.33.1
06067d