The branch, master has been updated via d762ab558ae locking: hide share_mode_lock definition via df2ffaaa209 locking: move share_mode_flags_[gs]et to share_mode_lock.c via 4b6f4ee43e3 smbd: Avoid references to share_mode_data->id via d220bae5a9d smbd: Remove a variable used just once via 271a369fb94 smbd: Don't set share_mode_lock modified in grant_new_fsp_lease() via f6abe33dd17 net_tdb: Use share_mode_data_dump() via 5c3a18e5145 locking: Add share_mode_data_dump() accessor function via ce64b3caf39 net_tdb: Use share_mode_filename() via affce737dc9 net_tdb: Use share_mode_servicepath() via 2337c1e3f80 net_tdb: Slightly restructure net_tdb_locking() via ee41ec8afe0 smbd: Use share_mode_servicepath() in scavenger.c via 5aab299dff2 locking: Add share_mode_servicepath() accessor function via 3d33eee5366 smbd: Avoid share_mode_lock dereference in scavenger via 53059dc6cbf smbd: Use share_mode_filename() in scavenger.c via d2662dff7e0 smbstatus: Use share_mode_filename() via 701da78cc84 locking: Add share_mode_filename() accessor function via ec387d04816 smbd: Use share_mode_changed_write_time() in smbd/close.c via 60f24079a90 smbd: Use share_mode_changed_write_time() in durable_disconnect() via a01cb7faa34 locking: Add share_mode_changed_write_time() accessor function via 3f54fcaffd7 smbd: Move setting d->modified=true to reset_share_mode_entry() via 84dba041a35 locking: Make share_mode_watch_send() take "share_mode_lock" via 2fe1e601c90 smbd: Move "struct share_mode_lock" to share_mode_lock.h via 13217e6eb91 smbd: Move share_mode_cleanup_disonnected() to scavenger.c via 15e9e2945c2 smbd: Give locking/share_mode_lock.c its own header file via 4da7de80d56 smbd: Align integer types via 401c5132a40 passdb: Align integer types via daa9d98cf80 auth: Align an integer type via fc88f2e0e43 vfs_error_inject: Align integer types via 76043ccb7f0 lib: Slightly optimize smb_fname_str_dbg() via 30c917c215c lib: Fix a theoretical out-of-bounds write via 1af086d23cf lib: Fix a signed/unsigned warning via be381fd4547 smbd: Use ISDOT[DOT] in can_delete_directory_fsp() via a342cf2cb89 locking: Remove an unused anonymous struct reference via 5ac44b83ee9 lib: Move generate_unique_u64_state into generate_unique_u64() via 6598e00e129 lib: talloc: Remove the ALWAYS_REALLOC code paths. from 18fdfe8c102 winbind: alternatively use prama fini for destructors if supported
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit d762ab558ae6c16ba5007fb38e44c9667d952e2b Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 12:39:48 2020 +0100 locking: hide share_mode_lock definition This makes "struct share_mode_lock" an opaque data structure opened up only to the code in locking/. This makes it much safer to modify the data structure with defined accessor functions in share_mode_lock.c. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> Autobuild-User(master): Jeremy Allison <j...@samba.org> Autobuild-Date(master): Tue Nov 10 21:12:48 UTC 2020 on sn-devel-184 commit df2ffaaa2097676cc1ddfc4239f53aef6afc4869 Author: Volker Lendecke <v...@samba.org> Date: Thu Nov 5 15:39:51 2020 +0100 locking: move share_mode_flags_[gs]et to share_mode_lock.c These routines parse and marshall the uint16 summary flag in share_mode_data. open_file_ntcreate() and open_directory() are the only real users of this. The user in oplock.c is just the lazy reset of the "read lease exists somewhere" after asynchronously breaking read oplocks after a write request. This moves handling the flags into locking/ to consolidate data structure handling of "share_mode_data" there. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 4b6f4ee43e376104f6a7f6556c135ff729f5d40b Author: Volker Lendecke <v...@samba.org> Date: Thu Nov 5 10:42:10 2020 +0100 smbd: Avoid references to share_mode_data->id When calling open_mode_check() we know the file id. We can pass it to the lower levels without dereferencing struct share_mode_lock. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit d220bae5a9d7f248c3611210c6e79c5ad8f95095 Author: Volker Lendecke <v...@samba.org> Date: Thu Nov 5 10:39:10 2020 +0100 smbd: Remove a variable used just once Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 271a369fb94fb4affdd8725c9cce829bb5d85c93 Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 15:51:51 2020 +0100 smbd: Don't set share_mode_lock modified in grant_new_fsp_lease() A new lease never triggers a retry. Setting d->modified to true just triggered the watchers needlessly. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit f6abe33dd1717465c8ef882f2b1e71300899619b Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 15:28:16 2020 +0100 net_tdb: Use share_mode_data_dump() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 5c3a18e51455c012ab691f00c259014041fb464d Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 15:27:56 2020 +0100 locking: Add share_mode_data_dump() accessor function This is a special case for net tdb dump. The alternative would be to change the net tdb dump behaviour. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit ce64b3caf3948459c1edf13896834a34d2a917e8 Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 15:12:33 2020 +0100 net_tdb: Use share_mode_filename() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit affce737dc904f46412e798f9ceaafa59fa377ad Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 15:11:40 2020 +0100 net_tdb: Use share_mode_servicepath() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 2337c1e3f8021e747a309f30a0d28cf9de351335 Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 15:09:40 2020 +0100 net_tdb: Slightly restructure net_tdb_locking() Remove the net_tdb_locking_fetch() subroutine. All of net_tdb_locking() is still very simple, and net_tdb_locking_fetch() did the fetch as such plus parsing the hex key. With this restructuring it was possible to avoid a direct reference to lck->data->id. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit ee41ec8afe05779f77a08441e7d283d4ccaf08e1 Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 13:46:02 2020 +0100 smbd: Use share_mode_servicepath() in scavenger.c Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 5aab299dff2b11607444876624e84cf33833fdf5 Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 13:42:03 2020 +0100 locking: Add share_mode_servicepath() accessor function Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 3d33eee53663e16f6b7c2e5e1d6632900ad7d6c2 Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 13:35:26 2020 +0100 smbd: Avoid share_mode_lock dereference in scavenger Pass "struct file_id" to callees without accessing share_mode_lock internals Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 53059dc6cbfcf70c86074f92f72d8ca5c1d0134b Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 13:32:14 2020 +0100 smbd: Use share_mode_filename() in scavenger.c Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit d2662dff7e03cb4ba97df70d562dc2cbbdfaea58 Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 13:20:09 2020 +0100 smbstatus: Use share_mode_filename() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 701da78cc84900f4b61b5d2da0ccc6f18b9099fa Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 13:19:46 2020 +0100 locking: Add share_mode_filename() accessor function Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit ec387d048161c84f885c0979d350bcc65ad0df20 Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 13:00:55 2020 +0100 smbd: Use share_mode_changed_write_time() in smbd/close.c Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 60f24079a904441853aa46e5f97befa21634b7da Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 12:53:47 2020 +0100 smbd: Use share_mode_changed_write_time() in durable_disconnect() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit a01cb7faa343e974d93ba471aeabd4356a154a8c Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 12:53:29 2020 +0100 locking: Add share_mode_changed_write_time() accessor function Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 3f54fcaffd771c098f1cc587c66d2e171494447c Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 12:53:03 2020 +0100 smbd: Move setting d->modified=true to reset_share_mode_entry() This function is only called from vfs_default_durable_reconnect(). It is really the lower-level routine that triggers the write of the locking.tdb record. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 84dba041a35d75657a2738157fdddc83aeb7a2a0 Author: Volker Lendecke <v...@samba.org> Date: Tue Nov 3 17:36:08 2020 +0100 locking: Make share_mode_watch_send() take "share_mode_lock" This makes clear that this can only be done under a lock Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 2fe1e601c90607062418cafb64cf6c063179ebde Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 11:34:54 2020 +0100 smbd: Move "struct share_mode_lock" to share_mode_lock.h share_mode_lock.c is where it's created Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 13217e6eb9163abcbb9ff3bb4716fd1f453a2bf8 Author: Volker Lendecke <v...@samba.org> Date: Tue Nov 3 13:25:57 2020 +0100 smbd: Move share_mode_cleanup_disonnected() to scavenger.c Reduce the complexity of share_mode_lock.c, scavenger.c is the only user of this routine. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 15e9e2945c2d404a4ba7b26744978ff22b4b7ef5 Author: Volker Lendecke <v...@samba.org> Date: Wed Oct 28 12:09:39 2020 +0100 smbd: Give locking/share_mode_lock.c its own header file To me this is then easier to figure out what is defined there, and where it's exactly used. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 4da7de80d566d2e19f4a6c5e219fcad993e0a3a7 Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 11:29:21 2020 +0100 smbd: Align integer types Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 401c5132a40b20e24dc321b6a9f924a53e949dab Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 11:12:59 2020 +0100 passdb: Align integer types Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit daa9d98cf8057d47b0f22a37d009f227b798f20e Author: Volker Lendecke <v...@samba.org> Date: Wed Nov 4 11:09:06 2020 +0100 auth: Align an integer type Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit fc88f2e0e4326519c00b1f6deb34eef9030099e4 Author: Volker Lendecke <v...@samba.org> Date: Fri Oct 30 15:43:03 2020 +0100 vfs_error_inject: Align integer types Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 76043ccb7f0f73e114776182469da8a96589a826 Author: Volker Lendecke <v...@samba.org> Date: Tue Nov 3 12:33:12 2020 +0100 lib: Slightly optimize smb_fname_str_dbg() Don't leak "fname" Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 30c917c215c627a8b306c4e245f9443a3b29606d Author: Volker Lendecke <v...@samba.org> Date: Fri Oct 30 11:04:21 2020 +0100 lib: Fix a theoretical out-of-bounds write This routine looked fishy: We do cap_vals[num_cap_vals++] = XXX based on #ifdefs and capabilities. Then later on we did a check that we did not overwrite the stack. The change I did is to just count the number of num_cap_vals++, right now it's 5. I know it is in different switch branches, but with the #ifdefs it's a bit clumsy to read the exact number of actual num_cap_vals++ that can happen in one run. On debian buster, cap_val_t is an int, so this is not really wasting too much. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 1af086d23cf43742aa497c2a23deb65cadac673c Author: Volker Lendecke <v...@samba.org> Date: Fri Oct 30 11:02:31 2020 +0100 lib: Fix a signed/unsigned warning Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit be381fd45471098099309067dab68cebc9ce5b53 Author: Volker Lendecke <v...@samba.org> Date: Wed Oct 28 15:40:39 2020 +0100 smbd: Use ISDOT[DOT] in can_delete_directory_fsp() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit a342cf2cb894477b3ef76fde35931800ddd6aafa Author: Volker Lendecke <v...@samba.org> Date: Wed Oct 28 11:47:49 2020 +0100 locking: Remove an unused anonymous struct reference This was used in share_mode_do_locked() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 5ac44b83ee94741a9bd044f8c4760ef6d8a367ae Author: Volker Lendecke <v...@samba.org> Date: Mon Oct 26 11:51:44 2020 +0100 lib: Move generate_unique_u64_state into generate_unique_u64() Make clear that generate_unique_u64() is the only function referencing it. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 6598e00e129bc8b36d6d38345b67aba48b3eb26d Author: Jeremy Allison <j...@samba.org> Date: Mon Nov 9 11:50:09 2020 -0800 lib: talloc: Remove the ALWAYS_REALLOC code paths. This is now never set, and also never tested, and only makes the talloc code more complicated. Once this is gone we can start looking at the memlimit stuff. Signed-off-by: Jeremy Allison <j...@samba.org> Reviewed-by: Alexander Bokovoy <a...@samba.org> ----------------------------------------------------------------------- Summary of changes: auth/ntlmssp/ntlmssp_client.c | 2 +- lib/talloc/talloc.c | 69 +--- lib/talloc/testsuite.c | 8 - lib/util/genrand_util.c | 10 +- source3/include/locking.h | 4 +- source3/lib/filename_util.c | 6 +- source3/lib/system.c | 13 +- source3/locking/locking.c | 2 + source3/locking/proto.h | 78 ----- source3/locking/share_mode_lock.c | 359 ++++++++------------- source3/locking/share_mode_lock.h | 126 ++++++++ .../locking/share_mode_lock_private.h | 14 +- source3/modules/vfs_delay_inject.c | 1 + source3/modules/vfs_error_inject.c | 2 +- source3/passdb/py_passdb.c | 17 +- source3/printing/queue_process.c | 1 + source3/printing/spoolssd.c | 1 + source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 1 + source3/smbd/blocking.c | 3 +- source3/smbd/close.c | 8 +- source3/smbd/dir.c | 10 +- source3/smbd/durable.c | 9 +- source3/smbd/open.c | 178 +++------- source3/smbd/oplock.c | 9 +- source3/smbd/reply.c | 1 + source3/smbd/scavenger.c | 194 +++++++++++ source3/smbd/server.c | 1 + source3/smbd/server_exit.c | 1 + source3/smbd/smb2_ioctl_network_fs.c | 2 +- source3/smbd/smb2_lock.c | 3 +- source3/smbd/smb2_query_directory.c | 1 + source3/smbd/smb2_setinfo.c | 3 +- source3/torture/locktest2.c | 1 + source3/torture/vfstest.c | 1 + source3/utils/net_tdb.c | 89 ++--- source3/utils/net_vfs.c | 1 + source3/utils/status.c | 10 +- 37 files changed, 611 insertions(+), 628 deletions(-) create mode 100644 source3/locking/share_mode_lock.h copy source4/kdc/mit_kdc_irpc.h => source3/locking/share_mode_lock_private.h (78%) Changeset truncated at 500 lines: diff --git a/auth/ntlmssp/ntlmssp_client.c b/auth/ntlmssp/ntlmssp_client.c index 58e4e3d6f42..af1642d3256 100644 --- a/auth/ntlmssp/ntlmssp_client.c +++ b/auth/ntlmssp/ntlmssp_client.c @@ -430,7 +430,7 @@ NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, const struct wbcBlob *wbc_auth_blob = NULL; const struct wbcBlob *wbc_session_key = NULL; wbcErr wbc_status; - int i; + size_t i; bool new_spnego = false; params.account_name = user; diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c index ef49429307a..29da190880a 100644 --- a/lib/talloc/talloc.c +++ b/lib/talloc/talloc.c @@ -54,11 +54,6 @@ #include <valgrind.h> #endif -/* use this to force every realloc to change the pointer, to stress test - code that might not cope */ -#define ALWAYS_REALLOC 0 - - #define MAX_TALLOC_SIZE 0x10000000 #define TALLOC_FLAG_FREE 0x01 @@ -1844,7 +1839,6 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons pool_hdr = tc->pool; } -#if (ALWAYS_REALLOC == 0) /* don't shrink if we have less than 1k to gain */ if (size < tc->size && tc->limit == NULL) { if (pool_hdr) { @@ -1878,7 +1872,6 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons */ return ptr; } -#endif /* * by resetting magic we catch users of the old memory @@ -1897,66 +1890,6 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons */ _talloc_chunk_set_free(tc, NULL); -#if (ALWAYS_REALLOC != 0) - if (pool_hdr) { - new_ptr = tc_alloc_pool(tc, size + TC_HDR_SIZE, 0); - if (new_ptr == NULL) { - /* - * Couldn't allocate from pool (pool size - * counts as already allocated for memlimit - * purposes). We must check memory limit - * before any real malloc. - */ - if (tc->limit) { - /* - * Note we're doing an extra malloc, - * on top of the pool size, so account - * for size only, not the difference - * between old and new size. - */ - if (!talloc_memlimit_check(tc->limit, size)) { - _talloc_chunk_set_not_free(tc); - errno = ENOMEM; - return NULL; - } - } - new_ptr = malloc(TC_HDR_SIZE+size); - malloced = true; - new_size = size; - } - - if (new_ptr) { - memcpy(new_ptr, tc, MIN(tc->size,size) + TC_HDR_SIZE); - TC_INVALIDATE_FULL_CHUNK(tc); - /* - * Only decrement the object count in the pool once - * we know we're returning a valid new_ptr. - */ - pool_hdr->object_count--; - } - } else { - /* We're doing malloc then free here, so record the difference. */ - old_size = tc->size; - new_size = size; - /* - * We must check memory limit - * before any real malloc. - */ - if (tc->limit && (size > old_size)) { - if (!talloc_memlimit_check(tc->limit, - (size - old_size))) { - _talloc_chunk_set_not_free(tc); - errno = ENOMEM; - return NULL; - } - } - new_ptr = malloc(size + TC_HDR_SIZE); - if (new_ptr) { - memcpy(new_ptr, tc, MIN(tc->size, size) + TC_HDR_SIZE); - free(tc); - } - } -#else if (pool_hdr) { struct talloc_chunk *pool_tc; void *next_tc = tc_next_chunk(tc); @@ -2102,7 +2035,7 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons new_ptr = realloc(tc, size + TC_HDR_SIZE); } got_new_ptr: -#endif + if (unlikely(!new_ptr)) { /* * Ok, this is a strange spot. We have to put back diff --git a/lib/talloc/testsuite.c b/lib/talloc/testsuite.c index 6f23ad4e18a..282ebc6956d 100644 --- a/lib/talloc/testsuite.c +++ b/lib/talloc/testsuite.c @@ -1307,7 +1307,6 @@ static bool test_pool(void) p4 = talloc_size(p3, 1000); memset(p4, 0x11, talloc_get_size(p4)); -#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ p2_2 = talloc_realloc_size(pool, p2, 20+1); torture_assert("pool realloc 20+1", p2_2 == p2, "failed: pointer changed"); memset(p2, 0x11, talloc_get_size(p2)); @@ -1372,8 +1371,6 @@ static bool test_pool(void) torture_assert("pool alloc 800", p3 == p1, "failed: pointer changed"); memset(p3, 0x11, talloc_get_size(p3)); -#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ - talloc_free(pool); return true; @@ -1408,7 +1405,6 @@ static bool test_pool_steal(void) p1_2 = p1; -#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ p1_2 = talloc_realloc_size(root, p1, 5 * 16); torture_assert("pool realloc 5 * 16", p1_2 > p2, "failed: pointer not changed"); memset(p1_2, 0x11, talloc_get_size(p1_2)); @@ -1420,13 +1416,11 @@ static bool test_pool_steal(void) p2_2 = talloc_realloc_size(root, p2, 3 * 16); torture_assert("pool realloc 5 * 16", p2_2 == p2, "failed: pointer changed"); memset(p2_2, 0x11, talloc_get_size(p2_2)); -#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ talloc_free(p1_2); p2_2 = p2; -#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ /* now we should reclaim the full pool */ p2_2 = talloc_realloc_size(root, p2, 8 * 16); torture_assert("pool realloc 8 * 16", p2_2 == p1, "failed: pointer not expected"); @@ -1438,8 +1432,6 @@ static bool test_pool_steal(void) torture_assert("pool realloc 2 * 1024", p2_2 != p1, "failed: pointer not expected"); memset(p2_2, 0x11, talloc_get_size(p2_2)); -#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ - talloc_free(p2_2); talloc_free(root); diff --git a/lib/util/genrand_util.c b/lib/util/genrand_util.c index 26b52a1c814..82085184e82 100644 --- a/lib/util/genrand_util.c +++ b/lib/util/genrand_util.c @@ -47,13 +47,13 @@ _PUBLIC_ uint64_t generate_random_u64(void) return BVAL(v, 0); } -static struct generate_unique_u64_state { - uint64_t next_value; - int pid; -} generate_unique_u64_state; - _PUBLIC_ uint64_t generate_unique_u64(uint64_t veto_value) { + static struct generate_unique_u64_state { + uint64_t next_value; + int pid; + } generate_unique_u64_state; + int pid = getpid(); if (unlikely(pid != generate_unique_u64_state.pid)) { diff --git a/source3/include/locking.h b/source3/include/locking.h index 1aad6626f34..3629d86c556 100644 --- a/source3/include/locking.h +++ b/source3/include/locking.h @@ -71,8 +71,6 @@ struct smbd_lock_element { uint64_t count; }; -struct share_mode_lock { - struct share_mode_data *data; -}; +struct share_mode_lock; #endif /* _LOCKING_H_ */ diff --git a/source3/lib/filename_util.c b/source3/lib/filename_util.c index fb79dab09bd..f535ea1f088 100644 --- a/source3/lib/filename_util.c +++ b/source3/lib/filename_util.c @@ -165,10 +165,8 @@ const char *smb_fname_str_dbg(const struct smb_filename *smb_fname) return ""; } - fname = talloc_asprintf(talloc_tos(), - "%s {%s}", - fname, - tstr); + fname = talloc_asprintf_append_buffer( + fname, " {%s}", tstr); if (fname == NULL) { return ""; } diff --git a/source3/lib/system.c b/source3/lib/system.c index 7c8cd19d11f..cf4c4d46c36 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -587,8 +587,9 @@ char *sys_getwd(void) static bool set_process_capability(enum smbd_capability capability, bool enable) { - cap_value_t cap_vals[2] = {0}; - int num_cap_vals = 0; + /* "5" is the number of "num_cap_vals++" below */ + cap_value_t cap_vals[5] = {0}; + size_t num_cap_vals = 0; cap_t cap; @@ -613,6 +614,12 @@ static bool set_process_capability(enum smbd_capability capability, } switch (capability) { + /* + * WARNING: If you add any #ifdef for a fresh + * capability, bump up the array size in the + * declaration of cap_vals[] above just to be + * trivially safe to never overwrite cap_vals[]. + */ case KERNEL_OPLOCK_CAPABILITY: #ifdef CAP_NETWORK_MGT /* IRIX has CAP_NETWORK_MGT for oplocks. */ @@ -639,8 +646,6 @@ static bool set_process_capability(enum smbd_capability capability, #endif } - SMB_ASSERT(num_cap_vals <= ARRAY_SIZE(cap_vals)); - if (num_cap_vals == 0) { cap_free(cap); return True; diff --git a/source3/locking/locking.c b/source3/locking/locking.c index 06c6a91cd59..5fd117ac31e 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -39,6 +39,8 @@ #include "lib/util/time_basic.h" #include "system/filesys.h" #include "lib/util/server_id.h" +#include "share_mode_lock.h" +#include "share_mode_lock_private.h" #include "locking/proto.h" #include "smbd/globals.h" #include "dbwrap/dbwrap.h" diff --git a/source3/locking/proto.h b/source3/locking/proto.h index f4c68bc5ca4..72d037040f2 100644 --- a/source3/locking/proto.h +++ b/source3/locking/proto.h @@ -124,51 +124,12 @@ NTSTATUS do_unlock(files_struct *fsp, enum brl_flavour lock_flav); void locking_close_file(files_struct *fsp, enum file_close_type close_type); -bool locking_init(void); -bool locking_init_readonly(void); -bool locking_end(void); char *share_mode_str(TALLOC_CTX *ctx, int num, const struct file_id *id, const struct share_mode_entry *e); struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx, struct file_id id); -struct share_mode_lock *get_share_mode_lock( - TALLOC_CTX *mem_ctx, - struct file_id id, - const char *servicepath, - const struct smb_filename *smb_fname, - const struct timespec *old_write_time); -bool file_has_read_lease(struct files_struct *fsp); - -struct db_record; -NTSTATUS share_mode_do_locked( - struct file_id id, - void (*fn)(const uint8_t *buf, - size_t buflen, - bool *modified_dependent, - void *private_data), - void *private_data); -NTSTATUS share_mode_wakeup_waiters(struct file_id id); -bool share_mode_have_entries(struct share_mode_lock *lck); - -struct tevent_req *share_mode_watch_send( - TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct file_id id, - struct server_id blocker); -NTSTATUS share_mode_watch_recv( - struct tevent_req *req, bool *blockerdead, struct server_id *blocker); - -struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx, - struct file_id id); -struct tevent_req *fetch_share_mode_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct file_id id, - bool *queued); -NTSTATUS fetch_share_mode_recv(struct tevent_req *req, - TALLOC_CTX *mem_ctx, - struct share_mode_lock **_lck); bool rename_share_filename(struct messaging_context *msg_ctx, struct share_mode_lock *lck, struct file_id id, @@ -182,28 +143,9 @@ void get_file_infos(struct file_id id, struct timespec *write_time); bool is_valid_share_mode_entry(const struct share_mode_entry *e); bool share_entry_stale_pid(struct share_mode_entry *e); -bool set_share_mode(struct share_mode_lock *lck, - struct files_struct *fsp, - uid_t uid, - uint64_t mid, - uint16_t op_type, - uint32_t share_access, - uint32_t access_mask); -bool reset_share_mode_entry( - struct share_mode_lock *lck, - struct server_id old_pid, - uint64_t old_share_file_id, - struct server_id new_pid, - uint64_t new_mid, - uint64_t new_share_file_id); NTSTATUS remove_lease_if_stale(struct share_mode_lock *lck, const struct GUID *client_guid, const struct smb2_lease_key *lease_key); -bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp); -bool mark_share_mode_disconnected(struct share_mode_lock *lck, - struct files_struct *fsp); -bool remove_share_oplock(struct share_mode_lock *lck, files_struct *fsp); -bool downgrade_share_oplock(struct share_mode_lock *lck, files_struct *fsp); bool get_delete_on_close_token(struct share_mode_lock *lck, uint32_t name_hash, const struct security_token **pp_nt_tok, @@ -222,32 +164,12 @@ bool set_sticky_write_time(struct file_id fileid, struct timespec write_time); bool set_write_time(struct file_id fileid, struct timespec write_time); struct timespec get_share_mode_write_time(struct share_mode_lock *lck); bool file_has_open_streams(files_struct *fsp); -int share_mode_forall(int (*fn)(struct file_id fid, - const struct share_mode_data *data, - void *private_data), - void *private_data); -int share_entry_forall(int (*fn)(struct file_id fid, - const struct share_mode_data *data, - const struct share_mode_entry *entry, - void *private_data), - void *private_data); -bool share_mode_cleanup_disconnected(struct file_id id, - uint64_t open_persistent_id); bool share_mode_forall_leases( struct share_mode_lock *lck, bool (*fn)(struct share_mode_entry *e, void *private_data), void *private_data); -bool share_mode_forall_entries( - struct share_mode_lock *lck, - bool (*fn)(struct share_mode_entry *e, - bool *modified, - void *private_data), - void *private_data); - -NTSTATUS share_mode_count_entries(struct file_id fid, size_t *num_share_modes); - /* The following definitions come from locking/posix.c */ bool is_posix_locked(files_struct *fsp, diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c index 1c4d3a42221..c9012f7454b 100644 --- a/source3/locking/share_mode_lock.c +++ b/source3/locking/share_mode_lock.c @@ -38,6 +38,8 @@ #include "includes.h" #include "system/filesys.h" #include "lib/util/server_id.h" +#include "share_mode_lock.h" +#include "share_mode_lock_private.h" #include "locking/proto.h" #include "smbd/globals.h" #include "dbwrap/dbwrap.h" @@ -1120,6 +1122,140 @@ bool share_mode_have_entries(struct share_mode_lock *lck) return lck->data->have_share_modes; } +NTTIME share_mode_changed_write_time(struct share_mode_lock *lck) +{ + return lck->data->changed_write_time; +} + +const char *share_mode_servicepath(struct share_mode_lock *lck) +{ + return lck->data->servicepath; +} + +char *share_mode_filename(TALLOC_CTX *mem_ctx, struct share_mode_lock *lck) +{ + struct share_mode_data *d = lck->data; + bool has_stream = (d->stream_name != NULL); + char *fname = NULL; + + fname = talloc_asprintf( + mem_ctx, + "%s%s%s", + d->base_name, + has_stream ? ":" : "", + has_stream ? d->stream_name : ""); + return fname; +} + +char *share_mode_data_dump( + TALLOC_CTX *mem_ctx, struct share_mode_lock *lck) +{ + struct ndr_print *p = talloc(mem_ctx, struct ndr_print); + char *ret = NULL; + + if (p == NULL) { + return NULL; + } + + *p = (struct ndr_print) { + .print = ndr_print_string_helper, + .depth = 1, + .private_data = talloc_strdup(mem_ctx, ""), + }; + + if (p->private_data == NULL) { + TALLOC_FREE(p); + return NULL; + } + + ndr_print_share_mode_data(p, "SHARE_MODE_DATA", lck->data); + + ret = p->private_data; + + TALLOC_FREE(p); + + return ret; +} + +void share_mode_flags_get( + struct share_mode_lock *lck, + uint32_t *access_mask, + uint32_t *share_mode, + uint32_t *lease_type) +{ + uint16_t flags = lck->data->flags; + + if (access_mask != NULL) { + *access_mask = + ((flags & SHARE_MODE_ACCESS_READ) ? + FILE_READ_DATA : 0) | + ((flags & SHARE_MODE_ACCESS_WRITE) ? + FILE_WRITE_DATA : 0) | + ((flags & SHARE_MODE_ACCESS_DELETE) ? + DELETE_ACCESS : 0); + } + if (share_mode != NULL) { + *share_mode = + ((flags & SHARE_MODE_SHARE_READ) ? + FILE_SHARE_READ : 0) | + ((flags & SHARE_MODE_SHARE_WRITE) ? + FILE_SHARE_WRITE : 0) | + ((flags & SHARE_MODE_SHARE_DELETE) ? + FILE_SHARE_DELETE : 0); + } + if (lease_type != NULL) { + *lease_type = + ((flags & SHARE_MODE_LEASE_READ) ? + SMB2_LEASE_READ : 0) | + ((flags & SHARE_MODE_LEASE_WRITE) ? + SMB2_LEASE_WRITE : 0) | -- Samba Shared Repository