blob: 7deb4ec09b39635caebde15de365e766c0fb570e [file] [log] [blame]
This patch is for a Samba bug [1] which results in creating a new
computer account in the default location instead of correctly
using a pre-created computer account if it already exists in
a non-default location (ie. different OU).
[1] - https://bugzilla.samba.org/show_bug.cgi?id=12696
diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c
index a356e40..1de1476 100644
--- a/source3/libnet/libnet_join.c
+++ b/source3/libnet/libnet_join.c
@@ -300,6 +300,7 @@ static ADS_STATUS libnet_join_precreate_machine_acct(TALLOC_CTX *mem_ctx,
LDAPMessage *res = NULL;
const char *attrs[] = { "dn", NULL };
bool moved = false;
+ const char *initial_account_ou = r->in.account_ou;
status = ads_check_ou_dn(mem_ctx, r->in.ads, &r->in.account_ou);
if (!ADS_ERR_OK(status)) {
@@ -332,6 +333,16 @@ static ADS_STATUS libnet_join_precreate_machine_acct(TALLOC_CTX *mem_ctx,
} else if ((status.error_type == ENUM_ADS_ERROR_LDAP) &&
(status.err.rc == LDAP_ALREADY_EXISTS)) {
status = ADS_SUCCESS;
+
+ if (initial_account_ou == NULL) {
+ /*
+ * Account already existed and
+ * admin didn't explicitly specify
+ * a different OU. Don't move the
+ * account, just return.
+ */
+ return status;
+ }
}
if (!ADS_ERR_OK(status)) {