/// <summary>
        /// Creates a ModifyDNRequest packet.
        /// </summary>
        /// <param name="context">The user context which contains message ID.</param>
        /// <param name="oldDn">The original DN to be modified.</param>
        /// <param name="newRdn">The new relative DN.</param>
        /// <param name="newParentDn">
        /// The new parent DN. For LDAP v3 only. Ignored when creating LDAP v2 requests.
        /// </param>
        /// <param name="delOldRdn">
        /// Whether to delete old RDN. For LDAP v3 only. Ignored when creating LDAP v2 requests.
        /// </param>
        /// <returns>The packet that contains the request.</returns>
        internal override AdtsModifyDnRequestPacket CreateModifyDnRequest(
            AdtsLdapContext context,
            string oldDn,
            string newRdn,
            string newParentDn,
            bool delOldRdn)
        {
            ModifyDNRequest modifyDnRequest = new ModifyDNRequest(
                new LDAPDN(oldDn ?? string.Empty),
                new RelativeLDAPDN(newRdn ?? string.Empty),
                new Asn1Boolean(delOldRdn),
                new LDAPDN(newParentDn));

            LDAPMessage_protocolOp operation = new LDAPMessage_protocolOp();

            operation.SetData(LDAPMessage_protocolOp.modifyDNRequest, modifyDnRequest);

            LDAPMessage message = new LDAPMessage(new MessageID(context.MessageId), operation);
            AdtsModifyDnRequestPacket packet = new AdtsModifyDnRequestPacket();

            packet.ldapMessagev2 = message;
            packet.messageId     = context.MessageId;

            return(packet);
        }
Beispiel #2
0
        /// <summary>
        /// Moves and / or renames an entry in the directory.
        /// </summary>
        /// <param name="distinguishedName">The distinguished name of the entry to move or rename.</param>
        /// <param name="newParentDistinguishedName">The distinguished name of the entry's new parent entry in the directory (if moving), or its current parent entry (if renaming).</param>
        /// <param name="newCommonName">The new common name of entry.</param>
        /// <returns>True if moved or renamed, false otherwise.</returns>
        public bool MoveRenameEntry(string distinguishedName, string newParentDistinguishedName, string newCommonName)
        {
            if (!string.IsNullOrWhiteSpace(distinguishedName) && !string.IsNullOrWhiteSpace(newParentDistinguishedName) && !string.IsNullOrWhiteSpace(newCommonName))
            {
                // Prepend the CN= if not already included.
                if (!newCommonName.StartsWith("CN="))
                {
                    newCommonName = "CN=" + newCommonName;
                }
                ModifyDNRequest request = new ModifyDNRequest(distinguishedName, newParentDistinguishedName, newCommonName);
                try
                {
                    ModifyDNResponse response = (ModifyDNResponse)connection.SendRequest(request);

                    // Check that a response was received.
                    if (response != null)
                    {
                        // A response was received.
                        if (response.ResultCode == ResultCode.Success)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        // A response was not received.
                        return(false);
                    }
                }
                catch
                {
                }
            }
            return(false);
        }
        public virtual DirectoryRequest[] GetUpdate()
        {
            var result = new List <DirectoryRequest>();

            if (Changes.ContainsKey(NameAttribute))
            {
                string orignalDn = Key;
                Key = string.Format("cn={0},{1}", Name, ContainerDn);

                ModifyDNRequest mdr = new ModifyDNRequest();
                mdr.DistinguishedName          = orignalDn;
                mdr.NewName                    = "cn=" + Name;
                mdr.NewParentDistinguishedName = ContainerDn;
                mdr.DeleteOldRdn               = true;

                result.Add(mdr);
            }

            ModifyRequest mr = new ModifyRequest();

            mr.DistinguishedName = Key;

            SetAttribute(mr.Modifications, DESCRIPTION, Description);
//			SetAttribute(mr.Modifications, NAME, Name);

            result.Add(mr);
            return(result.ToArray());
        }
        public void UpdateDN(string uniqueName, string originalName)
        {
            if (uniqueName == originalName)
            {
                return;
            }

            ModifyDNRequest mdr = new ModifyDNRequest();

            mdr.DistinguishedName = originalName;
            mdr.NewName           = uniqueName;

            using (LdapConnection conn = GetConnection())
                try
                {
                    conn.SendRequest(mdr);
                }
                finally
                {
                    if (conn != null)
                    {
                        conn.Dispose();
                    }
                }
        }
        public void DistinguishedName_Set_GetReturnsExpected()
        {
            var request = new ModifyDNRequest {
                DistinguishedName = "Name"
            };

            Assert.Equal("Name", request.DistinguishedName);
        }
        public void NewName_Set_GetReturnsExpected()
        {
            var request = new ModifyDNRequest {
                NewName = "NewName"
            };

            Assert.Equal("NewName", request.NewName);
        }
        public void DeleteOldRdn_Set_GetReturnsExpected()
        {
            var request = new ModifyDNRequest {
                DeleteOldRdn = false
            };

            Assert.False(request.DeleteOldRdn);
        }
        public void RequestId_Set_GetReturnsExpected()
        {
            var request = new ModifyDNRequest {
                RequestId = "Id"
            };

            Assert.Equal("Id", request.RequestId);
        }
