[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Wed Nov 24 01:22:01 MST 2010


The branch, master has been updated
       via  6ead7fb s3-libnetapi Load case tables earlier
       via  11b060d s3-libnetapi Add function header comments
       via  88d020a s3-netapi Add libnetapi_net_init(), don't double-init common Samba subsystems
       via  58920aa lib/debug Add clarifying comments
      from  ef46298 wintest Don't connect to localhost or unqualified hostname, bind interface only

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


- Log -----------------------------------------------------------------
commit 6ead7fbae534b7cc25310d8ea2875fc2e737a2b7
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Nov 24 18:04:02 2010 +1100

    s3-libnetapi Load case tables earlier
    
    If we don't load the case tables as the 'first' thing we do, we will
    segfault on the first case insensitive string comparison.
    
    Andrew Bartlett
    
    Autobuild-User: Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date: Wed Nov 24 09:21:05 CET 2010 on sn-devel-104

commit 11b060d345a0fa8613d2f98b4e7199dbce0e1251
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Nov 24 17:59:41 2010 +1100

    s3-libnetapi Add function header comments
    
    Andrew Bartlett

commit 88d020ade07bfe5cd7570b8c9b80a162adb39891
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Sun Nov 21 20:40:50 2010 +1100

    s3-netapi Add libnetapi_net_init(), don't double-init common Samba subsystems
    
    The issue here is that libnet and net were both trying to load the
    smb.conf files, the case tables and set the debug levels.  The set of
    the debug levels caused problems, because it would force the level to
    0, not (say) 10 as requested on the command line.
    
    This regression was apparently introduced in
    cf4de8ec2c8df2ceabbe3d836d296b058e7b19fb when eliminating
    AllowDebugChange.
    
    Andrew Bartlett

commit 58920aab0237aaa9f4a81577800bddba97e279a5
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Nov 3 07:09:45 2010 +1100

    lib/debug Add clarifying comments

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

Summary of changes:
 lib/util/debug.c                                   |    4 +-
 source3/lib/netapi/netapi.c                        |   52 +++++++++++++++-----
 .../lib/{version_test.c => netapi/netapi_net.h}    |   14 ++---
 source3/lib/netapi/netapi_private.h                |    2 +
 source3/utils/net_dom.c                            |    3 +-
 source3/utils/net_rpc.c                            |   11 ++--
 source3/utils/net_rpc_shell.c                      |    3 +-
 7 files changed, 59 insertions(+), 30 deletions(-)
 copy source3/lib/{version_test.c => netapi/netapi_net.h} (69%)


Changeset truncated at 500 lines:

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 789abe1..845240f 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -46,8 +46,8 @@ static struct {
 
 /* state variables for the debug system */
 static struct {
-	int fd;
-	enum debug_logtype logtype;
+	int fd;   /* The log file handle */
+	enum debug_logtype logtype; /* The type of logging we are doing: eg stdout, file, stderr */
 	const char *prog_name;
 	bool reopening_logs;
 } state;
diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c
index 7b3ab32..9d76017 100644
--- a/source3/lib/netapi/netapi.c
+++ b/source3/lib/netapi/netapi.c
@@ -49,14 +49,14 @@ static NET_API_STATUS libnetapi_init_private_context(struct libnetapi_ctx *ctx)
 }
 
 /****************************************************************
+Create a libnetapi context, for use in non-Samba applications.  This
+loads the smb.conf file and sets the debug level to 0, so that
+applications are not flooded with debug logs at level 10, when they
+were not expecting it.
 ****************************************************************/
 
 NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
 {
-	NET_API_STATUS status;
-	struct libnetapi_ctx *ctx = NULL;
-	char *krb5_cc_env = NULL;
-
 	if (stat_ctx && libnetapi_initialized) {
 		*context = stat_ctx;
 		return NET_API_STATUS_SUCCESS;
@@ -67,19 +67,15 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
 #endif
 	frame = talloc_stackframe();
 
-	ctx = talloc_zero(frame, struct libnetapi_ctx);
-	if (!ctx) {
-		TALLOC_FREE(frame);
-		return W_ERROR_V(WERR_NOMEM);
-	}
+	/* Case tables must be loaded before any string comparisons occour */
+	load_case_tables();
 
+	/* When libnetapi is invoked from an application, it does not
+	 * want to be swamped with level 10 debug messages, even if
+	 * this has been set for the server in smb.conf */
 	lp_set_cmdline("log level", "0");
-
-	/* prevent setup_logging() from closing x_stderr... */
 	setup_logging("libnetapi", DEBUG_STDERR);
 
-	load_case_tables();
-
 	if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) {
 		TALLOC_FREE(frame);
 		fprintf(stderr, "error loading %s\n", get_dyn_CONFIGFILE() );
@@ -92,6 +88,33 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
 
 	BlockSignals(True, SIGPIPE);
 
+	return libnetapi_net_init(context);
+}
+
+/****************************************************************
+Create a libnetapi context, for use inside the 'net' binary.
+
+As we know net has already loaded the smb.conf file, and set the debug
+level etc, this avoids doing so again (which causes trouble with -d on
+the command line).
+****************************************************************/
+
+NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context)
+{
+	NET_API_STATUS status;
+	struct libnetapi_ctx *ctx = NULL;
+	char *krb5_cc_env = NULL;
+
+	frame = talloc_stackframe();
+
+	ctx = talloc_zero(frame, struct libnetapi_ctx);
+	if (!ctx) {
+		TALLOC_FREE(frame);
+		return W_ERROR_V(WERR_NOMEM);
+	}
+
+	BlockSignals(True, SIGPIPE);
+
 	krb5_cc_env = getenv(KRB5_ENV_CCNAME);
 	if (!krb5_cc_env || (strlen(krb5_cc_env) == 0)) {
 		ctx->krb5_cc_env = talloc_strdup(frame, "MEMORY:libnetapi");
@@ -123,6 +146,7 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
 }
 
 /****************************************************************
+ Return the static libnetapi context
 ****************************************************************/
 
 NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx)
@@ -136,6 +160,7 @@ NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx)
 }
 
 /****************************************************************
+ Free the static libnetapi context
 ****************************************************************/
 
 NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx)
