From 152a4edf0b8c05e41fca22412299a6b8479e0b27 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 16 Aug 2023 16:47:24 +0200 Subject: [PATCH 01/10] s3:rpc_server: call reopen_logs before we print the copyright notice This matches what we do in smbd, winbindd and nmbd. For the workers it's important to call it at all, otherwise things like 'debug pid = yes' or 'debug class = yes' have no effect in the workers. We could argue if we want the copyright notice on the start of each worker at all, but that's a different discussion... Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett (cherry picked from commit 94723b6732a67482eb7792e82b01e26a807e8265) --- source3/rpc_server/rpc_host.c | 4 ++-- source3/rpc_server/rpc_worker.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source3/rpc_server/rpc_host.c b/source3/rpc_server/rpc_host.c index 1cb874569e2..b59916b5dda 100644 --- a/source3/rpc_server/rpc_host.c +++ b/source3/rpc_server/rpc_host.c @@ -2838,13 +2838,13 @@ int main(int argc, const char *argv[]) dump_core_setup(progname, lp_logfile(frame, lp_sub)); + reopen_logs(); + DEBUG(0, ("%s version %s started.\n", progname, samba_version_string())); DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE)); - reopen_logs(); - (void)winbind_off(); ok = init_guest_session_info(frame); (void)winbind_on(); diff --git a/source3/rpc_server/rpc_worker.c b/source3/rpc_server/rpc_worker.c index 4f47a0ad4f3..2ef90547dd6 100644 --- a/source3/rpc_server/rpc_worker.c +++ b/source3/rpc_server/rpc_worker.c @@ -1122,6 +1122,8 @@ int rpc_worker_main( /* Ignore children - no zombies. */ CatchChild(); + reopen_logs(); + DEBUG(0, ("%s version %s started.\n", progname, samba_version_string())); -- 2.38.0 From e5d9df53ae2143b221372e64cf428d788a1b9b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Jacke?= Date: Mon, 18 Sep 2023 23:42:31 +0200 Subject: [PATCH 02/10] profile: issues info message with lower log level BUG: https://bugzilla.samba.org/show_bug.cgi?id=15377 Signed-off-by: Bjoern Jacke Reviewed-by: Andrew Bartlett (cherry picked from commit 55d895dc42248ad524a10812b9975ac05a722fdc) --- source3/profile/profile_dummy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source3/profile/profile_dummy.c b/source3/profile/profile_dummy.c index 7d34d209fce..5d3213eec1a 100644 --- a/source3/profile/profile_dummy.c +++ b/source3/profile/profile_dummy.c @@ -27,5 +27,5 @@ bool profile_setup(struct messaging_context *msg_ctx, bool rdonly) void set_profile_level(int level, const struct server_id *src) { - DEBUG(1,("INFO: Profiling support unavailable in this build.\n")); + DBG_NOTICE("INFO: Profiling support unavailable in this build.\n"); } -- 2.38.0 From f925eec6c65d6e3062829f78b71b4dc7cb37dfa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Jacke?= Date: Mon, 18 Sep 2023 13:45:54 +0200 Subject: [PATCH 03/10] s4/server.c: move some log messages from ERR to NOTICE BUG: https://bugzilla.samba.org/show_bug.cgi?id=15377 Signed-off-by: Bjoern Jacke Reviewed-by: Andrew Bartlett (cherry picked from commit baa67024bca391f2e212b91131f544cc911c6895) --- source4/samba/server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source4/samba/server.c b/source4/samba/server.c index eb4ddeb7ce7..a66e1cf0363 100644 --- a/source4/samba/server.c +++ b/source4/samba/server.c @@ -801,7 +801,7 @@ static int binary_smbd_main(TALLOC_CTX *mem_ctx, if (max_runtime) { struct tevent_timer *te; - DBG_ERR("%s PID %d was called with maxruntime %d - " + DBG_NOTICE("%s PID %d was called with maxruntime %d - " "current ts %llu\n", binary_name, (int)getpid(), max_runtime, (unsigned long long) time(NULL)); @@ -905,7 +905,7 @@ static int binary_smbd_main(TALLOC_CTX *mem_ctx, return 1; } - DBG_ERR("%s: using '%s' process model\n", binary_name, model); + DBG_NOTICE("%s: using '%s' process model\n", binary_name, model); { int child_pipe[2]; -- 2.38.0 From 16e9eee70f83e0851da3704a69186ede28bd5867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Jacke?= Date: Tue, 6 Jun 2023 17:25:35 +0200 Subject: [PATCH 04/10] lib/util: move copyright define to copyright.h BUG: https://bugzilla.samba.org/show_bug.cgi?id=15377 Signed-off-by: Bjoern Jacke Reviewed-by: Andrew Bartlett (cherry picked from commit b7631bf603fbce9b80b19410f0680ce8c4170a1b) --- lib/util/copyright.h | 28 ++++++++++++++++++++++++++++ source3/include/includes.h | 3 +++ source3/include/smb.h | 3 --- source4/include/includes.h | 3 +++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 lib/util/copyright.h diff --git a/lib/util/copyright.h b/lib/util/copyright.h new file mode 100644 index 00000000000..a29f2285d13 --- /dev/null +++ b/lib/util/copyright.h @@ -0,0 +1,28 @@ +/* + Unix SMB/CIFS implementation. + + Copyright (C) Björn Jacke 2023 + + 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __LIB_UTIL_COPYRIGHT_H__ +#define __LIB_UTIL_COPYRIGHT_H__ + +/* logged when starting the various Samba daemons */ +#define COPYRIGHT_STARTUP_MESSAGE "Copyright Andrew Tridgell and the Samba Team 1992-2023" + +#endif /* __LIB_UTIL_COPYRIGHT_H__ */ + + diff --git a/source3/include/includes.h b/source3/include/includes.h index 02beb0a0c88..8bb6ee88803 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -242,6 +242,9 @@ enum timestamp_set_resolution { typedef char fstring[FSTRING_LEN]; #endif +/* copyright define */ +#include "../lib/util/copyright.h" + /* debug.h need to be included before samba_util.h for the macro SMB_ASSERT */ #include "../lib/util/debug.h" diff --git a/source3/include/smb.h b/source3/include/smb.h index 487a8b316d8..81d761d2280 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -29,9 +29,6 @@ #include "libcli/smb/smb_common.h" #include "libds/common/roles.h" -/* logged when starting the various Samba daemons */ -#define COPYRIGHT_STARTUP_MESSAGE "Copyright Andrew Tridgell and the Samba Team 1992-2023" - #define LARGE_WRITEX_HDR_SIZE 65 #define LARGE_WRITEX_BUFFER_SIZE (128*1024) diff --git a/source4/include/includes.h b/source4/include/includes.h index e7abf1a2492..8832b97ed02 100644 --- a/source4/include/includes.h +++ b/source4/include/includes.h @@ -57,6 +57,9 @@ #endif #include "../lib/util/attr.h" +/* copyright define */ +#include "../lib/util/copyright.h" + /* debug.h need to be included before samba_util.h for the macro SMB_ASSERT */ #include "../lib/util/debug.h" #include "../lib/util/samba_util.h" -- 2.38.0 From f5997410d35728acba06806eb8b085188b5284a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Jacke?= Date: Mon, 18 Sep 2023 13:48:06 +0200 Subject: [PATCH 05/10] debug.h: introduce DEBUG_STARTUP_NOTICE this is log level -1 and lowest syslog priority. This is used for start up messages and copyright notices, which should always be printed but which are no errors or warnings. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15377 Signed-off-by: Bjoern Jacke Reviewed-by: Andrew Bartlett (cherry picked from commit ccfe345fece0a5a44d766fb9426d43c2e046d040) --- lib/util/debug.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/util/debug.h b/lib/util/debug.h index 335a644718f..5433a585ec8 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -269,12 +269,14 @@ void debuglevel_set_class(size_t idx, int level); /* * Debug levels matching RFC 3164 */ +#define DBGLVL_STARTUP_NOTICE -1 /* startup notice */ #define DBGLVL_ERR 0 /* error conditions */ #define DBGLVL_WARNING 1 /* warning conditions */ #define DBGLVL_NOTICE 3 /* normal, but significant, condition */ #define DBGLVL_INFO 5 /* informational message */ #define DBGLVL_DEBUG 10 /* debug-level message */ +#define DBG_STARTUP_NOTICE(...) DBG_PREFIX(DBGLVL_STARTUP_NOTICE, (__VA_ARGS__)) #define DBG_ERR(...) DBG_PREFIX(DBGLVL_ERR, (__VA_ARGS__)) #define DBG_WARNING(...) DBG_PREFIX(DBGLVL_WARNING, (__VA_ARGS__)) #define DBG_NOTICE(...) DBG_PREFIX(DBGLVL_NOTICE, (__VA_ARGS__)) -- 2.38.0 From 2d2032589cf0f4bba33e56c278376103db27b444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Jacke?= Date: Mon, 5 Jun 2023 18:10:07 +0200 Subject: [PATCH 06/10] logging: use DBG_STARTUP_NOTICE for startup message BUG: https://bugzilla.samba.org/show_bug.cgi?id=15377 Signed-off-by: Bjoern Jacke Reviewed-by: Andrew Bartlett (cherry picked from commit 159cfde446c95c387ef212be103b109ea0dca93d) --- source3/rpc_server/rpc_host.c | 6 +++--- source3/rpc_server/rpc_worker.c | 8 ++++---- source3/smbd/server.c | 5 +++-- source3/winbindd/winbindd.c | 5 +++-- source4/samba/server.c | 7 +++---- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/source3/rpc_server/rpc_host.c b/source3/rpc_server/rpc_host.c index b59916b5dda..9e64fa62d0c 100644 --- a/source3/rpc_server/rpc_host.c +++ b/source3/rpc_server/rpc_host.c @@ -2840,10 +2840,10 @@ int main(int argc, const char *argv[]) reopen_logs(); - DEBUG(0, ("%s version %s started.\n", + DBG_STARTUP_NOTICE("%s version %s started.\n" + COPYRIGHT_STARTUP_MESSAGE "\n", progname, - samba_version_string())); - DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE)); + samba_version_string()); (void)winbind_off(); ok = init_guest_session_info(frame); diff --git a/source3/rpc_server/rpc_worker.c b/source3/rpc_server/rpc_worker.c index 2ef90547dd6..cde0e7bcd59 100644 --- a/source3/rpc_server/rpc_worker.c +++ b/source3/rpc_server/rpc_worker.c @@ -1124,10 +1124,10 @@ int rpc_worker_main( reopen_logs(); - DEBUG(0, ("%s version %s started.\n", - progname, - samba_version_string())); - DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE)); + DBG_STARTUP_NOTICE("%s version %s started.\n" + COPYRIGHT_STARTUP_MESSAGE "\n", + progname, + samba_version_string()); msg_ctx = global_messaging_context(); if (msg_ctx == NULL) { diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 18c79f9df35..ddef5b6de16 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -1743,8 +1743,9 @@ extern void build_options(bool screen); reopen_logs(); - DEBUG(0,("smbd version %s started.\n", samba_version_string())); - DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE)); + DBG_STARTUP_NOTICE("smbd version %s started.\n" + COPYRIGHT_STARTUP_MESSAGE "\n", + samba_version_string()); DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n", (int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid())); diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index 765e5a2561b..cdd6d4319cb 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -1438,8 +1438,9 @@ int main(int argc, const char **argv) reopen_logs(); - DEBUG(0,("winbindd version %s started.\n", samba_version_string())); - DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE)); + DBG_STARTUP_NOTICE("winbindd version %s started.\n" + COPYRIGHT_STARTUP_MESSAGE "\n", + samba_version_string()); /* After parsing the configuration file we setup the core path one more time * as the log file might have been set in the configuration and cores's diff --git a/source4/samba/server.c b/source4/samba/server.c index a66e1cf0363..e1ad646fae2 100644 --- a/source4/samba/server.c +++ b/source4/samba/server.c @@ -630,11 +630,10 @@ static int binary_smbd_main(TALLOC_CTX *mem_ctx, so set our umask to 0 */ umask(0); - DEBUG(0,("%s version %s started.\n", + DBG_STARTUP_NOTICE("%s version %s started.\n" + COPYRIGHT_STARTUP_MESSAGE "\n", binary_name, - SAMBA_VERSION_STRING)); - DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team" - " 1992-2023\n")); + SAMBA_VERSION_STRING); if (sizeof(uint16_t) < 2 || sizeof(uint32_t) < 4 || -- 2.38.0 From 967f94717aa0962a720de189210e2092140e6a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Jacke?= Date: Mon, 18 Sep 2023 14:34:29 +0200 Subject: [PATCH 07/10] lib/util/become_daemon.c: use DBG_STARTUP_NOTICE BUG: https://bugzilla.samba.org/show_bug.cgi?id=15377 Signed-off-by: Bjoern Jacke Reviewed-by: Andrew Bartlett (cherry picked from commit 50337acaa566b6696e035e38f6408f65805182a0) --- lib/util/become_daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/become_daemon.c b/lib/util/become_daemon.c index 9424656d403..c6795c585c8 100644 --- a/lib/util/become_daemon.c +++ b/lib/util/become_daemon.c @@ -147,5 +147,5 @@ void daemon_status(const char *daemon, const char *msg) sd_notifyf(0, "STATUS=%s: %s", daemon, msg); } #endif - DBG_ERR("daemon '%s' : %s\n", daemon, msg); + DBG_STARTUP_NOTICE("daemon '%s' : %s\n", daemon, msg); } -- 2.38.0 From d5118c854281f368c5956f4921171c7ad48408fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Jacke?= Date: Mon, 18 Sep 2023 14:35:55 +0200 Subject: [PATCH 08/10] source3/nmbd/nmbd.c: use DBG_STARTUP_NOTICE BUG: https://bugzilla.samba.org/show_bug.cgi?id=15377 Signed-off-by: Bjoern Jacke Reviewed-by: Andrew Bartlett (cherry picked from commit 72f20311acc4ab8851f18ac2b87f7ecc7803afad) --- source3/nmbd/nmbd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 7cdd9bd1303..1db16726851 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -898,7 +898,9 @@ static bool open_sockets(bool isdaemon, int port) reopen_logs(); - DBG_ERR("nmbd version %s started.\n%s\n", samba_version_string(), COPYRIGHT_STARTUP_MESSAGE); + DBG_STARTUP_NOTICE("nmbd version %s started.\n" + COPYRIGHT_STARTUP_MESSAGE "\n", + samba_version_string()); if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC && !lp_parm_bool(-1, "server role check", "inhibit", false)) { -- 2.38.0 From a81b1200f2a4d2e516cc3b4a3e2df837fde688de Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 22 Nov 2023 17:03:30 +0100 Subject: [PATCH 09/10] lib/util: add debug_set_forced_log_priority() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default the priority for syslog/systemd is derived from the log level of the debug message. But for things like startup messages we want to change the priority temporary, like this: debug_set_forced_log_priority(DBGLVL_NOTICE); D_ERR("Startup...\n"); debug_set_forced_log_priority(-1); BUG: https://bugzilla.samba.org/show_bug.cgi?id=15377 Signed-off-by: Stefan Metzmacher Reviewed-by: Björn Jacke Reviewed-by: Andrew Bartlett (cherry picked from commit bd21a0cdefb30ef5522f81d865c03d11a182a63c) --- lib/util/debug.c | 10 ++++++++++ lib/util/debug.h | 1 + 2 files changed, 11 insertions(+) diff --git a/lib/util/debug.c b/lib/util/debug.c index 0e13fa564e3..a3266148b12 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -94,6 +94,7 @@ static struct { char hostname[HOST_NAME_MAX+1]; bool reopening_logs; bool schedule_reopen_logs; + int forced_log_priority; struct debug_settings settings; debug_callback_fn callback; @@ -230,6 +231,10 @@ static int debug_level_to_priority(int level) }; int priority; + if (state.forced_log_priority != -1) { + level = state.forced_log_priority; + } + if (level < 0 || (size_t)level >= ARRAY_SIZE(priority_map)) priority = LOG_DEBUG; else @@ -1133,6 +1138,11 @@ void debug_set_hostname(const char *name) strlcpy(state.hostname, name, sizeof(state.hostname)); } +void debug_set_forced_log_priority(int forced_log_priority) +{ + state.forced_log_priority = forced_log_priority; +} + /** * Ensure debug logs are initialised. * diff --git a/lib/util/debug.h b/lib/util/debug.h index 5433a585ec8..b62f2d19bcc 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -356,6 +356,7 @@ 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); +void debug_set_forced_log_priority(int forced_log_priority); bool reopen_logs_internal( void ); void force_check_log_size( void ); bool need_to_check_log_size( void ); -- 2.38.0 From c5f92bc9790ee9a0dc2d5fc5cf8132771d416cb1 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 22 Nov 2023 17:18:29 +0100 Subject: [PATCH 10/10] lib/util: convert DBG_STARTUP_NOTICE() to use debug_set_forced_log_priority(DBGLVL_NOTICE) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using -1 as log level is not compatible without our infrastructure. As all backends are initialized with .log_level = -1, which means they don't log the message, but now they all try to handle the startup message even if they are not configured. E.g. is means that systemd's journalctl get the message twice now, first via the syslog and also the systemd backend. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15377 Signed-off-by: Stefan Metzmacher Reviewed-by: Björn Jacke Reviewed-by: Andrew Bartlett (cherry picked from commit cd8dcff9e9cbfffab8c502c8701c00b0c8e3512b) --- lib/util/debug.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/util/debug.h b/lib/util/debug.h index b62f2d19bcc..d4bd8246b97 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -269,14 +269,18 @@ void debuglevel_set_class(size_t idx, int level); /* * Debug levels matching RFC 3164 */ -#define DBGLVL_STARTUP_NOTICE -1 /* startup notice */ #define DBGLVL_ERR 0 /* error conditions */ #define DBGLVL_WARNING 1 /* warning conditions */ #define DBGLVL_NOTICE 3 /* normal, but significant, condition */ #define DBGLVL_INFO 5 /* informational message */ #define DBGLVL_DEBUG 10 /* debug-level message */ -#define DBG_STARTUP_NOTICE(...) DBG_PREFIX(DBGLVL_STARTUP_NOTICE, (__VA_ARGS__)) +#define DBG_STARTUP_NOTICE(...) do { \ + debug_set_forced_log_priority(DBGLVL_NOTICE); \ + D_ERR(__VA_ARGS__); \ + debug_set_forced_log_priority(-1); \ +} while(0) + #define DBG_ERR(...) DBG_PREFIX(DBGLVL_ERR, (__VA_ARGS__)) #define DBG_WARNING(...) DBG_PREFIX(DBGLVL_WARNING, (__VA_ARGS__)) #define DBG_NOTICE(...) DBG_PREFIX(DBGLVL_NOTICE, (__VA_ARGS__)) -- 2.38.0