mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Gaetan Boismal
12.55.2016 067a169bbdbe738f4bdd6dafe3eef133aee078c9
OPENDJ-2830 Fix ldifsearch size limit

If size limit was reached, ldifsearch returned 0 instead of the size
limit exceeded result code (4).
This commit fixes the issue by throwing an LDAPException in the reader
and catching it in LDIFSearch.
2 files modified
36 ■■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIF.java 22 ●●●● patch | view | raw | blame | history
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java 14 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldif/LDIF.java
@@ -16,6 +16,7 @@
package org.forgerock.opendj.ldif;
import static com.forgerock.opendj.ldap.CoreMessages.*;
import static org.forgerock.opendj.ldap.LdapException.newLdapException;
import java.io.IOException;
import java.io.StringWriter;
@@ -48,6 +49,7 @@
import org.forgerock.opendj.ldap.Modification;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.RDN;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.controls.SubtreeDeleteRequestControl;
import org.forgerock.opendj.ldap.requests.AddRequest;
@@ -699,16 +701,16 @@
            public boolean hasNext() throws IOException {
                if (nextEntry == null) {
                    final int sizeLimit = search.getSizeLimit();
                    if (sizeLimit == 0 || entryCount < sizeLimit) {
                        final DN baseDN = search.getName();
                        final SearchScope scope = search.getScope();
                        while (input.hasNext()) {
                            final Entry entry = input.readEntry();
                            if (entry.getName().isInScopeOf(baseDN, scope)
                                    && matcher.matches(entry).toBoolean()) {
                                nextEntry = filterEntry(entry);
                                break;
                            }
                    if (sizeLimit != 0 && entryCount >= sizeLimit) {
                        throw newLdapException(ResultCode.SIZE_LIMIT_EXCEEDED);
                    }
                    final DN baseDN = search.getName();
                    final SearchScope scope = search.getScope();
                    while (input.hasNext()) {
                        final Entry entry = input.readEntry();
                        if (entry.getName().isInScopeOf(baseDN, scope) && matcher.matches(entry).toBoolean()) {
                            nextEntry = filterEntry(entry);
                            break;
                        }
                    }
                }
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java
@@ -17,6 +17,7 @@
import static com.forgerock.opendj.cli.ArgumentConstants.*;
import static com.forgerock.opendj.cli.ToolVersionHandler.newSdkVersionHandler;
import static com.forgerock.opendj.ldap.tools.LDAPToolException.newToolException;
import static com.forgerock.opendj.ldap.tools.LDAPToolException.newToolParamException;
import static com.forgerock.opendj.ldap.tools.ToolsMessages.*;
import static com.forgerock.opendj.cli.Utils.filterExitCode;
@@ -38,6 +39,7 @@
import org.forgerock.i18n.LocalizedIllegalArgumentException;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.Filter;
import org.forgerock.opendj.ldap.LdapException;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.requests.Requests;
@@ -195,13 +197,13 @@
             final LDIFEntryWriter outputWriter = new LDIFEntryWriter(getLDIFToolOutputStream(this, outputFilename))) {
            outputWriter.setWrapColumn(computeWrapColumn(wrapColumn));
            LDIF.copyTo(LDIF.search(sourceReader, search), outputWriter);
        } catch (final LdapException e) {
            throw newToolException(
                    e, e.getResult().getResultCode(), ERR_LDIFSEARCH_FAILED.get(e.getLocalizedMessage()));
        } catch (final IOException e) {
            if (e instanceof LocalizableException) {
                errPrintln(ERR_LDIFSEARCH_FAILED.get(((LocalizableException) e).getMessageObject()));
            } else {
                errPrintln(ERR_LDIFSEARCH_FAILED.get(e.getLocalizedMessage()));
            }
            return ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue();
            throw newToolException(e, ResultCode.CLIENT_SIDE_LOCAL_ERROR, ERR_LDIFSEARCH_FAILED.get(
                    e instanceof LocalizableException ? ((LocalizableException) e).getMessageObject()
                                                      : e.getLocalizedMessage()));
        } catch (final ArgumentException ae) {
            throw newToolParamException(ae, ae.getMessageObject());
        }