r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[tprouty/samba.git] / source / nsswitch / winbindd_cm.c
index 82c85d624612b183aa498afc6c9c5e9f0458c90d..269dab0389b976eb52db0e59ac5b8996a3114c48 100644 (file)
@@ -11,7 +11,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -20,8 +20,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /*
@@ -82,13 +81,16 @@ static BOOL get_dcs(TALLOC_CTX *mem_ctx, const struct winbindd_domain *domain,
  Child failed to find DC's. Reschedule check.
 ****************************************************************/
 
-static void msg_failed_to_go_online(int msg_type, struct process_id src,
-                                   void *buf, size_t len, void *private_data)
+static void msg_failed_to_go_online(struct messaging_context *msg,
+                                   void *private_data,
+                                   uint32_t msg_type,
+                                   struct server_id server_id,
+                                   DATA_BLOB *data)
 {
        struct winbindd_domain *domain;
-       const char *domainname = (const char *)buf;
+       const char *domainname = (const char *)data->data;
 
-       if (buf == NULL || len == 0) {
+       if (data->data == NULL || data->length == 0) {
                return;
        }
 
@@ -118,13 +120,16 @@ static void msg_failed_to_go_online(int msg_type, struct process_id src,
  Actually cause a reconnect from a message.
 ****************************************************************/
 
-static void msg_try_to_go_online(int msg_type, struct process_id src,
-                                void *buf, size_t len, void *private_data)
+static void msg_try_to_go_online(struct messaging_context *msg,
+                                void *private_data,
+                                uint32_t msg_type,
+                                struct server_id server_id,
+                                DATA_BLOB *data)
 {
        struct winbindd_domain *domain;
-       const char *domainname = (const char *)buf;
+       const char *domainname = (const char *)data->data;
 
-       if (buf == NULL || len == 0) {
+       if (data->data == NULL || data->length == 0) {
                return;
        }
 
@@ -172,23 +177,21 @@ static BOOL fork_child_dc_connect(struct winbindd_domain *domain)
        /* Stop zombies */
        CatchChild();
 
-       message_block();
-
        child_pid = sys_fork();
 
        if (child_pid == -1) {
                DEBUG(0, ("fork_child_dc_connect: Could not fork: %s\n", strerror(errno)));
-               message_unblock();
                return False;
        }
 
        if (child_pid != 0) {
                /* Parent */
-               message_register(MSG_WINBIND_TRY_TO_GO_ONLINE,
-                                msg_try_to_go_online, NULL);
-               message_register(MSG_WINBIND_FAILED_TO_GO_ONLINE,
-                                msg_failed_to_go_online, NULL);
-               message_unblock();
+               messaging_register(winbind_messaging_context(), NULL,
+                                  MSG_WINBIND_TRY_TO_GO_ONLINE,
+                                  msg_try_to_go_online);
+               messaging_register(winbind_messaging_context(), NULL,
+                                  MSG_WINBIND_FAILED_TO_GO_ONLINE,
+                                  msg_failed_to_go_online);
                return True;
        }
 
@@ -219,18 +222,22 @@ static BOOL fork_child_dc_connect(struct winbindd_domain *domain)
 
        if ((!get_dcs(mem_ctx, domain, &dcs, &num_dcs)) || (num_dcs == 0)) {
                /* Still offline ? Can't find DC's. */
-               message_send_pid(pid_to_procid(parent_pid), MSG_WINBIND_FAILED_TO_GO_ONLINE,
-                               domain->name,
-                               strlen(domain->name)+1, False);
+               messaging_send_buf(winbind_messaging_context(),
+                                  pid_to_procid(parent_pid),
+                                  MSG_WINBIND_FAILED_TO_GO_ONLINE,
+                                  (uint8 *)domain->name,
+                                  strlen(domain->name)+1);
                _exit(0);
        }
 
        /* We got a DC. Send a message to our parent to get it to
           try and do the same. */
 
-       message_send_pid(pid_to_procid(parent_pid), MSG_WINBIND_TRY_TO_GO_ONLINE,
-                               domain->name,
-                               strlen(domain->name)+1, False);
+       messaging_send_buf(winbind_messaging_context(),
+                          pid_to_procid(parent_pid),
+                          MSG_WINBIND_TRY_TO_GO_ONLINE,
+                          (uint8 *)domain->name,
+                          strlen(domain->name)+1);
        _exit(0);
 }
 
@@ -250,9 +257,7 @@ static void check_domain_online_handler(struct event_context *ctx,
                  "%s (online = %s)\n", domain->name, 
                  domain->online ? "True" : "False" ));
 
-       if (domain->check_online_event) {
-               TALLOC_FREE(domain->check_online_event);
-       }
+       TALLOC_FREE(domain->check_online_event);
 
        /* Are we still in "startup" mode ? */
 
@@ -304,9 +309,7 @@ void set_domain_offline(struct winbindd_domain *domain)
        DEBUG(10,("set_domain_offline: called for domain %s\n",
                domain->name ));
 
-       if (domain->check_online_event) {
-               TALLOC_FREE(domain->check_online_event);
-       }
+       TALLOC_FREE(domain->check_online_event);
 
        if (domain->internal) {
                DEBUG(3,("set_domain_offline: domain %s is internal - logic error.\n",
@@ -345,7 +348,7 @@ void set_domain_offline(struct winbindd_domain *domain)
 
        /* The above *has* to succeed for winbindd to work. */
        if (!domain->check_online_event) {
-               smb_panic("set_domain_offline: failed to add online handler.\n");
+               smb_panic("set_domain_offline: failed to add online handler");
        }
 
        DEBUG(10,("set_domain_offline: added event handler for domain %s\n",
@@ -358,11 +361,11 @@ void set_domain_offline(struct winbindd_domain *domain)
                struct winbindd_child *idmap = idmap_child();
                
                if ( idmap->pid != 0 ) {
-                       message_send_pid(pid_to_procid(idmap->pid), 
-                                        MSG_WINBIND_OFFLINE
-                                        domain->name
-                                        strlen(domain->name)+1
-                                        False);
+                       messaging_send_buf(winbind_messaging_context(),
+                                          pid_to_procid(idmap->pid)
+                                          MSG_WINBIND_OFFLINE
+                                          (uint8 *)domain->name
+                                          strlen(domain->name)+1);
                }                       
        }
 
@@ -418,13 +421,13 @@ static void set_domain_online(struct winbindd_domain *domain)
 
        /* Ensure we have no online timeout checks. */
        domain->check_online_timeout = 0;
-       if (domain->check_online_event) {
-               TALLOC_FREE(domain->check_online_event);
-       }
+       TALLOC_FREE(domain->check_online_event);
 
        /* Ensure we ignore any pending child messages. */
-       message_deregister(MSG_WINBIND_TRY_TO_GO_ONLINE);
-       message_deregister(MSG_WINBIND_FAILED_TO_GO_ONLINE);
+       messaging_deregister(winbind_messaging_context(),
+                            MSG_WINBIND_TRY_TO_GO_ONLINE, NULL);
+       messaging_deregister(winbind_messaging_context(),
+                            MSG_WINBIND_FAILED_TO_GO_ONLINE, NULL);
 
        domain->online = True;
 
@@ -435,11 +438,11 @@ static void set_domain_online(struct winbindd_domain *domain)
                struct winbindd_child *idmap = idmap_child();
                
                if ( idmap->pid != 0 ) {
-                       message_send_pid(pid_to_procid(idmap->pid), 
-                                        MSG_WINBIND_ONLINE
-                                        domain->name
-                                        strlen(domain->name)+1
-                                        False);
+                       messaging_send_buf(winbind_messaging_context(),
+                                          pid_to_procid(idmap->pid)
+                                          MSG_WINBIND_ONLINE
+                                          (uint8 *)domain->name
+                                          strlen(domain->name)+1);
                }                       
        }
 
@@ -486,7 +489,7 @@ void set_domain_online_request(struct winbindd_domain *domain)
 
                /* The above *has* to succeed for winbindd to work. */
                if (!domain->check_online_event) {
-                       smb_panic("set_domain_online_request: failed to add online handler.\n");
+                       smb_panic("set_domain_online_request: failed to add online handler");
                }
        }
 
@@ -592,8 +595,8 @@ static BOOL get_dc_name_via_netlogon(const struct winbindd_domain *domain,
 
        orig_timeout = cli_set_timeout(netlogon_pipe->cli, 35000);
        
-       werr = rpccli_netlogon_getdcname(netlogon_pipe, mem_ctx, our_domain->dcname,
-                                          domain->name, tmp);
+       werr = rpccli_netlogon_getanydcname(netlogon_pipe, mem_ctx, our_domain->dcname,
+                                           domain->name, tmp);
 
        /* And restore our original timeout. */
        cli_set_timeout(netlogon_pipe->cli, orig_timeout);
@@ -601,12 +604,12 @@ static BOOL get_dc_name_via_netlogon(const struct winbindd_domain *domain,
        talloc_destroy(mem_ctx);
 
        if (!W_ERROR_IS_OK(werr)) {
-               DEBUG(10, ("rpccli_netlogon_getdcname failed: %s\n",
+               DEBUG(10, ("rpccli_netlogon_getanydcname failed: %s\n",
                           dos_errstr(werr)));
                return False;
        }
 
-       /* cli_netlogon_getdcname gives us a name with \\ */
+       /* cli_netlogon_getanydcname gives us a name with \\ */
        p = tmp;
        if (*p == '\\') {
                p+=1;
@@ -617,7 +620,7 @@ static BOOL get_dc_name_via_netlogon(const struct winbindd_domain *domain,
 
        fstrcpy(dcname, p);
 
-       DEBUG(10, ("rpccli_netlogon_getdcname returned %s\n", dcname));
+       DEBUG(10, ("rpccli_netlogon_getanydcname returned %s\n", dcname));
 
        if (!resolve_name(dcname, dc_ip, 0x20)) {
                return False;
@@ -971,7 +974,8 @@ static BOOL send_getdc_request(struct in_addr dc_ip,
        SSVAL(p, 6, 0xffff);
        p+=8;
 
-       return cli_send_mailslot(False, "\\MAILSLOT\\NET\\NTLOGON", 0,
+       return cli_send_mailslot(winbind_messaging_context(),
+                                False, "\\MAILSLOT\\NET\\NTLOGON", 0,
                                 outbuf, PTR_DIFF(p, outbuf),
                                 global_myname(), 0, domain_name, 0x1c,
                                 dc_ip);
@@ -2190,6 +2194,12 @@ NTSTATUS cm_connect_netlogon(struct winbindd_domain *domain,
  no_schannel:
        if ((lp_client_schannel() == False) ||
                        ((neg_flags & NETLOGON_NEG_SCHANNEL) == 0)) {
+
+               /*
+                * NetSamLogonEx only works for schannel
+                */
+               domain->can_do_samlogon_ex = False;
+
                /* We're done - just keep the existing connection to NETLOGON
                 * open */
                conn->netlogon_pipe = netlogon_pipe;
@@ -2221,6 +2231,11 @@ NTSTATUS cm_connect_netlogon(struct winbindd_domain *domain,
                return !NT_STATUS_IS_OK(result) ? result : NT_STATUS_PIPE_NOT_AVAILABLE;
        }
 
+       /*
+        * Try NetSamLogonEx for AD domains
+        */
+       domain->can_do_samlogon_ex = domain->active_directory;
+       
        *cli = conn->netlogon_pipe;
        return NT_STATUS_OK;
 }