From eda17c89b7fe0eddd1a412f7a573a753466b7e90 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 17 Jan 2019 16:29:37 +0100 Subject: [PATCH 1/5] manpages/samba.7.xml: smbcontrol can also work with 'samba' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG: https://bugzilla.samba.org/show_bug.cgi?id=13752 Signed-off-by: Stefan Metzmacher Reviewed-by: Björn Baumbach (cherry picked from commit 12b9adec3ff48f4356f9ff865891dc3c652ff86b) --- docs-xml/manpages/samba.7.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs-xml/manpages/samba.7.xml b/docs-xml/manpages/samba.7.xml index 6f0a83aa3b4f..c9db9e66209b 100644 --- a/docs-xml/manpages/samba.7.xml +++ b/docs-xml/manpages/samba.7.xml @@ -166,7 +166,7 @@ 1 smbcontrol is a utility that can change the behaviour of running - smbd, nmbd and + samba, smbd, nmbd and winbindd daemons. -- 2.17.1 From d49ecacd1cf8ac99507807f9205cf4db63f682d8 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 15 Jan 2019 01:39:06 +0100 Subject: [PATCH 2/5] s4:messaging: add support 'smbcontrol debug/debuglevel' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG: https://bugzilla.samba.org/show_bug.cgi?id=13752 Signed-off-by: Stefan Metzmacher Reviewed-by: Björn Baumbach (cherry picked from commit 3a0c1da432c53de234b54bac90a3fb84534994eb) --- source4/lib/messaging/messaging.c | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index b8d4e50f12c7..85be5baf258a 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -121,6 +121,68 @@ static void ringbuf_log_msg(struct imessaging_context *msg, imessaging_send(msg, src, MSG_RINGBUF_LOG, &blob); } +/**************************************************************************** + Receive a "set debug level" message. +****************************************************************************/ + +static void debug_imessage(struct imessaging_context *msg_ctx, + void *private_data, + uint32_t msg_type, + struct server_id src, + DATA_BLOB *data) +{ + const char *params_str = (const char *)data->data; + struct server_id_buf src_buf; + struct server_id dst = imessaging_get_server_id(msg_ctx); + struct server_id_buf dst_buf; + + /* Check, it's a proper string! */ + if (params_str[(data->length)-1] != '\0') { + DBG_ERR("Invalid debug message from pid %s to pid %s\n", + server_id_str_buf(src, &src_buf), + server_id_str_buf(dst, &dst_buf)); + return; + } + + DBG_ERR("INFO: Remote set of debug to `%s' (pid %s from pid %s)\n", + params_str, + server_id_str_buf(dst, &dst_buf), + server_id_str_buf(src, &src_buf)); + + debug_parse_levels(params_str); +} + +/**************************************************************************** + Return current debug level. +****************************************************************************/ + +static void debuglevel_imessage(struct imessaging_context *msg_ctx, + void *private_data, + uint32_t msg_type, + struct server_id src, + DATA_BLOB *data) +{ + char *message = debug_list_class_names_and_levels(); + DATA_BLOB blob = data_blob_null; + struct server_id_buf src_buf; + struct server_id dst = imessaging_get_server_id(msg_ctx); + struct server_id_buf dst_buf; + + DBG_DEBUG("Received REQ_DEBUGLEVEL message (pid %s from pid %s)\n", + server_id_str_buf(dst, &dst_buf), + server_id_str_buf(src, &src_buf)); + + if (message == NULL) { + DBG_ERR("debug_list_class_names_and_levels returned NULL\n"); + return; + } + + blob = data_blob_string_const_null(message); + imessaging_send(msg_ctx, src, MSG_DEBUGLEVEL, &blob); + + TALLOC_FREE(message); +} + /* return uptime of messaging server via irpc */ @@ -418,6 +480,16 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx, if (!NT_STATUS_IS_OK(status)) { goto fail; } + status = imessaging_register(msg, NULL, MSG_DEBUG, + debug_imessage); + if (!NT_STATUS_IS_OK(status)) { + goto fail; + } + status = imessaging_register(msg, NULL, MSG_REQ_DEBUGLEVEL, + debuglevel_imessage); + if (!NT_STATUS_IS_OK(status)) { + goto fail; + } status = IRPC_REGISTER(msg, irpc, IRPC_UPTIME, irpc_uptime, msg); if (!NT_STATUS_IS_OK(status)) { goto fail; -- 2.17.1 From 3565d0920a31b62f7ffb769d653367fd566a55f0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 28 Jan 2019 16:29:51 +0100 Subject: [PATCH 3/5] s4:server: avoid using pid=0 for the parent 'samba' process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It confuses the 'samba-tool processes' output and log messages. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13752 Signed-off-by: Stefan Metzmacher Reviewed-by: Björn Baumbach (cherry picked from commit 5bd7a8e5685caa09067745b108ef7e53e3108e97) --- source4/smbd/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/smbd/server.c b/source4/smbd/server.c index 60e2797eb749..d6914c6cea2f 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -269,7 +269,7 @@ static NTSTATUS setup_parent_messaging(struct server_state *state, msg = imessaging_init(state->event_ctx, lp_ctx, - cluster_id(0, SAMBA_PARENT_TASKID), + cluster_id(getpid(), SAMBA_PARENT_TASKID), state->event_ctx); NT_STATUS_HAVE_NO_MEMORY(msg); -- 2.17.1 From df59bba3ecf9895ab1ef334abdbf5b861cd65a8a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 17 Jan 2019 16:27:10 +0100 Subject: [PATCH 4/5] s4:server: add support for 'smbcontrol samba shutdown' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG: https://bugzilla.samba.org/show_bug.cgi?id=13752 Signed-off-by: Stefan Metzmacher Reviewed-by: Björn Baumbach (cherry picked from commit 832776c0fcf7cc658c128765514755c2d15b06a6) --- source4/smbd/server.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/source4/smbd/server.c b/source4/smbd/server.c index d6914c6cea2f..f7e12cdfa659 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -43,6 +43,7 @@ #include "lib/util/samba_modules.h" #include "nsswitch/winbind_client.h" #include "libds/common/roles.h" +#include "lib/util/server_id.h" struct server_state { struct tevent_context *event_ctx; @@ -244,6 +245,31 @@ static void prime_ldb_databases(struct tevent_context *event_ctx) } +/* + called from 'smbcontrol samba shutdown' + */ +static void samba_parent_shutdown(struct imessaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id src, + DATA_BLOB *data) +{ + struct server_state *state = + talloc_get_type_abort(private_data, + struct server_state); + struct server_id_buf src_buf; + struct server_id dst = imessaging_get_server_id(msg); + struct server_id_buf dst_buf; + + DBG_ERR("samba_shutdown of %s %s: from %s\n", + state->binary_name, + server_id_str_buf(dst, &dst_buf), + server_id_str_buf(src, &src_buf)); + + TALLOC_FREE(state); + exit(0); +} + /* called when a fatal condition occurs in a child task */ @@ -278,10 +304,19 @@ static NTSTATUS setup_parent_messaging(struct server_state *state, return status; } + status = imessaging_register(msg, state, MSG_SHUTDOWN, + samba_parent_shutdown); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + status = IRPC_REGISTER(msg, irpc, SAMBA_TERMINATE, samba_terminate, state); + if (!NT_STATUS_IS_OK(status)) { + return status; + } - return status; + return NT_STATUS_OK; } -- 2.17.1 From 3fb664c191fec829523f8f65be51eca3738cc899 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 17 Jan 2019 23:50:45 +0100 Subject: [PATCH 5/5] selftest:Samba4: use 'smbcontrol samba shutdown' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG: https://bugzilla.samba.org/show_bug.cgi?id=13752 Signed-off-by: Stefan Metzmacher Reviewed-by: Björn Baumbach Autobuild-User(master): Andreas Schneider Autobuild-Date(master): Wed Jan 30 01:51:48 CET 2019 on sn-devel-144 (cherry picked from commit d03991f569b54ae0a11911b622107fbae701715d) --- selftest/target/Samba4.pm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/selftest/target/Samba4.pm b/selftest/target/Samba4.pm index 7da68c447764..99cc9db79b57 100755 --- a/selftest/target/Samba4.pm +++ b/selftest/target/Samba4.pm @@ -1959,6 +1959,15 @@ sub teardown_env_terminate($$) my ($self, $envvars) = @_; my $pid; + # This should cause samba to terminate gracefully + my $smbcontrol = Samba::bindir_path($self, "smbcontrol"); + my $cmd = ""; + $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}"; + my $ret = system($cmd); + if ($ret != 0) { + warn "'$cmd' failed with '$ret'\n"; + } + # This should cause samba to terminate gracefully close($envvars->{STDIN_PIPE}); -- 2.17.1