Beispiel #9
0
        public void TestMoveAndRenameUser()
        {
            using (LdapConnection connection = GetConnection())
            {
                string ouName1 = "ProtocolsGroup7.1";
                string dn1     = "ou=" + ouName1;

                string ouName2 = "ProtocolsGroup7.2";
                string dn2     = "ou=" + ouName2;

                string userDn1 = "cn=protocolUser7.1" + "," + dn1;
                string userDn2 = "cn=protocolUser7.2" + "," + dn2;

                DeleteEntry(connection, userDn1);
                DeleteEntry(connection, userDn2);
                DeleteEntry(connection, dn1);
                DeleteEntry(connection, dn2);

                try
                {
                    AddOrganizationalUnit(connection, dn1);
                    SearchResultEntry sre = SearchOrganizationalUnit(connection, LdapConfiguration.Configuration.Domain, ouName1);
                    Assert.NotNull(sre);

                    AddOrganizationalUnit(connection, dn2);
                    sre = SearchOrganizationalUnit(connection, LdapConfiguration.Configuration.Domain, ouName2);
                    Assert.NotNull(sre);

                    AddOrganizationalRole(connection, userDn1);

                    string user1Root = dn1 + "," + LdapConfiguration.Configuration.Domain;
                    string user2Root = dn2 + "," + LdapConfiguration.Configuration.Domain;

                    sre = SearchUser(connection, user1Root, "protocolUser7.1");
                    Assert.NotNull(sre);

                    ModifyDNRequest modDnRequest = new ModifyDNRequest(userDn1 + "," + LdapConfiguration.Configuration.Domain,
                                                                       dn2 + "," + LdapConfiguration.Configuration.Domain,
                                                                       "cn=protocolUser7.2");
                    ModifyDNResponse modDnResponse = (ModifyDNResponse)connection.SendRequest(modDnRequest);
                    Assert.Equal(ResultCode.Success, modDnResponse.ResultCode);

                    sre = SearchUser(connection, user1Root, "protocolUser7.1");
                    Assert.Null(sre);

                    sre = SearchUser(connection, user2Root, "protocolUser7.2");
                    Assert.NotNull(sre);
                }
                finally
                {
                    DeleteEntry(connection, userDn1);
                    DeleteEntry(connection, userDn2);
                    DeleteEntry(connection, dn1);
                    DeleteEntry(connection, dn2);
                }
            }
        }
        public ModifyDNResponse MakeModifyDistinguishedName(string currentDistinguishedName,
                                                            string parentDistinguishedName, string newName)
        {
            using (var connection = _connectionService.OpenConnection())
            {
                var request = new ModifyDNRequest(currentDistinguishedName, parentDistinguishedName, newName);

                return((ModifyDNResponse)connection.SendRequest(request));
            }
        }
        public void DRSR_DRSInterDomainMove_LDAP_Move_Object_From_Child_To_Parent()
        {
            DrsrTestChecker.Check();
            EnvironmentConfig.Machine parentDcType = EnvironmentConfig.Machine.WritableDC1;
            DsServer parentDc = (DsServer)EnvironmentConfig.MachineStore[parentDcType];

            EnvironmentConfig.Machine childDcType = EnvironmentConfig.Machine.CDC;
            DsServer childDc = (DsServer)EnvironmentConfig.MachineStore[childDcType];
            DsUser   user    = EnvironmentConfig.UserStore[EnvironmentConfig.User.ParentDomainAdmin];

            string srcObjDn = ldapAdapter.TestAddUserObj(childDc);

            BaseTestSite.Log.Add(LogEntryKind.Comment, "LDAP add a new object: {0}.", srcObjDn);
            string newObjRdn      = DrsrHelper.GetRDNFromDN(srcObjDn);
            string tgtParentObjDn = "CN=Users," + DrsrHelper.GetNamingContextDN(parentDc.Domain, NamingContext.DomainNC);
            string newObjDn       = newObjRdn + "," + tgtParentObjDn;

            bool bNewObjAdded = ldapAdapter.IsObjectExist(parentDc, newObjDn);

            if (bNewObjAdded)
            {
                ResultCode rCode = ldapAdapter.DeleteObject(parentDc, newObjDn);
                BaseTestSite.Assume.AreEqual <ResultCode>(ResultCode.Success, rCode, "LDAP: {0} should be removed.", newObjDn);
            }

            using (LdapConnection connection = new LdapConnection(new LdapDirectoryIdentifier(childDc.DnsHostName))) // connecting to the child domain in which the object exists
            {
                connection.Credential = new System.Net.NetworkCredential(user.Username, user.Password, parentDc.Domain.DNSName);
                connection.SessionOptions.ProtocolVersion = 3;
                connection.SessionOptions.SspiFlag        = connection.SessionOptions.SspiFlag | 1; //Set Delegate flag.
                connection.AuthType = AuthType.Kerberos;
                connection.Bind();
                try
                {
                    BaseTestSite.Log.Add(LogEntryKind.Comment, "LDAP ModifyDN: moving object {0} to {1}.", srcObjDn, newObjDn);
                    ModifyDNRequest modDnRequest = new ModifyDNRequest(srcObjDn, tgtParentObjDn, newObjRdn);
                    modDnRequest.Controls.Add(new CrossDomainMoveControl(parentDc.DnsHostName)); // parent domain to which the object need to move
                    ModifyDNResponse modDnResponse = (ModifyDNResponse)connection.SendRequest(modDnRequest);
                    BaseTestSite.Assert.AreEqual <ResultCode>(ResultCode.Success, modDnResponse.ResultCode,
                                                              "LDAP ModifyDN: server should invoke IDL_DRSInterDomainMove on target Dc and move the object.");

                    bool bOldObjDeleted = ldapAdapter.IsObjectExist(childDc, srcObjDn);
                    bNewObjAdded = ldapAdapter.IsObjectExist(parentDc, newObjDn);
                    BaseTestSite.Assert.IsFalse(bOldObjDeleted, "LDAP ModifyDN: the old object should be deleted from source DC.");
                    BaseTestSite.Assert.IsTrue(bNewObjAdded, "LDAP ModifyDN: the new object should be added into target DC.");
                }
                catch (DirectoryOperationException e)
                {
                    BaseTestSite.Log.Add(LogEntryKind.Debug, "LDAP ModifyDN: ResultCode:{0}", e.Response.ResultCode.ToString());
                    BaseTestSite.Log.Add(LogEntryKind.Debug, "LDAP ModifyDN: ErrorMessage:{0}", e.Response.ErrorMessage.ToString());
                    BaseTestSite.Assert.AreEqual <ResultCode>(ResultCode.Success, e.Response.ResultCode,
                                                              "LDAP ModifyDN: server should invoke the IDL_DRSInterDomainMove on target Dc and move the object.");
                }
            }
        }
        public void Ctor_Default()
        {
            var request = new ModifyDNRequest();

            Assert.Empty(request.Controls);
            Assert.Null(request.DistinguishedName);
            Assert.Null(request.NewName);
            Assert.Null(request.NewParentDistinguishedName);
            Assert.True(request.DeleteOldRdn);
            Assert.Null(request.RequestId);
        }
        public void Ctor_DistinguishedName_NewParentDistinguishedName_NewName(string distinguishedName, string newParentDistinguishedName, string newName)
        {
            var request = new ModifyDNRequest(distinguishedName, newParentDistinguishedName, newName);

            Assert.Empty(request.Controls);
            Assert.Equal(distinguishedName, request.DistinguishedName);
            Assert.Equal(newName, request.NewName);
            Assert.Equal(newParentDistinguishedName, request.NewParentDistinguishedName);
            Assert.True(request.DeleteOldRdn);
            Assert.Null(request.RequestId);
        }
