]> git.ipfire.org Git - thirdparty/samba.git/log
thirdparty/samba.git
3 years agoctdb-tests: Avoid ShellCheck warnings
Martin Schwenke [Wed, 17 Aug 2022 02:12:30 +0000 (12:12 +1000)] 
ctdb-tests: Avoid ShellCheck warnings

Although this is a test stub, it is complicated enough to encourage
ShellCheck cleanliness.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-tests: Reformat script with "shfmt -w -p -i 0 -fn"
Martin Schwenke [Wed, 17 Aug 2022 01:41:33 +0000 (11:41 +1000)] 
ctdb-tests: Reformat script with "shfmt -w -p -i 0 -fn"

As per current Samba convention.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-scripts: Drop assumption that there are VLANs with no '@'
Martin Schwenke [Wed, 17 Aug 2022 01:04:10 +0000 (11:04 +1000)] 
ctdb-scripts: Drop assumption that there are VLANs with no '@'

VLAN configuration on Linux often uses a convention of naming a VLAN
on <iface> with VLAN ID <tag> as <iface>.<tag>.  To be able to monitor
the underlying interface, the original 10.interface code naively
simply stripped off the '.' and everything after (i.e. ".*", as a glob
pattern).

Some users do not use the above convention.  A VLAN can be named
without including the underlying interface, but still with a
tag (e.g. vlan<tag> - the word "vlan" following by the tag) or, more
generally, perhaps without a tag (e.g. <vlan> - an arbitrary name).
The ip(8) command lists a VLAN as <vlan>@<iface>.  The underlying
interface can be found by stripping everything up to and including an
'@' (i.e. "*@").

Commit bc71251433ce618c95c674d7cbe75b01a94adad9 added support for
stripping "*@".  However, on suspicion, it kept support for the case
where there is no '@', falling back to stripping ".*".  If ip(8) ever
did this then it was a long time ago - it has been printing a format
including '@' since at least 2004.

Stripping ".*" interferes with interesting administrative decisions,
like having '.' in interface names.

So, drop the fallback to stripping ".*" because it appears to be
unnecessary and can cause inconvenience.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoCVE-2020-25720 s4:dsdb/descriptor: explain lack of dSHeuristics check
Andrew Bartlett [Fri, 16 Sep 2022 02:18:37 +0000 (14:18 +1200)] 
CVE-2020-25720 s4:dsdb/descriptor: explain lack of dSHeuristics check

It is strange that sDRightsEffective pays no attention to the
dSHeuristics flags.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Fri Sep 16 03:31:42 UTC 2022 on sn-devel-184

3 years agoCVE-2020-25720 s4:dsdb/descriptor: Validate owner SIDs written to security descriptors
Joseph Sutton [Thu, 5 May 2022 05:21:42 +0000 (17:21 +1200)] 
CVE-2020-25720 s4:dsdb/descriptor: Validate owner SIDs written to security descriptors

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720 s4-acl: Omit sDRightsEffective for computers unless all rights are...
Joseph Sutton [Thu, 5 May 2022 07:30:13 +0000 (19:30 +1200)] 
CVE-2020-25720 s4-acl: Omit sDRightsEffective for computers unless all rights are granted

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720: s4-acl: Owner no longer has implicit Write DACL
Nadezhda Ivanova [Fri, 22 Oct 2021 18:33:03 +0000 (21:33 +0300)] 
CVE-2020-25720: s4-acl: Owner no longer has implicit Write DACL

The implicit right of an object's owner to modify its security
descriptor no longer exists, according to the new access rules. However,
we continue to grant this implicit right for fileserver access checks.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Signed-off-by: Nadezhda Ivanova <nivanova@symas.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720 s4:ntvfs: Use se_file_access_check() to check file access rights
Joseph Sutton [Mon, 5 Sep 2022 02:53:26 +0000 (14:53 +1200)] 
CVE-2020-25720 s4:ntvfs: Use se_file_access_check() to check file access rights

se_access_check() will be changed in a following commit to remove the
implicit WRITE_DAC right that comes with being the owner of an object.
We want to keep this implicit right for file access, and by using
se_file_access_check() we can preserve the existing behaviour.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720: s4-acl: Adjusted some tests to work with the new behavior
Nadezhda Ivanova [Fri, 22 Oct 2021 18:10:35 +0000 (21:10 +0300)] 
CVE-2020-25720: s4-acl: Adjusted some tests to work with the new behavior

Test using non-priviledged accounts now need to make sure they have
WP access on the prvided attributes, or Write-DACL
Some test create organizational units with a specific SD, and those now
need the user to have WD or else they give errors

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Signed-off-by: Nadezhda Ivanova <nivanova@symas.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720: s4-acl: Change behavior of Create Children check
Nadezhda Ivanova [Mon, 25 Oct 2021 10:10:56 +0000 (13:10 +0300)] 
CVE-2020-25720: s4-acl: Change behavior of Create Children check

Up to now, the rights to modify an attribute were not checked during an LDAP
add operation. This means that even if a user has no right to modify
an attribute, they can still specify any value during object creation,
and the validated writes were not checked.
This patch changes this behavior. During an add operation,
a security descriptor is created that does not include the one provided by the
user, and is used to verify that the user has the right to modify the supplied attributes.
Exception is made for an object's mandatory attributes, and if the user has Write DACL right,
further checks are skipped.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Pair-Programmed-With: Joseph Sutton <josephsutton@catalyst.net.nz>

