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