Beispiel #14
0
        /// <summary>
        /// This method shows how to modify an attribute.
        /// </summary>
        /// <param name="connection">An OPEN connection to LDAP server</param>
        /// <param name="oldUid">Old user UID</param>
        /// <param name="newUid">New user UID</param>
        public static void ChangeUserUid(LdapConnection connection, string oldUid, string newUid)
        {
            var oldDn = string.Format("uid={0},ou=users,dc=example,dc=com", oldUid);
            var newDn = string.Format("uid={0},ou=users,dc=example,dc=com", newUid);

            DirectoryRequest request = new ModifyDNRequest(oldDn, "ou=users,dc=example,dc=com", "uid=" + newUid);

            connection.SendRequest(request);

            request = new ModifyRequest(newDn, DirectoryAttributeOperation.Replace, "uid", new string[] { newUid });
            connection.SendRequest(request);
        }
        public bool MoveEntry(string oldDn, string newBaseDn, string cn)
        {
            if (this.whatIf)
            {
                return(true);
            }

            var request = new ModifyDNRequest(oldDn, newBaseDn, cn);
            DirectoryResponse response = this.ldapConnection.SendRequest(request);

            ////var addResponse = response as AddResponse;
            return(response?.ResultCode == ResultCode.Success);
        }
Beispiel #16
0
        static void Rename()
        {
            // keep the parent container same to just do rename without moving
            string newParent = targetOU;
            string newName   = "OU=sampleOUNew";

            // create a request to rename the object
            ModifyDNRequest modDnRequest = new ModifyDNRequest(ou1, newParent, newName);

            // send the request through the connection
            dsmlConnection.SendRequest(modDnRequest);

            // this is the new path of the object after rename operation
            ou1 = "OU=sampleOUNew," + targetOU;
            Console.WriteLine("Object has been renamed successfully.");
        }
