[SCM] Samba Shared Repository - branch master updated

Michael Adam obnox at samba.org
Thu Jul 31 13:13:04 MDT 2014


The branch, master has been updated
       via  95d1828 waf: socket_wrapper should check for HAVE_FUNCTION_ATTRIBUTE_FORMAT.
       via  8c251d6 uwrap: Support dropping all supplemetary groups with setgroups()
       via  de1f924 uwrap: Add logging if uwrap is enabled correctly.
       via  41d7b64 uwrap: Log error if we are out of memory.
       via  0a3d142 uwrap: Add a better logging function.
       via  6bbf9fa uwrap: Check for HAVE_FUNCTION_ATTRIBUTE_FORMAT.
       via  9711f77 uwrap: Fall back to RTLD_NEXT if we can't find libc.
       via  a88f5a6 uwrap: Add mutex in uwrap_destructor().
       via  b7f9d3b uwrap: Fix memory leak on error.
       via  e249e79 debug: Avoid dependency on str_list_make
       via  0e448f8 debug: Fix blank line endings
       via  8792de7 debug: Increase maximum header length
       via  06a0b1c debug: In dbghdrclass, don't call strlen repeatedly
       via  200d94e debug: Fix a typo
       via  85c5551 debug: Simplify debug_parse_levels
       via  610bb4a debug: Simplify Debug1() -- no va_args
       via  138a65c debug: Remove an "else"
       via  b0221d5 debug: Remove two pointless assignments
       via  1929b1f debug: Only call Debug1 once in dbghdrclass
       via  44c77e8 debug: Move adding timeval and loglevel
       via  cff585b debug: slprintf->snprintf
       via  601b2b0 debug: Use timeval_str_buf in dbghdrclass
       via  15b0f57 debug: Simplify dbghdrclass with an early return
       via  0753c1b lib: Create time_basic.[ch]
       via  8799120 lib: Use timeval_str_buf in timeval_string
       via  2aa1492 lib: Add timeval_str_buf
       via  9026820 debug: Statically allocate format_bufr
       via  dd4c019 debug: Fix debug_parse_params
       via  6c9be49 debug: Make Debug1 static
       via  1581356 nmbd: Call DEBUGADD instead of Debug1
       via  3349c56 debug: Remove a dependency on charconv
       via  2229969 debug: Add some readability to debug_logtype
       via  02a06ae debug: Factor out debug_parse_param()
       via  9aee4ba debug: Move variables where they are used
       via  d8cb678 debug: Fix indentation in debug_parse_params
       via  d997d93 lib: Remove unused serverid_register_msg_flags()
       via  f77c3a6 libcli: Fix a typo
       via  64b9f52 param: remove a redundant (and wrong) comment frop lpcfg_service_ok()
       via  b7f4b0c s3:param: remove unused function lp_string_set()
      from  98426ad lib/param: change the default for "winbind expand groups" to "0"

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 95d1828a248148d6f45aafc134ccb4aebfef7226
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jul 31 10:22:10 2014 +0200

    waf: socket_wrapper should check for HAVE_FUNCTION_ATTRIBUTE_FORMAT.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>
    
    Autobuild-User(master): Michael Adam <obnox at samba.org>
    Autobuild-Date(master): Thu Jul 31 21:12:07 CEST 2014 on sn-devel-104