Signed-off-by: Nadezhda Ivanova <nivanova@symas.com>
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720: s4-acl: Move definition of acl_check_self_membership()
Joseph Sutton [Fri, 22 Apr 2022 03:01:00 +0000 (15:01 +1200)] 
CVE-2020-25720: s4-acl: Move definition of acl_check_self_membership()

This allows us to make use of it in acl_add().

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720 s4-acl: Test Create Child permission should not allow full write to...
Nadezhda Ivanova [Mon, 25 Oct 2021 08:34:57 +0000 (11:34 +0300)] 
CVE-2020-25720 s4-acl: Test Create Child permission should not allow full write to all attributes

Up to now, the rights to modify an attribute were not checked during an LDAP
add operation. This means that even if a user has no right to modify
an attribute, they can still specify any value during object creation,
and the validated writes were not checked.
This patch includes tests for the proposed change of behavior.
test_add_c3 and c4 pass, because mandatory attributes can still be
set, and in the old behavior SD permissions were irrelevant

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Pair-Programmed-With: Joseph Sutton <josephsutton@catalyst.net.nz>

Signed-off-by: Nadezhda Ivanova <nivanova@symas.com>
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720 pydsdb: Add AD schema GUID constants
Joseph Sutton [Wed, 14 Sep 2022 01:21:34 +0000 (13:21 +1200)] 
CVE-2020-25720 pydsdb: Add AD schema GUID constants

This helps reduce the profusion of magic constant values in Python
tests.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720 pydsdb: Add dsHeuristics constant definitions
Joseph Sutton [Tue, 6 Sep 2022 07:23:13 +0000 (19:23 +1200)] 
CVE-2020-25720 pydsdb: Add dsHeuristics constant definitions

We want to be able to use these values in Python tests.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720 s4/dsdb/util: Add functions for dsHeuristics 28, 29
Joseph Sutton [Thu, 28 Apr 2022 08:34:36 +0000 (20:34 +1200)] 
CVE-2020-25720 s4/dsdb/util: Add functions for dsHeuristics 28, 29

These are the newly-added AttributeAuthorizationOnLDAPAdd and
BlockOwnerImplicitRights.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720 python:tests: Ensure that access checks don't succeed
Joseph Sutton [Sat, 30 Apr 2022 01:55:39 +0000 (13:55 +1200)] 
CVE-2020-25720 python:tests: Ensure that access checks don't succeed

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2020-25720 s4:tests/sec_descriptor: Add missing security descriptor modify
Joseph Sutton [Thu, 28 Apr 2022 09:00:56 +0000 (21:00 +1200)] 
CVE-2020-25720 s4:tests/sec_descriptor: Add missing security descriptor modify

The variable sub_sddl1 previously went unused, so this call to
modify_sd_on_dn() was presumably intended to go here.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14810

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agos3: libsmb: In cli_posix_open_internal_send() (SMBtrans2:TRANSACT2_SETPATHINFO) check...
Jeremy Allison [Fri, 9 Sep 2022 17:29:30 +0000 (10:29 -0700)] 
s3: libsmb: In cli_posix_open_internal_send() (SMBtrans2:TRANSACT2_SETPATHINFO) check for DFS pathname.

See smbtorture3: SMB1-DFS-PATHS: test_smb1_setpathinfo_XXXX()

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Sep 15 19:44:00 UTC 2022 on sn-devel-184

3 years agos3: libsmb: In cli_qpathinfo_send() (SMBtrans2:TRANSACT2_QPATHINFO) check for DFS...
Jeremy Allison [Fri, 9 Sep 2022 16:40:12 +0000 (09:40 -0700)] 
s3: libsmb: In cli_qpathinfo_send() (SMBtrans2:TRANSACT2_QPATHINFO) check for DFS pathname.

See smbtorture3: SMB1-DFS-PATHS: test_smb1_qpathinfo()

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_set_ea_path() (SMBtrans2:TRANSACT2_SETPATHINFO) check for DFS...
Jeremy Allison [Thu, 8 Sep 2022 23:21:20 +0000 (16:21 -0700)] 
s3: libsmb: In cli_set_ea_path() (SMBtrans2:TRANSACT2_SETPATHINFO) check for DFS pathname.

See smbtorture3: SMB1-DFS-PATHS: test_smb1_setpathinfo_XXXX()

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_ctemp_send() (SMBctemp) check for DFS pathname.
Jeremy Allison [Thu, 8 Sep 2022 21:28:41 +0000 (14:28 -0700)] 
s3: libsmb: In cli_ctemp_send() (SMBctemp) check for DFS pathname.

smbtorture3: SMB1-DFS-OPERATIONS: test_smb1_ctemp() shows
SMBctemp uses DFS paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_chkpath_send() (SMBcheckpath) check for DFS pathname.
Jeremy Allison [Thu, 8 Sep 2022 19:25:49 +0000 (12:25 -0700)] 
s3: libsmb: In cli_chkpath_send() (SMBcheckpath) check for DFS pathname.

