Directory Services |
The LDAP_SERVER_CROSSDOM_MOVE_TARGET_OID control is used with an extended LDAP rename function to move an LDAP object from one domain to another. The control specifies the DNS hostname of the domain controller in the destination domain.
To use this control, set the members of the LDAPControl structure as follows:
PWCHAR ldctl_oid = LDAP_SERVER_CROSSDOM_MOVE_TARGET_OID; struct berval ldctl_value; BOOLEAN ldctl_iscritical;
The following code example shows how to use the cross-domain control with the ldap_rename_ext_s function.
ULONG LDAPCrossDom ( LDAP *ldapConnection, PWCHAR pszOldDN, // source object DN in Unicode PWCHAR pszNewRDN, // destination object DN in Unicode PWCHAR pszNewParent, // destination object parent DN in Unicode PWCHAR pszDestDomain) // destination domain DNS name in unicode { ULONG ulErr; LDAPControl CrossDomControl; PLDAPControl controlArray[] = { &CrossDomControl, NULL }; LPSTR pszDestDomainUTF8 = NULL; int iDDSrclen = 0; int iDDlen; berval bvValue; // Verify input parameters. if (pszOldDN == NULL || pszNewRDN == NULL || pszNewParent == NULL || pszDestDomain == NULL ) return LDAP_PARAM_ERROR; // Get required length of UTF-8 string buffer. iDDSrclen = wcslen(pszDestDomain); iDDlen = LdapUnicodeToUTF8(pszDestDomain,iDDSrclen,NULL,0); // Check for zero length string if (0 == iDDlen) return LDAP_PARAM_ERROR; // Allocate buffer for UTF-8 string. pszDestDomainUTF8 = (LPSTR) malloc(iDDlen+1); if (pszDestDomainUTF8 == NULL) return LDAP_NO_MEMORY; // Convert Unicode to UTF-8. LdapUnicodeToUTF8(pszDestDomain,iDDSrclen,pszDestDomainUTF8,iDDlen+1); pszDestDomainUTF8[iDDlen] = '\0'; // Setup control data. bvValue.bv_val = (PCHAR) pszDestDomainUTF8; bvValue.bv_len = iDDlen; // Setup control. CrossDomControl.ldctl_oid = LDAP_SERVER_CROSSDOM_MOVE_TARGET_OID_W; CrossDomControl.ldctl_value = bvValue; CrossDomControl.ldctl_iscritical = TRUE; controlArray[0] = &CrossDomControl; controlArray[1] = NULL; // Rename object across domains. ulErr = ldap_rename_ext_s(ldapConnection, pszOldDN, pszNewRDN, pszNewParent, TRUE, controlArray, NULL); if (LDAP_SUCCESS == ulErr) wprintf(L"Successful move\n"); if (NULL != pszDestDomainUTF8) free(pszDestDomainUTF8); return ulErr; }
Note The user application must have the proper directory service access rights to successfully use this control. The user application must have permission to delete objects in the source domain and create objects in the destination domain.
Client: Included in Windows XP and
Windows 2000 Professional.
Server: Included in Windows Server 2003 and
Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension
on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Ntldap.h.