@@ -172,6 +197,7 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx)
 }
 
 /****************************************************************
+ Override the current log level for libnetapi
 ****************************************************************/
 
 NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx,
diff --git a/source3/lib/version_test.c b/source3/lib/netapi/netapi_net.h
similarity index 69%
copy from source3/lib/version_test.c
copy to source3/lib/netapi/netapi_net.h
index 880cfeb..c1b06ad 100644
--- a/source3/lib/version_test.c
+++ b/source3/lib/netapi/netapi_net.h
@@ -1,7 +1,7 @@
 /*
  *  Unix SMB/CIFS implementation.
- *  version_test - test program for samba_version_strion()
- *  Copyright (C) Michael Adam 2009
+ *  NetApi Support
+ *  Copyright (C) Andrew Bartlett 2010
  *
  *  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
@@ -17,10 +17,8 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "includes.h"
+/* This API header is private between the 'net' binary and and libnet */
 
-int main(void)
-{
-	printf("%s\n", samba_version_string());
-	return 0;
-}
+/* This function is to init the libnetapi subsystem, without
+ * re-reading config files or setting debug levels etc */
+NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **ctx);
diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h
index 859c064..fe8d72e 100644
--- a/source3/lib/netapi/netapi_private.h
+++ b/source3/lib/netapi/netapi_private.h
@@ -20,6 +20,8 @@
 #ifndef __LIB_NETAPI_PRIVATE_H__
 #define __LIB_NETAPI_PRIVATE_H__
 