smbtorture3: SMB1-DFS-OPERATIONS: test_smb1_chkpath() shows
SMBcheckpath uses DFS paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_setatr_send() (SMBsetatr) check for DFS pathname.
Jeremy Allison [Thu, 8 Sep 2022 18:53:33 +0000 (11:53 -0700)] 
s3: libsmb: In cli_setatr_send() (SMBsetatr) check for DFS pathname.

smbtorture3: SMB1-DFS-OPERATIONS: test_smb1_setatr() shows
SMBsetatr uses DFS paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_getatr_send() (SMBgetatr) check for DFS pathname.
Jeremy Allison [Thu, 8 Sep 2022 16:50:56 +0000 (09:50 -0700)] 
s3: libsmb: In cli_getatr_send() (SMBgetatr) check for DFS pathname.

smbtorture3: SMB1-DFS-OPERATIONS: test_smb1_getatr() shows
SMBgetatr uses DFS paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_openx_create() (SMBopenX) check for DFS pathname.
Jeremy Allison [Wed, 7 Sep 2022 19:52:42 +0000 (12:52 -0700)] 
s3: libsmb: In cli_openx_create() (SMBopenX) check for DFS pathname.

smbtorture3: SMB1-DFS-OPERATIONS: test_smb1_openx() shows
SMBopenX uses DFS paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_nttrans_create_send() (SMBnttrans:NT_TRANSACT_CREATE) check for...
Jeremy Allison [Wed, 7 Sep 2022 19:05:53 +0000 (12:05 -0700)] 
s3: libsmb: In cli_nttrans_create_send() (SMBnttrans:NT_TRANSACT_CREATE) check for DFS pathname.

smbtorture3: SMB1-DFS-OPERATIONS: test_smb1_nttrans_create() shows
SMBnttrans:NT_TRANSACT_CREATE uses DFS paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_ntcreate1_send() (SMBntcreateX) check for DFS pathname.
Jeremy Allison [Wed, 7 Sep 2022 18:26:46 +0000 (11:26 -0700)] 
s3: libsmb: In cli_ntcreate1_send() (SMBntcreateX) check for DFS pathname.

smbtorture3: SMB1-DFS-OPERATIONS: test_smb1_ntcreatex() shows
SMBntcreateX uses DFS paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_rmdir_send() (SMBrmdir) check for DFS pathname.
Jeremy Allison [Wed, 7 Sep 2022 17:47:37 +0000 (10:47 -0700)] 
s3: libsmb: In cli_rmdir_send() (SMBrmdir) check for DFS pathname.

smbtorture3: SMB1-DFS-OPERATIONS: test_smb1_rmdir() shows
SMBrmdir uses DFS paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_mkdir_send() (SMBmkdir) check for DFS pathname.
Jeremy Allison [Wed, 7 Sep 2022 17:45:01 +0000 (10:45 -0700)] 
s3: libsmb: In cli_mkdir_send() (SMBmkdir) check for DFS pathname.

smbtorture3: SMB1-DFS-OPERATIONS: test_smb1_mkdir() shows
SMBmkdir uses DFS paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_unlink_send() (SMBunlink) check for DFS pathname.
Jeremy Allison [Wed, 7 Sep 2022 00:26:58 +0000 (17:26 -0700)] 
s3: libsmb: In cli_unlink_send() (SMBunlink) check for DFS pathname.

smbtorture3: SMB1-DFS-OPERATIONS: test_smb1_unlink() shows
SMBunlink uses DFS paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_ntrename_internal_send() (SMBntrename) check for DFS dst pathname.
Jeremy Allison [Fri, 2 Sep 2022 20:18:06 +0000 (13:18 -0700)] 
s3: libsmb: In cli_ntrename_internal_send() (SMBntrename) check for DFS dst pathname.

See smbtorture3: SMB1-DFS-PATHS: test_smb1_ntrename_rename().
and smbtorture3: SMB1-DFS-PATHS: test_smb1_ntrename_hardlink().

Remove the old code that stripped a DFS name from the
destination filename, and go through smb1_dfs_share_path()
as we did for fname_src in the last commit.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_ntrename_internal_send() (SMBntrename) check for DFS source pathname.
Jeremy Allison [Fri, 2 Sep 2022 20:12:51 +0000 (13:12 -0700)] 
s3: libsmb: In cli_ntrename_internal_send() (SMBntrename) check for DFS source pathname.

smbtorture3: SMB1-DFS-PATHS: test_smb1_ntrename_rename() shows
SMBntrename uses DFS for src and dst.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_cifs_rename_send() (SMBmv) check for DFS dst pathname.
Jeremy Allison [Fri, 2 Sep 2022 19:40:19 +0000 (12:40 -0700)] 
s3: libsmb: In cli_cifs_rename_send() (SMBmv) check for DFS dst pathname.

See smbtorture3: SMB1-DFS-PATHS: test_smb1_mv().

Remove the old code that stripped a DFS name from the
destination filename, and go through smb1_dfs_share_path()
as we did for fname_src in the last commit.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_cifs_rename_send() (SMBmv) check for DFS source pathname.
Jeremy Allison [Fri, 2 Sep 2022 19:33:48 +0000 (12:33 -0700)] 
s3: libsmb: In cli_cifs_rename_send() (SMBmv) check for DFS source pathname.

