From d5b62b5901ed5861e53a47c236e1ca5e0452e86c Mon Sep 17 00:00:00 2001 From: Anatoliy Atanasov Date: Mon, 2 Aug 2010 16:47:38 +0300 Subject: [PATCH] s4/vampire: update dNSHostName for the Server object --- source4/libnet/libnet_vampire.c | 58 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 58 insertions(+), 0 deletions(-) diff --git a/source4/libnet/libnet_vampire.c b/source4/libnet/libnet_vampire.c index b85869e..eb69e69 100644 --- a/source4/libnet/libnet_vampire.c +++ b/source4/libnet/libnet_vampire.c @@ -40,6 +40,7 @@ #include "param/param.h" #include "param/provision.h" #include "libcli/security/dom_sid.h" +#include "dsdb/common/util.h" /* List of tasks vampire.py must perform: @@ -88,6 +89,7 @@ struct libnet_vampire_cb_state { struct tevent_context *event_ctx; unsigned total_objects; char *last_partition; + const char *server_dn_str; }; /* Caller is expected to keep supplied pointers around for the lifetime of the structure */ @@ -152,6 +154,7 @@ NTSTATUS libnet_vampire_cb_prepare_db(void *private_data, s->ldb = talloc_steal(s, result.samdb); s->lp_ctx = talloc_steal(s, result.lp_ctx); s->provision_schema = dsdb_get_schema(s->ldb, s); + s->server_dn_str = talloc_steal(s, p->dest_dsa->server_dn_str); /* wrap the entire vapire operation in a transaction. This isn't just cosmetic - we use this to ensure that linked @@ -701,6 +704,55 @@ NTSTATUS libnet_vampire_cb_store_chunk(void *private_data, return NT_STATUS_OK; } +static NTSTATUS update_dnshostname_for_server(TALLOC_CTX *mem_ctx, + struct ldb_context *ldb, + const char *server_dn_str, + const char *netbios_name, + const char *realm) +{ + int ret; + struct ldb_message *msg; + struct ldb_message_element *el; + struct ldb_dn *server_dn; + const char *dNSHostName = strlower_talloc(mem_ctx, + talloc_asprintf(mem_ctx, + "%s.%s", + netbios_name, + realm)); + msg = ldb_msg_new(mem_ctx); + if (msg == NULL) { + return NT_STATUS_NO_MEMORY; + } + + server_dn = ldb_dn_new(mem_ctx, ldb, server_dn_str); + if (!server_dn) { + return NT_STATUS_INTERNAL_ERROR; + } + + msg->dn = server_dn; + ret = ldb_msg_add_empty(msg, "dNSHostName", LDB_FLAG_MOD_ADD, &el); + if (ret != LDB_SUCCESS) { + return NT_STATUS_NO_MEMORY; + } + + ret = ldb_msg_add_steal_string(msg, + "dNSHostName", + talloc_asprintf(el->values, "%s", dNSHostName)); + if (ret != LDB_SUCCESS) { + return NT_STATUS_INTERNAL_ERROR; + } + + ret = dsdb_modify(ldb, msg, DSDB_MODIFY_PERMISSIVE); + if (ret != LDB_SUCCESS) { + DEBUG(0,(__location__ ": Failed to add dnsHostName to the Server object: %s\n", + ldb_errstring(ldb))); + return NT_STATUS_INTERNAL_ERROR; + } + + return NT_STATUS_OK; +} + + NTSTATUS libnet_Vampire(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_Vampire *r) { @@ -880,6 +932,12 @@ NTSTATUS libnet_Vampire(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, return NT_STATUS_INTERNAL_DB_ERROR; } + /* during dcpromo the 2nd computer adds dNSHostName attribute to his Server object + * the attribute appears on the original DC after replication + */ + + update_dnshostname_for_server(s, s->ldb, s->server_dn_str, s->netbios_name, s->realm); + talloc_free(s); return NT_STATUS_OK; -- 1.7.0.4