]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:winbind: Move sigterm handling functions to winbindd-lib subsystem
authorSamuel Cabrero <scabrero@samba.org>
Wed, 2 Mar 2022 17:30:19 +0000 (18:30 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 8 Apr 2022 20:13:37 +0000 (20:13 +0000)
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>
source3/winbindd/winbindd.c
source3/winbindd/winbindd_dual.c
source3/winbindd/winbindd_proto.h

index 8a472b17300605394e918bd25c6d88727a70a1ad..2de457ce7739837c192ba78c5780cf8ffb0e3c6b 100644 (file)
@@ -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;
index b275dfb128c3c9c59033f28b5e05b457eb2b2671..e532c5657384c0600bb7fe907957068d211cea06 100644 (file)
@@ -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;
+}
index 35ff72c36f4f86fe966f55f2c37892624bbc482f..49178d0a0c7d67252fa5be975dd5c5f1974d8d38 100644 (file)
@@ -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);