smbtorture3: SMB1-DFS-PATHS: test_smb1_mv() shows
SMBmv uses DFS for src and dst.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: Make cli_setpathinfo_send() (SMBtrans2: TRANSACT2_SETPATHINFO) DFS path...
Jeremy Allison [Fri, 2 Sep 2022 19:27:36 +0000 (12:27 -0700)] 
s3: libsmb: Make cli_setpathinfo_send() (SMBtrans2: TRANSACT2_SETPATHINFO) DFS path aware.

See smbtorture3: SMB1-DFS-PATHS: test_smb1_setpathinfo_XXXX()

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbcacls: Now cli_resolve_path() and cli_list() can handle DFS names we no longer...
Jeremy Allison [Fri, 2 Sep 2022 18:46:08 +0000 (11:46 -0700)] 
s3: smbcacls: Now cli_resolve_path() and cli_list() can handle DFS names we no longer need local_cli_resolve_path().

Remove local_cli_resolve_path(). No more special treatment for DFS names in smbcacls.

Signed-off-by: Jeremy Allison <jra@samba.org>
Signed-off-by: Noel Power <noel.power@suse.com>
3 years agos3: libsmb: Fix cli_resolve_path() to cope with DFS paths passed in as well as local...
Jeremy Allison [Fri, 2 Sep 2022 18:44:47 +0000 (11:44 -0700)] 
s3: libsmb: Fix cli_resolve_path() to cope with DFS paths passed in as well as local paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: Fix SMB1 cli_list_old_send() to cope with DFS paths.
Jeremy Allison [Thu, 1 Sep 2022 23:12:35 +0000 (16:12 -0700)] 
s3: libsmb: Fix SMB1 cli_list_old_send() to cope with DFS paths.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: Fix SMB1 cli_list_trans_send() (SMBtrans2:TRANSACT2_FINDFIRST) to cope...
Jeremy Allison [Thu, 1 Sep 2022 23:10:49 +0000 (16:10 -0700)] 
s3: libsmb: Fix SMB1 cli_list_trans_send() (SMBtrans2:TRANSACT2_FINDFIRST) to cope with DFS paths.

See smbtorture3: SMB1-DFS-SEARCH-PATHS: test_smb1_findfirst_path

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: Add smb1_dfs_share_path() to convert a name into a DFS path if needed.
Jeremy Allison [Thu, 1 Sep 2022 23:07:10 +0000 (16:07 -0700)] 
s3: libsmb: Add smb1_dfs_share_path() to convert a name into a DFS path if needed.

Not yet used.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: For SMB2 opens on a DFS share, convert to a DFS path if not already done.
Jeremy Allison [Thu, 1 Sep 2022 22:32:40 +0000 (15:32 -0700)] 
s3: libsmb: For SMB2 opens on a DFS share, convert to a DFS path if not already done.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: Add cli_dfs_is_already_full_path() function.
Jeremy Allison [Fri, 19 Aug 2022 21:59:04 +0000 (14:59 -0700)] 
s3: libsmb: Add cli_dfs_is_already_full_path() function.

Returns true if it's already a fully qualified DFS path.

Not yet used.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_list_old_send(), push state->mask into the packet, not just mask.
Jeremy Allison [Thu, 1 Sep 2022 23:07:34 +0000 (16:07 -0700)] 
s3: libsmb: In cli_list_old_send(), push state->mask into the packet, not just mask.

This doesn't matter right now, but it will when I
add DFS path awareness to cli_list().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: Make cli_state_save_tcon()/cli_state_restore_tcon() static.
Jeremy Allison [Wed, 24 Aug 2022 00:40:55 +0000 (17:40 -0700)] 
s3: libsmb: Make cli_state_save_tcon()/cli_state_restore_tcon() static.

There are no external callers.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbcacls: In cli_lsa_lookup_domain_sid(), replace cli_state_save_tcon()/cli_state...
Jeremy Allison [Wed, 24 Aug 2022 00:37:48 +0000 (17:37 -0700)] 
s3: smbcacls: In cli_lsa_lookup_domain_sid(), replace cli_state_save_tcon()/cli_state_restore_tcon() with cli_state_save_tcon_share()/cli_state_restore_tcon_share().

There are now no more external users of cli_state_save_tcon()/cli_state_restore_tcon()
so we can make them static.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: utils: In show_userlist() replace cli_state_save_tcon()/cli_state_restore_tcon...
Jeremy Allison [Wed, 24 Aug 2022 00:34:43 +0000 (17:34 -0700)] 
s3: utils: In show_userlist() replace cli_state_save_tcon()/cli_state_restore_tcon() with cli_state_save_tcon_share()/cli_state_restore_tcon_share().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: torture: In run_tcon_test() replace cli_state_save_tcon()/cli_state_restore_tcon...
Jeremy Allison [Wed, 24 Aug 2022 00:32:46 +0000 (17:32 -0700)] 
s3: torture: In run_tcon_test() replace cli_state_save_tcon()/cli_state_restore_tcon() with cli_state_save_tcon_share()/cli_state_restore_tcon_share().