Beispiel #17
0
        static void Move()
        {
            // move sampleOU3 under sampleOU2
            string newParent = ou2;

            // keep the name same to just move without renaming
            string newName = "OU=sampleOU3";

            // create a request to move the object
            ModifyDNRequest modDnRequest = new ModifyDNRequest(ou3, newParent, newName);

            // send the request through the connection
            dsmlConnection.SendRequest(modDnRequest);

            Console.WriteLine("Object is moved successfully.");
        }
Beispiel #18
0
 public bool MoveUser(string username, string olddn, string newdn)
 {
     if (username != "Administrator")
     {
         try
         {
             moverequest = new ModifyDNRequest(olddn, newdn, username);
             this.connection.SendRequest(moverequest);
         }
         catch (Exception e)
         {
             Debug.WriteLine(e.Message);
             return(false);
         }
     }
     return(true);
 }
        internal static string ToLogString(this ModifyDNRequest modifyDNRequest)
        {
            var sb = new StringBuilder();

            sb.AppendLine("Modify DN Request >");
            sb.AppendLine("Current Distinguished Name: " + modifyDNRequest.DistinguishedName);
            sb.AppendLine("New Naming Context: " + modifyDNRequest.NewParentDistinguishedName);
            sb.AppendLine("New Common Name: " + modifyDNRequest.NewName);
            sb.AppendLine("Request ID: " + modifyDNRequest.RequestId);
            sb.AppendLine("Delete Old Rdn: " + modifyDNRequest.DeleteOldRdn);
            sb.AppendLine("Controls: ");
            foreach (DirectoryControl control in modifyDNRequest.Controls)
            {
                control.AppendTo(sb);
            }

            return(sb.ToString());
        }
Beispiel #20
0
        public override SyncResult OnRenameEntry(ExSearchResultEntry entry)
        {
            if (this.type != SyncTreeType.Configuration)
            {
                return(SyncResult.None);
            }
            ExSearchResultEntry targetEntry = this.GetTargetEntry(entry);

            if (targetEntry == null)
            {
                Guid empty = Guid.Empty;
                DirectoryAttribute directoryAttribute = null;
                if (entry.Attributes.TryGetValue("objectGUID", out directoryAttribute))
                {
                    byte[] b = (byte[])directoryAttribute.GetValues(typeof(byte[]))[0];
                    empty = new Guid(b);
                }
                this.logSession.LogEvent(EdgeSyncLoggingLevel.Medium, EdgeSyncEvent.TargetConnection, string.Format(CultureInfo.InvariantCulture, "Rename convert into Add/Modify for {0} because can't locate target object based on sourceGuid {1}", new object[]
                {
                    entry.DistinguishedName,
                    empty
                }), "Rename");
                return(SyncResult.None);
            }
            string          text            = DistinguishedName.ExtractRDN(entry.DistinguishedName);
            ModifyDNRequest modifyDNRequest = new ModifyDNRequest();

            modifyDNRequest.NewName                    = text;
            modifyDNRequest.DistinguishedName          = targetEntry.DistinguishedName;
            modifyDNRequest.NewParentDistinguishedName = DistinguishedName.Parent(targetEntry.DistinguishedName);
            ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string, string>((long)this.GetHashCode(), "About to rename target DN {0} with new RDN {1}", targetEntry.DistinguishedName, text);
            this.SendRequest(modifyDNRequest);
            this.logSession.LogEvent(EdgeSyncLoggingLevel.Medium, EdgeSyncEvent.TargetConnection, string.Format(CultureInfo.InvariantCulture, "Rename: Target:{0}, NewRDN:{1}", new object[]
            {
                targetEntry.DistinguishedName,
                text
            }), "Successfully Renamed Entry");
            ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string, string>((long)this.GetHashCode(), "Rename target {0} with new RDN {1}", targetEntry.DistinguishedName, text);
            return(SyncResult.Renamed);
        }
        private static async Task <ModifyDNResponse> SendModifyDnRequestAsync(LdapConnection connection, string dn, string parentDn, string newName, bool?deleteOldRDN, DirectoryControl[] controls,
                                                                              ILinqToLdapLogger log = null, PartialResultProcessing resultProcessing = LdapConfiguration.DefaultAsyncResultProcessing)
        {
            var request = new ModifyDNRequest
            {
                DistinguishedName          = dn,
                NewParentDistinguishedName = parentDn,
                NewName = newName,
            };

            if (deleteOldRDN.HasValue)
            {
                request.DeleteOldRdn = deleteOldRDN.Value;
            }
            if (controls != null)
            {
                request.Controls.AddRange(controls);
            }
            if (log != null && log.TraceEnabled)
            {
                log.Trace(request.ToLogString());
            }

#if NET45
            return(await Task.Factory.FromAsync(
                       (callback, state) =>
            {
                return connection.BeginSendRequest(request, resultProcessing, callback, state);
            },
                       (asyncresult) =>
            {
                return connection.EndSendRequest(asyncresult) as ModifyDNResponse;
            },
                       null
                       ).ConfigureAwait(false));
#else
            return(await Task.Run(() => connection.SendRequest(request) as ModifyDNResponse).ConfigureAwait(false));
#endif
        }
        private void SendMoveRequest(string newOuDn, string newName = null)
        {
            string oldName  = SplitDnParts(DistinguishedName).First();
            var    _newName = SplitDnParts(DistinguishedName).First();

            if (!String.IsNullOrWhiteSpace(newName))
            {
                if (!newName.Contains("="))
                {
                    var pre = _newName.Split("=".ToCharArray())[0];
                    _newName = $"{pre}=\"{newName}\"";
                }
                else
                {
                    _newName = newName;
                }
            }

            if (DistinguishedName == _newName)
            {
                return;
            }

            var mr = new ModifyDNRequest();

            mr.DeleteOldRdn               = true;
            mr.DistinguishedName          = DistinguishedName;
            mr.NewName                    = _newName;
            mr.NewParentDistinguishedName = newOuDn;

            var result = _ldap.Connect().SendRequest(mr);

            if (result.ResultCode == ResultCode.Success)
            {
                DistinguishedName = $"{_newName},{newOuDn}";
            }
        }
