diff options
author | Andrew Bartlett <abartlet@samba.org> | 2006-01-17 03:44:37 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:51:13 -0500 |
commit | 1f72942873ee28a17947d2124b885c22f9d83ffc (patch) | |
tree | b1f90278afcff9b555ecba4727f76e8e1950f99e /source4/libnet/libnet_join.c | |
parent | b0f70f066a93d4c131d5480a3a5779a81b311764 (diff) | |
download | samba-1f72942873ee28a17947d2124b885c22f9d83ffc.tar.gz samba-1f72942873ee28a17947d2124b885c22f9d83ffc.tar.bz2 samba-1f72942873ee28a17947d2124b885c22f9d83ffc.zip |
r12976: Patch from Brad Henry <j0j0@riod.ca>:
This patch pulls the AD site name generation and site join code from
libnet/libnet_join.c and puts it into a new file, libnet/libnet_site.c.
This way, a common means for site name, configuration dn and server dn
generation exists so it doesn't need to be rewritten in new code (such
as the future libnet_leave for example).
I've made a couple of changes, but nothing dramatic. Nice work Brad!
Andrew Bartlett
(This used to be commit 45f67b3f6d506cc8cb9922184a8c0c9b59a8f702)
Diffstat (limited to 'source4/libnet/libnet_join.c')
-rw-r--r-- | source4/libnet/libnet_join.c | 171 |
1 files changed, 2 insertions, 169 deletions
diff --git a/source4/libnet/libnet_join.c b/source4/libnet/libnet_join.c index a467999023..f4e4091ce3 100644 --- a/source4/libnet/libnet_join.c +++ b/source4/libnet/libnet_join.c @@ -25,175 +25,10 @@ #include "librpc/gen_ndr/ndr_drsuapi.h" #include "lib/ldb/include/ldb.h" #include "lib/ldb/include/ldb_errors.h" -#include "libcli/cldap/cldap.h" #include "passdb/secrets.h" #include "dsdb/samdb/samdb.h" /* - * find out Site specific stuff: - * 1.) setup an CLDAP socket - * 2.) lookup the Site name - * 3.) Add entry CN=<netbios name>,CN=Servers,CN=<site name>,CN=Sites,CN=Configuration,<domain dn>. - * TODO: 4.) use DsAddEntry() to create CN=NTDS Settings,CN=<netbios name>,CN=Servers,CN=<site name>... - */ -static NTSTATUS libnet_JoinSite(struct libnet_context *ctx, - struct dcerpc_pipe *drsuapi_pipe, - struct policy_handle drsuapi_bind_handle, - struct ldb_context *remote_ldb, - struct libnet_JoinDomain *libnet_r) -{ - NTSTATUS status; - TALLOC_CTX *tmp_ctx; - - struct cldap_socket *cldap = NULL; - struct cldap_netlogon search; - - struct ldb_dn *server_dn; - struct ldb_message *msg; - int rtn; - - const char *site_name; - const char *server_dn_str; - const char *config_dn_str; - - tmp_ctx = talloc_named(libnet_r, 0, "libnet_JoinSite temp context"); - if (!tmp_ctx) { - libnet_r->out.error_string = NULL; - return NT_STATUS_NO_MEMORY; - } - - /* Resolve the site name. */ - - ZERO_STRUCT(search); - search.in.dest_address = libnet_r->out.samr_binding->host; - search.in.acct_control = -1; - search.in.version = 6; - - cldap = cldap_socket_init(tmp_ctx, NULL); - status = cldap_netlogon(cldap, tmp_ctx, &search); - if (!NT_STATUS_IS_OK(status)) { - /* Default to using Default-First-Site-Name rather than returning status at this point. */ - site_name = talloc_asprintf(tmp_ctx, "%s", "Default-First-Site-Name"); - if (!site_name) { - libnet_r->out.error_string = NULL; - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - } else { - site_name = search.out.netlogon.logon5.site_name; - } - - config_dn_str = talloc_asprintf(tmp_ctx, "CN=Configuration,%s", libnet_r->out.domain_dn_str); - if (!config_dn_str) { - libnet_r->out.error_string = NULL; - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - - server_dn_str = talloc_asprintf(tmp_ctx, "CN=%s,CN=Servers,CN=%s,CN=Sites,%s", - libnet_r->in.netbios_name, site_name, config_dn_str); - if (!server_dn_str) { - libnet_r->out.error_string = NULL; - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - - /* - Add entry CN=<netbios name>,CN=Servers,CN=<site name>,CN=Sites,CN=Configuration,<domain dn>. - */ - msg = ldb_msg_new(tmp_ctx); - if (!msg) { - libnet_r->out.error_string = NULL; - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - - rtn = ldb_msg_add_string(msg, "objectClass", "server"); - if (rtn != 0) { - libnet_r->out.error_string = NULL; - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - rtn = ldb_msg_add_string(msg, "systemFlags", "50000000"); - if (rtn != 0) { - libnet_r->out.error_string = NULL; - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - rtn = ldb_msg_add_string(msg, "serverReference",libnet_r->out.account_dn_str); - if (rtn != 0) { - libnet_r->out.error_string = NULL; - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - - server_dn = ldb_dn_explode(tmp_ctx, server_dn_str); - if (server_dn == NULL) { - libnet_r->out.error_string = talloc_asprintf(libnet_r, - "Invalid server dn: %s", - server_dn_str); - talloc_free(tmp_ctx); - return NT_STATUS_UNSUCCESSFUL; - } - - msg->dn = server_dn; - - rtn = ldb_add(remote_ldb, msg); - if (rtn == LDB_ERR_ENTRY_ALREADY_EXISTS) { - int i; - - /* make a 'modify' msg, and only for serverReference */ - msg = ldb_msg_new(tmp_ctx); - if (!msg) { - libnet_r->out.error_string = NULL; - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - msg->dn = server_dn; - - rtn = ldb_msg_add_string(msg, "serverReference",libnet_r->out.account_dn_str); - if (rtn != 0) { - libnet_r->out.error_string = NULL; - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - - /* mark all the message elements (should be just one) - as LDB_FLAG_MOD_REPLACE */ - for (i=0;i<msg->num_elements;i++) { - msg->elements[i].flags = LDB_FLAG_MOD_REPLACE; - } - - rtn = ldb_modify(remote_ldb, msg); - if (rtn != 0) { - libnet_r->out.error_string - = talloc_asprintf(libnet_r, - "Failed to modify server entry %s: %s: %d", - server_dn_str, - ldb_errstring(remote_ldb), rtn); - talloc_free(tmp_ctx); - return NT_STATUS_INTERNAL_DB_CORRUPTION; - } - } else if (rtn != 0) { - libnet_r->out.error_string - = talloc_asprintf(libnet_r, - "Failed to add server entry %s: %s: %d", - server_dn_str, - ldb_errstring(remote_ldb), rtn); - talloc_free(tmp_ctx); - return NT_STATUS_INTERNAL_DB_CORRUPTION; - } - DEBUG(0, ("We still need to perform a DsAddEntry() so that we can create the CN=NTDS Settings container.\n")); - - /* Store the server DN in libnet_r */ - libnet_r->out.server_dn_str = server_dn_str; - talloc_steal(libnet_r, server_dn_str); - - talloc_free(tmp_ctx); - return NT_STATUS_OK; -} - -/* * complete a domain join, when joining to a AD domain: * 1.) connect and bind to the DRSUAPI pipe * 2.) do a DsCrackNames() to find the machine account dn @@ -532,10 +367,8 @@ static NTSTATUS libnet_JoinADSDomain(struct libnet_context *ctx, struct libnet_J r->out.kvno = kvno; - if (r->in.acct_type == ACB_SVRTRUST) { - status = libnet_JoinSite(ctx, - drsuapi_pipe, drsuapi_bind_handle, - remote_ldb, r); + if (r->in.acct_type == ACB_SVRTRUST) { + status = libnet_JoinSite(remote_ldb, r); } talloc_free(tmp_ctx); |