[ 
https://issues.apache.org/jira/browse/DIRSERVER-2308?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17098746#comment-17098746
 ] 

Emmanuel Lécharny commented on DIRSERVER-2308:
----------------------------------------------

Confirmed. If we have a new superior (even if it's the same... That could be 
optimized as a simple rename operation), then we don't check the existence of 
the target entry, leading to the problem.

{code:java}
    /**
     * {@inheritDoc}
     */
    @Override
    public void moveAndRename( MoveAndRenameOperationContext 
moveAndRenameContext ) throws LdapException
    {
        Dn oldDn = moveAndRenameContext.getDn();

        // Don't allow M&R in the SSSE
        if ( oldDn.getNormName().equals( subschemSubentryDn.getNormName() ) )
        {
            throw new LdapUnwillingToPerformException( 
ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
                subschemSubentryDn, subschemSubentryDn ) );
        }

// SOME CHECK IS MISSING HERE....
        
        // Remove the original entry from the NotAlias cache, if needed
        synchronized ( notAliasCache )
        {
            if ( notAliasCache.containsKey( oldDn.getNormName() ) )
            {
                notAliasCache.remove( oldDn.getNormName() );
            }
        }

        next( moveAndRenameContext );
    }
{code}


Here is the fix :

{code:java}
    /**
     * {@inheritDoc}
     */
    @Override
    public void moveAndRename( MoveAndRenameOperationContext 
moveAndRenameContext ) throws LdapException
    {
        Dn oldDn = moveAndRenameContext.getDn();

        // Don't allow M&R in the SSSE
        if ( oldDn.getNormName().equals( subschemSubentryDn.getNormName() ) )
        {
            throw new LdapUnwillingToPerformException( 
ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
                subschemSubentryDn, subschemSubentryDn ) );
        }
        
        // check to see if target entry exists
        Dn newDn = moveAndRenameContext.getNewDn();

        HasEntryOperationContext hasEntryContext = new 
HasEntryOperationContext( moveAndRenameContext.getSession(), newDn );
        hasEntryContext.setPartition( moveAndRenameContext.getPartition() );
        hasEntryContext.setTransaction( moveAndRenameContext.getTransaction() );

        if ( nexus.hasEntry( hasEntryContext ) )
        {
            // Ok, the target entry already exists.
            // If the target entry has the same name than the modified entry, 
it's a rename on itself,
            // we want to allow this.
            if ( !newDn.equals( oldDn ) )
            {
                throw new LdapEntryAlreadyExistsException( I18n.err( 
I18n.ERR_250_ENTRY_ALREADY_EXISTS, newDn.getName() ) );
            }
        }

        // Remove the original entry from the NotAlias cache, if needed
        synchronized ( notAliasCache )
        {
            if ( notAliasCache.containsKey( oldDn.getNormName() ) )
            {
                notAliasCache.remove( oldDn.getNormName() );
            }
        }

        next( moveAndRenameContext );
    }

{code}

> Moddn overrides existing entry
> ------------------------------
>
>                 Key: DIRSERVER-2308
>                 URL: https://issues.apache.org/jira/browse/DIRSERVER-2308
>             Project: Directory ApacheDS
>          Issue Type: Bug
>          Components: ldap
>    Affects Versions: 2.0.0.AM26
>            Reporter: Stefan Seelmann
>            Priority: Major
>             Fix For: 2.0.0.AM27
>
>
> Moddn operation where the new DN matches an already existing entry overrides 
> that entry
> {noformat}
> dn: uid=bar,dc=example,dc=com
> changetype: add
> objectClass: inetOrgPerson
> objectClass: organizationalPerson
> objectClass: person
> objectClass: top
> uid: bar
> cn: bar
> sn: bar
> dn: uid=foo,dc=example,dc=com
> changetype: add
> objectClass: inetOrgPerson
> objectClass: organizationalPerson
> objectClass: person
> objectClass: top
> uid: foo
> cn: foo
> sn: foo
> dn: uid=bar,dc=example,dc=com
> changetype: moddn
> newrdn: uid=foo
> deleteoldrdn: 1
> newsuperior: dc=example,dc=com
> {noformat}
> Result is that uid=bar is gone and uid=foo has attributes of bar.
> {noformat}
> dn: uid=foo,dc=example,dc=com
> objectClass: inetOrgPerson
> objectClass: organizationalPerson
> objectClass: person
> objectClass: top
> cn: bar
> sn: bar
> uid: foo
> {noformat}
> Expected: Error 68 (entryAlreadyExists)



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to