libcli/security Provide a common, top level libcli/security/security.h
[sfrench/samba-autobuild/.git] / source3 / winbindd / winbindd_dual.c
index 277b17430695e80b1e0a4231b086e56f7886e2be..5058788e784057fa8395e10ae76f063e24fc5ce6 100644 (file)
@@ -31,6 +31,9 @@
 #include "winbindd.h"
 #include "../../nsswitch/libwbclient/wbc_async.h"
 #include "librpc/gen_ndr/messaging.h"
+#include "secrets.h"
+#include "../lib/util/select.h"
+#include "../libcli/security/security.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
@@ -407,7 +410,7 @@ void setup_child(struct winbindd_domain *domain, struct winbindd_child *child,
        if (logprefix && logname) {
                char *logbase = NULL;
 
-               if (lp_logfile()) {
+               if (*lp_logfile()) {
                        char *end = NULL;
 
                        if (asprintf(&logbase, "%s", lp_logfile()) < 0) {
@@ -439,8 +442,8 @@ void setup_child(struct winbindd_domain *domain, struct winbindd_child *child,
        child->table = table;
        child->queue = tevent_queue_create(NULL, "winbind_child");
        SMB_ASSERT(child->queue != NULL);
-       child->rpccli = wbint_rpccli_create(NULL, domain, child);
-       SMB_ASSERT(child->rpccli != NULL);
+       child->binding_handle = wbint_binding_handle(NULL, domain, child);
+       SMB_ASSERT(child->binding_handle != NULL);
 }
 
 static struct winbindd_child *winbindd_children = NULL;
@@ -1129,9 +1132,11 @@ bool winbindd_reinit_after_fork(const char *logfilename)
        struct winbindd_child *cl;
        NTSTATUS status;
 
-       status = reinit_after_fork(winbind_messaging_context(),
-                                  winbind_event_context(),
-                                  procid_self(), true);
+       status = reinit_after_fork(
+               winbind_messaging_context(),
+               winbind_event_context(),
+               procid_self(),
+               true);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                return false;
@@ -1292,6 +1297,10 @@ static bool fork_domain_child(struct winbindd_child *child)
                           MSG_DUMP_EVENT_LIST, child_msg_dump_event_list);
        messaging_register(winbind_messaging_context(), NULL,
                           MSG_DEBUG, debug_message);
+       messaging_register(winbind_messaging_context(), NULL,
+                          MSG_WINBIND_IP_DROPPED,
+                          winbind_msg_ip_dropped);
+
 
        primary_domain = find_our_domain();
 
@@ -1303,7 +1312,7 @@ static bool fork_domain_child(struct winbindd_child *child)
         * try to bring domain online after fork. */
        if ( child->domain ) {
                child->domain->startup = True;
-               child->domain->startup_time = time(NULL);
+               child->domain->startup_time = time_mono(NULL);
                /* we can be in primary domain or in trusted domain
                 * If we are in trusted domain, set the primary domain
                 * in start-up mode */
@@ -1311,7 +1320,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                        set_domain_online_request(child->domain);
                        if (!(child->domain->primary)) {
                                primary_domain->startup = True;
-                               primary_domain->startup_time = time(NULL);
+                               primary_domain->startup_time = time_mono(NULL);
                                set_domain_online_request(primary_domain);
                        }
                }
@@ -1366,7 +1375,7 @@ static bool fork_domain_child(struct winbindd_child *child)
 
        while (1) {
 
-               int ret;
+               int ret = 0;
                fd_set r_fds;
                fd_set w_fds;
                int maxfd;
@@ -1378,7 +1387,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                int iov_count;
                NTSTATUS status;
 
-               if (run_events(winbind_event_context(), 0, NULL, NULL)) {
+               if (run_events(winbind_event_context(), &ret, NULL, NULL)) {
                        TALLOC_FREE(frame);
                        continue;
                }
@@ -1386,7 +1395,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                GetTimeOfDay(&now);
 
                if (child->domain && child->domain->startup &&
-                               (now.tv_sec > child->domain->startup_time + 30)) {
+                               (time_mono(NULL) > child->domain->startup_time + 30)) {
                        /* No longer in "startup" mode. */
                        DEBUG(10,("fork_domain_child: domain %s no longer in 'startup' mode.\n",
                                child->domain->name ));
@@ -1416,7 +1425,7 @@ static bool fork_domain_child(struct winbindd_child *child)
 
                ret = sys_select(maxfd + 1, &r_fds, &w_fds, NULL, tp);
 
-               if (run_events(winbind_event_context(), ret, &r_fds, &w_fds)) {
+               if (run_events(winbind_event_context(), &ret, &r_fds, &w_fds)) {
                        /* We got a signal - continue. */
                        TALLOC_FREE(frame);
                        continue;
@@ -1483,3 +1492,21 @@ static bool fork_domain_child(struct winbindd_child *child)
                TALLOC_FREE(frame);
        }
 }
+
+void winbind_msg_ip_dropped_parent(struct messaging_context *msg_ctx,
+                                  void *private_data,
+                                  uint32_t msg_type,
+                                  struct server_id server_id,
+                                  DATA_BLOB *data)
+{
+       struct winbindd_child *child;
+
+       winbind_msg_ip_dropped(msg_ctx, private_data, msg_type,
+                              server_id, data);
+
+
+       for (child = winbindd_children; child != NULL; child = child->next) {
+               messaging_send_buf(msg_ctx, pid_to_procid(child->pid),
+                                  msg_type, data->data, data->length);
+       }
+}