r26264: pass name resolve order explicitly, use torture context for settings in dssyn...
[idra/samba.git] / source4 / libnet / libnet_site.c
index 444a9ba485851354ad53d545a268b48fd03f3e3d..251cecb3b097a7a5dceb3d9b4026a37e9b0c8614 100644 (file)
@@ -5,7 +5,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,
@@ -14,8 +14,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 "includes.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"
 
-/*
+/**
  * 1. Setup a CLDAP socket.
  * 2. Lookup the default Site-Name.
  */
@@ -69,7 +70,7 @@ NTSTATUS libnet_FindSite(TALLOC_CTX *ctx, struct libnet_JoinSite *r)
                }
        } else {
                site_name_str = talloc_asprintf(tmp_ctx, "%s",
-                                       search.out.netlogon.logon5.site_name);
+                                       search.out.netlogon.logon5.client_site);
                if (!site_name_str) {
                        r->out.error_string = NULL;
                        talloc_free(tmp_ctx);
@@ -78,6 +79,7 @@ NTSTATUS libnet_FindSite(TALLOC_CTX *ctx, struct libnet_JoinSite *r)
        }
 
        /* Generate the CN=Configuration,... DN. */
+/* TODO: look it up! */
        config_dn_str = talloc_asprintf(tmp_ctx, "CN=Configuration,%s", r->in.domain_dn_str);
        if (!config_dn_str) {
                r->out.error_string = NULL;
@@ -127,6 +129,8 @@ NTSTATUS libnet_JoinSite(struct ldb_context *remote_ldb,
 
        const char *server_dn_str;
        const char *config_dn_str;
+       struct nbt_name name;
+       const char *dest_addr = NULL;
 
        tmp_ctx = talloc_named(libnet_r, 0, "libnet_JoinSite temp context");
        if (!tmp_ctx) {
@@ -141,8 +145,16 @@ NTSTATUS libnet_JoinSite(struct ldb_context *remote_ldb,
                return NT_STATUS_NO_MEMORY;
        }
 
+       make_nbt_name_client(&name, libnet_r->out.samr_binding->host);
+       status = resolve_name(&name, r, &dest_addr, NULL, lp_name_resolve_order(global_loadparm));
+       if (!NT_STATUS_IS_OK(status)) {
+               libnet_r->out.error_string = NULL;
+               talloc_free(tmp_ctx);
+               return status;
+       }
+
        /* Resolve the site name and AD DN's. */
-       r->in.dest_address = libnet_r->out.samr_binding->host;
+       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;
 
@@ -151,7 +163,7 @@ NTSTATUS libnet_JoinSite(struct ldb_context *remote_ldb,
                libnet_r->out.error_string =
                        talloc_steal(libnet_r, r->out.error_string);
                talloc_free(tmp_ctx);
-               return NT_STATUS_NO_MEMORY;
+               return status;
        }
 
        config_dn_str = r->out.config_dn_str;
@@ -186,8 +198,8 @@ NTSTATUS libnet_JoinSite(struct ldb_context *remote_ldb,
                return NT_STATUS_NO_MEMORY;
        }
 
-       server_dn = ldb_dn_explode(tmp_ctx, server_dn_str);
-       if (server_dn == NULL) {
+       server_dn = ldb_dn_new(tmp_ctx, remote_ldb, server_dn_str);
+       if ( ! ldb_dn_validate(server_dn)) {
                libnet_r->out.error_string = talloc_asprintf(libnet_r,
                                        "Invalid server dn: %s",
                                        server_dn_str);