[SCM] Samba Shared Repository - branch master updated

Ralph Böhme slow at samba.org
Mon Nov 1 07:30:01 UTC 2021


The branch, master has been updated
       via  494eb0c22a6 debug: Add new smb.conf option "debug syslog format"
       via  5e1e9d74ab6 debug: Add debug_syslog_format setting
      from  be3a47e22ad s3:modules:recycle - fix crash in recycle_unlink_internal

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


- Log -----------------------------------------------------------------
commit 494eb0c22a67f0a9672a53f8941ad6fecf291a77
Author: Martin Schwenke <martin at meltin.net>
Date:   Sun Oct 31 11:59:30 2021 +1100

    debug: Add new smb.conf option "debug syslog format"
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    
    Autobuild-User(master): Ralph Böhme <slow at samba.org>
    Autobuild-Date(master): Mon Nov  1 07:29:47 UTC 2021 on sn-devel-184

commit 5e1e9d74ab6f59a62ac8dae3239299a0ef334708
Author: Martin Schwenke <martin at meltin.net>
Date:   Thu Oct 28 19:05:19 2021 +1100

    debug: Add debug_syslog_format setting
    
    Without debug_hires_timestamp this produces a syslog style header
    containing:
    
      "MON DD HH:MM:SS HOSTNAME PROGNAME[PID] "
    
    With debug_hires_timestamp this produces a syslog style header
    containing:
    
      "RFC5424-TIMESTAMP HOSTNAME PROGNAME[PID] "
    
    All other settings are ignored.
    
    This will be made visible via smb.conf in a subsequent commit.
    
    This commit adds some simple hostname handling.  It avoids using
    get_myname() from util.c because using that potentially pulls in all
    manner of dependencies.  No real error handling is done.  In the worst
    case debug_set_hostname() sets the hostname to a truncated version of
    the given string.  Similarly, in an even weirder world,
    ensure_hostname() sets the hostname to a truncation of "unknown".
    Both of these are unlikely in all reasonable cases.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Ralph Boehme <slow at samba.org>

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

Summary of changes:
 .../smbdotconf/logging/debughirestimestamp.xml     |  3 +-
 docs-xml/smbdotconf/logging/debugsyslogformat.xml  | 21 ++++++
 lib/param/loadparm.c                               |  2 +
 lib/util/debug.c                                   | 75 +++++++++++++++++++++-
 lib/util/debug.h                                   |  2 +
 lib/util/debug_s3.c                                |  2 +
 source3/param/loadparm.c                           |  1 +
 7 files changed, 104 insertions(+), 2 deletions(-)
 create mode 100644 docs-xml/smbdotconf/logging/debugsyslogformat.xml


Changeset truncated at 500 lines:

diff --git a/docs-xml/smbdotconf/logging/debughirestimestamp.xml b/docs-xml/smbdotconf/logging/debughirestimestamp.xml
index 72598d757ca..79d928ab3d9 100644
--- a/docs-xml/smbdotconf/logging/debughirestimestamp.xml
+++ b/docs-xml/smbdotconf/logging/debughirestimestamp.xml
@@ -9,7 +9,8 @@
     </para>
 
     <para>
-    Note that the parameter <smbconfoption name="debug timestamp"/> must be on for this to have an effect.
+    Note that the parameter <smbconfoption name="debug timestamp"/> or
+    <smbconfoption name="debug syslog format"/> must be on for this to have an effect.
     </para>
 
 </description>
diff --git a/docs-xml/smbdotconf/logging/debugsyslogformat.xml b/docs-xml/smbdotconf/logging/debugsyslogformat.xml
new file mode 100644
index 00000000000..f943f3a5323
--- /dev/null
+++ b/docs-xml/smbdotconf/logging/debugsyslogformat.xml
@@ -0,0 +1,21 @@
+<samba:parameter name="debug syslog format"
+                 context="G"
+                 type="boolean"
+                 xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
+<description>
+    <para>
+    With this option enabled, debug messages are printed in a
+    single-line format like that traditionally produced by syslog.
+    The timestamp consists of an abbreviated month, space-padded date,
+    and time including seconds.  This is followed by the hostname and
+    the program name, with the process-ID in square brackets.
+    </para>
+
+    <para>
+    If <smbconfoption name="debug hires timestamp"/> is also enabled
+    then an RFC5424 timestamp is used instead.
+    </para>
+
+</description>
+<value type="default">no</value>
+</samba:parameter>
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index 2eac1ba7c38..9c725402758 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -2559,6 +2559,7 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
 	lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
 	lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
 	lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
+	lpcfg_do_global_parameter(lp_ctx, "debug syslog format", "No");
 	lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
 	lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
 	lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
@@ -3102,6 +3103,7 @@ static bool lpcfg_update(struct loadparm_context *lp_ctx)
 	settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
 	settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
 	settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
+	settings.debug_syslog_format = lp_ctx->globals->debug_syslog_format;
 	settings.debug_pid = lp_ctx->globals->debug_pid;
 	settings.debug_uid = lp_ctx->globals->debug_uid;
 	settings.debug_class = lp_ctx->globals->debug_class;
diff --git a/lib/util/debug.c b/lib/util/debug.c
index b0ac6ce40ea..2f4a86734ce 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -24,6 +24,8 @@
 #include "system/filesys.h"
 #include "system/syslog.h"
 #include "system/locale.h"
+#include "system/network.h"
+#include "system/time.h"
 #include "time_basic.h"
 #include "close_low_fd.h"
 #include "memory.h"
