]> git.ipfire.org Git - thirdparty/samba.git/log
thirdparty/samba.git
3 years agodocs-xml: Remove references to obsolete 'write cache size' parameter
Joseph Sutton [Fri, 23 Sep 2022 23:49:16 +0000 (11:49 +1200)] 
docs-xml: Remove references to obsolete 'write cache size' parameter

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agodocs-xml: Fix reference to obsolete 'lock spin count' parameter
Joseph Sutton [Fri, 23 Sep 2022 23:48:58 +0000 (11:48 +1200)] 
docs-xml: Fix reference to obsolete 'lock spin count' parameter

We should not create a dangling link.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agodocs-xml: Fix section links
Joseph Sutton [Fri, 23 Sep 2022 23:48:37 +0000 (11:48 +1200)] 
docs-xml: Fix section links

These are not valid smbconfoptions, so we end up with dangling links.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agopytest: samba-tool: Fix undefined escape sequence
Joseph Sutton [Fri, 16 Sep 2022 00:55:58 +0000 (12:55 +1200)] 
pytest: samba-tool: Fix undefined escape sequence

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agopyldb: Fix tests going unused
Joseph Sutton [Thu, 15 Sep 2022 04:16:43 +0000 (16:16 +1200)] 
pyldb: Fix tests going unused

These tests are redeclared later and so are never used. Give them new
names so that they will be run again.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agolib:crypto: Change error return to SMB_ASSERT()
Joseph Sutton [Fri, 23 Sep 2022 04:22:14 +0000 (16:22 +1200)] 
lib:crypto: Change error return to SMB_ASSERT()

Getting an HMAC too long to fit our array is a programming error. It
should always be 64 bytes exactly.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agolib:krb5_wrap: Use case-sensitive comparison against 'krbtgt'
Joseph Sutton [Tue, 17 May 2022 08:25:19 +0000 (20:25 +1200)] 
lib:krb5_wrap: Use case-sensitive comparison against 'krbtgt'

This matches the other comparisons against krbtgt, kadmin, etc., which
are all case-sensitive.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agos4-auth: Add missing newlines to log messages
Joseph Sutton [Fri, 29 Apr 2022 00:19:35 +0000 (12:19 +1200)] 
s4-auth: Add missing newlines to log messages

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agotests/krb5: Add create_ccache_with_ticket()
Joseph Sutton [Fri, 6 May 2022 03:21:20 +0000 (15:21 +1200)] 
tests/krb5: Add create_ccache_with_ticket()

This function returns a ccache containing a previously obtained ticket.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agotests/krb5: Make use of client_opts for TGS-REQs
Joseph Sutton [Fri, 6 May 2022 02:58:52 +0000 (14:58 +1200)] 
tests/krb5: Make use of client_opts for TGS-REQs

Previously we would ignore 'client_opts' and always use the same user
and machine accounts for TGS-REQs. Use 'client_opts' and add a new
'armor_opts' parameter for specifying options of the armoring account.

Furthermore, our test-specific ticket caching is no longer of use, for
get_tgt() and get_service_ticket() now implement ticket caching. Remove
it and eliminate the possibility of mistakenly using stale tickets.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agopython: Handle LdbError thrown from functions operating on DNs
Joseph Sutton [Thu, 29 Sep 2022 22:50:30 +0000 (11:50 +1300)] 
python: Handle LdbError thrown from functions operating on DNs

None of these functions can return False now. Instead we must catch the
LdbError if we want to perform further error handling.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agopyldb: Have functions operating on DNs raise LdbError
Joseph Sutton [Thu, 29 Sep 2022 22:46:40 +0000 (11:46 +1300)] 
pyldb: Have functions operating on DNs raise LdbError

The return codes of these functions are not often checked. Throwing an
exception ensures we won't continue blindly on if DN manipulation fails.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agopython/samba: Fix typos in error messages
Joseph Sutton [Wed, 27 Jul 2022 02:12:07 +0000 (14:12 +1200)] 
python/samba: Fix typos in error messages

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agopdb_samba_dsdb: Handle dsdb_search_one() errors
Joseph Sutton [Thu, 25 Aug 2022 23:32:50 +0000 (11:32 +1200)] 
pdb_samba_dsdb: Handle dsdb_search_one() errors

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoselftest: Simplify krb5 test environments
Joseph Sutton [Fri, 4 Mar 2022 03:57:27 +0000 (16:57 +1300)] 
selftest: Simplify krb5 test environments

We don't need the local configuration here.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
3 years agoCVE-2007-4559 python: ensure sanity in our tarfiles
Douglas Bagnall [Fri, 23 Sep 2022 00:32:25 +0000 (12:32 +1200)] 
CVE-2007-4559 python: ensure sanity in our tarfiles

Python's tarfile module is not very careful about paths that step out
of the target directory. We can be a bit better at little cost.

This was reported in 2007[1], and has recently been publicised [2, for
example].

We were informed of this bug in December 2021 by Luis Alberto López
Alvar, but decided then that there were no circumstances under which
this was a security concern. That is, if you can alter the backup
files, you can already do worse things. But there is a case to guard
against an administrator being tricked into trying to restore a file
that isn't based on a real backup.

