From d9804ae3cc2c435f9983ca47f6f1b6b96e5c03ca Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 15 Apr 2009 15:40:00 -0700 Subject: Fix bug #6089 - Winbind samr_OpenDomain not possible with Samba 3.2.6+ What a difference a name makes... :-). Just because something is missnamed SAMR_ACCESS_OPEN_DOMAIN, when it should actually be SAMR_ACCESS_LOOKUP_DOMAIN, don't automatically use it for a security check in _samr_OpenDomain(). Jeremy. --- lib/util/smb_threads.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/util/smb_threads.h b/lib/util/smb_threads.h index 945e93803a..c2ba53321a 100644 --- a/lib/util/smb_threads.h +++ b/lib/util/smb_threads.h @@ -77,7 +77,7 @@ static int smb_lock_pthread(void *plock, enum smb_thread_lock_type lock_type, co } \ } \ \ -static pthread_mutex_t create_tls_mutex = PTHREAD_MUTEX_INITIALIZER; \ +static pthread_mutex_t smb_create_tls_mutex = PTHREAD_MUTEX_INITIALIZER; \ \ static int smb_create_tls_once_pthread(const char *keyname, void **ppkey, const char *location) \ { \ -- cgit From 56aae35a234f19eda9702ce321b92fa382a1ada6 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 16 Apr 2009 07:51:01 +0200 Subject: tsocket: fix the build without ipv6 support metze --- lib/tsocket/tsocket_bsd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c index 87586e08e3..29097bd987 100644 --- a/lib/tsocket/tsocket_bsd.c +++ b/lib/tsocket/tsocket_bsd.c @@ -523,9 +523,11 @@ static char *tsocket_address_bsd_string(const struct tsocket_address *addr, case AF_INET: prefix = "ipv4"; break; +#ifdef HAVE_IPV6 case AF_INET6: prefix = "ipv6"; break; +#endif default: errno = EINVAL; return NULL; -- cgit From 3d2e95c296a1858986b9c806dff67c9cc3d8f70d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 20 Apr 2009 03:04:42 -0700 Subject: Fix the pthread_once initialization issue. Make talloc_stackframe use this. Jeremy. --- lib/util/smb_threads.c | 25 ++++++++++++++--- lib/util/smb_threads.h | 61 ++++++++++++++++++++++++----------------- lib/util/smb_threads_internal.h | 11 +++++--- lib/util/talloc_stack.c | 26 ++++++++++++++---- 4 files changed, 85 insertions(+), 38 deletions(-) (limited to 'lib') diff --git a/lib/util/smb_threads.c b/lib/util/smb_threads.c index fa2d8da186..783e660b7f 100644 --- a/lib/util/smb_threads.c +++ b/lib/util/smb_threads.c @@ -92,8 +92,26 @@ int smb_thread_set_functions(const struct smb_thread_functions *tf) SMB_THREADS_DEF_PTHREAD_IMPLEMENTATION(tf); +static smb_thread_once_t ot = SMB_THREAD_ONCE_INIT; void *pkey = NULL; +static void init_fn(void) +{ + int ret; + + if (!global_tfp) { + /* Non-thread safe init case. */ + if (ot) { + return; + } + ot = true; + } + + if ((ret = SMB_THREAD_CREATE_TLS("test_tls", pkey)) != 0) { + printf("Create tls once error: %d\n", ret); + } +} + /* Test function. */ int test_threads(void) { @@ -101,9 +119,8 @@ int test_threads(void) void *plock = NULL; smb_thread_set_functions(&tf); - if ((ret = SMB_THREAD_CREATE_TLS_ONCE("test_tls", pkey)) != 0) { - printf("Create tls once error: %d\n", ret); - } + SMB_THREAD_ONCE(&ot, init_fn); + if ((ret = SMB_THREAD_CREATE_MUTEX("test", plock)) != 0) { printf("Create lock error: %d\n", ret); } @@ -114,7 +131,7 @@ int test_threads(void) printf("unlock error: %d\n", ret); } SMB_THREAD_DESTROY_MUTEX(plock); - SMB_THREAD_DESTROY_TLS_ONCE(pkey); + SMB_THREAD_DESTROY_TLS(pkey); return 0; } diff --git a/lib/util/smb_threads.h b/lib/util/smb_threads.h index c2ba53321a..f4ed1fcb9a 100644 --- a/lib/util/smb_threads.h +++ b/lib/util/smb_threads.h @@ -20,6 +20,23 @@ #ifndef _smb_threads_h_ #define _smb_threads_h_ +#if defined(HAVE_PTHREAD_H) +#include +#endif + +/* Data types needed for smb_thread_once call. */ +#if defined(HAVE_PTHREAD_H) +#define smb_thread_once_t pthread_once_t +#else +#define smb_thread_once_t bool +#endif + +#if defined(HAVE_PTHREAD_H) +#define SMB_THREAD_ONCE_INIT PTHREAD_ONCE_INIT +#else +#define SMB_THREAD_ONCE_INIT false +#endif + enum smb_thread_lock_type { SMB_THREAD_LOCK = 1, SMB_THREAD_UNLOCK @@ -35,11 +52,14 @@ struct smb_thread_functions { int (*lock_mutex)(void *plock, enum smb_thread_lock_type lock_type, const char *location); + /* Once initialization. */ + int (*smb_thread_once)(smb_thread_once_t *p_once, void (*init_fn)(void)); + /* Thread local storage. */ - int (*create_tls_once)(const char *keyname, + int (*create_tls)(const char *keyname, void **ppkey, const char *location); - void (*destroy_tls_once)(void **pkey, + void (*destroy_tls)(void **pkey, const char *location); int (*set_tls)(void *pkey, const void *pval, const char *location); void *(*get_tls)(void *pkey, const char *location); @@ -77,45 +97,35 @@ static int smb_lock_pthread(void *plock, enum smb_thread_lock_type lock_type, co } \ } \ \ -static pthread_mutex_t smb_create_tls_mutex = PTHREAD_MUTEX_INITIALIZER; \ +static int smb_thread_once_pthread(smb_thread_once_t *p_once, void (*init_fn)(void)) \ +{ \ + return pthread_once(p_once, init_fn); \ +} \ \ -static int smb_create_tls_once_pthread(const char *keyname, void **ppkey, const char *location) \ +static int smb_create_tls_pthread(const char *keyname, void **ppkey, const char *location) \ { \ int ret; \ pthread_key_t *pkey; \ - ret = pthread_mutex_lock(&create_tls_mutex); \ - if (ret) { \ - return ret; \ - } \ - if (*ppkey) { \ - pthread_mutex_unlock(&create_tls_mutex); \ - return 0; \ - } \ pkey = (pthread_key_t *)malloc(sizeof(pthread_key_t)); \ if (!pkey) { \ - pthread_mutex_unlock(&create_tls_mutex); \ return ENOMEM; \ } \ ret = pthread_key_create(pkey, NULL); \ if (ret) { \ free(pkey); \ - pthread_mutex_unlock(&create_tls_mutex); \ return ret; \ } \ *ppkey = (void *)pkey; \ - pthread_mutex_unlock(&create_tls_mutex); \ return 0; \ } \ \ -static void smb_destroy_tls_once_pthread(void **ppkey, const char *location) \ +static void smb_destroy_tls_pthread(void **ppkey, const char *location) \ { \ - pthread_mutex_lock(&create_tls_mutex); \ if (*ppkey) { \ pthread_key_delete(*(pthread_key_t *)ppkey); \ free(*ppkey); \ *ppkey = NULL; \ } \ - pthread_mutex_unlock(&create_tls_mutex); \ } \ \ static int smb_set_tls_pthread(void *pkey, const void *pval, const char *location) \ @@ -129,12 +139,13 @@ static void *smb_get_tls_pthread(void *pkey, const char *location) \ } \ \ static const struct smb_thread_functions (tf) = { \ - smb_create_mutex_pthread, \ - smb_destroy_mutex_pthread, \ - smb_lock_pthread, \ - smb_create_tls_once_pthread, \ - smb_destroy_tls_once_pthread, \ - smb_set_tls_pthread, \ - smb_get_tls_pthread } + smb_create_mutex_pthread, \ + smb_destroy_mutex_pthread, \ + smb_lock_pthread, \ + smb_thread_once_pthread, \ + smb_create_tls_pthread, \ + smb_destroy_tls_pthread, \ + smb_set_tls_pthread, \ + smb_get_tls_pthread } #endif diff --git a/lib/util/smb_threads_internal.h b/lib/util/smb_threads_internal.h index 58c6fe3f99..b7e862af72 100644 --- a/lib/util/smb_threads_internal.h +++ b/lib/util/smb_threads_internal.h @@ -33,13 +33,16 @@ #define SMB_THREAD_LOCK(plock, type) \ (global_tfp ? global_tfp->lock_mutex((plock), (type), __location__) : 0) -#define SMB_THREAD_CREATE_TLS_ONCE(keyname, key) \ - (global_tfp ? global_tfp->create_tls_once((keyname), &(key), __location__) : 0) +#define SMB_THREAD_ONCE(ponce, init_fn) \ + (global_tfp ? global_tfp->smb_thread_once((ponce), (init_fn)) : ((init_fn()), 0)) -#define SMB_THREAD_DESTROY_TLS_ONCE(key) \ +#define SMB_THREAD_CREATE_TLS(keyname, key) \ + (global_tfp ? global_tfp->create_tls((keyname), &(key), __location__) : 0) + +#define SMB_THREAD_DESTROY_TLS(key) \ do { \ if (global_tfp) { \ - global_tfp->destroy_tls_once(&(key), __location__); \ + global_tfp->destroy_tls(&(key), __location__); \ }; \ } while (0) diff --git a/lib/util/talloc_stack.c b/lib/util/talloc_stack.c index f572dd6c77..f5ca9d21d5 100644 --- a/lib/util/talloc_stack.c +++ b/lib/util/talloc_stack.c @@ -55,7 +55,25 @@ struct talloc_stackframe { static void *global_ts; -static struct talloc_stackframe *talloc_stackframe_init(void) +/* Variable to ensure TLS value is only initialized once. */ +static smb_thread_once_t ts_initialized = SMB_THREAD_ONCE_INIT; + +static void talloc_stackframe_init(void) +{ + if (!global_tfp) { + /* Non-thread safe init case. */ + if (ts_initialized) { + return; + } + ts_initialized = true; + } + + if (SMB_THREAD_CREATE_TLS("talloc_stackframe", global_ts)) { + smb_panic("talloc_stackframe_init create_tls failed"); + } +} + +static struct talloc_stackframe *talloc_stackframe_create(void) { #if defined(PARANOID_MALLOC_CHECKER) #ifdef malloc @@ -74,9 +92,7 @@ static struct talloc_stackframe *talloc_stackframe_init(void) ZERO_STRUCTP(ts); - if (SMB_THREAD_CREATE_TLS_ONCE("talloc_stackframe", global_ts)) { - smb_panic("talloc_stackframe_init create_tls failed"); - } + SMB_THREAD_ONCE(&ts_initialized, talloc_stackframe_init); if (SMB_THREAD_SET_TLS(global_ts, ts)) { smb_panic("talloc_stackframe_init set_tls failed"); @@ -115,7 +131,7 @@ static TALLOC_CTX *talloc_stackframe_internal(size_t poolsize) (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts); if (ts == NULL) { - ts = talloc_stackframe_init(); + ts = talloc_stackframe_create(); } if (ts->talloc_stack_arraysize < ts->talloc_stacksize + 1) { -- cgit From 399c765538d91c696efd1496fffd9ae1e876f3ae Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 20 Apr 2009 04:00:06 -0700 Subject: Attempt to fix build farm on platforms where pthread_once_t is a struct. Jeremy. --- lib/util/smb_threads.h | 5 ++++- lib/util/talloc_stack.c | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/util/smb_threads.h b/lib/util/smb_threads.h index f4ed1fcb9a..682e142c5b 100644 --- a/lib/util/smb_threads.h +++ b/lib/util/smb_threads.h @@ -33,8 +33,11 @@ #if defined(HAVE_PTHREAD_H) #define SMB_THREAD_ONCE_INIT PTHREAD_ONCE_INIT +#define SMB_THREAD_ONCE_IS_INITIALIZED(val) (true) +#define SMB_THREAD_ONCE_INITIALIZE(val) #else -#define SMB_THREAD_ONCE_INIT false +#define SMB_THREAD_ONCE_IS_INITIALIZED(val) ((val) == true) +#define SMB_THREAD_ONCE_INITIALIZE(val) ((val) = true) #endif enum smb_thread_lock_type { diff --git a/lib/util/talloc_stack.c b/lib/util/talloc_stack.c index f5ca9d21d5..2ed18fa113 100644 --- a/lib/util/talloc_stack.c +++ b/lib/util/talloc_stack.c @@ -62,10 +62,10 @@ static void talloc_stackframe_init(void) { if (!global_tfp) { /* Non-thread safe init case. */ - if (ts_initialized) { + if (SMB_THREAD_ONCE_IS_INITIALIZED(ts_initialized)) { return; } - ts_initialized = true; + SMB_THREAD_ONCE_INITIALIZE(ts_initialized); } if (SMB_THREAD_CREATE_TLS("talloc_stackframe", global_ts)) { -- cgit From 5cbd7556c23c4dddc96f19b6977d57b8e3f551d7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 20 Apr 2009 04:25:26 -0700 Subject: Ensure we have all the definitions needed in both threaded and non-threaded versions. Jeremy. --- lib/util/smb_threads.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/util/smb_threads.h b/lib/util/smb_threads.h index 682e142c5b..3d3d48ecb2 100644 --- a/lib/util/smb_threads.h +++ b/lib/util/smb_threads.h @@ -20,22 +20,17 @@ #ifndef _smb_threads_h_ #define _smb_threads_h_ -#if defined(HAVE_PTHREAD_H) -#include -#endif - /* Data types needed for smb_thread_once call. */ -#if defined(HAVE_PTHREAD_H) -#define smb_thread_once_t pthread_once_t -#else -#define smb_thread_once_t bool -#endif #if defined(HAVE_PTHREAD_H) +#include +#define smb_thread_once_t pthread_once_t #define SMB_THREAD_ONCE_INIT PTHREAD_ONCE_INIT #define SMB_THREAD_ONCE_IS_INITIALIZED(val) (true) #define SMB_THREAD_ONCE_INITIALIZE(val) #else +#define smb_thread_once_t bool +#define SMB_THREAD_ONCE_INIT false #define SMB_THREAD_ONCE_IS_INITIALIZED(val) ((val) == true) #define SMB_THREAD_ONCE_INITIALIZE(val) ((val) = true) #endif -- cgit From fbf4293d7ec80b93d2b289698f85641dbf26750a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 20 Apr 2009 15:21:39 +0200 Subject: Move check for syslog out of libreplace to source3/ and source4/. This should help compiling talloc on Windows. --- lib/replace/libreplace.m4 | 2 +- lib/replace/samba.m4 | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/replace/libreplace.m4 b/lib/replace/libreplace.m4 index 30d7017d0f..4eae00c54f 100644 --- a/lib/replace/libreplace.m4 +++ b/lib/replace/libreplace.m4 @@ -279,7 +279,7 @@ m4_include(timegm.m4) m4_include(repdir.m4) m4_include(crypt.m4) -AC_CHECK_FUNCS([syslog printf memset memcpy],,[AC_MSG_ERROR([Required function not found])]) +AC_CHECK_FUNCS([printf memset memcpy],,[AC_MSG_ERROR([Required function not found])]) echo "LIBREPLACE_BROKEN_CHECKS: END" ]) dnl end AC_LIBREPLACE_BROKEN_CHECKS diff --git a/lib/replace/samba.m4 b/lib/replace/samba.m4 index ccb6f2e20d..4514728d03 100644 --- a/lib/replace/samba.m4 +++ b/lib/replace/samba.m4 @@ -33,3 +33,5 @@ SMB_SUBSYSTEM(LIBREPLACE_HOSTCC, [${LIBREPLACE_HOSTCC_OBJS}], [], [-Ilib/replace]) + +AC_CHECK_FUNCS([syslog],,[AC_MSG_ERROR([Required function not found])]) -- cgit From e5233ccf9e32cd5d399f91512d7f310d43558e31 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 20 Apr 2009 15:39:48 +0200 Subject: Cope with the fact that only _mkdir() exists on Windows and that it doesn't take a mode argument. --- lib/replace/replace.c | 4 ++++ lib/replace/system/filesys.h | 4 ++++ lib/replace/test/os2_delete.c | 4 ++++ 3 files changed, 12 insertions(+) (limited to 'lib') diff --git a/lib/replace/replace.c b/lib/replace/replace.c index 78c688d50c..a648391b23 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -31,6 +31,10 @@ #include "system/locale.h" #include "system/wait.h" +#ifdef _WIN32 +#define mkdir(d,m) _mkdir(d) +#endif + void replace_dummy(void); void replace_dummy(void) {} diff --git a/lib/replace/system/filesys.h b/lib/replace/system/filesys.h index 4bf1f64865..1cf6f231b7 100644 --- a/lib/replace/system/filesys.h +++ b/lib/replace/system/filesys.h @@ -179,4 +179,8 @@ #define SEEK_SET 0 #endif +#ifdef _WIN32 +#define mkdir(d,m) _mkdir(d) +#endif + #endif diff --git a/lib/replace/test/os2_delete.c b/lib/replace/test/os2_delete.c index 44efeea08a..8b52837018 100644 --- a/lib/replace/test/os2_delete.c +++ b/lib/replace/test/os2_delete.c @@ -27,6 +27,10 @@ static int test_readdir_os2_delete_ret; #define MIN(a,b) ((a)<(b)?(a):(b)) #endif +#ifdef _WIN32 +#define mkdir(d,m) _mkdir(d) +#endif + static void cleanup(void) { /* I'm a lazy bastard */ -- cgit From 20e1ba1c09631a3b1c850d9c8cbb42d863d0cb39 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 20 Apr 2009 15:47:19 +0200 Subject: Only define waitpid replacement if wait4 is available. (It isn't on Windows.) --- lib/replace/libreplace.m4 | 2 +- lib/replace/replace.c | 2 +- lib/replace/system/wait.h | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/replace/libreplace.m4 b/lib/replace/libreplace.m4 index 4eae00c54f..2d90d9c7e8 100644 --- a/lib/replace/libreplace.m4 +++ b/lib/replace/libreplace.m4 @@ -106,7 +106,7 @@ AC_CHECK_HEADERS(stropts.h) AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror) AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename) -AC_CHECK_FUNCS(waitpid strlcpy strlcat initgroups memmove strdup) +AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup) AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2) AC_CHECK_FUNCS(isatty chown lchown link readlink symlink realpath) AC_HAVE_DECL(setresuid, [#include ]) diff --git a/lib/replace/replace.c b/lib/replace/replace.c index a648391b23..be27744592 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -359,7 +359,7 @@ char *rep_strndup(const char *s, size_t n) } #endif -#ifndef HAVE_WAITPID +#if !defined(HAVE_WAITPID) && defined(HAVE_WAIT4) int rep_waitpid(pid_t pid,int *status,int options) { return wait4(pid, status, options, NULL); diff --git a/lib/replace/system/wait.h b/lib/replace/system/wait.h index 5784b1ae92..79583ad2ab 100644 --- a/lib/replace/system/wait.h +++ b/lib/replace/system/wait.h @@ -52,4 +52,8 @@ typedef int sig_atomic_t; #endif +#if !defined(HAVE_WAITPID) && defined(HAVE_WAIT4) +int rep_waitpid(pid_t pid,int *status,int options) +#endif + #endif -- cgit From bb0f43006403106fda6231ef9b5c9674ebb53e14 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 20 Apr 2009 15:54:02 +0200 Subject: Error out at runtime when seteuid/setresuid or setegid/setresgid are not available. This means it's possible to compile libreplace when these functions are not available and use it, as long as this particular function is not used. --- lib/replace/replace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/replace/replace.c b/lib/replace/replace.c index be27744592..fc15717349 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -372,7 +372,8 @@ int rep_seteuid(uid_t euid) #ifdef HAVE_SETRESUID return setresuid(-1, euid, -1); #else -# error "You need a seteuid function" + errno = ENOSYS; + return -1; #endif } #endif @@ -383,7 +384,8 @@ int rep_setegid(gid_t egid) #ifdef HAVE_SETRESGID return setresgid(-1, egid, -1); #else -# error "You need a setegid function" + errno = ENOSYS; + return -1; #endif } #endif -- cgit