summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Cabrero <scabrero@samba.org>2022-03-02 18:30:19 +0100
committerJeremy Allison <jra@samba.org>2022-04-08 20:13:37 +0000
commitdfba83e14ab36967fe98469d8dead7c94aa71df6 (patch)
tree87eb30f825f6a9b365bf5e07a4e9da7bd0b7ad3e
parent1903cf39da37660c44df58649b3795bf74799953 (diff)
downloadsamba-dfba83e14ab36967fe98469d8dead7c94aa71df6.tar.gz
s3:winbind: Move sigterm handling functions to winbindd-lib subsystem
The source3/winbindd/winbindd.c file does not belong to 'winbindd-lib' subsystem. Funtions called from winbindd-lib must be part of it. Signed-off-by: Samuel Cabrero <scabrero@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r--source3/winbindd/winbindd.c104
-rw-r--r--source3/winbindd/winbindd_dual.c105
-rw-r--r--source3/winbindd/winbindd_proto.h1
3 files changed, 106 insertions, 104 deletions
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
index 8a472b17300..2de457ce773 100644
--- a/source3/winbindd/winbindd.c
+++ b/source3/winbindd/winbindd.c
@@ -112,62 +112,6 @@ static void flush_caches_noinit(void)
}
}
-/* Handle the signal by unlinking socket and exiting */
-
-static void winbindd_terminate(bool is_parent)
-{
- if (is_parent) {
- /* When parent goes away we should
- * remove the socket file. Not so
- * when children terminate.
- */
- char *path = NULL;
-
- if (asprintf(&path, "%s/%s",
- lp_winbindd_socket_directory(), WINBINDD_SOCKET_NAME) > 0) {
- unlink(path);
- SAFE_FREE(path);
- }
- }
-
- idmap_close();
-
- netlogon_creds_cli_close_global_db();
-
-#if 0
- if (interactive) {
- TALLOC_CTX *mem_ctx = talloc_init("end_description");
- char *description = talloc_describe_all(mem_ctx);
-
- DEBUG(3, ("tallocs left:\n%s\n", description));
- talloc_destroy(mem_ctx);
- }
-#endif
-
- if (is_parent) {
- pidfile_unlink(lp_pid_directory(), "winbindd");
- }
-
- exit(0);
-}
-
-static void winbindd_sig_term_handler(struct tevent_context *ev,
- struct tevent_signal *se,
- int signum,
- int count,
- void *siginfo,
- void *private_data)
-{
- bool *p = talloc_get_type_abort(private_data, bool);
- bool is_parent = *p;
-
- TALLOC_FREE(p);
-
- DEBUG(0,("Got sig[%d] terminate (is_parent=%d)\n",
- signum, is_parent));
- winbindd_terminate(is_parent);
-}
-
/*
handle stdin becoming readable when we are in --foreground mode
*/
@@ -188,54 +132,6 @@ static void winbindd_stdin_handler(struct tevent_context *ev,
}
}
-bool winbindd_setup_sig_term_handler(bool parent)
-{
- struct tevent_signal *se;
- bool *is_parent;
-
- is_parent = talloc(global_event_context(), bool);
- if (!is_parent) {
- return false;
- }
-
- *is_parent = parent;
-
- se = tevent_add_signal(global_event_context(),
- is_parent,
- SIGTERM, 0,
- winbindd_sig_term_handler,
- is_parent);
- if (!se) {
- DEBUG(0,("failed to setup SIGTERM handler"));
- talloc_free(is_parent);
- return false;
- }
-
- se = tevent_add_signal(global_event_context(),
- is_parent,
- SIGINT, 0,
- winbindd_sig_term_handler,
- is_parent);
- if (!se) {
- DEBUG(0,("failed to setup SIGINT handler"));
- talloc_free(is_parent);
- return false;
- }
-
- se = tevent_add_signal(global_event_context(),
- is_parent,
- SIGQUIT, 0,
- winbindd_sig_term_handler,
- is_parent);
- if (!se) {
- DEBUG(0,("failed to setup SIGINT handler"));
- talloc_free(is_parent);
- return false;
- }
-
- return true;
-}
-
bool winbindd_setup_stdin_handler(bool parent, bool foreground)
{
bool *is_parent;
diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c
index b275dfb128c..e532c565738 100644
--- a/source3/winbindd/winbindd_dual.c
+++ b/source3/winbindd/winbindd_dual.c
@@ -43,6 +43,9 @@
#include "passdb.h"
#include "lib/util/string_wrappers.h"
#include "lib/global_contexts.h"
+#include "idmap.h"
+#include "libcli/auth/netlogon_creds_cli.h"
+#include "../lib/util/pidfile.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_WINBIND
@@ -1900,3 +1903,105 @@ void winbind_msg_ip_dropped_parent(struct messaging_context *msg_ctx,
forall_children(winbind_msg_relay_fn, &state);
}
+
+void winbindd_terminate(bool is_parent)
+{
+ if (is_parent) {
+ /* When parent goes away we should
+ * remove the socket file. Not so
+ * when children terminate.
+ */
+ char *path = NULL;
+
+ if (asprintf(&path, "%s/%s",
+ lp_winbindd_socket_directory(), WINBINDD_SOCKET_NAME) > 0) {
+ unlink(path);
+ SAFE_FREE(path);
+ }
+ }
+
+ idmap_close();
+
+ netlogon_creds_cli_close_global_db();
+
+#if 0
+ if (interactive) {
+ TALLOC_CTX *mem_ctx = talloc_init("end_description");
+ char *description = talloc_describe_all(mem_ctx);
+
+ DEBUG(3, ("tallocs left:\n%s\n", description));
+ talloc_destroy(mem_ctx);
+ }
+#endif
+
+ if (is_parent) {
+ pidfile_unlink(lp_pid_directory(), "winbindd");
+ }
+
+ exit(0);
+}
+
+static void winbindd_sig_term_handler(struct tevent_context *ev,
+ struct tevent_signal *se,
+ int signum,
+ int count,
+ void *siginfo,
+ void *private_data)
+{
+ bool *p = talloc_get_type_abort(private_data, bool);
+ bool is_parent = *p;
+
+ TALLOC_FREE(p);
+
+ DEBUG(0,("Got sig[%d] terminate (is_parent=%d)\n",
+ signum, is_parent));
+ winbindd_terminate(is_parent);
+}
+
+bool winbindd_setup_sig_term_handler(bool parent)
+{
+ struct tevent_signal *se;
+ bool *is_parent;
+
+ is_parent = talloc(global_event_context(), bool);
+ if (!is_parent) {
+ return false;
+ }
+
+ *is_parent = parent;
+
+ se = tevent_add_signal(global_event_context(),
+ is_parent,
+ SIGTERM, 0,
+ winbindd_sig_term_handler,
+ is_parent);
+ if (!se) {
+ DEBUG(0,("failed to setup SIGTERM handler"));
+ talloc_free(is_parent);
+ return false;
+ }
+
+ se = tevent_add_signal(global_event_context(),
+ is_parent,
+ SIGINT, 0,
+ winbindd_sig_term_handler,
+ is_parent);
+ if (!se) {
+ DEBUG(0,("failed to setup SIGINT handler"));
+ talloc_free(is_parent);
+ return false;
+ }
+
+ se = tevent_add_signal(global_event_context(),
+ is_parent,
+ SIGQUIT, 0,
+ winbindd_sig_term_handler,
+ is_parent);
+ if (!se) {
+ DEBUG(0,("failed to setup SIGINT handler"));
+ talloc_free(is_parent);
+ return false;
+ }
+
+ return true;
+}
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index 35ff72c36f4..49178d0a0c7 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -25,6 +25,7 @@
/* The following definitions come from winbindd/winbindd.c */
struct imessaging_context *winbind_imessaging_context(void);
+void winbindd_terminate(bool is_parent);
bool winbindd_setup_sig_term_handler(bool parent);
bool winbindd_setup_stdin_handler(bool parent, bool foreground);
bool winbindd_setup_sig_hup_handler(const char *lfile);