[1] https://nvd.nist.gov/vuln/detail/CVE-2007-4559
[2] https://www.theregister.com/2022/09/22/python_vulnerability_tarfile/

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Tue Oct  4 03:48:43 UTC 2022 on sn-devel-184

3 years agosamba-tool: Use authentication file to pass credentials
Nikola Radovanovic [Fri, 30 Sep 2022 07:38:12 +0000 (09:38 +0200)] 
samba-tool: Use authentication file to pass credentials

In order not to pass credentials in clear-text directly over command line, this is a patch to store username/password/domain in a file and use it during domain join for example.

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

Signed-off-by: Nikola Radovanovic <radovanovic.extern@univention.de>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
3 years agopython-drs: Add client-side debug and fallback for GET_ANC
Andrew Bartlett [Thu, 15 Sep 2022 05:10:24 +0000 (17:10 +1200)] 
python-drs: Add client-side debug and fallback for GET_ANC

Samba 4.5 and earlier will fail to do GET_ANC correctly and will not
replicate non-critical parents of objects with isCriticalSystemObject=TRUE
when DRSUAPI_DRS_CRITICAL_ONLY is set.

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
3 years agos4-libnet: Add messages to object count mismatch failures
Andrew Bartlett [Tue, 20 Sep 2022 01:37:30 +0000 (13:37 +1200)] 
s4-libnet: Add messages to object count mismatch failures

This helps explain these better than WERR_GEN_FAILURE.

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
3 years agoselftest: Enable "old Samba" mode regarding GET_ANC/GET_TGT
Andrew Bartlett [Thu, 29 Sep 2022 01:54:14 +0000 (14:54 +1300)] 
selftest: Enable "old Samba" mode regarding GET_ANC/GET_TGT

The chgdcpass server now emulates older verions of Samba that
fail to implement DRSUAPI_DRS_GET_ANC correctly and totally fails to support
DRSUAPI_DRS_GET_TGT.

We now show this is in effect by the fact that tests now fail.

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
3 years agos4-rpc_server:getncchanges Add "old Samba" mode regarding GET_ANC/GET_TGT
Andrew Bartlett [Thu, 29 Sep 2022 01:53:38 +0000 (14:53 +1300)] 
s4-rpc_server:getncchanges Add "old Samba" mode regarding GET_ANC/GET_TGT

This emulates older verions of Samba that fail to implement
DRSUAPI_DRS_GET_ANC correctly and totally fails to support
DRSUAPI_DRS_GET_TGT.

This will allow testing of a client-side fallback, allowing migration
from sites that run very old Samba versions over DRSUAPI (currently
the only option is to attempt an in-place upgrade).

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
3 years agoselftest: Add tests for GetNCChanges GET_ANC using samba-tool drs clone-dc-database
Andrew Bartlett [Thu, 29 Sep 2022 03:05:03 +0000 (03:05 +0000)] 
selftest: Add tests for GetNCChanges GET_ANC using samba-tool drs clone-dc-database

This test, compared with the direct to RPC tests, will succeed, then fail once the
server is changed to emulate Samba 4.5 and and again succeed once the python code
changes to allow skipping the DRSUAPI_DRS_CRITICAL_ONLY step

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
3 years agoselftest: Prepare for "old Samba" mode regarding getncchanges GET_ANC/GET_TGT
Andrew Bartlett [Wed, 14 Sep 2022 21:36:45 +0000 (09:36 +1200)] 
selftest: Prepare for "old Samba" mode regarding getncchanges GET_ANC/GET_TGT

The chgdcpass environment will emulate older verions of Samba
that fail to implement DRSUAPI_DRS_GET_ANC correctly and
totally fails to support DRSUAPI_DRS_GET_TGT.

This will allow testing of a client-side fallback, allowing migration
from sites that run very old Samba versions over DRSUAPI (currently
the only option is to attempt an in-place upgrade).

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
3 years agotevent: Fix flag clearing
Joseph Sutton [Fri, 29 Apr 2022 00:20:06 +0000 (12:20 +1200)] 
tevent: Fix flag clearing

We presumably meant to clear this bit, rather than clearing all bits
other than it.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Mon Oct  3 21:05:31 UTC 2022 on sn-devel-184

3 years agolibsmb: Fix the smbclient readlink command
Volker Lendecke [Thu, 29 Sep 2022 13:41:30 +0000 (15:41 +0200)] 
libsmb: Fix the smbclient readlink command

We use cli_smb2_qpathinfo_basic() for cli_resolve_path() before
calling cli_readlink(). This fails as it never tries with
FILE_OPEN_REPARSE_POINT, so we never get to the point where we
actually can issue the FSCTL_GET_REPARSE_POINT.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibsmb: Remove unused cli_smb2_set_reparse_point_fnum_send/recv
Volker Lendecke [Thu, 29 Sep 2022 10:49:10 +0000 (12:49 +0200)] 
libsmb: Remove unused cli_smb2_set_reparse_point_fnum_send/recv

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibsmb: Convert cli_symlink to cli_fsctl
Volker Lendecke [Thu, 29 Sep 2022 10:47:45 +0000 (12:47 +0200)] 
libsmb: Convert cli_symlink to cli_fsctl

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibsmb: Remove unused cli_smb2_get_reparse_point_fnum_send/recv
Volker Lendecke [Thu, 29 Sep 2022 10:41:54 +0000 (12:41 +0200)] 
libsmb: Remove unused cli_smb2_get_reparse_point_fnum_send/recv

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibsmb: Convert cli_readlink() to cli_fsctl_send/recv
Volker Lendecke [Thu, 29 Sep 2022 10:40:45 +0000 (12:40 +0200)] 
libsmb: Convert cli_readlink() to cli_fsctl_send/recv

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibsmb: Add cli_fsctl_send/recv
Volker Lendecke [Thu, 29 Sep 2022 10:22:10 +0000 (12:22 +0200)] 
libsmb: Add cli_fsctl_send/recv

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibsmb: Add cli_smb2_fsctl_send/recv
Volker Lendecke [Thu, 29 Sep 2022 10:21:53 +0000 (12:21 +0200)] 
libsmb: Add cli_smb2_fsctl_send/recv

