[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Thu Dec 20 06:19:05 UTC 2018


The branch, master has been updated
       via  1b263ed631c s3-vfs-streams_xattr: add close call
       via  5c928d7cd1d lib/audit_logging: actually create talloc
       via  35349fecbd0 docs-xml: document "log level" changes
       via  08d37b4a44b debug: enable per debug-class logfiles
       via  3dbda63284c debug: remove fd and debugf from state, use dbgc_config[DBGC_ALL]
       via  781f5a95edd debug: update logsize checking for per debug-class logfiles
       via  d792f15ff14 debug: update need_to_check_log_size() for per debug-class logfiles
       via  249bdd93783 debug: add support for per debug-class logfiles
       via  abfb3c6bbf5 debug: add resource cleanup for per debug-class logfiles
       via  43c693511d9 debug: add logfile and fd to struct debug_class
       via  7369674787d debug: factor out logfile size check
       via  4341f24069f debug: add a call to debug_parse_levels() to reopen_logs()
       via  2bc7e254a62 debug: add an empty line
       via  240b08c414c debug: factor out a function that opens and closes the new and old logfile
       via  e6655f08873 debug: track current debug message class
       via  63f330761e7 debug: convert dbgc_config to an array of struct debug_class
       via  d346cf94a44 debug: README.Coding fixes
       via  3b293c66902 debug: rename DEBUGLEVEL_CLASS variable to dbgc_config
       via  7a2562fd2b4 debug: move some definitions around
      from  357fe04bd47 s4: Add kerberos tracing

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


- Log -----------------------------------------------------------------
commit 1b263ed631c86bf4117c9388fce3fa1f24cea4c9
Author: Günther Deschner <gd at samba.org>
Date:   Tue Dec 18 17:20:29 2018 +0100

    s3-vfs-streams_xattr: add close call
    
    https://bugzilla.samba.org/show_bug.cgi?id=13725
    
    We cannot always rely on vfs_default to close the fake fds. This mostly is
    relevant when used with another non-local VFS filesystem module such as
    gluster.
    
    Guenther
    
    Signed-off-by: Günther Deschner <gd at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Thu Dec 20 07:18:20 CET 2018 on sn-devel-144

commit 5c928d7cd1d0ac994fe95892eec235b939ad2ec9
Author: Philipp Gesang <philipp.gesang at intra2net.com>
Date:   Tue Dec 18 16:09:19 2018 +0100

    lib/audit_logging: actually create talloc
    
    Heal damage of 79f494e51e..
    
    That context is being passed around and freed but is never
    actually allocated on that stack.
    
    Signed-off-by: Philipp Gesang <philipp.gesang at intra2net.com>
    Reviewed-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 35349fecbd075a5e5dd4c87be465d61c5104fb21
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 21:04:42 2018 +0100

    docs-xml: document "log level" changes
    
    "log level" now takes an optional per debug-class logfile:
    
      log level = 1 full_audit:1@/var/log/audit.log winbind:2
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 08d37b4a44bc7daed3c1c5774a3d7e796de582ef
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 22:46:49 2018 +0100

    debug: enable per debug-class logfiles
    
    This finally enables per debug-class logfiles by hooking into
    reopen_logs_internal() calls to reopen_one_log() per configured
    debug-class.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3dbda63284cdeb2f060931c85388842627c955a1
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 22:49:15 2018 +0100

    debug: remove fd and debugf from state, use dbgc_config[DBGC_ALL]
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 781f5a95edde4cd27627515869bfe2fc626fbb3a
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 14:43:22 2018 +0100

    debug: update logsize checking for per debug-class logfiles
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d792f15ff1406cde7f38ddc5febb08a8b39b90e8
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 14:54:41 2018 +0100

    debug: update need_to_check_log_size() for per debug-class logfiles
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 249bdd9378306c146dca0eec6711e2c6b8eae29a
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 13:11:26 2018 +0100

    debug: add support for per debug-class logfiles
    
    This adds support for per debug-class logfiles to the function parsing
    the "log level" option.
    
    The enhanced syntax is:
    
      log level = CLASS:LEVEL[@PATH] [CLASS:LEVEL[@PATH] ... ]
    
    Eg
    
      log level = full_audit:1@/var/log/audit.logfile
    
    While the option is already parsed and stored in in the dbgc_config[]
    array, the feature is still effectively disabled, as
    reopen_logs_internal() still doesn't open the per debug-class logfiles.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit abfb3c6bbf5d3d27ca61cd973ffb15c3d8e2be4f
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 13:09:03 2018 +0100

    debug: add resource cleanup for per debug-class logfiles
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 43c693511d971210107535644b975a465b012373
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 12:51:16 2018 +0100

    debug: add logfile and fd to struct debug_class
    
    Initialized to -1. Already checked in debug_file_log() without affecting
    behaviour until subsequent commits set per-debug-class fds.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 7369674787d91c40f8eff7bc71f6d73dab341315
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 12:45:11 2018 +0100

    debug: factor out logfile size check
    
    The new function will also be used for upcoming per-debug-class logfiles.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 4341f24069f991dc7119093e418aac392e0a1b50
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 12:43:47 2018 +0100

    debug: add a call to debug_parse_levels() to reopen_logs()
    
    This allows correct refresh of the "log level" setting when reloading config.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2bc7e254a62cfc6a60ecff425fc71173c6d21a10
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 08:48:35 2018 +0100

    debug: add an empty line
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 240b08c414c375c16ad0b1524202f1337b7e9e6d
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 12:35:42 2018 +0100

    debug: factor out a function that opens and closes the new and old logfile
    
    The new function reopen_one_log() will also be used for per-class
    logfiles in subsequent commmits.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e6655f0887313a9ad99406a89a66c6950ba970bb
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 22:22:44 2018 +0100

    debug: track current debug message class
    
    This is analog to current_msg_level.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 63f330761e7bebf9ee9200a9e1302c373519d226
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 22:21:57 2018 +0100

    debug: convert dbgc_config to an array of struct debug_class
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d346cf94a44a7a4fd45b33d9369dbbc404e0ebb0
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 11:57:05 2018 +0100

    debug: README.Coding fixes
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3b293c669024e55d2c5343e85f1f43a03682b478
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 22:19:06 2018 +0100

    debug: rename DEBUGLEVEL_CLASS variable to dbgc_config
    
    Variable names should not be given in uppercase.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 7a2562fd2b426ec25131f5fd83d4f835ad604847
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Dec 12 08:57:28 2018 +0100

    debug: move some definitions around
    
    They will be needed by some function in a subsequent commit.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 docs-xml/smbdotconf/logging/loglevel.xml |  11 +-
 lib/audit_logging/audit_logging.c        |   6 +
 lib/util/debug.c                         | 417 +++++++++++++++++++++----------
 lib/util/debug_s3.c                      |   2 +
 source3/modules/vfs_streams_xattr.c      |  26 ++
 5 files changed, 324 insertions(+), 138 deletions(-)


Changeset truncated at 500 lines:

diff --git a/docs-xml/smbdotconf/logging/loglevel.xml b/docs-xml/smbdotconf/logging/loglevel.xml
index 42912720655..1bc4146dac9 100644
--- a/docs-xml/smbdotconf/logging/loglevel.xml
+++ b/docs-xml/smbdotconf/logging/loglevel.xml
@@ -12,8 +12,9 @@
 
     <para>This parameter has been extended since the 2.2.x 
     series, now it allows one to specify the debug level for multiple 
-    debug classes. This is to give greater flexibility in the configuration 
-    of the system. The following debug classes are currently implemented:
+    debug classes and distinct logfiles for debug classes. This is to give
+    greater flexibility in the configuration of the system. The following
+    debug classes are currently implemented:
     </para>
 
     <itemizedlist>
@@ -54,6 +55,11 @@
         <listitem><para><parameter moreinfo="none">dsdb_transaction_json_audit</parameter></para></listitem>
     </itemizedlist>
 
+    <para>To configure the logging for specific classes to go into a different
+    file then <smbconfoption name="log file"/>, you can append
+    <emphasis>@PATH</emphasis> to the class, eg <parameter>log level = 1
+    full_audit:1@/var/log/audit.log</parameter>.</para>
+
     <para>Authentication and authorization audit information is logged
     under the auth_audit, and if Samba was not compiled with
     --without-json, a JSON representation is logged under
@@ -91,4 +97,5 @@
 </description>
 <value type="default">0</value>
 <value type="example">3 passdb:5 auth:10 winbind:2</value>
+<value type="example">1 full_audit:1@/var/log/audit.log winbind:2</value>
 </samba:parameter>
diff --git a/lib/audit_logging/audit_logging.c b/lib/audit_logging/audit_logging.c
index 42b93137c07..6944da7f872 100644
--- a/lib/audit_logging/audit_logging.c
+++ b/lib/audit_logging/audit_logging.c
@@ -245,6 +245,12 @@ void audit_message_send(
 		return;
 	}
 
+	ctx = talloc_new(NULL);
+	if (ctx == NULL) {
+		DBG_ERR("Out of memory creating temporary context\n");
+		return;
+	}
+
 	/* Need to refetch the address each time as the destination server may
 	 * have disconnected and reconnected in the interim, in which case
 	 * messages may get lost
diff --git a/lib/util/debug.c b/lib/util/debug.c
index b5f120bb3a4..30e5a28a233 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -86,23 +86,89 @@
 /* state variables for the debug system */
 static struct {
 	bool initialized;
-	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;
 	bool schedule_reopen_logs;
 
 	struct debug_settings settings;
-	char *debugf;
 	debug_callback_fn callback;
 	void *callback_private;
 } state = {
 	.settings = {
 		.timestamp_logs = true
 	},
-	.fd = 2 /* stderr by default */
 };
 
+struct debug_class {
+	/*
+	 * The debug loglevel of the class.
+	 */
+	int loglevel;
+
+	/*
+	 * An optional class specific logfile, may be NULL in which case the
+	 * "global" logfile is used and fd is -1.
+	 */
+	char *logfile;
+	int fd;
+};
+
+static const char *default_classname_table[] = {
+	[DBGC_ALL] =			"all",
+	[DBGC_TDB] =			"tdb",
+	[DBGC_PRINTDRIVERS] =		"printdrivers",
+	[DBGC_LANMAN] =			"lanman",
+	[DBGC_SMB] =			"smb",
+	[DBGC_RPC_PARSE] =		"rpc_parse",
+	[DBGC_RPC_SRV] =		"rpc_srv",
+	[DBGC_RPC_CLI] =		"rpc_cli",
+	[DBGC_PASSDB] =			"passdb",
+	[DBGC_SAM] =			"sam",
+	[DBGC_AUTH] =			"auth",
+	[DBGC_WINBIND] =		"winbind",
+	[DBGC_VFS] =			"vfs",
+	[DBGC_IDMAP] =			"idmap",
+	[DBGC_QUOTA] =			"quota",
+	[DBGC_ACLS] =			"acls",
+	[DBGC_LOCKING] =		"locking",
+	[DBGC_MSDFS] =			"msdfs",
+	[DBGC_DMAPI] =			"dmapi",
+	[DBGC_REGISTRY] =		"registry",
+	[DBGC_SCAVENGER] =		"scavenger",
+	[DBGC_DNS] =			"dns",
+	[DBGC_LDB] =			"ldb",
+	[DBGC_TEVENT] =			"tevent",
+	[DBGC_AUTH_AUDIT] =		"auth_audit",
+	[DBGC_AUTH_AUDIT_JSON] =	"auth_json_audit",
+	[DBGC_KERBEROS] =       	"kerberos",
+	[DBGC_DRS_REPL] =       	"drs_repl",
+	[DBGC_SMB2] =           	"smb2",
+	[DBGC_SMB2_CREDITS] =   	"smb2_credits",
+	[DBGC_DSDB_AUDIT] =		"dsdb_audit",
+	[DBGC_DSDB_AUDIT_JSON] =	"dsdb_json_audit",
+	[DBGC_DSDB_PWD_AUDIT]  =	"dsdb_password_audit",
+	[DBGC_DSDB_PWD_AUDIT_JSON] =	"dsdb_password_json_audit",
+	[DBGC_DSDB_TXN_AUDIT]  =	"dsdb_transaction_audit",
+	[DBGC_DSDB_TXN_AUDIT_JSON] =	"dsdb_transaction_json_audit",
+	[DBGC_DSDB_GROUP_AUDIT] =	"dsdb_group_audit",
+	[DBGC_DSDB_GROUP_AUDIT_JSON] =	"dsdb_group_json_audit",
+};
+
+/*
+ * This is to allow reading of dbgc_config before the debug
+ * system has been initialized.
+ */
+static struct debug_class debug_class_list_initial[ARRAY_SIZE(default_classname_table)] = {
+	[DBGC_ALL] = (struct debug_class) { .fd = 2 },
+};
+
+static size_t debug_num_classes = 0;
+static struct debug_class *dbgc_config = debug_class_list_initial;
+
+static int current_msg_level = 0;
+static int current_msg_class = 0;
+
 #if defined(WITH_SYSLOG) || defined(HAVE_LIBSYSTEMD_JOURNAL) || defined(HAVE_LIBSYSTEMD)
 static int debug_level_to_priority(int level)
 {
@@ -141,10 +207,18 @@ static void debug_file_log(int msg_level,
 			   const char *msg, const char *msg_no_nl)
 {
 	ssize_t ret;
+	int fd;
 
 	check_log_size();
+
+	if (dbgc_config[current_msg_class].fd != -1) {
+		fd = dbgc_config[current_msg_class].fd;
+	} else {
+		fd = dbgc_config[DBGC_ALL].fd;
+	}
+
 	do {
-		ret = write(state.fd, msg, strlen(msg));
+		ret = write(fd, msg, strlen(msg));
 	} while (ret == -1 && errno == EINTR);
 }
 
@@ -512,64 +586,14 @@ static void debug_backends_log(const char *msg, int msg_level)
 */
 bool    override_logfile;
 
-static const char *default_classname_table[] = {
-	[DBGC_ALL] =		"all",
-	[DBGC_TDB] =		"tdb",
-	[DBGC_PRINTDRIVERS] =	"printdrivers",
-	[DBGC_LANMAN] =		"lanman",
-	[DBGC_SMB] =		"smb",
-	[DBGC_RPC_PARSE] =	"rpc_parse",
-	[DBGC_RPC_SRV] =	"rpc_srv",
-	[DBGC_RPC_CLI] =	"rpc_cli",
-	[DBGC_PASSDB] =		"passdb",
-	[DBGC_SAM] =		"sam",
-	[DBGC_AUTH] =		"auth",
-	[DBGC_WINBIND] =	"winbind",
-	[DBGC_VFS] =		"vfs",
-	[DBGC_IDMAP] =		"idmap",
-	[DBGC_QUOTA] =		"quota",
-	[DBGC_ACLS] =		"acls",
-	[DBGC_LOCKING] =	"locking",
-	[DBGC_MSDFS] =		"msdfs",
-	[DBGC_DMAPI] =		"dmapi",
-	[DBGC_REGISTRY] =	"registry",
-	[DBGC_SCAVENGER] =	"scavenger",
-	[DBGC_DNS] =		"dns",
-	[DBGC_LDB] =		"ldb",
-	[DBGC_TEVENT] =		"tevent",
-	[DBGC_AUTH_AUDIT] =	"auth_audit",
-	[DBGC_AUTH_AUDIT_JSON] = "auth_json_audit",
-	[DBGC_KERBEROS] =       "kerberos",
-	[DBGC_DRS_REPL] =       "drs_repl",
-	[DBGC_SMB2] =           "smb2",
-	[DBGC_SMB2_CREDITS] =   "smb2_credits",
-	[DBGC_DSDB_AUDIT]  =	"dsdb_audit",
-	[DBGC_DSDB_AUDIT_JSON] = "dsdb_json_audit",
-	[DBGC_DSDB_PWD_AUDIT]  =	"dsdb_password_audit",
-	[DBGC_DSDB_PWD_AUDIT_JSON] = "dsdb_password_json_audit",
-	[DBGC_DSDB_TXN_AUDIT]  =	"dsdb_transaction_audit",
-	[DBGC_DSDB_TXN_AUDIT_JSON] = "dsdb_transaction_json_audit",
-	[DBGC_DSDB_GROUP_AUDIT] =	"dsdb_group_audit",
-	[DBGC_DSDB_GROUP_AUDIT_JSON] = "dsdb_group_json_audit",
-};
-
-/*
- * This is to allow reading of DEBUGLEVEL_CLASS before the debug
- * system has been initialized.
- */
-static int debug_class_list_initial[ARRAY_SIZE(default_classname_table)];
-
-static size_t debug_num_classes = 0;
-static int    *DEBUGLEVEL_CLASS = debug_class_list_initial;
-
 int debuglevel_get_class(size_t idx)
 {
-	return DEBUGLEVEL_CLASS[idx];
+	return dbgc_config[idx].loglevel;
 }
 
 void debuglevel_set_class(size_t idx, int level)
 {
-	DEBUGLEVEL_CLASS[idx] = level;
+	dbgc_config[idx].loglevel = level;
 }
 
 
@@ -597,7 +621,6 @@ void debuglevel_set_class(size_t idx, int level)
  */
 
 static int     debug_count    = 0;
-static int     current_msg_level   = 0;
 static char format_bufr[FORMAT_BUFR_SIZE];
 static size_t     format_pos     = 0;
 static bool    log_overflow   = false;
@@ -627,9 +650,10 @@ void gfree_debugsyms(void)
 
 	TALLOC_FREE(classname_table);
 
-	if ( DEBUGLEVEL_CLASS != debug_class_list_initial ) {
-		TALLOC_FREE( DEBUGLEVEL_CLASS );
-		DEBUGLEVEL_CLASS = discard_const_p(int, debug_class_list_initial);
+	if ( dbgc_config != debug_class_list_initial ) {
+		TALLOC_FREE( dbgc_config );
+		dbgc_config = discard_const_p(struct debug_class,
+						   debug_class_list_initial);
 	}
 
 	debug_num_classes = 0;
@@ -654,7 +678,7 @@ char *debug_list_class_names_and_levels(void)
 		buf = talloc_asprintf_append(buf,
 					     "%s:%d%s",
 					     classname_table[i],
-					     DEBUGLEVEL_CLASS[i],
+					     dbgc_config[i].loglevel,
 					     i == (debug_num_classes - 1) ? "\n" : " ");
 		if (buf == NULL) {
 			return NULL;
@@ -687,45 +711,57 @@ static int debug_lookup_classname_int(const char* classname)
 int debug_add_class(const char *classname)
 {
 	int ndx;
-	int *new_class_list;
+	struct debug_class *new_class_list = NULL;
 	char **new_name_list;
 	int default_level;
 
-	if (!classname)
+	if (classname == NULL) {
 		return -1;
+	}
 
 	/* check the init has yet been called */
 	debug_init();
 
 	ndx = debug_lookup_classname_int(classname);
-	if (ndx >= 0)
+	if (ndx >= 0) {
 		return ndx;
+	}
 	ndx = debug_num_classes;
 
-	if (DEBUGLEVEL_CLASS == debug_class_list_initial) {
+	if (dbgc_config == debug_class_list_initial) {
 		/* Initial loading... */
 		new_class_list = NULL;
 	} else {
-		new_class_list = DEBUGLEVEL_CLASS;
+		new_class_list = dbgc_config;
 	}
 
-	default_level = DEBUGLEVEL_CLASS[DBGC_ALL];
+	default_level = dbgc_config[DBGC_ALL].loglevel;
 
-	new_class_list = talloc_realloc(NULL, new_class_list, int, ndx + 1);
-	if (!new_class_list)
+	new_class_list = talloc_realloc(NULL,
+					new_class_list,
+					struct debug_class,
+					ndx + 1);
+	if (new_class_list == NULL) {
 		return -1;
-	DEBUGLEVEL_CLASS = new_class_list;
+	}
+
+	dbgc_config = new_class_list;
 
-	DEBUGLEVEL_CLASS[ndx] = default_level;
+	dbgc_config[ndx] = (struct debug_class) {
+		.loglevel = default_level,
+		.fd = -1,
+	};
 
 	new_name_list = talloc_realloc(NULL, classname_table, char *, ndx + 1);
-	if (!new_name_list)
+	if (new_name_list == NULL) {
 		return -1;
+	}
 	classname_table = new_name_list;
 
 	classname_table[ndx] = talloc_strdup(classname_table, classname);
-	if (! classname_table[ndx])
+	if (classname_table[ndx] == NULL) {
 		return -1;
+	}
 
 	debug_num_classes = ndx + 1;
 
@@ -766,13 +802,14 @@ static void debug_dump_status(int level)
 		const char *classname = classname_table[q];
 		DEBUGADD(level, ("  %s: %d\n",
 				 classname,
-				 DEBUGLEVEL_CLASS[q]));
+				 dbgc_config[q].loglevel));
 	}
 }
 
 static bool debug_parse_param(char *param)
 {
 	char *class_name;
+	char *class_file = NULL;
 	char *class_level;
 	char *saveptr = NULL;
 	int ndx;
@@ -782,18 +819,30 @@ static bool debug_parse_param(char *param)
 		return false;
 	}
 
-	class_level = strtok_r(NULL, "\0", &saveptr);
+	class_level = strtok_r(NULL, "@\0", &saveptr);
 	if (class_level == NULL) {
 		return false;
 	}
 
+	class_file = strtok_r(NULL, "\0", &saveptr);
+
 	ndx = debug_lookup_classname(class_name);
 	if (ndx == -1) {
 		return false;
 	}
 
-	DEBUGLEVEL_CLASS[ndx] = atoi(class_level);
+	dbgc_config[ndx].loglevel = atoi(class_level);
+
+	if (class_file == NULL) {
+		return true;
+	}
+
+	TALLOC_FREE(dbgc_config[ndx].logfile);
 
+	dbgc_config[ndx].logfile = talloc_strdup(NULL, class_file);
+	if (dbgc_config[ndx].logfile == NULL) {
+		return false;
+	}
 	return true;
 }
 
@@ -824,15 +873,16 @@ bool debug_parse_levels(const char *params_str)
 	 * v.s. "all:10", this is the traditional way to set DEBUGLEVEL
 	 */
 	if (isdigit(tok[0])) {
-		DEBUGLEVEL_CLASS[DBGC_ALL] = atoi(tok);
+		dbgc_config[DBGC_ALL].loglevel = atoi(tok);
 		tok = strtok_r(NULL, LIST_SEP, &saveptr);
 	} else {
-		DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
+		dbgc_config[DBGC_ALL].loglevel = 0;
 	}
 
 	/* Array is debug_num_classes long */
 	for (i = DBGC_ALL+1; i < debug_num_classes; i++) {
-		DEBUGLEVEL_CLASS[i] = DEBUGLEVEL_CLASS[DBGC_ALL];
+		dbgc_config[i].loglevel = dbgc_config[DBGC_ALL].loglevel;
+		TALLOC_FREE(dbgc_config[i].logfile);
 	}
 
 	while (tok != NULL) {
@@ -883,6 +933,7 @@ static void debug_init(void)
 	for (i = 0; i < ARRAY_SIZE(default_classname_table); i++) {
 		debug_add_class(default_classname_table[i]);
 	}
+	dbgc_config[DBGC_ALL].fd = 2;
 
 	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
 		debug_backends[i].log_level = -1;
@@ -965,8 +1016,8 @@ void debug_set_logfile(const char *name)
 		/* this copes with calls when smb.conf is not loaded yet */
 		return;
 	}
-	TALLOC_FREE(state.debugf);
-	state.debugf = talloc_strdup(NULL, name);
+	TALLOC_FREE(dbgc_config[DBGC_ALL].logfile);
+	dbgc_config[DBGC_ALL].logfile = talloc_strdup(NULL, name);
 }
 
 static void debug_close_fd(int fd)