Also fix a comment in run_uid_regression_test().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: torture: In run_smb2_basic(), replace cli_state_save_tcon()/cli_state_restore_tco...
Jeremy Allison [Wed, 24 Aug 2022 00:30:14 +0000 (17:30 -0700)] 
s3: torture: In run_smb2_basic(), replace cli_state_save_tcon()/cli_state_restore_tcon() with cli_state_save_tcon_share()/cli_state_restore_tcon_share().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_check_msdfs_proxy() replace cli_state_save_tcon()/cli_state_restor...
Jeremy Allison [Wed, 24 Aug 2022 00:28:21 +0000 (17:28 -0700)] 
s3: libsmb: In cli_check_msdfs_proxy() replace cli_state_save_tcon()/cli_state_restore_tcon() with cli_state_save_tcon_share()/cli_state_restore_tcon_share().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_lsa_lookup_name() replace cli_state_save_tcon()/cli_state_restore_...
Jeremy Allison [Wed, 24 Aug 2022 00:25:40 +0000 (17:25 -0700)] 
s3: libsmb: In cli_lsa_lookup_name() replace cli_state_save_tcon()/cli_state_restore_tcon() with cli_state_save_tcon_share()/cli_state_restore_tcon_share().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: In cli_lsa_lookup_sid() replace cli_state_save_tcon()/cli_state_restore_t...
Jeremy Allison [Wed, 24 Aug 2022 00:18:16 +0000 (17:18 -0700)] 
s3: libsmb: In cli_lsa_lookup_sid() replace cli_state_save_tcon()/cli_state_restore_tcon() with cli_state_save_tcon_share()/cli_state_restore_tcon_share().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: Add pair cli_state_save_tcon_share()/cli_state_restore_tcon_share().
Jeremy Allison [Wed, 24 Aug 2022 00:13:58 +0000 (17:13 -0700)] 
s3: libsmb: Add pair cli_state_save_tcon_share()/cli_state_restore_tcon_share().

Wraps cli_state_save_tcon()//cli_state_restore_tcon() but
also returns cli->sharename.

We are going to replace all uses of cli_state_save_tcon()/cli_state_restore_tcon()
so we also save/restore the cli->share for DFS purposes.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviwed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: Cleanup - remove unused fname_src parameter from cli_dfs_target_check().
Jeremy Allison [Fri, 2 Sep 2022 18:00:09 +0000 (11:00 -0700)] 
s3: libsmb: Cleanup - remove unused fname_src parameter from cli_dfs_target_check().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: Add missing memory allocation fail check in cli_openx_create().
Jeremy Allison [Wed, 7 Sep 2022 19:50:25 +0000 (12:50 -0700)] 
s3: libsmb: Add missing memory allocation fail check in cli_openx_create().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: libsmb: Add missing memory allocation fail checks in cli_ntcreate1_send().
Jeremy Allison [Wed, 7 Sep 2022 18:12:08 +0000 (11:12 -0700)] 
s3: libsmb: Add missing memory allocation fail checks in cli_ntcreate1_send().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add test_smb1_qpathinfo() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Fri, 9 Sep 2022 16:35:38 +0000 (09:35 -0700)] 
s3: smbtorture3: Add test_smb1_qpathinfo() DFS test to run_smb1_dfs_operations().

Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Sep 14 18:37:06 UTC 2022 on sn-devel-184

3 years agos3: smbtorture3: Add test_smb1_ctemp() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Thu, 8 Sep 2022 21:24:38 +0000 (14:24 -0700)] 
s3: smbtorture3: Add test_smb1_ctemp() DFS test to run_smb1_dfs_operations().

NB. This passes against Windows, but SMBctemp is broken on a Windows DFS
share and always returns NT_STATUS_FILE_IS_A_DIRECTORY.

When we fix the Samba server to correctly process DFS
pathnames we'll have to change this test to understand
it's running against smbd and modify the expected behavior
to match a working server.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add test_smb1_chkpath() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Thu, 8 Sep 2022 19:23:23 +0000 (12:23 -0700)] 
s3: smbtorture3: Add test_smb1_chkpath() DFS test to run_smb1_dfs_operations().

Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
Signed-off--by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add test_smb1_setatr() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Thu, 8 Sep 2022 18:45:54 +0000 (11:45 -0700)] 
s3: smbtorture3: Add test_smb1_setatr() DFS test to run_smb1_dfs_operations().

Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add test_smb1_getatr() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Wed, 7 Sep 2022 23:04:03 +0000 (16:04 -0700)] 
s3: smbtorture3: Add test_smb1_getatr() DFS test to run_smb1_dfs_operations().

Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add test_smb1_create() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Wed, 7 Sep 2022 22:42:09 +0000 (15:42 -0700)] 
s3: smbtorture3: Add test_smb1_create() DFS test to run_smb1_dfs_operations().

Tests SMBcreate and SMBmknew.

Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add test_smb1_open() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Wed, 7 Sep 2022 22:26:55 +0000 (15:26 -0700)] 
s3: smbtorture3: Add test_smb1_open() DFS test to run_smb1_dfs_operations().

Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add test_smb1_openx() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Wed, 7 Sep 2022 19:48:53 +0000 (12:48 -0700)] 
s3: smbtorture3: Add test_smb1_openx() DFS test to run_smb1_dfs_operations().

Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add test_smb1_nttrans_create() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Wed, 7 Sep 2022 19:03:08 +0000 (12:03 -0700)] 
s3: smbtorture3: Add test_smb1_nttrans_create() DFS test to run_smb1_dfs_operations().

Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add test_smb1_ntcreatex() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Wed, 7 Sep 2022 18:23:45 +0000 (11:23 -0700)] 
s3: smbtorture3: Add test_smb1_ntcreatex() DFS test to run_smb1_dfs_operations().

Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
3 years agos3: smbtorture3: Add test_smb1_rmdir() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Wed, 7 Sep 2022 17:41:53 +0000 (10:41 -0700)] 
s3: smbtorture3: Add test_smb1_rmdir() DFS test to run_smb1_dfs_operations().

Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add test_smb1_mkdir() DFS test to run_smb1_dfs_operations().
Jeremy Allison [Wed, 7 Sep 2022 00:49:05 +0000 (17:49 -0700)] 
s3: smbtorture3: Add test_smb1_mkdir() DFS test to run_smb1_dfs_operations().