Slightly refactor the symlink operations later based on this

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibsmb: Centralize the SMB2 protocol check
Volker Lendecke [Thu, 29 Sep 2022 09:08:12 +0000 (11:08 +0200)] 
libsmb: Centralize the SMB2 protocol check

Instead of checking protocol correctness in every highlevel routine,
we should rely on the lowerlevel one in smbXcli_base.c to give the
INVALID_PARAMETER error return when running on SMB1

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosmbXcli: Align smb2cli_req_create() with tevent_req conventions
Volker Lendecke [Thu, 29 Sep 2022 09:00:41 +0000 (11:00 +0200)] 
smbXcli: Align smb2cli_req_create() with tevent_req conventions

We don't return NULL if tevent_req_create() succeeded, and elsewhere
in this function we already pass tevent_req_nterror or
tevent_req_nomem (via set_endtime).

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agopython: whitespace fixes
Volker Lendecke [Tue, 20 Sep 2022 14:21:44 +0000 (16:21 +0200)] 
python: whitespace fixes

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agotorture3: Align integer types
Volker Lendecke [Thu, 29 Sep 2022 08:45:19 +0000 (10:45 +0200)] 
torture3: Align integer types

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agovfs: Fix a typo
Volker Lendecke [Thu, 22 Sep 2022 08:46:56 +0000 (10:46 +0200)] 
vfs: Fix a typo

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3: smbtorture3: Add new SMB2-DFS-SHARE-NON-DFS-PATH test.
Jeremy Allison [Tue, 27 Sep 2022 17:37:41 +0000 (10:37 -0700)] 
s3: smbtorture3: Add new SMB2-DFS-SHARE-NON-DFS-PATH test.

Uses non-DFS names and DFS-names against a DFS share, shows that Windows
looks correctly at the DFS flag when SMB2 requests are
made on a DFS share. Passes against Windows 2022.

Mark as knownfail for smbd.

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

3 years agos3: torture: Fix test SMB2-DFS-PATHS to pass against Windows server 2022.
Jeremy Allison [Tue, 27 Sep 2022 01:05:49 +0000 (18:05 -0700)] 
s3: torture: Fix test SMB2-DFS-PATHS to pass against Windows server 2022.

There is only one difference between Windows 2022 and Windows 2008.

Opening an empty ("") DFS path succeeds in opening the share
root on Windows 2008 but fails with NT_STATUS_INVALID_PARAMETER
on Windows 2022. Allow the test to cope with both.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
3 years agosamba-tool dsacl: Add additional unit test for delete subcommand
Christian Merten [Mon, 19 Sep 2022 21:28:07 +0000 (23:28 +0200)] 
samba-tool dsacl: Add additional unit test for delete subcommand

Added one more unit test to the delete subcommand. This test adds
two ACEs, deletes one of them and checks if the right one was deleted
and the other one stayed the same.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Sep 27 17:46:22 UTC 2022 on sn-devel-184

3 years agopython security: Add unit tests for comparing ACEs and exporting as SDDL
Christian Merten [Mon, 19 Sep 2022 21:22:04 +0000 (23:22 +0200)] 
python security: Add unit tests for comparing ACEs and exporting as SDDL

Added two unit tests for the python functions to compare ACEs and to
export an ACE as SDDL.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosamba-tool dsacl: Add get and delete subcommand to samba-tool dsacl man section
Christian Merten [Thu, 15 Sep 2022 08:38:22 +0000 (10:38 +0200)] 
samba-tool dsacl: Add get and delete subcommand to samba-tool dsacl man section

Added get and delete subcommands to the man section of samba-tool dsacl.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosamba-tool dsacl: Create common superclass for dsacl commands
Christian Merten [Thu, 15 Sep 2022 08:20:04 +0000 (10:20 +0200)] 
samba-tool dsacl: Create common superclass for dsacl commands

Created a base class for dsacl commands providing print_acl and some fixed command line options to
reduce code duplication.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosamba-tool dsacl: Create helper functions to remove code duplication
Christian Merten [Thu, 15 Sep 2022 08:08:47 +0000 (10:08 +0200)] 
samba-tool dsacl: Create helper functions to remove code duplication

Make multiple methods of dsacl command classes separate helper functions to avoid code duplication.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosamba-tool dsacl: Add unit tests for delete subcommand
Christian Merten [Tue, 13 Sep 2022 23:33:18 +0000 (01:33 +0200)] 
samba-tool dsacl: Add unit tests for delete subcommand

