From b075458ee7f7632dfa57c1ad8e35d5818f1bcc12 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 15 Jun 2002 11:15:31 +0000 Subject: This patch does 2 things: It extends the 'server mutex' to conver security=server, becouse the connection race condition exists here too, and while people *should* use security=domain, some sites don't.... (This probably should be done in 2.2 as well). Also, start to actually extract and use the information that the remote server returns in the info3 struct. The server mutex code is now in a new file. Andrew Bartlett (This used to be commit 9b0dabdf4ec3bb45879caae76e03b57ccdad8b4b) --- source3/lib/server_mutex.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 source3/lib/server_mutex.c (limited to 'source3/lib/server_mutex.c') diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c new file mode 100644 index 0000000000..416d77564d --- /dev/null +++ b/source3/lib/server_mutex.c @@ -0,0 +1,57 @@ +/* + Unix SMB/CIFS implementation. + Authenticate against a remote domain + Copyright (C) Andrew Tridgell 1992-2002 + Copyright (C) Andrew Bartlett 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* For reasons known only to MS, many of their NT/Win2k versions + need serialised access only. Two connections at the same time + may (in certain situations) cause connections to be reset, + or access to be denied. + + This locking allows smbd's mutlithread architecture to look + like the single-connection that NT makes. */ + +static char *mutex_server_name; + +BOOL grab_server_mutex(const char *name) +{ + mutex_server_name = strdup(name); + if (!mutex_server_name) { + DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name)); + return False; + } + if (!message_named_mutex(mutex_server_name, 20)) { + DEBUG(10,("grab_server_mutex: failed for %s\n", name)); + SAFE_FREE(mutex_server_name); + return False; + } + + return True; +} + +void release_server_mutex(void) +{ + if (mutex_server_name) { + message_named_mutex_release(mutex_server_name); + SAFE_FREE(mutex_server_name); + } +} + -- cgit From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/lib/server_mutex.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/lib/server_mutex.c') diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c index 416d77564d..3e5512c734 100644 --- a/source3/lib/server_mutex.c +++ b/source3/lib/server_mutex.c @@ -38,7 +38,7 @@ BOOL grab_server_mutex(const char *name) DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name)); return False; } - if (!message_named_mutex(mutex_server_name, 20)) { + if (!secrets_named_mutex(mutex_server_name, 10)) { DEBUG(10,("grab_server_mutex: failed for %s\n", name)); SAFE_FREE(mutex_server_name); return False; @@ -50,8 +50,7 @@ BOOL grab_server_mutex(const char *name) void release_server_mutex(void) { if (mutex_server_name) { - message_named_mutex_release(mutex_server_name); + secrets_named_mutex_release(mutex_server_name); SAFE_FREE(mutex_server_name); } } - -- cgit From 6b2eb72df0bcf9143d013e64410ebde78d57b1c4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 16 Jan 2003 20:08:26 +0000 Subject: Fixed up mutex protection around winbindd logon code. Sync with APP-HEAD. Jeremy. (This used to be commit daf179bcd6297b525bfc644efb154734723f4d58) --- source3/lib/server_mutex.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/lib/server_mutex.c') diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c index 3e5512c734..878e5497d8 100644 --- a/source3/lib/server_mutex.c +++ b/source3/lib/server_mutex.c @@ -30,6 +30,8 @@ like the single-connection that NT makes. */ static char *mutex_server_name; +/* FIXME. ref_count should be allocated per name... JRA. */ +size_t ref_count; BOOL grab_server_mutex(const char *name) { @@ -38,7 +40,7 @@ BOOL grab_server_mutex(const char *name) DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name)); return False; } - if (!secrets_named_mutex(mutex_server_name, 10)) { + if (!secrets_named_mutex(mutex_server_name, 10, &ref_count)) { DEBUG(10,("grab_server_mutex: failed for %s\n", name)); SAFE_FREE(mutex_server_name); return False; @@ -50,7 +52,7 @@ BOOL grab_server_mutex(const char *name) void release_server_mutex(void) { if (mutex_server_name) { - secrets_named_mutex_release(mutex_server_name); + secrets_named_mutex_release(mutex_server_name, &ref_count); SAFE_FREE(mutex_server_name); } } -- cgit From a8eaea53ed70ef998a510b6dcf0288462207f9a0 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 17 Mar 2003 23:06:12 +0000 Subject: Merge from HEAD - make winbindd locking sane again: Original message: This patch attemptes to clean up winbindd's mutex locking. The current locking scheme in winbind is a complete mess - indeed, the next step should be to push the locking into cli_full_connection(), but I'll leave it for now. This patch works on the noted behaviour that 2 parts of the connection process need protection - and independent protection. Tim Potter did some work on this a little while back, verifying the second case. The two cases are: - between connect() and first session setup - during the auth2 phase of the netlogon pipe setup. I've removed the counter on the lock, as I fail to see what it gains us. This patch also adds 'anonymous fallback' to our winbindd -> DC connection. If the authenticated connection fails (wbinfo -A specifed) - say that account isn't trusted by a trusted DC - then we try an anonymous. Both tpot and mbp like the patch. Andrew Bartlett (This used to be commit b5283c00a900393b83f0edb2785c5caf402404eb) --- source3/lib/server_mutex.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/lib/server_mutex.c') diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c index 878e5497d8..3e5512c734 100644 --- a/source3/lib/server_mutex.c +++ b/source3/lib/server_mutex.c @@ -30,8 +30,6 @@ like the single-connection that NT makes. */ static char *mutex_server_name; -/* FIXME. ref_count should be allocated per name... JRA. */ -size_t ref_count; BOOL grab_server_mutex(const char *name) { @@ -40,7 +38,7 @@ BOOL grab_server_mutex(const char *name) DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name)); return False; } - if (!secrets_named_mutex(mutex_server_name, 10, &ref_count)) { + if (!secrets_named_mutex(mutex_server_name, 10)) { DEBUG(10,("grab_server_mutex: failed for %s\n", name)); SAFE_FREE(mutex_server_name); return False; @@ -52,7 +50,7 @@ BOOL grab_server_mutex(const char *name) void release_server_mutex(void) { if (mutex_server_name) { - secrets_named_mutex_release(mutex_server_name, &ref_count); + secrets_named_mutex_release(mutex_server_name); SAFE_FREE(mutex_server_name); } } -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/lib/server_mutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/server_mutex.c') diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c index 3e5512c734..2267fba9c8 100644 --- a/source3/lib/server_mutex.c +++ b/source3/lib/server_mutex.c @@ -33,7 +33,7 @@ static char *mutex_server_name; BOOL grab_server_mutex(const char *name) { - mutex_server_name = strdup(name); + mutex_server_name = SMB_STRDUP(name); if (!mutex_server_name) { DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name)); return False; -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/server_mutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/server_mutex.c') diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c index 2267fba9c8..45acfccc79 100644 --- a/source3/lib/server_mutex.c +++ b/source3/lib/server_mutex.c @@ -6,7 +6,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/lib/server_mutex.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/server_mutex.c') diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c index 45acfccc79..ad4a9710bf 100644 --- a/source3/lib/server_mutex.c +++ b/source3/lib/server_mutex.c @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/lib/server_mutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/server_mutex.c') diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c index ad4a9710bf..2700aa103b 100644 --- a/source3/lib/server_mutex.c +++ b/source3/lib/server_mutex.c @@ -30,7 +30,7 @@ static char *mutex_server_name; -BOOL grab_server_mutex(const char *name) +bool grab_server_mutex(const char *name) { mutex_server_name = SMB_STRDUP(name); if (!mutex_server_name) { -- cgit From 1ebfc66b2c145289d1e1314e8415d9e3c6f405ae Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 10 Mar 2008 21:08:29 +0100 Subject: Use a separate tdb for mutexes Another preparation to convert secrets.c to dbwrap: The dbwrap API does not provide a sane tdb_lock_with_timeout abstraction. In the clustered case the DC mutex is needed per-node anyway, so it is perfectly fine to use a local mutex only. (This used to be commit f94a63cd8f94490780ad9331da229c0bcb2ca5d6) --- source3/lib/server_mutex.c | 57 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 17 deletions(-) (limited to 'source3/lib/server_mutex.c') diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c index 2700aa103b..43c0de1975 100644 --- a/source3/lib/server_mutex.c +++ b/source3/lib/server_mutex.c @@ -28,28 +28,51 @@ This locking allows smbd's mutlithread architecture to look like the single-connection that NT makes. */ -static char *mutex_server_name; +struct named_mutex { + struct tdb_wrap *tdb; + char *name; +}; -bool grab_server_mutex(const char *name) +static int unlock_named_mutex(struct named_mutex *mutex) { - mutex_server_name = SMB_STRDUP(name); - if (!mutex_server_name) { - DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name)); - return False; + tdb_unlock_bystring(mutex->tdb->tdb, mutex->name); + return 0; +} + +struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name, + int timeout) +{ + struct named_mutex *result; + + result = talloc(mem_ctx, struct named_mutex); + if (result == NULL) { + DEBUG(0, ("talloc failed\n")); + return NULL; } - if (!secrets_named_mutex(mutex_server_name, 10)) { - DEBUG(10,("grab_server_mutex: failed for %s\n", name)); - SAFE_FREE(mutex_server_name); - return False; + + result->name = talloc_strdup(result, name); + if (result->name == NULL) { + DEBUG(0, ("talloc failed\n")); + TALLOC_FREE(result); + return NULL; } - return True; -} + result->tdb = tdb_wrap_open(result, lock_path("mutex.tdb"), 0, + TDB_DEFAULT, O_RDWR|O_CREAT, 0600); + if (result->tdb == NULL) { + DEBUG(1, ("Could not open mutex.tdb: %s\n", + strerror(errno))); + TALLOC_FREE(result); + return NULL; + } -void release_server_mutex(void) -{ - if (mutex_server_name) { - secrets_named_mutex_release(mutex_server_name); - SAFE_FREE(mutex_server_name); + if (tdb_lock_bystring_with_timeout(result->tdb->tdb, name, + timeout) == -1) { + DEBUG(1, ("Could not get the lock for %s\n", name)); + TALLOC_FREE(result); + return NULL; } + + talloc_set_destructor(result, unlock_named_mutex); + return result; } -- cgit