Passes against Windows.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add an SMB1 operations torture tester.
Jeremy Allison [Wed, 7 Sep 2022 00:25:18 +0000 (17:25 -0700)] 
s3: smbtorture3: Add an SMB1 operations torture tester.

Only tests SMB1unlink for now, but I will add other operations
later.

smbtorture3 test is: SMB1-DFS-OPERATIONS.

Passes fully against Windows. Adds knownfail for smbd.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agos3: smbtorture3: Add a new test SMB2-NON-DFS-SHARE.
Jeremy Allison [Thu, 8 Sep 2022 23:42:26 +0000 (16:42 -0700)] 
s3: smbtorture3: Add a new test SMB2-NON-DFS-SHARE.

This one is tricky. It sends SMB2 DFS pathnames to a non-DFS
share, and sets the SMB2 flag FLAGS2_DFS_PATHNAMES in the SMB2
packet.

Windows will have non of it and (correctly) treats the pathnames
as local paths (they're going to a non-DFS share). Samba fails.

This proves the server looks as the share DFS capability to
override the flag in the SMB2 packet.

Passes against Windows. Added knownfail for Samba.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agoCVE-2021-20251 s3: Ensure bad password count atomic updates for SAMR AES password...
Joseph Sutton [Tue, 2 Aug 2022 02:43:19 +0000 (14:43 +1200)] 
CVE-2021-20251 s3: Ensure bad password count atomic updates for SAMR AES password change

The bad password count is supposed to limit the number of failed login
attempt a user can make before being temporarily locked out, but race
conditions between processes have allowed determined attackers to make
many more than the specified number of attempts.  This is especially
bad on constrained or overcommitted hardware.

To fix this, once a bad password is detected, we reload the sam account
information under a user-specific mutex, ensuring we have an up to
date bad password count.

We also update the bad password count if the password is wrong, which we
did not previously do.

Derived from a similar patch to source3/auth/check_samsec.c by
Jeremy Allison <jra@samba.org>

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Tue Sep 13 00:08:07 UTC 2022 on sn-devel-184

3 years agoCVE-2021-20251 s3:rpc_server: Split change_oem_password() call out of samr_set_passwo...
Joseph Sutton [Tue, 2 Aug 2022 02:43:09 +0000 (14:43 +1200)] 
CVE-2021-20251 s3:rpc_server: Split change_oem_password() call out of samr_set_password_aes()

Now samr_set_password_aes() just returns the new password in a similar
manner to check_oem_password(). This simplifies the logic for the
following change to recheck whether the account is locked out, and to
update the bad password count.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 dsdb/common: Remove transaction logic from samdb_set_password()
Joseph Sutton [Tue, 2 Aug 2022 02:40:01 +0000 (14:40 +1200)] 
CVE-2021-20251 dsdb/common: Remove transaction logic from samdb_set_password()

All of its callers, where necessary, take out a transaction covering the
entire password set or change operation, so a transaction is no longer
needed here.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4-rpc_server: Extend scope of transaction for ChangePasswordUser3
Joseph Sutton [Tue, 2 Aug 2022 02:39:43 +0000 (14:39 +1200)] 
CVE-2021-20251 s4-rpc_server: Extend scope of transaction for ChangePasswordUser3

Now the initial account search is performed under the transaction,
ensuring the overall password change is atomic. We set DSDB_SESSION_INFO
to drop our privileges to those of the user before we perform the actual
password change, and restore them afterwards if we need to update the
bad password count.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4-rpc_server: Use user privileges for SAMR password change
Joseph Sutton [Tue, 2 Aug 2022 02:39:06 +0000 (14:39 +1200)] 
CVE-2021-20251 s4-rpc_server: Use user privileges for SAMR password change

We don't (and shouldn't) need system prvileges to perform the password
change, so drop to the privileges of the user by setting
DSDB_SESSION_INFO. We need to reuse the same sam_ctx: creating a new one
with only user privileges would not work, because any database
modifications would be blocked by the transaction taken out on the
original context.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4-rpc_server: Use authsam_search_account() to find the user
Joseph Sutton [Tue, 2 Aug 2022 02:37:52 +0000 (14:37 +1200)] 
CVE-2021-20251 s4-rpc_server: Use authsam_search_account() to find the user

This helps the bad password and audit log handling code as it
allows assumptions to be made about the attributes found in
the variable "msg", such as that DSDB_SEARCH_SHOW_EXTENDED_DN
was used.

This ensures we can re-search on the DN via the embedded GUID,
which in in turn rename-proof.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agos3:rpc_server: Use BURN_STR() to zero password
Joseph Sutton [Tue, 6 Sep 2022 02:54:08 +0000 (14:54 +1200)] 
s3:rpc_server: Use BURN_STR() to zero password

