r23779: Change from v2 or later to v3 or later.
[amitay/samba.git] / source3 / nsswitch / winbindd_misc.c
index 6c6dc5b7651cc60bfc8fbb13128f09c1950b0e26..bfc03041f0c059198fe393412448bdc62c8e6141 100644 (file)
@@ -8,7 +8,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,
@@ -100,10 +100,41 @@ enum winbindd_result winbindd_dual_check_machine_acct(struct winbindd_domain *do
 
 void winbindd_list_trusted_domains(struct winbindd_cli_state *state)
 {
+       struct winbindd_domain *d = NULL;
+       int extra_data_len = 0;
+       char *extra_data = NULL;
+       
        DEBUG(3, ("[%5lu]: list trusted domains\n",
                  (unsigned long)state->pid));
 
-       sendto_domain(state, find_our_domain());
+       for ( d=domain_list(); d; d=d->next ) {
+               if ( !extra_data ) {
+                       extra_data = talloc_asprintf(state->mem_ctx, "%s\\%s\\%s",
+                                                    d->name,
+                                                    d->alt_name ? d->alt_name : d->name,
+                                                    sid_string_static(&d->sid));
+               } else {
+                       extra_data = talloc_asprintf(state->mem_ctx, "%s\n%s\\%s\\%s",
+                                                    extra_data,
+                                                    d->name,
+                                                    d->alt_name ? d->alt_name : d->name,
+                                                    sid_string_static(&d->sid));
+               }
+       }
+       
+       extra_data_len = 0;
+       if (extra_data != NULL) {
+               extra_data_len = strlen(extra_data);
+       }
+
+       if (extra_data_len > 0) {
+               state->response.extra_data.data = SMB_STRDUP(extra_data);
+               state->response.length += extra_data_len+1;
+       }
+
+       TALLOC_FREE( extra_data );      
+
+       request_ok(state);      
 }
 
 enum winbindd_result winbindd_dual_list_trusted_domains(struct winbindd_domain *domain,
@@ -124,6 +155,12 @@ enum winbindd_result winbindd_dual_list_trusted_domains(struct winbindd_domain *
                                                  &num_domains, &names,
                                                  &alt_names, &sids);
 
+       if (!NT_STATUS_IS_OK(result)) {
+               DEBUG(3, ("winbindd_dual_list_trusted_domains: trusted_domains returned %s\n",
+                       nt_errstr(result) ));
+               return WINBINDD_ERROR;
+       }
+
        extra_data = talloc_strdup(state->mem_ctx, "");
 
        if (num_domains > 0)
@@ -189,6 +226,8 @@ enum winbindd_result winbindd_dual_getdcname(struct winbindd_domain *domain,
        char *p;
        struct rpc_pipe_client *netlogon_pipe;
        NTSTATUS result;
+       WERROR werr;
+       unsigned int orig_timeout;
 
        state->request.domain_name
                [sizeof(state->request.domain_name)-1] = '\0';
@@ -203,12 +242,19 @@ enum winbindd_result winbindd_dual_getdcname(struct winbindd_domain *domain,
                return WINBINDD_ERROR;
        }
 
-       result = rpccli_netlogon_getdcname(netlogon_pipe, state->mem_ctx, domain->dcname,
-                                          state->request.domain_name,
-                                          dcname_slash);
+       /* This call can take a long time - allow the server to time out.
+          35 seconds should do it. */
 
-       if (!NT_STATUS_IS_OK(result)) {
-               DEBUG(5, ("Error requesting DCname: %s\n", nt_errstr(result)));
+       orig_timeout = cli_set_timeout(netlogon_pipe->cli, 35000);
+
+       werr = rpccli_netlogon_getanydcname(netlogon_pipe, state->mem_ctx, domain->dcname,
+                                           state->request.domain_name,
+                                           dcname_slash);
+       /* And restore our original timeout. */
+       cli_set_timeout(netlogon_pipe->cli, orig_timeout);
+
+       if (!W_ERROR_IS_OK(werr)) {
+               DEBUG(5, ("Error requesting DCname: %s\n", dos_errstr(werr)));
                return WINBINDD_ERROR;
        }
 
@@ -295,7 +341,8 @@ void winbindd_show_sequence(struct winbindd_cli_state *state)
 
 static void sequence_recv(void *private_data, BOOL success)
 {
-       struct sequence_state *state = private_data;
+       struct sequence_state *state =
+               (struct sequence_state *)private_data;
        uint32 seq = DOM_SEQUENCE_NONE;
 
        if ((success) && (state->response->result == WINBINDD_OK))
@@ -416,7 +463,8 @@ void winbindd_domain_info(struct winbindd_cli_state *state)
 
 static void domain_info_init_recv(void *private_data, BOOL success)
 {
-       struct domain_info_state *istate = private_data;
+       struct domain_info_state *istate =
+               (struct domain_info_state *)private_data;
        struct winbindd_cli_state *state = istate->cli_state;
        struct winbindd_domain *domain = istate->domain;