Beispiel #23
0
        private static ModifyDNResponse SendModifyDnRequest(LdapConnection connection, string dn, string parentDn, string newName, bool?deleteOldRDN, DirectoryControl[] controls, ILinqToLdapLogger log = null)
        {
            var request = new ModifyDNRequest
            {
                DistinguishedName          = dn,
                NewParentDistinguishedName = parentDn,
                NewName = newName,
            };

            if (deleteOldRDN.HasValue)
            {
                request.DeleteOldRdn = deleteOldRDN.Value;
            }
            if (controls != null)
            {
                request.Controls.AddRange(controls);
            }
            if (log != null && log.TraceEnabled)
            {
                log.Trace(request.ToLogString());
            }

            return(connection.SendRequest(request) as ModifyDNResponse);
        }
Beispiel #24
0
        /// <summary>
        /// Send all pending changes to the directory service.  If there is a pending rename / re-superior,
        /// it will fire first.
        /// </summary>
        /// <param name="ldap"></param>
        public void CommitChanges(LdapConnection ldap)
        {
            CheckForDeletion();

            if (this.IsDnDirty)
            {
                ModifyDNRequest req = new ModifyDNRequest();
                req.DistinguishedName = this.OriginalDn;

                req.NewName = this.RDN;
                logger.Info("Request new name {0}", req.NewName);

                req.DeleteOldRdn = true;

                if (this.IsSuperiorDirty)
                {
                    req.NewParentDistinguishedName = this.SuperiorDn;
                    logger.Info("Request new superior {0}", req.NewParentDistinguishedName);
                }

                ldap.SendRequest(req);

                this.IsDnDirty       = false;
                this.IsSuperiorDirty = false;
                this.OriginalDn      = this.DistinguishedName;
            }

            if (_changes.Count > 0)
            {
                if (this.IsNewEntry)
                {
                    AddRequest req = new AddRequest(this.DistinguishedName);

                    foreach (DirectoryAttributeModification dm in this.ChangesAsDAMC())
                    {
                        req.Attributes.Add(new DirectoryAttribute(dm.Name, dm.GetValues(typeof(string))));
                    }

                    ldap.SendRequest(req);
                }
                else
                {
                    ModifyRequest req = new ModifyRequest(this.DistinguishedName);

                    foreach (DirectoryAttributeModification dm in this.ChangesAsDAMC())
                    {
                        req.Modifications.Add(dm);
                    }

                    ldap.SendRequest(req);
                }

                _changes.Clear();
                this.IsNewEntry = false;

                logger.Info("Commit on {0} complete", this.DistinguishedName);
            }
            else
            {
                logger.Info("Nothing to commit on {0}", this.DistinguishedName);

                if (this.IsNewEntry)
                {
                    throw new InvalidOperationException(
                              "Cannot commit a new directory object with no attributes");
                }
            }
        }
        public static DERProtocolOperation Extract(ICollection <byte> buffer)
        {
            var result = new DERProtocolOperation();

            result.ExtractTagAndLength(buffer);
            switch (result.Tag.LdapCommand)
            {
            case LdapCommands.SearchRequest:
                result.Operation = SearchRequest.Extract(buffer);
                break;

            case LdapCommands.BindRequest:
                result.Operation = BindRequest.Extract(buffer);
                break;

            case LdapCommands.UnbindRequest:
                result.Operation = UnbindRequest.Extract(buffer);
                break;

            case LdapCommands.AddRequest:
                result.Operation = AddRequest.Extract(buffer);
                break;

            case LdapCommands.DelRequest:
                result.Operation = DelRequest.Extract(buffer, result.Length);
                break;

            case LdapCommands.ModifyDNRequest:
                result.Operation = ModifyDNRequest.Extract(buffer);
                break;

            case LdapCommands.CompareRequest:
                result.Operation = CompareRequest.Extract(buffer);
                break;

            case LdapCommands.AbandonRequest:
                result.Operation = AbandonRequest.Extract(buffer);
                break;

            case LdapCommands.ModifyRequest:
                result.Operation = ModifyRequest.Extract(buffer);
                break;

            case LdapCommands.SearchResultDone:
                result.Operation = SearchResultDone.Extract(buffer);
                break;

            case LdapCommands.BindResponse:
                result.Operation = BindResponse.Extract(buffer);
                break;

            case LdapCommands.AddResponse:
                result.Operation = AddResponse.Extract(buffer);
                break;

            case LdapCommands.SearchResultEntry:
                result.Operation = SearchResultEntry.Extract(buffer);
                break;
            }

            return(result);
        }
        /// <summary>
        /// Creates a ModifyDNRequest packet.
        /// </summary>
        /// <param name="context">The user context which contains message ID.</param>
        /// <param name="oldDn">The original DN to be modified.</param>
        /// <param name="newRdn">The new relative DN.</param>
        /// <param name="newParentDn">
        /// The new parent DN. For LDAP v3 only. Ignored when creating LDAP v2 requests.
        /// </param>
        /// <param name="delOldRdn">
        /// Whether to delete old RDN. For LDAP v3 only. Ignored when creating LDAP v2 requests.
        /// </param>
        /// <returns>The packet that contains the request.</returns>
        internal override AdtsModifyDnRequestPacket CreateModifyDnRequest(
            AdtsLdapContext context,
            string oldDn,
            string newRdn,
            string newParentDn,
            bool delOldRdn)
        {
            ModifyDNRequest modifyDnRequest = new ModifyDNRequest(
                new LDAPDN(oldDn ?? string.Empty),
                new RelativeLDAPDN(newRdn ?? string.Empty),
                new Asn1Boolean(delOldRdn),
                new LDAPDN(newParentDn ?? string.Empty));

            LDAPMessage_protocolOp operation = new LDAPMessage_protocolOp();
            operation.SetData(LDAPMessage_protocolOp.modDNRequest, modifyDnRequest);

            LDAPMessage message = new LDAPMessage(new MessageID(context.MessageId), operation, null);
            AdtsModifyDnRequestPacket packet = new AdtsModifyDnRequestPacket();
            packet.ldapMessagev3 = message;
            packet.messageId = context.MessageId;

            return packet;
        }