Two unit tests for the new samba-tool dsacl delete command have been added.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agosamba-tool dsacl: Add subcommand to delete ACEs
Christian Merten [Tue, 13 Sep 2022 23:29:34 +0000 (01:29 +0200)] 
samba-tool dsacl: Add subcommand to delete ACEs

A new subcommand has been added to samba-tool dsacl to delete one or multiple ACEs from the security
descriptor of an object.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibrpc ndr/py_security: Export sddl_encode_ace to python
Christian Merten [Mon, 19 Sep 2022 21:12:59 +0000 (23:12 +0200)] 
librpc ndr/py_security: Export sddl_encode_ace to python

Added sddl_encode_ace as new method as_sddl to security_ace class in python.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibrpc ndr/py_security: Export security_ace_equal as richcmp to python
Christian Merten [Mon, 19 Sep 2022 21:11:37 +0000 (23:11 +0200)] 
librpc ndr/py_security: Export security_ace_equal as richcmp to python

Patched security_ace with a richcmp function given by
security_ace_equal.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibrpc ndr/py_security: Export ACE deletion functions to python
Christian Merten [Mon, 19 Sep 2022 21:01:34 +0000 (23:01 +0200)] 
librpc ndr/py_security: Export ACE deletion functions to python

Exported security_descriptor_sacl_del and security_descriptor_dacl_del as new methods of the
security descriptor class to python.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibcli security/sddl: Make sddl_encode_ace visible
Christian Merten [Mon, 19 Sep 2022 20:53:45 +0000 (22:53 +0200)] 
libcli security/sddl: Make sddl_encode_ace visible

Removed static flag from sddl_encode_ace and added to headers.

Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
Signed-off-by: Christian Merten <christian@merten.dev>
3 years agolibcli security_descriptor: Compare object type and inherited object type when compar...
Christian Merten [Mon, 19 Sep 2022 20:50:58 +0000 (22:50 +0200)] 
libcli security_descriptor: Compare object type and inherited object type when comparing ACEs

Fixed security_ace_equal returning true, despite differing object type, by checking (inherited) object type
of both ACEs is equal.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agolibcli security_descriptor: Add function to delete a given ace from a security descriptor
Christian Merten [Mon, 19 Sep 2022 20:47:10 +0000 (22:47 +0200)] 
libcli security_descriptor: Add function to delete a given ace from a security descriptor

Two functions have been added to delete a given ace from the SACL or the DACL of a security descriptor.

Signed-off-by: Christian Merten <christian@merten.dev>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3: smbd: Fix memory leak in smbd_server_connection_terminate_done().
Jeremy Allison [Thu, 15 Sep 2022 00:05:05 +0000 (17:05 -0700)] 
s3: smbd: Fix memory leak in smbd_server_connection_terminate_done().

The function smbd_server_connection_terminate_done() does not free subreq
which is allocated in smbXsrv_connection_shutdown_send, this can be a
memory leakage if multi-channel is enabled.

Suggested fix by haihua yang <hhyangdev@gmail.com>

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

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <noel.power@suse.com>
Autobuild-User(master): Noel Power <npower@samba.org>
Autobuild-Date(master): Fri Sep 23 09:51:20 UTC 2022 on sn-devel-184

3 years agovfs_gpfs: Protect against timestamps before the Unix epoch
Volker Lendecke [Mon, 22 Aug 2022 13:24:01 +0000 (15:24 +0200)] 
vfs_gpfs: Protect against timestamps before the Unix epoch

In addition to b954d181cd2 we should also protect against timestamps
before the epoch.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=15151
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Fri Sep 23 06:50:17 UTC 2022 on sn-devel-184

3 years agoctdb-scripts: Add debugging variable CTDB_KILLTCP_DEBUGLEVEL
Martin Schwenke [Tue, 6 Sep 2022 01:59:11 +0000 (11:59 +1000)] 
ctdb-scripts: Add debugging variable CTDB_KILLTCP_DEBUGLEVEL

To debug ctdb_killtcp failures, add

  CTDB_KILLTCP_DEBUGLEVEL=DEBUG

to script.options.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Tue Sep 20 11:42:16 UTC 2022 on sn-devel-184

3 years agoctdb-common: Support IB in pcap-based capture
Martin Schwenke [Mon, 15 Aug 2022 00:52:27 +0000 (10:52 +1000)] 
ctdb-common: Support IB in pcap-based capture

Add simple support for IPoIB via DLT_LINUX_SLL and DLT_LINUX_SLL2.
This seems to work, even when an IB interface is specified.

If this is later found to be insufficient, support for DLT_IPOIB can
be implemented.  See https://www.tcpdump.org/linktypes.html for a
starting point.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-common: Support "any" interface for pcap-based capture
Martin Schwenke [Mon, 15 Aug 2022 00:51:47 +0000 (10:51 +1000)] 
ctdb-common: Support "any" interface for pcap-based capture

This uses Linux cooked capture link-layer headers.  See:

  https://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL.html
  https://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL2.html

The header type needs to be checked to ensure the protocol
type (i.e. ether type, for the protocols we might be interested in) is
meaningful.  The size of the header needs to be known so it can be
skipped, allowing the IP header to be found and parsed.

