s3: In winbind, close parent/child sockets
[samba.git] / source3 / winbindd / winbindd_dual.c
index 2490073262eee1f14a4705de65faa17bdf208c7f..47ab6c17b707991f5e43236ba9c9f3e2c3338470 100644 (file)
 #include "includes.h"
 #include "winbindd.h"
 #include "nsswitch/wb_reqtrans.h"
-#include "librpc/gen_ndr/messaging.h"
 #include "secrets.h"
 #include "../lib/util/select.h"
 #include "../libcli/security/security.h"
 #include "system/select.h"
+#include "messages.h"
+#include "ntdomain.h"
+#include "../lib/util/tevent_unix.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
@@ -1165,7 +1167,8 @@ static void child_msg_dump_event_list(struct messaging_context *msg,
        dump_event_list(winbind_event_context());
 }
 
-bool winbindd_reinit_after_fork(const char *logfilename)
+bool winbindd_reinit_after_fork(const struct winbindd_child *myself,
+                               const char *logfilename)
 {
        struct winbindd_domain *domain;
        struct winbindd_child *cl;
@@ -1240,6 +1243,14 @@ bool winbindd_reinit_after_fork(const char *logfilename)
                 * go through the parent.
                 */
                cl->pid = (pid_t)0;
+
+               /*
+                * Close service sockets to all other children
+                */
+               if ((cl != myself) && (cl->sock != -1)) {
+                       close(cl->sock);
+                       cl->sock = -1;
+               }
         }
        /*
         * This is a little tricky, children must not
@@ -1323,7 +1334,7 @@ static bool fork_domain_child(struct winbindd_child *child)
        state.sock = fdpair[0];
        close(fdpair[1]);
 
-       if (!winbindd_reinit_after_fork(child->logfilename)) {
+       if (!winbindd_reinit_after_fork(child, child->logfilename)) {
                _exit(0);
        }