diff options
-rw-r--r-- | source4/libnet/libnet_become_dc.c | 112 |
1 files changed, 111 insertions, 1 deletions
diff --git a/source4/libnet/libnet_become_dc.c b/source4/libnet/libnet_become_dc.c index cda31bc446..420c13efc1 100644 --- a/source4/libnet/libnet_become_dc.c +++ b/source4/libnet/libnet_become_dc.c @@ -98,6 +98,8 @@ struct libnet_BecomeDC_state { const char *ntds_dn_str; struct GUID ntds_guid; } infrastructure_fsmo; + + struct becomeDC_fsmo rid_manager_fsmo; }; static void becomeDC_connect_ldap1(struct libnet_BecomeDC_state *s); @@ -394,6 +396,9 @@ static NTSTATUS becomeDC_ldap1_infrastructure_fsmo(struct libnet_BecomeDC_state server_dn = ldb_dn_get_parent(s, ntds_dn); NT_STATUS_HAVE_NO_MEMORY(server_dn); + s->infrastructure_fsmo.server_dn_str = ldb_dn_alloc_linearized(s, server_dn); + NT_STATUS_HAVE_NO_MEMORY(s->infrastructure_fsmo.server_dn_str); + ret = ldb_search(s->ldap1.ldb, server_dn, LDB_SCOPE_BASE, "(objectClass=*)", dns_attrs, &r); if (ret != LDB_SUCCESS) { @@ -422,7 +427,109 @@ static NTSTATUS becomeDC_ldap1_infrastructure_fsmo(struct libnet_BecomeDC_state talloc_free(r); - return NT_STATUS_NOT_IMPLEMENTED; + return NT_STATUS_OK; +} + +static NTSTATUS becomeDC_ldap1_rid_manager_fsmo(struct libnet_BecomeDC_state *s) +{ + int ret; + struct ldb_result *r; + struct ldb_dn *basedn; + const char *reference_dn_str; + struct ldb_dn *ntds_dn; + struct ldb_dn *server_dn; + static const char *rid_attrs[] = { + "rIDManagerReference", + NULL + }; + static const char *fsmo_attrs[] = { + "fSMORoleOwner", + NULL + }; + static const char *dns_attrs[] = { + "dnsHostName", + NULL + }; + static const char *guid_attrs[] = { + "objectGUID", + NULL + }; + + basedn = ldb_dn_new(s, s->ldap1.ldb, s->domain.dn_str); + NT_STATUS_HAVE_NO_MEMORY(basedn); + + ret = ldb_search(s->ldap1.ldb, basedn, LDB_SCOPE_BASE, + "(objectClass=*)", rid_attrs, &r); + talloc_free(basedn); + if (ret != LDB_SUCCESS) { + return NT_STATUS_LDAP(ret); + } else if (r->count != 1) { + talloc_free(r); + return NT_STATUS_INVALID_NETWORK_RESPONSE; + } + + reference_dn_str = samdb_result_string(r->msgs[0], "rIDManagerReference", NULL); + if (!reference_dn_str) return NT_STATUS_INVALID_NETWORK_RESPONSE; + + basedn = ldb_dn_new(s, s->ldap1.ldb, reference_dn_str); + NT_STATUS_HAVE_NO_MEMORY(basedn); + + talloc_free(r); + + ret = ldb_search(s->ldap1.ldb, basedn, LDB_SCOPE_BASE, + "(objectClass=*)", fsmo_attrs, &r); + talloc_free(basedn); + if (ret != LDB_SUCCESS) { + return NT_STATUS_LDAP(ret); + } else if (r->count != 1) { + talloc_free(r); + return NT_STATUS_INVALID_NETWORK_RESPONSE; + } + + s->rid_manager_fsmo.ntds_dn_str = samdb_result_string(r->msgs[0], "fSMORoleOwner", NULL); + if (!s->rid_manager_fsmo.ntds_dn_str) return NT_STATUS_INVALID_NETWORK_RESPONSE; + talloc_steal(s, s->rid_manager_fsmo.ntds_dn_str); + + talloc_free(r); + + ntds_dn = ldb_dn_new(s, s->ldap1.ldb, s->rid_manager_fsmo.ntds_dn_str); + NT_STATUS_HAVE_NO_MEMORY(ntds_dn); + + server_dn = ldb_dn_get_parent(s, ntds_dn); + NT_STATUS_HAVE_NO_MEMORY(server_dn); + + s->rid_manager_fsmo.server_dn_str = ldb_dn_alloc_linearized(s, server_dn); + NT_STATUS_HAVE_NO_MEMORY(s->rid_manager_fsmo.server_dn_str); + + ret = ldb_search(s->ldap1.ldb, server_dn, LDB_SCOPE_BASE, + "(objectClass=*)", dns_attrs, &r); + if (ret != LDB_SUCCESS) { + return NT_STATUS_LDAP(ret); + } else if (r->count != 1) { + talloc_free(r); + return NT_STATUS_INVALID_NETWORK_RESPONSE; + } + + s->rid_manager_fsmo.dns_name = samdb_result_string(r->msgs[0], "dnsHostName", NULL); + if (!s->rid_manager_fsmo.dns_name) return NT_STATUS_INVALID_NETWORK_RESPONSE; + talloc_steal(s, s->rid_manager_fsmo.dns_name); + + talloc_free(r); + + ret = ldb_search(s->ldap1.ldb, ntds_dn, LDB_SCOPE_BASE, + "(objectClass=*)", guid_attrs, &r); + if (ret != LDB_SUCCESS) { + return NT_STATUS_LDAP(ret); + } else if (r->count != 1) { + talloc_free(r); + return NT_STATUS_INVALID_NETWORK_RESPONSE; + } + + s->rid_manager_fsmo.ntds_guid = samdb_result_guid(r->msgs[0], "objectGUID"); + + talloc_free(r); + + return NT_STATUS_OK; } @@ -451,6 +558,9 @@ static void becomeDC_connect_ldap1(struct libnet_BecomeDC_state *s) c->status = becomeDC_ldap1_infrastructure_fsmo(s); if (!composite_is_ok(c)) return; + c->status = becomeDC_ldap1_rid_manager_fsmo(s); + if (!composite_is_ok(c)) return; + composite_error(c, NT_STATUS_NOT_IMPLEMENTED); } |