It would be possible to define support for DLT_LINUX_SLL2 if it is
missing.  However, if a platform is missing support in the header file
then it is almost certainly missing in the run-time library too.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-common: Add packet type detection to pcap-based capture
Martin Schwenke [Sun, 14 Aug 2022 23:43:58 +0000 (09:43 +1000)] 
ctdb-common: Add packet type detection to pcap-based capture

The current code will almost certainly generate ENOMSG for
non-ethernet packets, even for ethernet packets when the "any"
interface is used.

pcap_datalink(3PCAP) says:

  Do NOT assume that the packets for a given capture or ``savefile``
  will have any given link-layer header type, such as DLT_EN10MB for
  Ethernet.  For example, the "any" device on Linux will have a
  link-layer header type of DLT_LINUX_SLL or DLT_LINUX_SLL2 even if
  all devices on the sys‐ tem at the time the "any" device is opened
  have some other data link type, such as DLT_EN10MB for Ethernet.

So, pcap_datalink() must be used.

Detect pcap packet types that are supported (currently only ethernet)
in the open code. There is no use continuing if the read code can't
parse packets.  The pattern of using switch statements supports future
addition of other packet types.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-tools: Improve/add debug
Martin Schwenke [Sun, 14 Aug 2022 23:41:09 +0000 (09:41 +1000)] 
ctdb-tools: Improve/add debug

In particular, knowing the reason fetching the packet fails can help
with debugging unsupported protocols in the pcap code.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-common: Improve/add debug
Martin Schwenke [Mon, 15 Aug 2022 04:30:09 +0000 (14:30 +1000)] 
ctdb-common: Improve/add debug

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-common: Use pcap_get_selectable_fd()
Martin Schwenke [Wed, 10 Aug 2022 23:00:25 +0000 (09:00 +1000)] 
ctdb-common: Use pcap_get_selectable_fd()

This is preferred because it will fail for devices that do not support
epoll_wait() and similar.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-common: Stop a pcap-related crash on error
Martin Schwenke [Tue, 9 Aug 2022 03:49:42 +0000 (13:49 +1000)] 
ctdb-common: Stop a pcap-related crash on error

errbuf can't be NULL.  Might as well use it.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-common: Fix a warning in the pcap code
Martin Schwenke [Mon, 8 Aug 2022 01:31:03 +0000 (11:31 +1000)] 
ctdb-common: Fix a warning in the pcap code

[173/416] Compiling ctdb/common/system_socket.c
../../common/system_socket.c: In function ‘ctdb_sys_read_tcp_packet’:
../../common/system_socket.c:1016:15: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual]
 1016 |         eth = (struct ether_header *)buffer;
      |               ^

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-common: Do not use raw socket when ENABLE_PCAP is defined
Martin Schwenke [Mon, 8 Aug 2022 01:30:15 +0000 (11:30 +1000)] 
ctdb-common: Do not use raw socket when ENABLE_PCAP is defined

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-common: Move a misplaced comment
Martin Schwenke [Mon, 8 Aug 2022 01:29:36 +0000 (11:29 +1000)] 
ctdb-common: Move a misplaced comment

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-build: Add --enable-pcap configure option
Martin Schwenke [Mon, 8 Aug 2022 01:26:54 +0000 (11:26 +1000)] 
ctdb-build: Add --enable-pcap configure option

This forces the use pcap for packet capture on Linux.

It appears that using a raw socket for capture does not work with
infiniband - pcap support for that to come.

Don't (yet?) change the default capture method to pcap.  On some
platforms (e.g. my personal Intel NUC, running Debian testing), pcap
is much less reliable than the raw socket.  However, pcap seems fine
on most other platforms.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agoctdb-build: Use pcap-config when available
Martin Schwenke [Fri, 23 Jul 2021 04:39:05 +0000 (14:39 +1000)] 
ctdb-build: Use pcap-config when available

The build currently fails on AIX, which can't find the pcap headers
because they're installed in a non-standard place.  However, there is
a pcap-config script available.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
3 years agos3:locking: remove unused get_share_mode_lock()
Stefan Metzmacher [Wed, 31 Aug 2022 13:51:21 +0000 (15:51 +0200)] 
s3:locking: remove unused get_share_mode_lock()

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Sep 20 01:34:55 UTC 2022 on sn-devel-184