This ensures these calls are not optimised away.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agolibcli:auth: Keep passwords from convert_string_talloc() secret
Joseph Sutton [Tue, 2 Aug 2022 02:35:50 +0000 (14:35 +1200)] 
libcli:auth: Keep passwords from convert_string_talloc() secret

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agolib:util: Check memset_s() error code in talloc_keep_secret_destructor()
Joseph Sutton [Tue, 2 Aug 2022 02:35:33 +0000 (14:35 +1200)] 
lib:util: Check memset_s() error code in talloc_keep_secret_destructor()

Panic if memset_s() fails.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s3: Ensure bad password count atomic updates for SAMR password change
Joseph Sutton [Tue, 5 Jul 2022 08:17:33 +0000 (20:17 +1200)] 
CVE-2021-20251 s3: Ensure bad password count atomic updates for SAMR password change

The bad password count is supposed to limit the number of failed login
attempt a user can make before being temporarily locked out, but race
conditions between processes have allowed determined attackers to make
many more than the specified number of attempts.  This is especially
bad on constrained or overcommitted hardware.

To fix this, once a bad password is detected, we reload the sam account
information under a user-specific mutex, ensuring we have an up to
date bad password count.

Derived from a similar patch to source3/auth/check_samsec.c by
Jeremy Allison <jra@samba.org>

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s3: ensure bad password count atomic updates
Jeremy Allison [Mon, 11 Jan 2021 20:11:35 +0000 (12:11 -0800)] 
CVE-2021-20251 s3: ensure bad password count atomic updates

The bad password count is supposed to limit the number of failed login
attempt a user can make before being temporarily locked out, but race
conditions between processes have allowed determined attackers to make
many more than the specified number of attempts.  This is especially
bad on constrained or overcommitted hardware.

To fix this, once a bad password is detected, we reload the sam account
information under a user-specific mutex, ensuring we have an up to
date bad password count.

Discovered by Nathaniel W. Turner.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4:auth_winbind: Check return status of authsam_logon_success_accounting()
Joseph Sutton [Mon, 4 Jul 2022 08:51:38 +0000 (20:51 +1200)] 
CVE-2021-20251 s4:auth_winbind: Check return status of authsam_logon_success_accounting()

This may return an error if we find the account is locked out.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4-rpc_server: Check badPwdCount update return status
Joseph Sutton [Sat, 9 Jul 2022 03:55:02 +0000 (15:55 +1200)] 
CVE-2021-20251 s4-rpc_server: Check badPwdCount update return status

If the account has been locked out in the meantime (indicated by
NT_STATUS_ACCOUNT_LOCKED_OUT), we should return the appropriate error
code.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4:kdc: Check badPwdCount update return status
Joseph Sutton [Sat, 9 Jul 2022 03:54:52 +0000 (15:54 +1200)] 
CVE-2021-20251 s4:kdc: Check badPwdCount update return status

If the account has been locked out in the meantime (indicated by
NT_STATUS_ACCOUNT_LOCKED_OUT), we should return the appropriate error
code.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4:kdc: Check return status of authsam_logon_success_accounting()
Joseph Sutton [Fri, 1 Jul 2022 03:04:41 +0000 (15:04 +1200)] 
CVE-2021-20251 s4:kdc: Check return status of authsam_logon_success_accounting()

If we find that the user has been locked out sometime during the request
(due to a race), we will now return an error code.

Note that we cannot avoid the MIT KDC aspect of the issue by checking
the return status of mit_samba_zero_bad_password_count(), because
kdb_vftabl::audit_as_req() returning void means we cannot pass on the
result.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4:kdc: Move logon success accounting code into existing branch
Joseph Sutton [Tue, 5 Jul 2022 23:11:43 +0000 (11:11 +1200)] 
CVE-2021-20251 s4:kdc: Move logon success accounting code into existing branch

This simplifies the code for the following commit.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4:dsdb: Make badPwdCount update atomic
Joseph Sutton [Sat, 9 Jul 2022 03:54:12 +0000 (15:54 +1200)] 
CVE-2021-20251 s4:dsdb: Make badPwdCount update atomic

We reread the account details inside the transaction in case the account
has been locked out in the meantime. If it has, we return the
appropriate error code.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4:dsdb: Update bad password count inside transaction
Joseph Sutton [Sat, 9 Jul 2022 03:44:21 +0000 (15:44 +1200)] 
CVE-2021-20251 s4:dsdb: Update bad password count inside transaction

Previously, there was a gap between calling dsdb_update_bad_pwd_count()
and dsdb_module_modify() where no transaction was in effect. Another
process could slip in and modify badPwdCount, only for our update to
immediately overwrite it. Doing the update inside the transaction will
help for the following commit when we make it atomic.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4-auth: Pass through error code from badPwdCount update
Joseph Sutton [Sat, 9 Jul 2022 03:53:51 +0000 (15:53 +1200)] 
CVE-2021-20251 s4-auth: Pass through error code from badPwdCount update

The error code may be NT_STATUS_ACCOUNT_LOCKED_OUT, which we use in
preference to NT_STATUS_WRONG_PASSWORD.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 auth4: Avoid reading the database twice by precaculating some variables
Andrew Bartlett [Tue, 30 Mar 2021 03:48:31 +0000 (16:48 +1300)] 
CVE-2021-20251 auth4: Avoid reading the database twice by precaculating some variables