@@ -89,6 +91,7 @@ static struct {
 	bool initialized;
 	enum debug_logtype logtype; /* The type of logging we are doing: eg stdout, file, stderr */
 	char prog_name[255];
+	char hostname[HOST_NAME_MAX+1];
 	bool reopening_logs;
 	bool schedule_reopen_logs;
 
@@ -1071,6 +1074,35 @@ void debug_set_settings(struct debug_settings *settings,
 	debug_set_backends(logging_param);
 }
 
+static void ensure_hostname(void)
+{
+	int ret;
+
+	if (state.hostname[0] != '\0') {
+		return;
+	}
+
+	ret = gethostname(state.hostname, sizeof(state.hostname));
+	if (ret != 0) {
+		strlcpy(state.hostname, "unknown", sizeof(state.hostname));
+		return;
+	}
+
+	/*
+	 * Ensure NUL termination, since POSIX isn't clear about that.
+	 *
+	 * Don't worry about truncating at the first '.' or similar,
+	 * since this is usually not fully qualified.  Trying to
+	 * truncate opens up the multibyte character gates of hell.
+	 */
+	state.hostname[sizeof(state.hostname) - 1] = '\0';
+}
+
+void debug_set_hostname(const char *name)
+{
+	strlcpy(state.hostname, name, sizeof(state.hostname));
+}
+
 /**
   control the name of the logfile and whether logging will be to stdout, stderr
   or a file, and set up syslog
@@ -1671,11 +1703,52 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
 	 * not yet loaded, then default to timestamps on.
 	 */
 	if (!(state.settings.timestamp_logs ||
-	      state.settings.debug_prefix_timestamp)) {
+	      state.settings.debug_prefix_timestamp ||
+	      state.settings.debug_syslog_format)) {
 		return true;
 	}
 
 	GetTimeOfDay(&tv);
+
+	if (state.settings.debug_syslog_format) {
+		if (state.settings.debug_hires_timestamp) {
+			timeval_str_buf(&tv, true, true, &tvbuf);
+		} else {
+			time_t t;
+			struct tm *tm;
+
+			t = (time_t)tv.tv_sec;
+			tm = localtime(&t);
+			if (tm != NULL) {
+				size_t len;
+				len = strftime(tvbuf.buf,
+					       sizeof(tvbuf.buf),
+					       "%b %e %T",
+					       tm);
+				if (len == 0) {
+					/* Trigger default time format below */
+					tm = NULL;
+				}
+			}
+			if (tm == NULL) {
+				snprintf(tvbuf.buf,
+					 sizeof(tvbuf.buf),
+					 "%ld seconds since the Epoch", (long)t);
+			}
+		}
+
+		ensure_hostname();
+		state.hs_len = snprintf(state.header_str,
+					sizeof(state.header_str),
+					"%s %s %s[%u]: ",
+					tvbuf.buf,
+					state.hostname,
+					state.prog_name,
+					(unsigned int) getpid());
+
+		goto full;
+	}
+
 	timeval_str_buf(&tv, false, state.settings.debug_hires_timestamp,
 			&tvbuf);
 
diff --git a/lib/util/debug.h b/lib/util/debug.h
index 9ab699a4148..7317c2f43c5 100644
--- a/lib/util/debug.h
+++ b/lib/util/debug.h
@@ -300,6 +300,7 @@ struct debug_settings {
 	bool timestamp_logs;
 	bool debug_prefix_timestamp;
 	bool debug_hires_timestamp;
+	bool debug_syslog_format;
 	bool debug_pid;
 	bool debug_uid;
 	bool debug_class;
@@ -315,6 +316,7 @@ void debug_set_logfile(const char *name);
 void debug_set_settings(struct debug_settings *settings,
 			const char *logging_param,
 			int syslog_level, bool syslog_only);
+void debug_set_hostname(const char *name);
 bool reopen_logs_internal( void );
 void force_check_log_size( void );
 bool need_to_check_log_size( void );
diff --git a/lib/util/debug_s3.c b/lib/util/debug_s3.c
index 151227c3419..1fd8637a65f 100644
--- a/lib/util/debug_s3.c
+++ b/lib/util/debug_s3.c
@@ -36,6 +36,7 @@ bool reopen_logs(void)
 			.timestamp_logs = lp_timestamp_logs(),
 			.debug_prefix_timestamp = lp_debug_prefix_timestamp(),
 			.debug_hires_timestamp = lp_debug_hires_timestamp(),
+			.debug_syslog_format = lp_debug_syslog_format(),
 			.debug_pid = lp_debug_pid(),
 			.debug_uid = lp_debug_uid(),
 			.debug_class = lp_debug_class(),
@@ -60,6 +61,7 @@ bool reopen_logs(void)
 			.timestamp_logs = true,
 			.debug_prefix_timestamp = false,
 			.debug_hires_timestamp = true,
+			.debug_syslog_format = false,
 			.debug_pid = false,
 			.debug_uid = false,
 			.debug_class = false,
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 6c9830563c3..f35db213c14 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -675,6 +675,7 @@ static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
 	lpcfg_string_set(Globals.ctx, &Globals.log_level, "0");
 	Globals.debug_prefix_timestamp = false;
 	Globals.debug_hires_timestamp = true;
+	Globals.debug_syslog_format = false;
 	Globals.debug_pid = false;
 	Globals.debug_uid = false;
 	Globals.debug_class = false;


-- 
Samba Shared Repository



More information about the samba-cvs mailing list