3 years agos3:smbd: make use of share_mode_entry_prepare_{lock_add,unlock}() in open_{file_ntcre...
Stefan Metzmacher [Mon, 29 Aug 2022 14:48:04 +0000 (16:48 +0200)] 
s3:smbd: make use of share_mode_entry_prepare_{lock_add,unlock}() in open_{file_ntcreate,directory}()

This gives a nice speed up...

The following test with 256 commections all looping with open/close
on the same inode (share root) is improved drastically:

  smbtorture //127.0.0.1/m -Uroot%test smb2.bench.path-contention-shared \
         --option='torture:bench_path=' \
         --option="torture:timelimit=60" \
         --option="torture:nprocs=256" \
         --option="torture:qdepth=1"

From something like this:

    open[num/s=11536,avslat=0.011450,minlat=0.000039,maxlat=0.052707]
    close[num/s=11534,avslat=0.010878,minlat=0.000022,maxlat=0.052342]

(only this commit with the close part reverted) to:

    open[num/s=12722,avslat=0.009548,minlat=0.000051,maxlat=0.054338]
    close[num/s=12720,avslat=0.010701,minlat=0.000033,maxlat=0.054372]

(with both patches) to:

    open[num/s=37680,avslat=0.003471,minlat=0.000040,maxlat=0.061411]
    close[num/s=37678,avslat=0.003440,minlat=0.000022,maxlat=0.051536]

So we are finally perform similar like we did in Samba 4.12,
which resulted in:

    open[num/s=36846,avslat=0.003574,minlat=0.000043,maxlat=0.020378]
    close[num/s=36844,avslat=0.003552,minlat=0.000026,maxlat=0.020321]

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: let open_file_ntcreate() calculate info = FILE_WAS_* before get_share_mode_l...
Stefan Metzmacher [Tue, 13 Sep 2022 00:41:14 +0000 (02:41 +0200)] 
s3:smbd: let open_file_ntcreate() calculate info = FILE_WAS_* before get_share_mode_lock()

This will simplify further changes.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: make use of share_mode_entry_prepare_{lock_del,unlock}() in close_{remove_sh...
Stefan Metzmacher [Tue, 30 Aug 2022 05:31:41 +0000 (05:31 +0000)] 
s3:smbd: make use of share_mode_entry_prepare_{lock_del,unlock}() in close_{remove_share_mode,directory}()

This gives a nice speed up...

The following test with 256 commections all looping with open/close
on the same inode (share root) is improved drastically:

  smbtorture //127.0.0.1/m -Uroot%test smb2.bench.path-contention-shared \
         --option='torture:bench_path=' \
         --option="torture:timelimit=60" \
         --option="torture:nprocs=256" \
         --option="torture:qdepth=1"

From some like this:

    open[num/s=11536,avslat=0.011450,minlat=0.000039,maxlat=0.052707]
    close[num/s=11534,avslat=0.010878,minlat=0.000022,maxlat=0.052342]

to:
    open[num/s=13225,avslat=0.010504,minlat=0.000042,maxlat=0.054023]
    close[num/s=13223,avslat=0.008971,minlat=0.000022,maxlat=0.053838]

But this is only half of the solution, the next commits will
add a similar optimization to the open code, at the end we'll
perform like we did in Samba 4.12:

    open[num/s=37680,avslat=0.003471,minlat=0.000040,maxlat=0.061411]
    close[num/s=37678,avslat=0.003440,minlat=0.000022,maxlat=0.051536]

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: make use of close_share_mode_lock_{prepare,cleanup}() in close_directory()
Stefan Metzmacher [Tue, 30 Aug 2022 05:31:41 +0000 (05:31 +0000)] 
s3:smbd: make use of close_share_mode_lock_{prepare,cleanup}() in close_directory()

It's good to have this in common as close_remove_share_mode()
and in the end we'll avoid get_existing_share_mode_lock()
and call them via share_mode_entry_prepare_{lock,unlock}(),
so that they can run under a tdb chainlock.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: split out some generic code from close_remove_share_mode()
Stefan Metzmacher [Tue, 30 Aug 2022 05:31:41 +0000 (05:31 +0000)] 
s3:smbd: split out some generic code from close_remove_share_mode()

close_share_mode_lock_prepare() will operates on share_mode_lock
in order to check if the object needs to be deleted or if
we can remove the share_mode_entry directly.

close_share_mode_lock_cleanup() will finish after the object
has been deleted.

We can reuse these function in close_directory() soon and
in the end we'll avoid get_existing_share_mode_lock()
and call them via share_mode_entry_prepare_{lock,unlock}(),
so that they can run under a tdb chainlock.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: avoid remove_oplock() in close_remove_share_mode()
Stefan Metzmacher [Mon, 12 Sep 2022 23:30:48 +0000 (01:30 +0200)] 
s3:smbd: avoid remove_oplock() in close_remove_share_mode()

This inlines remove_oplock() into close_remove_share_mode() and
calls remove_share_oplock() and release_file_oplock() directly.

The idea is that we'll soon call remove_share_oplock()
under a tdb chainlock, while release_file_oplock() needs to be called outside.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: let close_directory() only change the user if needed
Stefan Metzmacher [Mon, 12 Sep 2022 17:49:09 +0000 (19:49 +0200)] 
s3:smbd: let close_directory() only change the user if needed

The logic is now similar to close_remove_share_mode().

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: remove one indentation level in close_directory()
Stefan Metzmacher [Mon, 12 Sep 2022 17:41:25 +0000 (19:41 +0200)] 
s3:smbd: remove one indentation level in close_directory()

We now use a goto done in order to skip the deletion part.

This means the code flow is now almost idential compared to
close_remove_share_mode().

It prepares to split common code to be shared by
close_remove_share_mode() and close_directory().

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: let close_directory() use the same delete_dir logic as close_remove_share_mode()
Stefan Metzmacher [Mon, 12 Sep 2022 17:35:38 +0000 (19:35 +0200)] 
s3:smbd: let close_directory() use the same delete_dir logic as close_remove_share_mode()

This will make further changes simpler.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: improve !delete_file logic in close_remove_share_mode()
Stefan Metzmacher [Mon, 12 Sep 2022 16:00:39 +0000 (18:00 +0200)] 
s3:smbd: improve !delete_file logic in close_remove_share_mode()

This makes it much easier to understand the logic (at least for me).

It will make the following changes easier.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: let close_directory() hold the lock during delete_all_streams/rmdir_internals
Stefan Metzmacher [Mon, 12 Sep 2022 17:15:58 +0000 (19:15 +0200)] 
s3:smbd: let close_directory() hold the lock during delete_all_streams/rmdir_internals

Now that we're using g_lock, it doesn't mean we're holding a tdb
chainlock.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: remove static from release_file_oplock()
Stefan Metzmacher [Tue, 30 Aug 2022 07:48:40 +0000 (09:48 +0200)] 
s3:smbd: remove static from release_file_oplock()

It will be used in close.c in the next commit.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: maintain all SHARE_MODE_LEASE_* flags not only _READ
Stefan Metzmacher [Mon, 15 Aug 2022 15:42:33 +0000 (17:42 +0200)] 
s3:smbd: maintain all SHARE_MODE_LEASE_* flags not only _READ

Remember SMB2 Create is the only was to upgrade a lease.

The strategy is that opening of a file will always result
in storing the total lease bits.

But we're lazy clearing the flags on close.

We'll only clear them by traversing all entries when
we break a NONE or when opening a new handle.

We don't do any decision on SHARE_MODE_LEASE_{HANDLE,WRITE},
maybe we'll do in future, but at least it should be much more
sane for debugging now!

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: split out check_and_store_share_mode()
Stefan Metzmacher [Mon, 15 Aug 2022 06:08:37 +0000 (08:08 +0200)] 
s3:smbd: split out check_and_store_share_mode()

This shows that the code in open_file_ntcreate() and
open_directory() is basically the same now, which
simplifies things a lot.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: also call handle_share_mode_lease for directories
Stefan Metzmacher [Wed, 10 Aug 2022 09:23:25 +0000 (09:23 +0000)] 
s3:smbd: also call handle_share_mode_lease for directories

It means we call open_mode_check() now only via handle_share_mode_lease()
and the fact that we never grant any directory leases (yet), means
that delay_for_oplocks() avoids the share_mode_forall_entries() loop.

This is a way into supporting directory leases, but that's not
the point for this commit, the point is that.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: prepare delay_for_oplock() for directories
Stefan Metzmacher [Fri, 19 Aug 2022 10:00:15 +0000 (12:00 +0200)] 
s3:smbd: prepare delay_for_oplock() for directories

We don't support directory leases yet, so it should be
an noop for now.

The point is that we want to call
delay_for_oplock(oplock_request=NO_OPLOCK)
for directories soon.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: call set_file_oplock() after set_share_mode()
Stefan Metzmacher [Wed, 10 Aug 2022 08:48:25 +0000 (08:48 +0000)] 
s3:smbd: call set_file_oplock() after set_share_mode()

The important part is the call to get a kernel oplock is deferred
until after set_share_mode(). The goal is to get the code
between get_share_mode_lock() and set_share_mode() free of any
blocking operation.

As we were optimistic to get the oplock that was asked for,
we need to remove_share_oplock() in order to set NO_OPLOCK
also in the share_mode entry.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: call grant_fsp_lease() after set_share_mode()
Stefan Metzmacher [Wed, 10 Aug 2022 08:48:25 +0000 (08:48 +0000)] 
s3:smbd: call grant_fsp_lease() after set_share_mode()

This means we don't have to call remove_lease_if_stale() if
set_share_mode() fails. It's easier to cleanup the share mode entry.

And it makes the code flow easier to the following changes.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: move grant_fsp_lease()/set_file_oplock() out of handle_share_mode_lease()
Stefan Metzmacher [Wed, 10 Aug 2022 08:30:18 +0000 (08:30 +0000)] 
s3:smbd: move grant_fsp_lease()/set_file_oplock() out of handle_share_mode_lease()

The aim is to call set_file_oplock() after set_share_mode(), so that we
only ask for kernel oplocks after set_share_mode().

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: move grant_fsp_lease()/set_file_oplock() out of delay_for_oplocks()
Stefan Metzmacher [Wed, 10 Aug 2022 07:58:02 +0000 (07:58 +0000)] 
s3:smbd: move grant_fsp_lease()/set_file_oplock() out of delay_for_oplocks()

It means delay_for_oplocks() is no longer asking for kernel oplocks.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:smbd: add more detailed debugging to delay_for_oplock()
Stefan Metzmacher [Sun, 21 Aug 2022 09:46:16 +0000 (11:46 +0200)] 
s3:smbd: add more detailed debugging to delay_for_oplock()

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:locking: add share_mode_entry_prepare_{lock,unlock}() infrastructure
Stefan Metzmacher [Mon, 29 Aug 2022 11:44:00 +0000 (13:44 +0200)] 
s3:locking: add share_mode_entry_prepare_{lock,unlock}() infrastructure

When adding or deleting share mode entries elements, we typically
have a pattern like this:

1. get the g_lock via get_[existing_]share_mode_lock()
2. do some checking of the existing record
3. add/delete a share_mode_entry to the record
4. do some vfs operations still protected by the g_lock
5. (optional) cleanup of the record on failure
6. release the g_lock

We can optimize this to:

- Run 1-3. under a tdb chainlock
- Only protect vfs operations with the g_lock
  if a new file was created/will be deleted
- Regrab the g_lock for a cleanup.

The new share_mode_entry_prepare_lock()
allows the caller to run a function within a tdb chainlock
similar to share_mode_do_locked_vfs_denied() where vfs calls are denied
and the execution is done within a tdb chainlock.

But the callback function is allowed to decide if it wants to
keep the lock at the g_lock layer on return.

The decision is kept in struct share_mode_entry_prepare_state,
which is then passed to share_mode_entry_prepare_unlock()
with an optional callback to do some cleanup under the
still existing g_lock or a regrabed g_lock.

In the ideal case the callback function passed to
share_mode_entry_prepare_lock() is able to decide that
it can drop the g_lock and the share_mode_entry_prepare_unlock().
gets a NULL callback as there's nothing to cleanup.
In this case share_mode_entry_prepare_unlock() is a noop.

This will allow us to avoid fallbacks to the dbwrap_watch based
waiting for the g_lock in the SMB2 Create and Close code paths.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:locking: optimize share_mode_do_locked_vfs_denied() with g_lock_lock callback
Stefan Metzmacher [Mon, 29 Aug 2022 10:50:20 +0000 (12:50 +0200)] 
s3:locking: optimize share_mode_do_locked_vfs_denied() with g_lock_lock callback

It means that in callers function will run under a single tdb chainlock,
which means callers from the outside will never see the record being
locked at g_lock level, as the g_lock is only held in memory.
within the single tdb chainlock. As a result we'll very unlikely hit
the case where we need to wait for a g_lock using the dbwrap_watch
logic.

Review with: git show -w

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:locking: add current_share_mode_glck helper functions
Stefan Metzmacher [Mon, 29 Aug 2022 10:50:20 +0000 (12:50 +0200)] 
s3:locking: add current_share_mode_glck helper functions

We'll soon make use of callback functions passed to g_lock_lock(),
during these callback function we'll only be allowed to
call 'g_lock_lock_cb_state' based functions.

Given that nesting of share_mode call, we need to
make it transparent to the callers and the detail
that we optimize using g_lock_lock() callbacks.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:g_lock: add callback function to g_lock_lock()
Stefan Metzmacher [Sun, 28 Aug 2022 11:08:48 +0000 (13:08 +0200)] 
s3:g_lock: add callback function to g_lock_lock()

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:g_lock: add callback function to g_lock_lock_send()
Stefan Metzmacher [Sun, 28 Aug 2022 10:38:24 +0000 (12:38 +0200)] 
s3:g_lock: add callback function to g_lock_lock_send()

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:g_lock: add callback function to g_lock_lock_simple_fn()
Stefan Metzmacher [Sun, 28 Aug 2022 09:41:46 +0000 (11:41 +0200)] 
s3:g_lock: add callback function to g_lock_lock_simple_fn()

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:g_lock: add callback function to g_lock_trylock()
Stefan Metzmacher [Sun, 28 Aug 2022 10:38:24 +0000 (12:38 +0200)] 
s3:g_lock: add callback function to g_lock_trylock()

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:g_lock: reorder the logic in g_lock_trylock()
Stefan Metzmacher [Sun, 28 Aug 2022 10:31:23 +0000 (12:31 +0200)] 
s3:g_lock: reorder the logic in g_lock_trylock()

We now have only one code path that stores the fully
granted lock.

This is not change in behavior, but it will simplify further
changes.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:g_lock: remove redundant code in g_lock_trylock()
Stefan Metzmacher [Sun, 28 Aug 2022 09:58:14 +0000 (11:58 +0200)] 
s3:g_lock: remove redundant code in g_lock_trylock()

g_lock_cleanup_shared() handles lck.num_shared == 0 just fine...

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:g_lock: add g_lock_ctx->busy and assert it to false
Stefan Metzmacher [Sun, 28 Aug 2022 09:41:46 +0000 (11:41 +0200)] 
s3:g_lock: add g_lock_ctx->busy and assert it to false

This prepares some helper functions in order to
allow callers of g_lock_lock() to pass in a callback function
that will run under the tdb chainlock when G_LOCK_WRITE was granted.

The idea is that the callers callback function would run with
g_lock_ctx->busy == true and all key based function are not be allowed
during the execution of the callback function. Only the
g_lock_lock_cb_state based helper function are allowed to be used.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:g_lock: add g_lock_lock_cb_state infrastructure
Stefan Metzmacher [Sun, 28 Aug 2022 09:41:46 +0000 (11:41 +0200)] 
s3:g_lock: add g_lock_lock_cb_state infrastructure

This prepares some helper functions in order to
allow callers of g_lock_lock() to pass in a callback function
that will run under the tdb chainlock when G_LOCK_WRITE was granted.

The idea is that the callers callback function would only be allowed
to run these new helper functions, while all key based function are
not to be allowed.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
3 years agos3:g_lock: reorder the logic in g_lock_lock_simple_fn()
Stefan Metzmacher [Sun, 28 Aug 2022 08:30:38 +0000 (10:30 +0200)] 
s3:g_lock: reorder the logic in g_lock_lock_simple_fn()

First we fully check if we'll get the lock
and then store the lock.

This is not change in behavior, but it will simplify further changes.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>