@@ -1022,6 +1073,33 @@ static void debug_callback_log(const char *msg, int msg_level)
  Fix from dgibson at linuxcare.com.
 **************************************************************************/
 
+static bool reopen_one_log(int *fd, const char *logfile)
+{
+	int old_fd = *fd;
+	int new_fd;
+
+	if (logfile == NULL) {
+		debug_close_fd(old_fd);
+		*fd = -1;
+		return true;
+	}
+
+	new_fd = open(logfile, O_WRONLY|O_APPEND|O_CREAT, 0644);
+	if (new_fd == -1) {
+		log_overflow = true;
+		DBG_ERR("Unable to open new log file '%s': %s\n",
+			logfile, strerror(errno));
+		log_overflow = false;
+		return false;
+	}
+
+	debug_close_fd(old_fd);
+	smb_set_close_on_exec(new_fd);
+	*fd = new_fd;
+
+	return true;
+}
+
 /**
   reopen the log file (usually called because the log file name might have changed)
 */
@@ -1029,8 +1107,8 @@ bool reopen_logs_internal(void)
 {
 	mode_t oldumask;
 	int new_fd = 0;
-	int old_fd = 0;
-	bool ret = true;
+	size_t i;
+	bool ok;
 
 	if (state.reopening_logs) {
 		return true;
@@ -1044,14 +1122,14 @@ bool reopen_logs_internal(void)
 		return true;
 	case DEBUG_STDOUT:
 	case DEBUG_DEFAULT_STDOUT:
-		debug_close_fd(state.fd);
-		state.fd = 1;
+		debug_close_fd(dbgc_config[DBGC_ALL].fd);
+		dbgc_config[DBGC_ALL].fd = 1;
 		return true;
 
 	case DEBUG_DEFAULT_STDERR:
 	case DEBUG_STDERR:
-		debug_close_fd(state.fd);
-		state.fd = 2;
+		debug_close_fd(dbgc_config[DBGC_ALL].fd);
+		dbgc_config[DBGC_ALL].fd = 2;
 		return true;
 
 	case DEBUG_FILE:
@@ -1060,24 +1138,23 @@ bool reopen_logs_internal(void)
 
 	oldumask = umask( 022 );
 
-	if (!state.debugf) {
+	for (i = DBGC_ALL; i < debug_num_classes; i++) {
+		if (dbgc_config[DBGC_ALL].logfile != NULL) {
+			break;
+		}
+	}
+	if (i == debug_num_classes) {
 		return false;


-- 
Samba Shared Repository



More information about the samba-cvs mailing list