4.1.29.2.9 DuplicateObject

 Procedure DuplicateObject (
              originalObj : DSName, 
              newObjParent : DSName, 
              newObjRdn : string, 
              tlInfo : TranslationInfo) : DSName

Informative summary of behavior: This procedure creates a new object by copying data from an existing object. When copying data, it replaces any reference to the original DC in the object data with a reference to the new DC. The new object is created under newObjectParent and its RDN is set to newObjRdn.

 Procedure DuplicateObject (
              originalObj : DSName, 
              newObjParent : DSName, 
              newObjRdn : string, 
              tlInfo : TranslationInfo) : DSName
  
     newObj : DSName
     forwardLinkAttribute : string
     referenceObj : DSName
  
     newObj!distinguishedName := newObjRdn + ',' + 
         newObjParent!distinguishedName
  
     foreach attribute in originalObj!attr
       if attribute in {
           objectClass, objectCategory, userAccountControl,
           hasMasterNCs, msDS-hasMasterNCs, dMDLocation, msDS-HasDomainNCs,
           options, systemFlags, showInAdvancedViewOnly,
           msDS-NeverRevealGroup, msDS-RevealOnDemandGroup,
           msDS-RevealedUsers, managedBy, msDS-Behavior-Version,
           msDS-HasDomainNCs, msDS-hasFullReplicaNCs, enabledConnection,
           fromServer} then
         newObj!attribute := originalObj!attribute
       else if attribute in {sAMAccountName, dNSHostName} then
         newObj!attribute.Value := ReplaceName(originalObj!attribute.Value, 
                  tlInfo.originalDC.Name, tlInfo.newDC.Name)
       else if attribute in {serverReference, msDS-KrbTgtLink,
             msDFSR-ComputerReference} then
         /* replace reference to original DC-related object with new
            DC object using objMap*/
         newObj!attribute.Value :=
             tlInfo.objMap[originalObj!distinguishedName]
       else if attribute = servicePrincipalName then
           foreach servicePrincipalName in originalDC!servicePrincipalName
               newServicePrincipalName : string
               newServicePrincipalName := servicePrincipalName
               if newServicePrincipalName contains tlInfo.OriginalDC.Name then
                   newServicePrincipalName :=
                       ReplaceName(newServicePrincipalName,
                                   tlInfo.OriginalDC.Name,
                                   tlInfo.NewDC.Name)
                   newObj!servicePricipalName :=
                       newObj!servicePricipalName +
                       {newServicePrincipalName}
               else if newServicePrincipalName
                     contains(tlInfo.originalDC.dnsHostName) then
                   newServicePrincipalName :=
                       ReplaceName(newServicePrincipalName,
                                   tlInfo.OriginalDC.dnsHostName,
                                   tlInfo.newDC.dnsHostName)
                   newObj!servicePricipalName :=
                       newObj!servicePricipalName +
                       {newServicePrincipalName}
               endif
           endfor
       else if attribute = invocationId then
           newObj!invocationId := a random guid
       else if attribute = nTSecurityDescriptor then
           if tlInfo.newDC.Sid ≠ null then
               newObj!nTSecurityDescriptor := ReplaceSIDInSecurityDescriptor ( 
                     originalDC!nTSecurityDescriptor, tlInfo.originalDC.Sid,
                     tlInfo.newDC.Sid)
           endif
       endif
     endfor
  
     /* If a back link points to the original DC object, update the forward
        link in the referenced object
     */
     foreach attribute in originalObj!Attributes
         if attribute in {memberOf, msDS-NC-RO-Replica-Locations-BL} then
            if attribute = isMemberOf then
                forwardLinkAttribute := member
            else if attribute = msDS-NC-RO-Replica-Locations-BL then
                forwardLinkAttribute := msDS-NC-RO-Replica-Locations
            endIf
            if tlInfo.objMap.Keys.exists(originalObj!attribute) then
                referenceObj := tlInfo.objMap[originalObj!attribute]
            else
                referenceObj := select o from all 
                  where o!distinguishedName = originalObj!attribute
            endif
            referenceObj!forwardLinkAttribute := newObj
         endif
     endfor
     return newObj
Show: