r26333: No more global_loadparm in finddcs.
[samba.git] / source4 / libcli / finddcs.c
index 417b33f2778b1c6362709ac5fbfb6442c9052d31..83bf9837f98ace73166fc71f6248824294ad3343 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,
@@ -17,8 +17,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/>.
 */
 
 #include "include/includes.h"
 #include "libcli/composite/composite.h"
 #include "libcli/libcli.h"
 #include "libcli/resolve/resolve.h"
+#include "libcli/finddcs.h"
+#include "param/param.h"
 
 struct finddcs_state {
        struct composite_context *ctx;
        struct messaging_context *msg_ctx;
 
+       const char *my_netbios_name;
        const char *domain_name;
        struct dom_sid *domain_sid;
 
@@ -59,6 +61,7 @@ static void fallback_node_status_replied(struct nbt_name_request *name_req);
  */
 
 struct composite_context *finddcs_send(TALLOC_CTX *mem_ctx,
+                                      const char *my_netbios_name,
                                       const char *domain_name,
                                       int name_type,
                                       struct dom_sid *domain_sid,
@@ -79,6 +82,7 @@ struct composite_context *finddcs_send(TALLOC_CTX *mem_ctx,
 
        state->ctx = c;
 
+       state->my_netbios_name = talloc_strdup(state, my_netbios_name);
        state->domain_name = talloc_strdup(state, domain_name);
        if (composite_nomem(state->domain_name, c)) return c;
 
@@ -92,8 +96,7 @@ struct composite_context *finddcs_send(TALLOC_CTX *mem_ctx,
        state->msg_ctx = msg_ctx;
 
        make_nbt_name(&name, state->domain_name, name_type);
-       creq = resolve_name_send(&name, event_ctx,
-                                methods);
+       creq = resolve_name_send(&name, event_ctx, methods);
        composite_continue(c, creq, finddcs_name_resolved, state);
        return c;
 }
@@ -112,12 +115,15 @@ static void finddcs_name_resolved(struct composite_context *ctx)
        struct finddcs_state *state =
                talloc_get_type(ctx->async.private_data, struct finddcs_state);
        struct irpc_request *ireq;
-       uint32_t *nbt_servers;
+       struct server_id *nbt_servers;
        const char *address;
 
        state->ctx->status = resolve_name_recv(ctx, state, &address);
        if (!composite_is_ok(state->ctx)) return;
 
+       /* TODO: This should try and find all the DCs, and give the
+        * caller them in the order they responded */
+
        state->num_dcs = 1;
        state->dcs = talloc_array(state, struct nbt_dc_name, state->num_dcs);
        if (composite_nomem(state->dcs, state->ctx)) return;
@@ -133,23 +139,22 @@ static void finddcs_name_resolved(struct composite_context *ctx)
                return;
        }
 
-       nbt_servers = irpc_servers_byname(state->msg_ctx, "nbt_server");
-       if ((nbt_servers == NULL) || (nbt_servers[0] == 0)) {
+       nbt_servers = irpc_servers_byname(state->msg_ctx, state, "nbt_server");
+       if ((nbt_servers == NULL) || (nbt_servers[0].id == 0)) {
                fallback_node_status(state);
                return;
        }
 
        state->r.in.domainname = state->domain_name;
        state->r.in.ip_address = state->dcs[0].address;
-       state->r.in.my_computername = lp_netbios_name();
-       state->r.in.my_accountname = talloc_asprintf(state, "%s$",
-                                                    lp_netbios_name());
+       state->r.in.my_computername = state->my_netbios_name;
+       state->r.in.my_accountname = talloc_asprintf(state, "%s$", state->my_netbios_name);
        if (composite_nomem(state->r.in.my_accountname, state->ctx)) return;
        state->r.in.account_control = ACB_WSTRUST;
        state->r.in.domain_sid = state->domain_sid;
 
        ireq = irpc_call_send(state->msg_ctx, nbt_servers[0],
-                             &dcerpc_table_irpc, DCERPC_NBTD_GETDCNAME,
+                             &ndr_table_irpc, NDR_NBTD_GETDCNAME,
                              &state->r, state);
        if (!ireq) {
                fallback_node_status(state);
@@ -241,6 +246,7 @@ NTSTATUS finddcs_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
 }
 
 NTSTATUS finddcs(TALLOC_CTX *mem_ctx,
+                const char *my_netbios_name,
                 const char *domain_name, int name_type, 
                 struct dom_sid *domain_sid,
                 const char **methods,
@@ -249,6 +255,7 @@ NTSTATUS finddcs(TALLOC_CTX *mem_ctx,
                 int *num_dcs, struct nbt_dc_name **dcs)
 {
        struct composite_context *c = finddcs_send(mem_ctx,
+                                                  my_netbios_name,
                                                   domain_name, name_type,
                                                   domain_sid, methods, 
                                                   event_ctx, msg_ctx);