summaryrefslogtreecommitdiff
path: root/source4/libnet
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-12-05 13:21:47 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:28:53 -0500
commit047f2c7091581b629bac96970ff92b07ab118172 (patch)
tree50def8970ff2ee9c26d16988407cbfdea17ae687 /source4/libnet
parenta99d5b799b27e818857dc55f09d4b107d248bf73 (diff)
downloadsamba-047f2c7091581b629bac96970ff92b07ab118172.tar.gz
samba-047f2c7091581b629bac96970ff92b07ab118172.tar.bz2
samba-047f2c7091581b629bac96970ff92b07ab118172.zip
r20042: move the computer account to the CN=Computers container if needed
metze (This used to be commit f9019565980058439091c4e17256676f7bbde044)
Diffstat (limited to 'source4/libnet')
-rw-r--r--source4/libnet/libnet_unbecome_dc.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/source4/libnet/libnet_unbecome_dc.c b/source4/libnet/libnet_unbecome_dc.c
index c0629a6949..8f7122732a 100644
--- a/source4/libnet/libnet_unbecome_dc.c
+++ b/source4/libnet/libnet_unbecome_dc.c
@@ -266,6 +266,57 @@ static NTSTATUS unbecomeDC_ldap_modify_computer(struct libnet_UnbecomeDC_state *
return NT_STATUS_OK;
}
+static NTSTATUS unbecomeDC_ldap_move_computer(struct libnet_UnbecomeDC_state *s)
+{
+ int ret;
+ struct ldb_result *r;
+ struct ldb_dn *basedn;
+ struct ldb_dn *old_dn;
+ struct ldb_dn *new_dn;
+ static const char *_1_1_attrs[] = {
+ "1.1",
+ NULL
+ };
+
+ basedn = ldb_dn_new_fmt(s, s->ldap.ldb, "<WKGUID=aa312825768811d1aded00c04fd8d5cd,%s>",
+ s->domain.dn_str);
+ NT_STATUS_HAVE_NO_MEMORY(basedn);
+
+ ret = ldb_search(s->ldap.ldb, basedn, LDB_SCOPE_BASE,
+ "(objectClass=*)", _1_1_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;
+ }
+
+ old_dn = ldb_dn_new(r, s->ldap.ldb, s->dest_dsa.computer_dn_str);
+ NT_STATUS_HAVE_NO_MEMORY(old_dn);
+
+ new_dn = r->msgs[0]->dn;
+
+ if (!ldb_dn_add_child_fmt(new_dn, "CN=%s", s->dest_dsa.netbios_name)) {
+ talloc_free(r);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ if (ldb_dn_compare(old_dn, new_dn) == 0) {
+ /* we don't need to rename if the old and new dn match */
+ talloc_free(r);
+ return NT_STATUS_OK;
+ }
+
+ ret = ldb_rename(s->ldap.ldb, old_dn, new_dn);
+ talloc_free(r);
+ if (ret != LDB_SUCCESS) {
+ return NT_STATUS_LDAP(ret);
+ }
+
+ return NT_STATUS_OK;
+}
+
static void unbecomeDC_connect_ldap(struct libnet_UnbecomeDC_state *s)
{
struct composite_context *c = s->creq;
@@ -282,6 +333,9 @@ static void unbecomeDC_connect_ldap(struct libnet_UnbecomeDC_state *s)
c->status = unbecomeDC_ldap_modify_computer(s);
if (!composite_is_ok(c)) return;
+ c->status = unbecomeDC_ldap_move_computer(s);
+ if (!composite_is_ok(c)) return;
+
composite_error(c, NT_STATUS_NOT_IMPLEMENTED);
}