commit 8c251d6390abf3b7de03d1323f8525ec1d2c2528
Author: Jakub Hrozek <jakub.hrozek at gmail.com>
Date:   Thu Jul 31 10:20:40 2014 +0200

    uwrap: Support dropping all supplemetary groups with setgroups()
    
    Dropping all supplementary groups is a common practice when changing
    UIDs. This patch adds support for dropping all supplementary groups when
    setgroups is called with size=0.
    
    Signed-off-by: Jakub Hrozek <jakub.hrozek at gmail.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit de1f924f08b2da65871645041c06443d2b6e6a87
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jul 31 10:19:58 2014 +0200

    uwrap: Add logging if uwrap is enabled correctly.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 41d7b64744c4ed33634ad106e5becd1d816f33a2
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jul 31 10:19:28 2014 +0200

    uwrap: Log error if we are out of memory.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 0a3d14248473be3d964d50b75b92a6328b8f82cd
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jul 31 10:18:59 2014 +0200

    uwrap: Add a better logging function.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 6bbf9fa6df11dd60e6a808cf2e81b88c4e211a90
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jul 31 10:18:13 2014 +0200

    uwrap: Check for HAVE_FUNCTION_ATTRIBUTE_FORMAT.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 9711f77313e6d72696b0807acfea5d41ff89dfa7
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jul 31 10:13:40 2014 +0200

    uwrap: Fall back to RTLD_NEXT if we can't find libc.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit a88f5a6da24ba6ffa15bc35b00fca85d23cd1216
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jul 31 10:13:10 2014 +0200

    uwrap: Add mutex in uwrap_destructor().
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit b7f9d3b49160538d9d77723e80307cdfb2d071d0
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jul 31 10:12:15 2014 +0200

    uwrap: Fix memory leak on error.
    
    Found by Coverity.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit e249e794ecff42acfea264ecdd01af5bb661b503
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 20:01:31 2014 +0200

    debug: Avoid dependency on str_list_make
    
    strtok_r just also does the job and is available in libc
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 0e448f8d358b067319143ab64103bd5870adce42
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Jul 30 09:35:43 2014 +0000

    debug: Fix blank line endings
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 8792de7a16239214bf0863182ee5f1d85d89982c
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Jul 30 09:22:59 2014 +0000

    debug: Increase maximum header length
    
    With function names it can become quite long
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 06a0b1c85150d68bcbb6d6f81a66bf3976e0223e
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Jul 30 09:22:21 2014 +0000

    debug: In dbghdrclass, don't call strlen repeatedly
    
    Also properly protect against header_str overflow
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 200d94e5636d1852ae3c435d9a8335f655b95c27
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 20:44:28 2014 +0200

    debug: Fix a typo
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 85c5551618805ff868154e82595592426fe7b6ec
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 16:09:10 2014 +0000

    debug: Simplify debug_parse_levels
    
    Just some minimal refactoring
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 610bb4a1085681bd850d17735d499798fb3c627f
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 16:04:25 2014 +0000

    debug: Simplify Debug1() -- no va_args
    
    All callers just have "%s" as format string now, so we don't need to
    vasprintf anymore.
    
    This could speed up DEBUG a bit, we don't do a separate copy and the
    printf logic
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 138a65c12a8dd4a59b503180fa5aaff7386c1e4b
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 15:59:06 2014 +0000

    debug: Remove an "else"
    
    No else necessary, we just did a "goto done:"
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit b0221d58f9f17227246d479cbbe334093f9e08be
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 15:47:07 2014 +0000

    debug: Remove two pointless assignments
    
    "goto done:" jumps to that exact assignment :-)
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 1929b1fa20a43a1c78d08e0c28523f00da9a3411
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 15:31:48 2014 +0000

    debug: Only call Debug1 once in dbghdrclass
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 44c77e80326c17a80c70140ee1b64a8847a4f779
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 15:26:22 2014 +0000

    debug: Move adding timeval and loglevel
    
    The whole routine incrementally creates the hdr_string, do it for the
    time string and the debuglevel as well
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit cff585b6e2dff316c9478d470e11aa69faf0f4d5
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 15:09:00 2014 +0000

    debug: slprintf->snprintf
    
    snprintf does not need the -1 in sizeof(buf)-1
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 601b2b04530445344255992ebf6fb08a5ccf6eaa
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 15:06:17 2014 +0000

    debug: Use timeval_str_buf in dbghdrclass
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 15b0f57696cf8c1ae1c8760008b414f9a456bc49
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 15:02:22 2014 +0000

    debug: Simplify dbghdrclass with an early return
    
    No code change, visible with "git diff -w"
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 0753c1bec1ff5888068eeba5878c460ce07cef2a
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 20:54:44 2014 +0200

    lib: Create time_basic.[ch]
    
    Make the two functions that debug.c needs a subsystem of their own. The
    goal is to put debug.c on a diet. Anybody who wants to use it should
    not be forced to pull in half of Samba :-)
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 8799120abd07d4f3b243f473614d782fb7182bfc
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 14:52:42 2014 +0000

    lib: Use timeval_str_buf in timeval_string
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 2aa1492c7bc2fa5fe9943c27a294aa9efea6e701
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 14:43:39 2014 +0000

    lib: Add timeval_str_buf
    
    Similarly to server_id_str_buf it does not do any allocation
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 9026820e5cadc1f42ca2d88fdb53c0c715e2f221
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 12:58:53 2014 +0000

    debug: Statically allocate format_bufr
    
    Everybody needs this, so there's no point talloc'ing it. The side effect
    is that it removes a dependency on smb_panic()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit dd4c019d9ffaa5453e536c8aaaa8e03463dc2959
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 12:48:55 2014 +0000

    debug: Fix debug_parse_params
    
    The additional check this patch removes potentially drops some debuglevel
    class settings. While not documented, it is possible to add a debug class
    like for example "tdb:10" multiple times with multiple values. Later
    settings overwrite earlier ones, but only if the overall number of
    settings does not exceed the total number of available debug classes.
    
    This patch changes our behaviour, but I can't imagine a situation where
    someone relies on this check.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 6c9be497a3f41824411fe2507b4183d764a5f58e
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 12:22:05 2014 +0000

    debug: Make Debug1 static
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 15813561cce814adb6f94753dc6dda108be1eb77
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 12:11:54 2014 +0000

    nmbd: Call DEBUGADD instead of Debug1
    
    These were the only external callers of Debug1. To be honest, I don't
    really care if these debug messages now look a bit differently :-)
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 3349c566a5346ba0a3187bd424cb48fc28c57922
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 11:22:09 2014 +0000

    debug: Remove a dependency on charconv
    
    util_str has:
    
            /* characters below 0x3F are guaranteed to not appear in
               non-initial position in multi-byte charsets */
            if ((c & 0xC0) == 0) {
                    return strrchr(s, c);
            }
    
    '/' is 0x2f, so there's no point in calling strrchr_m and thus pulling
    in a whole lot of stuff
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 222996931d5ef8661ec69f34a9a0e2f4e8a980fb
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 11:20:27 2014 +0000

    debug: Add some readability to debug_logtype
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 02a06ae6170666b78bfcba011d65918997e6f290
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 11:05:06 2014 +0000

    debug: Factor out debug_parse_param()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 9aee4ba4786e49e7cb27b9f8428bb97622ccfb95
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 10:25:32 2014 +0000

    debug: Move variables where they are used
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit d8cb678bb65b2f5616122e68ee3d2d76fb88ddd2
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 10:23:04 2014 +0000

    debug: Fix indentation in debug_parse_params
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit d997d93af1dadb8bc1342a58b5733bfb495764a6
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jul 28 12:27:29 2014 +0000

    lib: Remove unused serverid_register_msg_flags()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit f77c3a65dbbe02ba754089125a0b6e4e53957a93
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 10:05:42 2014 +0000

    libcli: Fix a typo
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 64b9f520d2835d113bd9ab7ef86e4f9df541a70d
Author: Michael Adam <obnox at samba.org>
Date:   Tue Jul 29 12:19:23 2014 +0200

    param: remove a redundant (and wrong) comment frop lpcfg_service_ok()
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit b7f4b0ca00a276e7ccdd5a3554b273c25eddea4d
Author: Michael Adam <obnox at samba.org>
Date:   Tue Jul 29 12:09:39 2014 +0200

    s3:param: remove unused function lp_string_set()
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/param/loadparm.c                               |    1 -
 lib/param/loadparm.h                               |    1 -
 lib/socket_wrapper/wscript                         |   12 +
 lib/uid_wrapper/uid_wrapper.c                      |  113 ++++++++-
 lib/uid_wrapper/wscript                            |   12 +
 lib/util/debug.c                                   |  270 ++++++++++----------
 lib/util/debug.h                                   |   10 +-
 lib/util/time.c                                    |   71 ++----
 lib/util/time_basic.c                              |   80 ++++++
 .../srv_epmapper.h => lib/util/time_basic.h        |   30 ++-
 lib/util/wscript_build                             |    7 +-
 source3/include/serverid.h                         |    6 -
 source3/lib/serverid.c                             |   55 ----
 source3/nmbd/nmbd_browserdb.c                      |   17 +-
 source3/param/loadparm.c                           |    4 -
 source4/libcli/resolve/dns_ex.c                    |    2 +-
 16 files changed, 406 insertions(+), 285 deletions(-)
 create mode 100644 lib/util/time_basic.c
 copy source3/rpc_server/epmapper/srv_epmapper.h => lib/util/time_basic.h (53%)


