From b705a7f3f49cf24590c25c288d269f616be3e502 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 5b72d6598714..836ed23619f6 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 1e6f8913db984d548f0a2d8cdd68def3214e9442 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 935951f3fbae..4a71b2b76bbd 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 @@ static struct imessaging_context *imessaging_init_internal(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 7784fc3bc7df415cbb61777b00b60baa74244029 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 5eca0b9e869b..645705136d52 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -316,7 +316,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 5d7408f7eb30e37a5c8a85d88b1574636441ec78 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 645705136d52..db570710ca90 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -45,6 +45,7 @@ #include "libds/common/roles.h" #include "lib/util/tfork.h" #include "dsdb/samdb/ldb_modules/util.h" +#include "lib/util/server_id.h" #ifdef HAVE_PTHREAD #include @@ -291,6 +292,31 @@ static int prime_ldb_databases(struct tevent_context *event_ctx, bool *am_backup return LDB_SUCCESS; } +/* + 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 */ @@ -325,10 +351,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 46b2989dc604d0ca39570ab7d36eccf19f1f1ecd 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 a21ada84eb21..b565d4664776 100755 --- a/selftest/target/Samba4.pm +++ b/selftest/target/Samba4.pm @@ -2033,6 +2033,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