These variables are not important to protect against a race with
and a double-read can easily be avoided by moving them up the file
a little.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoCVE-2021-20251 auth4: Inline samdb_result_effective_badPwdCount() in authsam_logon_su...
Andrew Bartlett [Thu, 25 Mar 2021 02:33:08 +0000 (15:33 +1300)] 
CVE-2021-20251 auth4: Inline samdb_result_effective_badPwdCount() in authsam_logon_success_accounting()

By bringing this function inline it can then be split out in a
subsequent commit.

Based on work by Gary Lockyer <gary@catalyst.net.nz>

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoCVE-2021-20251 auth4: Split authsam_calculate_lastlogon_sync_interval() out
Andrew Bartlett [Thu, 25 Mar 2021 01:42:39 +0000 (14:42 +1300)] 
CVE-2021-20251 auth4: Split authsam_calculate_lastlogon_sync_interval() out

authsam_calculate_lastlogon_sync_interval() is split out of authsam_update_lastlogon_timestamp()

Based on work by Gary Lockyer <gary@catalyst.net.nz>

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoCVE-2021-20251 auth4: Return only the result message and free the surrounding result
Gary Lockyer [Wed, 24 Mar 2021 22:30:59 +0000 (11:30 +1300)] 
CVE-2021-20251 auth4: Return only the result message and free the surrounding result

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoCVE-2021-20251 auth4: Add missing newline to debug message on PSO read failure
Andrew Bartlett [Tue, 30 Mar 2021 03:35:44 +0000 (16:35 +1300)] 
CVE-2021-20251 auth4: Add missing newline to debug message on PSO read failure

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoCVE-2021-20251 s4 auth: make bad password count increment atomic
Andrew Bartlett [Tue, 30 Mar 2021 05:01:39 +0000 (18:01 +1300)] 
CVE-2021-20251 s4 auth: make bad password count increment atomic

Ensure that the bad password count is incremented atomically,
and that the successful logon accounting data is updated atomically.

Use bad password indicator (in a distinct TDB) to determine if to open a transaction

We open a transaction when we have seen the hint that this user
has recorded a bad password.  This allows us to avoid always
needing one, while not missing a possible lockout.

We also go back and get a transation if we did not take out
one out but we chose to do a write (eg for lastLogonTimestamp)

Based on patches by Gary Lockyer <gary@catalyst.net.nz>

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoCVE-2021-20251 auth4: Detect ACCOUNT_LOCKED_OUT error for password change
Joseph Sutton [Tue, 5 Jul 2022 08:17:49 +0000 (20:17 +1200)] 
CVE-2021-20251 auth4: Detect ACCOUNT_LOCKED_OUT error for password change

This is more specific than NT_STATUS_UNSUCCESSFUL, and for the SAMR
password change, matches the result the call to samdb_result_passwords()
would give.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4 auth test: Unit tests for source4/auth/sam.c
Gary Lockyer [Mon, 8 Feb 2021 22:59:05 +0000 (11:59 +1300)] 
CVE-2021-20251 s4 auth test: Unit tests for source4/auth/sam.c

cmocka unit tests for the authsam_reread_user_logon_data in
source4/auth/sam.c

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 auth4: Reread the user record if a bad password is noticed.
Andrew Bartlett [Tue, 30 Mar 2021 04:57:10 +0000 (17:57 +1300)] 
CVE-2021-20251 auth4: Reread the user record if a bad password is noticed.

As is, this is pointless, as we need a transaction to make this
any less of a race, but this provides the steps towards that goal.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoCVE-2021-20251 s4 auth: Prepare to make bad password count increment atomic
Gary Lockyer [Wed, 27 Jan 2021 01:24:58 +0000 (14:24 +1300)] 
CVE-2021-20251 s4 auth: Prepare to make bad password count increment atomic

To ensure that the bad password count is incremented atomically,
and that the successful logon accounting data is updated atomically,
without always opening a transaction, we will need to make a note
of all bad and successful passwords in a side-DB outside the
transaction lock.

This provides the functions needed for that and hooks them in
(future commits will handle errors and use the results).

Based on patches by Gary Lockyer <gary@catalyst.net.nz>

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
3 years agoCVE-2021-20251 auth4: split samdb_result_msds_LockoutObservationWindow() out
Gary Lockyer [Mon, 15 Mar 2021 21:52:58 +0000 (10:52 +1300)] 
CVE-2021-20251 auth4: split samdb_result_msds_LockoutObservationWindow() out

samdb_result_msds_LockoutObservationWindow() is split out of
samdb_result_effective_badPwdCount()

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2021-20251 s4-rpc_server: Use authsam_search_account() to find the user
Andrew Bartlett [Mon, 29 Mar 2021 21:51:26 +0000 (10:51 +1300)] 
CVE-2021-20251 s4-rpc_server: Use authsam_search_account() to find the user

This helps the bad password and audit log handling code as it
allows assumptions to be made about the attributes found in
the variable "msg", such as that DSDB_SEARCH_SHOW_EXTENDED_DN
was used.

This ensures we can re-search on the DN via the embedded GUID,
which in in turn rename-proof.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14611

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>