Changeset truncated at 500 lines:

diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index 21798d9..4154260 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -963,7 +963,6 @@ bool lpcfg_service_ok(struct loadparm_service *service)
 		service->bAvailable = false;
 	}
 
-	/* If a service is flagged unavailable, log the fact at level 0. */
 	if (!service->bAvailable)
 		DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
 			  service->szService));
diff --git a/lib/param/loadparm.h b/lib/param/loadparm.h
index d4177e5..11632de 100644
--- a/lib/param/loadparm.h
+++ b/lib/param/loadparm.h
@@ -280,7 +280,6 @@ bool lp_is_security_and_server_role_valid(int server_role, int security);
 struct loadparm_global * get_globals(void);
 unsigned int * get_flags(void);
 char * lp_string(TALLOC_CTX *, const char *);
-bool lp_string_set(char **, const char *);
 int getservicebyname(const char *, struct loadparm_service *);
 bool lp_include(struct loadparm_context *, struct loadparm_service *,
 	       	const char *, char **);
diff --git a/lib/socket_wrapper/wscript b/lib/socket_wrapper/wscript
index 6542b81..de5bedd 100644
--- a/lib/socket_wrapper/wscript
+++ b/lib/socket_wrapper/wscript
@@ -38,6 +38,18 @@ def configure(conf):
             addmain=False,
             msg='Checking for library destructor support')
 