+#include "lib/netapi/netapi_net.h"
+
 #define LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, fn) \
 	DEBUG(10,("redirecting call %s to localhost\n", #fn)); \
 	if (!r->in.server_name) { \
diff --git a/source3/utils/net_dom.c b/source3/utils/net_dom.c
index d07a1d4..d1eb9ed 100644
--- a/source3/utils/net_dom.c
+++ b/source3/utils/net_dom.c
@@ -22,6 +22,7 @@
 #include "../librpc/gen_ndr/cli_initshutdown.h"
 #include "../librpc/gen_ndr/ndr_winreg.h"
 #include "lib/netapi/netapi.h"
+#include "lib/netapi/netapi_net.h"
 
 int net_dom_usage(struct net_context *c, int argc, const char **argv)
 {
@@ -372,7 +373,7 @@ int net_dom(struct net_context *c, int argc, const char **argv)
 		{NULL, NULL, 0, NULL, NULL}
 	};
 
-	status = libnetapi_init(&c->netapi_ctx);
+	status = libnetapi_net_init(&c->netapi_ctx);
 	if (status != 0) {
 		return -1;
 	}
diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c
index 1b0e469..228f7eb 100644
--- a/source3/utils/net_rpc.c
+++ b/source3/utils/net_rpc.c
@@ -35,6 +35,7 @@
 #include "../librpc/gen_ndr/cli_winreg.h"
 #include "secrets.h"
 #include "lib/netapi/netapi.h"
+#include "lib/netapi/netapi_net.h"
 #include "rpc_client/init_lsa.h"
 #include "../libcli/security/security.h"
 
@@ -1050,7 +1051,7 @@ int net_rpc_user(struct net_context *c, int argc, const char **argv)
 		{NULL, NULL, 0, NULL, NULL}
 	};
 
-	status = libnetapi_init(&c->netapi_ctx);
+	status = libnetapi_net_init(&c->netapi_ctx);
 	if (status != 0) {
 		return -1;
 	}
@@ -2899,7 +2900,7 @@ int net_rpc_group(struct net_context *c, int argc, const char **argv)
 		{NULL, NULL, 0, NULL, NULL}
 	};
 
-	status = libnetapi_init(&c->netapi_ctx);
+	status = libnetapi_net_init(&c->netapi_ctx);
 	if (status != 0) {
 		return -1;
 	}
@@ -4745,7 +4746,7 @@ int net_rpc_share(struct net_context *c, int argc, const char **argv)
 		{NULL, NULL, 0, NULL, NULL}
 	};
 
-	status = libnetapi_init(&c->netapi_ctx);
+	status = libnetapi_net_init(&c->netapi_ctx);
 	if (status != 0) {
 		return -1;
 	}
@@ -5021,7 +5022,7 @@ int net_rpc_file(struct net_context *c, int argc, const char **argv)
 		{NULL, NULL, 0, NULL, NULL}
 	};
 
-	status = libnetapi_init(&c->netapi_ctx);
+	status = libnetapi_net_init(&c->netapi_ctx);
 	if (status != 0) {
 		return -1;
 	}
@@ -7428,7 +7429,7 @@ int net_rpc(struct net_context *c, int argc, const char **argv)
 		{NULL, NULL, 0, NULL, NULL}
 	};
 
-	status = libnetapi_init(&c->netapi_ctx);
+	status = libnetapi_net_init(&c->netapi_ctx);
 	if (status != 0) {
 		return -1;
 	}
diff --git a/source3/utils/net_rpc_shell.c b/source3/utils/net_rpc_shell.c
index 82f9f29..c238425 100644
--- a/source3/utils/net_rpc_shell.c
+++ b/source3/utils/net_rpc_shell.c
@@ -23,6 +23,7 @@
 #include "utils/net.h"
 #include "../librpc/gen_ndr/ndr_samr.h"
 #include "lib/netapi/netapi.h"
+#include "lib/netapi/netapi_net.h"
 #include "../libcli/smbreadline/smbreadline.h"
 
 static NTSTATUS rpc_sh_info(struct net_context *c,
@@ -222,7 +223,7 @@ int net_rpc_shell(struct net_context *c, int argc, const char **argv)
 		return -1;
 	}
 
-	if (libnetapi_init(&c->netapi_ctx) != 0) {
+	if (libnetapi_net_init(&c->netapi_ctx) != 0) {
 		return -1;
 	}
 	libnetapi_set_username(c->netapi_ctx, c->opt_user_name);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list