s4-loadparm: 2nd half of lp_ to lpcfg_ conversion
[kai/samba.git] / source4 / libnet / libnet_site.c
index bb65de1f54be4837d24ae67df656f1d11a42a15e..e4f037d0b8491e3894cef468c1df6cdf1015f3ee 100644 (file)
@@ -22,9 +22,9 @@
 #include "libcli/cldap/cldap.h"
 #include "lib/ldb/include/ldb.h"
 #include "lib/ldb/include/ldb_errors.h"
-#include "librpc/rpc/dcerpc.h"
 #include "libcli/resolve/resolve.h"
 #include "param/param.h"
+#include "lib/tsocket/tsocket.h"
 
 /**
  * 1. Setup a CLDAP socket.
@@ -41,6 +41,8 @@ NTSTATUS libnet_FindSite(TALLOC_CTX *ctx, struct libnet_context *lctx, struct li
 
        struct cldap_socket *cldap = NULL;
        struct cldap_netlogon search;
+       int ret;
+       struct tsocket_address *dest_address;
 
        tmp_ctx = talloc_named(ctx, 0, "libnet_FindSite temp context");
        if (!tmp_ctx) {
@@ -50,15 +52,32 @@ NTSTATUS libnet_FindSite(TALLOC_CTX *ctx, struct libnet_context *lctx, struct li
 
        /* Resolve the site name. */
        ZERO_STRUCT(search);
-       search.in.dest_address = r->in.dest_address;
-       search.in.dest_port = r->in.cldap_port;
+       search.in.dest_address = NULL;
+       search.in.dest_port = 0;
        search.in.acct_control = -1;
        search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
        search.in.map_response = true;
 
-       cldap = cldap_socket_init(tmp_ctx, lctx->event_ctx, lp_iconv_convenience(global_loadparm));
+       ret = tsocket_address_inet_from_strings(tmp_ctx, "ip",
+                                               r->in.dest_address,
+                                               r->in.cldap_port,
+                                               &dest_address);
+       if (ret != 0) {
+               r->out.error_string = NULL;
+               status = map_nt_error_from_unix(errno);
+               return status;
+       }
+
+       /* we want to use non async calls, so we're not passing an event context */
+       status = cldap_socket_init(tmp_ctx, NULL, NULL, dest_address, &cldap);
+       if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(tmp_ctx);
+               r->out.error_string = NULL;
+               return status;
+       }
        status = cldap_netlogon(cldap, tmp_ctx, &search);
-       if (!NT_STATUS_IS_OK(status) || !search.out.netlogon.nt5_ex.client_site) {
+       if (!NT_STATUS_IS_OK(status)
+           || !search.out.netlogon.data.nt5_ex.client_site) {
                /*
                  If cldap_netlogon() returns in error,
                  default to using Default-First-Site-Name.
@@ -72,7 +91,7 @@ NTSTATUS libnet_FindSite(TALLOC_CTX *ctx, struct libnet_context *lctx, struct li
                }
        } else {
                site_name_str = talloc_asprintf(tmp_ctx, "%s",
-                                       search.out.netlogon.nt5_ex.client_site);
+                                       search.out.netlogon.data.nt5_ex.client_site);
                if (!site_name_str) {
                        r->out.error_string = NULL;
                        talloc_free(tmp_ctx);
@@ -149,7 +168,7 @@ NTSTATUS libnet_JoinSite(struct libnet_context *ctx,
        }
 
        make_nbt_name_client(&name, libnet_r->out.samr_binding->host);
-       status = resolve_name(lp_resolve_context(ctx->lp_ctx), &name, r, &dest_addr, ctx->event_ctx);
+       status = resolve_name(lpcfg_resolve_context(ctx->lp_ctx), &name, r, &dest_addr, ctx->event_ctx);
        if (!NT_STATUS_IS_OK(status)) {
                libnet_r->out.error_string = NULL;
                talloc_free(tmp_ctx);
@@ -160,7 +179,7 @@ NTSTATUS libnet_JoinSite(struct libnet_context *ctx,
        r->in.dest_address = dest_addr;
        r->in.netbios_name = libnet_r->in.netbios_name;
        r->in.domain_dn_str = libnet_r->out.domain_dn_str;
-       r->in.cldap_port = lp_cldap_port(ctx->lp_ctx);
+       r->in.cldap_port = lpcfg_cldap_port(ctx->lp_ctx);
 
        status = libnet_FindSite(tmp_ctx, ctx, r);
        if (!NT_STATUS_IS_OK(status)) {
@@ -215,7 +234,7 @@ NTSTATUS libnet_JoinSite(struct libnet_context *ctx,
 
        rtn = ldb_add(remote_ldb, msg);
        if (rtn == LDB_ERR_ENTRY_ALREADY_EXISTS) {
-               int i;
+               unsigned int i;
 
                /* make a 'modify' msg, and only for serverReference */
                msg = ldb_msg_new(tmp_ctx);