+        # check HAVE_FUNCTION_ATTRIBUTE_FORMAT
+        conf.CHECK_CODE('''
+            void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
+
+            int main(void) {
+                return 0;
+            }
+            ''',
+            'HAVE_FUNCTION_ATTRIBUTE_FORMAT',
+            addmain=False,
+            msg='Checking for printf format validation support')
+
         conf.CHECK_HEADERS('sys/signalfd.h')
         conf.CHECK_HEADERS('sys/eventfd.h')
         conf.CHECK_HEADERS('sys/timerfd.h')
diff --git a/lib/uid_wrapper/uid_wrapper.c b/lib/uid_wrapper/uid_wrapper.c
index cb99481..2181767 100644
--- a/lib/uid_wrapper/uid_wrapper.c
+++ b/lib/uid_wrapper/uid_wrapper.c
@@ -49,11 +49,12 @@
 #define DESTRUCTOR_ATTRIBUTE
 #endif /* HAVE_DESTRUCTOR_ATTRIBUTE */
 
-#ifdef NDEBUG
-#define UWRAP_DEBUG(...)
+/* GCC have printf type attribute check. */
+#ifdef HAVE_FUNCTION_ATTRIBUTE_FORMAT
+#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
 #else
-#define UWRAP_DEBUG(...) fprintf(stderr, __VA_ARGS__)
-#endif
+#define PRINTF_ATTRIBUTE(a,b)
+#endif /* HAVE_FUNCTION_ATTRIBUTE_FORMAT */
 
 #define UWRAP_DLIST_ADD(list,item) do { \
 	if (!(list)) { \
@@ -90,6 +91,70 @@
 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
 #endif
 
+/*****************
+ * LOGGING
+ *****************/
+
+enum uwrap_dbglvl_e {
+	UWRAP_LOG_ERROR = 0,
+	UWRAP_LOG_WARN,
+	UWRAP_LOG_DEBUG,
+	UWRAP_LOG_TRACE
+};
+
+#ifdef NDEBUG
+# define UWRAP_LOG(...)
+#else /* NDEBUG */
+static void uwrap_log(enum uwrap_dbglvl_e dbglvl, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
+# define UWRAP_LOG(dbglvl, ...) uwrap_log((dbglvl), __VA_ARGS__)
+
+static void uwrap_log(enum uwrap_dbglvl_e dbglvl, const char *format, ...)
+{
+	char buffer[1024];
+	va_list va;
+	const char *d;
+	unsigned int lvl = 0;
+
+	d = getenv("UID_WRAPPER_DEBUGLEVEL");
+	if (d != NULL) {
+		lvl = atoi(d);
+	}
+
+	va_start(va, format);
+	vsnprintf(buffer, sizeof(buffer), format, va);
+	va_end(va);
+
+	if (lvl >= dbglvl) {
+		switch (dbglvl) {
+			case UWRAP_LOG_ERROR:
+				fprintf(stderr,
+					"UWRAP_ERROR(%d): %s\n",
+					(int)getpid(), buffer);
+				break;
+			case UWRAP_LOG_WARN:
+				fprintf(stderr,
+					"UWRAP_WARN(%d): %s\n",
+					(int)getpid(), buffer);
+				break;
+			case UWRAP_LOG_DEBUG:
+				fprintf(stderr,
+					"UWRAP_DEBUG(%d): %s\n",
+					(int)getpid(), buffer);
+				break;
+			case UWRAP_LOG_TRACE:
+				fprintf(stderr,
+					"UWRAP_TRACE(%d): %s\n",
+					(int)getpid(), buffer);
+				break;
+		}
+	}
+}
+#endif /* NDEBUG */
+
+/*****************
+ * LIBC
+ *****************/
+
 #define LIBC_NAME "libc.so"
 
 struct uwrap_libc_fns {
@@ -194,10 +259,6 @@ static void *uwrap_load_lib_handle(enum uwrap_lib lib)
 	void *handle = NULL;
 	int i;
 
-#ifdef HAVE_APPLE
-	return RTLD_NEXT;
-#endif
-
 #ifdef RTLD_DEEPBIND
 	flags |= RTLD_DEEPBIND;
 #endif
@@ -223,10 +284,14 @@ static void *uwrap_load_lib_handle(enum uwrap_lib lib)
 	}
 
 	if (handle == NULL) {
+#ifdef RTLD_NEXT
+		handle = uwrap.libc.handle = RTLD_NEXT;
+#else
 		fprintf(stderr,
 			"Failed to dlopen library: %s\n",
 			dlerror());
 		exit(-1);
+#endif
 	}
 
 	return handle;
@@ -425,12 +490,15 @@ static int uwrap_new_id(pthread_t tid, bool do_alloc)
 	if (do_alloc) {
 		id = malloc(sizeof(struct uwrap_thread));
 		if (id == NULL) {
+			UWRAP_LOG(UWRAP_LOG_ERROR, "Unable to allocate memory");
 			errno = ENOMEM;
 			return -1;
 		}
 
 		id->groups = malloc(sizeof(gid_t) * 1);
 		if (id->groups == NULL) {
+			UWRAP_LOG(UWRAP_LOG_ERROR, "Unable to allocate memory");
+			SAFE_FREE(id);
 			errno = ENOMEM;
 			return -1;
 		}
@@ -510,6 +578,8 @@ static void uwrap_init(void)
 		return;
 	}
 
+	UWRAP_LOG(UWRAP_LOG_DEBUG, "Initialize uid_wrapper");
+
 	/*
 	 * If we hold a lock and the application forks, then the child
 	 * is not able to unlock the mutex and we are in a deadlock.
@@ -543,9 +613,15 @@ static void uwrap_init(void)
 		}
 
 		uwrap.enabled = true;
+
+		UWRAP_LOG(UWRAP_LOG_DEBUG,
+			  "Enabled uid_wrapper as %s",
+			  uwrap.myuid == 0 ? "root" : "user");
 	}
 
 	pthread_mutex_unlock(&uwrap_id_mutex);
+
+	UWRAP_LOG(UWRAP_LOG_DEBUG, "Succeccfully initialized uid_wrapper");
 }
 
 bool uid_wrapper_enabled(void)
@@ -880,7 +956,11 @@ static int uwrap_setgroups_thread(size_t size, const gid_t *list)
 
 	pthread_mutex_lock(&uwrap_id_mutex);
 
-	if (size > 0) {
+	if (size == 0) {
+		free(id->groups);
+		id->groups = NULL;
+		id->ngroups = 0;
+	} else if (size > 0) {
 		gid_t *tmp;
 
 		tmp = realloc(id->groups, sizeof(gid_t) * size);
@@ -908,7 +988,13 @@ static int uwrap_setgroups(size_t size, const gid_t *list)
 
 	pthread_mutex_lock(&uwrap_id_mutex);
 
-	if (size > 0) {
+	if (size == 0) {
+		for (id = uwrap.ids; id; id = id->next) {
+			free(id->groups);
+			id->groups = NULL;
+			id->ngroups = 0;
+		}
+	} else if (size > 0) {
 		for (id = uwrap.ids; id; id = id->next) {
 			gid_t *tmp;
 
@@ -1109,8 +1195,9 @@ static long int uwrap_syscall (long int sysno, va_list vp)
 			}
 			break;
 		default:
-			UWRAP_DEBUG("UID_WRAPPER calling non-wrapped syscall "
-				    "%lu\n", sysno);
+			UWRAP_LOG(UWRAP_LOG_DEBUG,
+				  "UID_WRAPPER calling non-wrapped syscall %lu\n",
+				  sysno);
 
 			rc = libc_vsyscall(sysno, vp);
 			break;
@@ -1161,6 +1248,7 @@ void uwrap_destructor(void)
 {
 	struct uwrap_thread *u = uwrap.ids;
 
+	pthread_mutex_lock(&uwrap_id_mutex);
 	while (u != NULL) {
 		UWRAP_DLIST_REMOVE(uwrap.ids, u);
 
@@ -1169,6 +1257,7 @@ void uwrap_destructor(void)
 
 		u = uwrap.ids;
 	}
+	pthread_mutex_unlock(&uwrap_id_mutex);
 
 	if (uwrap.libc.handle != NULL) {
 		dlclose(uwrap.libc.handle);
diff --git a/lib/uid_wrapper/wscript b/lib/uid_wrapper/wscript
index 63be473..3e73e83 100644
--- a/lib/uid_wrapper/wscript
+++ b/lib/uid_wrapper/wscript
@@ -38,6 +38,18 @@ def configure(conf):
             addmain=False,
             msg='Checking for library destructor support')
 
+        # check HAVE_FUNCTION_ATTRIBUTE_FORMAT
+        conf.CHECK_CODE('''
+            void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
+
+            int main(void) {
+                return 0;
+            }
+            ''',
+            'HAVE_FUNCTION_ATTRIBUTE_FORMAT',
+            addmain=False,
+            msg='Checking for printf format validation support')
+
         # Create full path to uid_wrapper
         srcdir = os.path.realpath(conf.srcdir)
         libuid_wrapper_so_path = srcdir + '/bin/default/lib/uid_wrapper/libuid-wrapper.so'
diff --git a/lib/util/debug.c b/lib/util/debug.c
index 77d485f..33cbed2 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -22,7 +22,7 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "system/syslog.h"
-#include "lib/util/time.h"
+#include "lib/util/time_basic.h"
 
 /* define what facility to use for syslog */
 #ifndef SYSLOG_FACILITY
@@ -142,7 +142,7 @@ int     *DEBUGLEVEL_CLASS = discard_const_p(int, debug_class_list_initial);
 
 static int     debug_count    = 0;
 static int     current_msg_level   = 0;
-static char *format_bufr = NULL;
+static char format_bufr[FORMAT_BUFR_SIZE];
 static size_t     format_pos     = 0;
 static bool    log_overflow   = false;
 
@@ -200,8 +200,6 @@ void gfree_debugsyms(void)
 		DEBUGLEVEL_CLASS = discard_const_p(int, debug_class_list_initial);
 	}
 
-	TALLOC_FREE(format_bufr);
-
 	debug_num_classes = 0;
 
 	state.initialized = false;
@@ -217,7 +215,7 @@ char *debug_list_class_names_and_levels(void)
 	unsigned int i;
 	/* prepare strings */
 	for (i = 0; i < debug_num_classes; i++) {
-		buf = talloc_asprintf_append(buf, 
+		buf = talloc_asprintf_append(buf,
 					     "%s:%d%s",
 					     classname_table[i],
 					     DEBUGLEVEL_CLASS[i],
@@ -336,49 +334,30 @@ static void debug_dump_status(int level)
 	}
 }
 
-/****************************************************************************
- parse the debug levels from smbcontrol. Example debug level parameter:
- printdrivers:7
-****************************************************************************/
-
-static bool debug_parse_params(char **params)
+static bool debug_parse_param(char *param)
 {
-	int   i, ndx;
 	char *class_name;
 	char *class_level;
+	char *saveptr;
+	int ndx;
 
-	if (!params)
+	class_name = strtok_r(param, ":", &saveptr);
+	if (class_name == NULL) {
 		return false;
-
-	/* Allow DBGC_ALL to be specified w/o requiring its class name e.g."10"
-	 * v.s. "all:10", this is the traditional way to set DEBUGLEVEL
-	 */
-	if (isdigit((int)params[0][0])) {
-		DEBUGLEVEL_CLASS[DBGC_ALL] = atoi(params[0]);
-		i = 1; /* start processing at the next params */
-	} else {
-		DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
-		i = 0; /* DBGC_ALL not specified OR class name was included */
 	}
 
-	/* Array is debug_num_classes long */
-	for (ndx = DBGC_ALL; ndx < debug_num_classes; ndx++) {
-		DEBUGLEVEL_CLASS[ndx] = DEBUGLEVEL_CLASS[DBGC_ALL];
+	class_level = strtok_r(NULL, "\0", &saveptr);
+	if (class_level == NULL) {
+		return false;
 	}
-		
-	/* Fill in new debug class levels */
-	for (; i < debug_num_classes && params[i]; i++) {
-		char *saveptr;
-		if ((class_name = strtok_r(params[i],":", &saveptr)) &&
-			(class_level = strtok_r(NULL, "\0", &saveptr)) &&
-            ((ndx = debug_lookup_classname(class_name)) != -1)) {
-				DEBUGLEVEL_CLASS[ndx] = atoi(class_level);
-		} else {
-			DEBUG(0,("debug_parse_params: unrecognized debug class name or format [%s]\n", params[i]));
-			return false;
-		}
+
+	ndx = debug_lookup_classname(class_name);
+	if (ndx == -1) {
+		return false;
 	}
 
+	DEBUGLEVEL_CLASS[ndx] = atoi(class_level);
+
 	return true;
 }
 
@@ -390,21 +369,52 @@ static bool debug_parse_params(char **params)
 
 bool debug_parse_levels(const char *params_str)
 {
-	char **params;
+	size_t str_len = strlen(params_str);
+	char str[str_len+1];
+	char *tok, *saveptr;
+	int i;
 
 	/* Just in case */
 	debug_init();
 
-	params = str_list_make(NULL, params_str, NULL);
+	memcpy(str, params_str, str_len+1);
 
-	if (debug_parse_params(params)) {
-		debug_dump_status(5);
-		TALLOC_FREE(params);
+	tok = strtok_r(str, LIST_SEP, &saveptr);
+	if (tok == NULL) {
 		return true;
+	}
+
+	/* Allow DBGC_ALL to be specified w/o requiring its class name e.g."10"
+	 * v.s. "all:10", this is the traditional way to set DEBUGLEVEL
+	 */
+	if (isdigit(tok[0])) {
+		DEBUGLEVEL_CLASS[DBGC_ALL] = atoi(tok);
+		tok = strtok_r(NULL, LIST_SEP, &saveptr);
 	} else {
-		TALLOC_FREE(params);
-		return false;
+		DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
 	}
+
+	/* Array is debug_num_classes long */
+	for (i = DBGC_ALL+1; i < debug_num_classes; i++) {
+		DEBUGLEVEL_CLASS[i] = DEBUGLEVEL_CLASS[DBGC_ALL];
+	}
+
+	while (tok != NULL) {
+		bool ok;
+
+		ok = debug_parse_param(tok);
+		if (!ok) {
+			DEBUG(0,("debug_parse_params: unrecognized debug "
+				 "class name or format [%s]\n", tok));
+			return false;
+		}
+
+		tok = strtok_r(NULL, LIST_SEP, &saveptr);
+	}
+
+	debug_dump_status(5);
+
+	return true;
 }
 
 /* setup for logging of talloc warnings */
@@ -437,10 +447,6 @@ static void debug_init(void)
 	for(p = default_classname_table; *p; p++) {
 		debug_add_class(*p);
 	}
-	format_bufr = talloc_array(NULL, char, FORMAT_BUFR_SIZE);
-	if (!format_bufr) {
-		smb_panic("debug_init: unable to create buffer");
-	}
 }
 
 /* This forces in some smb.conf derived values into the debug system.
@@ -474,7 +480,7 @@ void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
 
 	if (state.logtype == DEBUG_FILE) {
 #ifdef WITH_SYSLOG
-		const char *p = strrchr_m( prog_name,'/' );
+		const char *p = strrchr(prog_name, '/');
 		if (p)
 			prog_name = p + 1;
 #ifdef LOG_DAEMON
@@ -609,7 +615,7 @@ bool reopen_logs_internal(void)
 		if (dup2(state.fd, 2) == -1) {
 			/* Close stderr too, if dup2 can't point it -
 			   at the logfile.  There really isn't much
-			   that can be done on such a fundemental
+			   that can be done on such a fundamental
 			   failure... */
 			close_low_fds(false, false, true);
 		}
@@ -697,12 +703,12 @@ void check_log_size( void )
 		if (state.fd > 2 && (fstat(state.fd, &st) == 0
 				     && st.st_size > maxlog)) {
 			char *name = NULL;
-			
+
 			if (asprintf(&name, "%s.old", state.debugf ) < 0) {
 				return;
 			}
 			(void)rename(state.debugf, name);
-			
+
 			if (!reopen_logs_internal()) {
 				/* We failed to reopen a log - continue using the old name. */
 				(void)rename(name, state.debugf);
@@ -743,35 +749,30 @@ void check_log_size( void )
  This is called by dbghdr() and format_debug_text().
 ************************************************************************/
 
- int Debug1( const char *format_str, ... )
+static int Debug1(const char *msg)
 {


-- 
Samba Shared Repository


More information about the samba-cvs mailing list