LDIFSearch.java revision d20053afa42700e3ec7a6f6fb474622e8680f4cc
c2a5a4a3cf815bce5fcc28180d9301a3d76023a5Mark Andrews/*
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CDDL HEADER START
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
7c74e180c206e6ed99e8beb820da5f399d845c3eDavid Lawrence * The contents of this file are subject to the terms of the
7c74e180c206e6ed99e8beb820da5f399d845c3eDavid Lawrence * Common Development and Distribution License, Version 1.0 only
7c74e180c206e6ed99e8beb820da5f399d845c3eDavid Lawrence * (the "License"). You may not use this file except in compliance
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * with the License.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * You can obtain a copy of the license at
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * trunk/opends/resource/legal-notices/OpenDS.LICENSE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * See the License for the specific language governing permissions
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * and limitations under the License.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence * When distributing Covered Code, include this CDDL HEADER in each
866d106459313499d0ca7bfccb4b2d23d5e4377cDavid Lawrence * file and include the License file at
74cb99072c4b0ebd2ccafcfa284288fa760f7a1aMark Andrews * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
866d106459313499d0ca7bfccb4b2d23d5e4377cDavid Lawrence * add the following below this CDDL HEADER, with the fields enclosed
866d106459313499d0ca7bfccb4b2d23d5e4377cDavid Lawrence * by brackets "[]" replaced with your own identifying information:
7c74e180c206e6ed99e8beb820da5f399d845c3eDavid Lawrence * Portions Copyright [yyyy] [name of copyright owner]
b4028939fdffc92cf659764deb9c6e3c805cc948Mark Andrews *
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * CDDL HEADER END
866d106459313499d0ca7bfccb4b2d23d5e4377cDavid Lawrence *
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley *
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * Portions Copyright 2006-2007 Sun Microsystems, Inc.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley */
be801b0fdbcf9b55b3a8cc6bf042ff6c86be6b11Mark Andrewspackage org.opends.server.tools;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport java.util.ArrayList;
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport java.util.Iterator;
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport java.util.LinkedHashSet;
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport java.util.LinkedList;
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport org.opends.server.core.DirectoryServer;
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport org.opends.server.extensions.ConfigFileHandler;
3d776d762914d1b675b4fd49728ce353ccf6f77eBrian Wellingtonimport org.opends.server.protocols.ldap.LDAPResultCode;
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport org.opends.server.types.AttributeType;
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrenceimport org.opends.server.types.DN;
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrenceimport org.opends.server.types.Entry;
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrenceimport org.opends.server.types.ExistingFileBehavior;
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrenceimport org.opends.server.types.LDIFExportConfig;
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrenceimport org.opends.server.types.LDIFImportConfig;
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafssonimport org.opends.server.types.ObjectClass;
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafssonimport org.opends.server.types.SearchFilter;
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafssonimport org.opends.server.types.SearchScope;
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafssonimport org.opends.server.util.LDIFException;
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafssonimport org.opends.server.util.LDIFReader;
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrenceimport org.opends.server.util.LDIFWriter;
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrenceimport org.opends.server.util.args.ArgumentException;
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrenceimport org.opends.server.util.args.ArgumentParser;
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrenceimport org.opends.server.util.args.BooleanArgument;
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrenceimport org.opends.server.util.args.FileBasedArgument;
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrenceimport org.opends.server.util.args.IntegerArgument;
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrenceimport org.opends.server.util.args.MultiChoiceArgument;
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrenceimport org.opends.server.util.args.StringArgument;
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrenceimport static org.opends.server.messages.MessageHandler.*;
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halleyimport static org.opends.server.messages.ToolMessages.*;
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halleyimport static org.opends.server.util.StaticUtils.*;
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley
8e06cea14c857429ab7e7299af2dce5eeeaa5ff0Michael Graff
ce8c568e0d6106bb87069453505e09bc66754b40Andreas Gustafsson
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley/**
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley * This class provides a program that may be used to search LDIF files. It is
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley * modeled after the LDAPSearch tool, with the primary differencing being that
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley * all of its data comes from LDIF rather than communicating over LDAP.
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley * However, it does have a number of differences that allow it to perform
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley * multiple operations in a single pass rather than requiring multiple passes
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley * through the LDIF.
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley */
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halleypublic class LDIFSearch
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley{
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley /**
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley * The fully-qualified name of this class.
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley */
8e06cea14c857429ab7e7299af2dce5eeeaa5ff0Michael Graff private static final String CLASS_NAME = "org.opends.server.tools.LDIFSearch";
8e06cea14c857429ab7e7299af2dce5eeeaa5ff0Michael Graff
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson /**
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson * The search scope string that will be used for baseObject searches.
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson */
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson private static final String SCOPE_STRING_BASE = "base";
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
b587e1d83f007ce68a9ae93097c461d8eb7aa373Mark Andrews /**
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence * The search scope string that will be used for singleLevel searches.
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence */
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence private static final String SCOPE_STRING_ONE = "one";
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence /**
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence * The search scope string that will be used for wholeSubtree searches.
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence */
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence private static final String SCOPE_STRING_SUB = "sub";
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence /**
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence * The search scope string that will be used for subordinateSubtree searches.
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence */
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence private static final String SCOPE_STRING_SUBORDINATE = "subordinate";
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence /**
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence * Provides the command line arguments to the <CODE>mainSearch</CODE> method
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence * so that they can be processed.
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence *
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence * @param args The command line arguments provided to this program.
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence */
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence public static void main(String[] args)
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence {
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence int exitCode = mainSearch(args);
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence if (exitCode != 0)
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence {
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence System.exit(exitCode);
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence }
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence }
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence /**
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence * Parses the provided command line arguments and performs the appropriate
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence * search operation.
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence *
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence * @param args The command line arguments provided to this program.
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence *
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence * @return The return code for this operation. A value of zero indicates
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence * that all processing completed successfully. A nonzero value
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence * indicates that some problem occurred during processing.
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence */
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence public static int mainSearch(String[] args)
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence {
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence LinkedHashSet<String> scopeStrings = new LinkedHashSet<String>(4);
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence scopeStrings.add(SCOPE_STRING_BASE);
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence scopeStrings.add(SCOPE_STRING_ONE);
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence scopeStrings.add(SCOPE_STRING_SUB);
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence scopeStrings.add(SCOPE_STRING_SUBORDINATE);
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence BooleanArgument dontWrap;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence BooleanArgument overwriteExisting;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence BooleanArgument showUsage;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence FileBasedArgument filterFile;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence IntegerArgument sizeLimit;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence IntegerArgument timeLimit;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence MultiChoiceArgument scopeString;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence StringArgument baseDNString;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence StringArgument configClass;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff StringArgument configFile;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff StringArgument ldifFile;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff StringArgument outputFile;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff
1ce985ab3c6670662d555c108b35fed84a6a1001David Lawrence String toolDescription = getMessage(MSGID_LDIFSEARCH_TOOL_DESCRIPTION);
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence false, true, 0, 0,
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence "[filter] [attributes ...]");
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence try
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence {
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence ldifFile = new StringArgument("ldiffile", 'l', "ldifFile", false, true,
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence true, "{ldifFile}", null, null,
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence MSGID_LDIFSEARCH_DESCRIPTION_LDIF_FILE);
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence argParser.addArgument(ldifFile);
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence baseDNString = new StringArgument("basedn", 'b', "baseDN", false, true,
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence true, "{baseDN}", "", null,
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence MSGID_LDIFSEARCH_DESCRIPTION_BASEDN);
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence argParser.addArgument(baseDNString);
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence scopeString = new MultiChoiceArgument("scope", 's', "scope", false, false,
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence true, "{scope}", SCOPE_STRING_SUB,
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence null, scopeStrings, false,
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence MSGID_LDIFSEARCH_DESCRIPTION_SCOPE);
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence argParser.addArgument(scopeString);
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff configFile = new StringArgument("configfile", 'c', "configFile", false,
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff false, true, "{configFile}", null, null,
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff MSGID_LDIFSEARCH_DESCRIPTION_CONFIG_FILE);
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff configFile.setHidden(true);
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff argParser.addArgument(configFile);
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff configClass = new StringArgument("configclass", 'C', "configClass", false,
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff false, true, "{configClass}",
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff ConfigFileHandler.class.getName(), null,
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff MSGID_LDIFSEARCH_DESCRIPTION_CONFIG_CLASS);
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson configClass.setHidden(true);
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson argParser.addArgument(configClass);
641da3ca1184d9951d5cf91538524a345bf5f271Mark Andrews
641da3ca1184d9951d5cf91538524a345bf5f271Mark Andrews filterFile = new FileBasedArgument("filterfile", 'f', "filterFile", false,
641da3ca1184d9951d5cf91538524a345bf5f271Mark Andrews false, "{filterFile}", null, null,
641da3ca1184d9951d5cf91538524a345bf5f271Mark Andrews MSGID_LDIFSEARCH_DESCRIPTION_FILTER_FILE);
641da3ca1184d9951d5cf91538524a345bf5f271Mark Andrews argParser.addArgument(filterFile);
80badf38c74c326a694e24281ee258aa26984171Mark Andrews
641da3ca1184d9951d5cf91538524a345bf5f271Mark Andrews outputFile = new StringArgument("outputfile", 'o', "outputFile", false,
641da3ca1184d9951d5cf91538524a345bf5f271Mark Andrews false, true, "{outputFile}", null, null,
641da3ca1184d9951d5cf91538524a345bf5f271Mark Andrews MSGID_LDIFSEARCH_DESCRIPTION_OUTPUT_FILE);
641da3ca1184d9951d5cf91538524a345bf5f271Mark Andrews argParser.addArgument(outputFile);
641da3ca1184d9951d5cf91538524a345bf5f271Mark Andrews
9fe28a624c659e380d47dbf45527637dab03b998Mark Andrews overwriteExisting =
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews new BooleanArgument("overwriteexisting", 'O',"overwriteExisting",
9fe28a624c659e380d47dbf45527637dab03b998Mark Andrews MSGID_LDIFSEARCH_DESCRIPTION_OVERWRITE_EXISTING);
9fe28a624c659e380d47dbf45527637dab03b998Mark Andrews argParser.addArgument(overwriteExisting);
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews dontWrap = new BooleanArgument("dontwrap", 'T', "dontWrap",
9fe28a624c659e380d47dbf45527637dab03b998Mark Andrews MSGID_LDIFSEARCH_DESCRIPTION_DONT_WRAP);
9fe28a624c659e380d47dbf45527637dab03b998Mark Andrews argParser.addArgument(dontWrap);
9fe28a624c659e380d47dbf45527637dab03b998Mark Andrews
9fe28a624c659e380d47dbf45527637dab03b998Mark Andrews sizeLimit = new IntegerArgument("sizelimit", 'z', "sizeLimit", false,
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews false, true, "{sizeLimit}", 0, null,
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews true, 0, false, 0,
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews MSGID_LDIFSEARCH_DESCRIPTION_SIZE_LIMIT);
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews argParser.addArgument(sizeLimit);
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews timeLimit = new IntegerArgument("timelimit", 't', "timeLimit", false,
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews false, true, "{timeLimit}", 0, null,
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews true, 0, false, 0,
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews MSGID_LDIFSEARCH_DESCRIPTION_TIME_LIMIT);
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews argParser.addArgument(timeLimit);
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews
9fe28a624c659e380d47dbf45527637dab03b998Mark Andrews
9fe28a624c659e380d47dbf45527637dab03b998Mark Andrews showUsage = new BooleanArgument("help", 'H', "help",
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson MSGID_LDIFSEARCH_DESCRIPTION_USAGE);
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson argParser.addArgument(showUsage);
39b973d8873996c3bfb6e5b4cc69731f6c3b77b5Mark Andrews argParser.setUsageArgument(showUsage);
6342df69b05f2f62d060fd4affdf536e51504084Mark Andrews }
6342df69b05f2f62d060fd4affdf536e51504084Mark Andrews catch (ArgumentException ae)
6342df69b05f2f62d060fd4affdf536e51504084Mark Andrews {
6342df69b05f2f62d060fd4affdf536e51504084Mark Andrews int msgID = MSGID_LDIFSEARCH_CANNOT_INITIALIZE_ARGS;
6342df69b05f2f62d060fd4affdf536e51504084Mark Andrews String message = getMessage(msgID, ae.getMessage());
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson System.err.println(message);
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson return 1;
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson }
c654449ccf403ccd2b81be2038b1013d6fbb06ccMark Andrews
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson // Parse the command-line arguments provided to the program.
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson try
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson {
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson argParser.parseArguments(args);
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson }
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington catch (ArgumentException ae)
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington {
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington int msgID = MSGID_LDIFSEARCH_ERROR_PARSING_ARGS;
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington String message = getMessage(msgID, ae.getMessage());
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington System.err.println(message);
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington System.err.println(argParser.getUsage());
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington }
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson // If we should just display usage information, then print it and exit.
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson if (argParser.usageDisplayed())
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson {
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson return 0;
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson }
8f3dd8f8e73e4465221a5297819db70e6b383138Mark Andrews
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews // Make sure that at least one filter was provided. Also get the attribute
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews // list at the same time because it may need to be specified in the same
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews // way.
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews boolean allUserAttrs = false;
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews boolean allOperationalAttrs = false;
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews LinkedList<String> attributeNames = new LinkedList<String>();
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews LinkedList<String> objectClassNames = new LinkedList<String>();
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews LinkedList<String> filterStrings;
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews if (filterFile.isPresent())
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews {
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews filterStrings = filterFile.getValues();
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews ArrayList<String> trailingArguments = argParser.getTrailingArguments();
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews if ((trailingArguments == null) || trailingArguments.isEmpty())
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews {
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews attributeNames = new LinkedList<String>();
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson }
754cca729dd82ae8363917dc00ad44f9d900635bMark Andrews else
754cca729dd82ae8363917dc00ad44f9d900635bMark Andrews {
754cca729dd82ae8363917dc00ad44f9d900635bMark Andrews attributeNames = new LinkedList<String>();
754cca729dd82ae8363917dc00ad44f9d900635bMark Andrews for (String attributeName : trailingArguments)
754cca729dd82ae8363917dc00ad44f9d900635bMark Andrews {
754cca729dd82ae8363917dc00ad44f9d900635bMark Andrews String lowerName = toLowerCase(attributeName);
754cca729dd82ae8363917dc00ad44f9d900635bMark Andrews if (lowerName.equals("*"))
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson {
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews allUserAttrs = true;
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews }
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews else if (lowerName.equals("+"))
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews {
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews allOperationalAttrs = true;
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews }
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews else if (lowerName.startsWith("@"))
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews {
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews objectClassNames.add(lowerName.substring(1));
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews }
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews else
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews {
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews attributeNames.add(lowerName);
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews }
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews }
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews }
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews }
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews else
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews {
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews ArrayList<String> trailingArguments = argParser.getTrailingArguments();
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews if ((trailingArguments == null) || trailingArguments.isEmpty())
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson {
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson int msgID = MSGID_LDIFSEARCH_NO_FILTER;
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson String message = getMessage(msgID);
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson System.err.println(message);
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson return 1;
963c48ba4d06a112c70d50328e827749e95f58dbMark Andrews }
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson else
963c48ba4d06a112c70d50328e827749e95f58dbMark Andrews {
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson Iterator<String> iterator = trailingArguments.iterator();
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson filterStrings = new LinkedList<String>();
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson filterStrings.add(iterator.next());
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson attributeNames = new LinkedList<String>();
a1898260ad19d02e88ab76c1855d33c67add9defMark Andrews while (iterator.hasNext())
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson {
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson String lowerName = toLowerCase(iterator.next());
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson if (lowerName.equals("*"))
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson {
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson allUserAttrs = true;
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson }
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson else if (lowerName.equals("+"))
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson {
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson allOperationalAttrs = true;
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson }
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson else if (lowerName.startsWith("@"))
a1898260ad19d02e88ab76c1855d33c67add9defMark Andrews {
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson objectClassNames.add(lowerName.substring(1));
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson }
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson else
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson {
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson attributeNames.add(lowerName);
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson }
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson }
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson }
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson }
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson if (attributeNames.isEmpty() && objectClassNames.isEmpty() &&
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson (! allOperationalAttrs))
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson {
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff // This will be true if no attributes were requested, which is effectively
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff // all user attributes. It will also be true if just "*" was included,
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff // but the net result will be the same.
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff allUserAttrs = true;
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff }
13faa8b6a2d0d45e0659049983928366252ab3faMichael Graff
13faa8b6a2d0d45e0659049983928366252ab3faMichael Graff
13faa8b6a2d0d45e0659049983928366252ab3faMichael Graff // Bootstrap the Directory Server configuration for use as a client.
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson DirectoryServer directoryServer = DirectoryServer.getInstance();
13faa8b6a2d0d45e0659049983928366252ab3faMichael Graff directoryServer.bootstrapClient();
61d5bfc06be978ea962b1c64309894ac80351771Mark Andrews
61d5bfc06be978ea962b1c64309894ac80351771Mark Andrews
3d8dfd44a3be708f00380064411c16b2fa28303aMark Andrews // If we're to use the configuration then initialize it, along with the
13faa8b6a2d0d45e0659049983928366252ab3faMichael Graff // schema.
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews boolean checkSchema = configFile.isPresent();
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews if (checkSchema)
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews {
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews try
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews {
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews directoryServer.initializeJMX();
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews }
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews catch (Exception e)
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews {
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews int msgID = MSGID_LDIFSEARCH_CANNOT_INITIALIZE_JMX;
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews String message = getMessage(msgID,
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews String.valueOf(configFile.getValue()),
5f9e583552f53de12062bfff12e47250abce378fBrian Wellington e.getMessage());
5f9e583552f53de12062bfff12e47250abce378fBrian Wellington System.err.println(message);
3fcf6b956f47405750724bd84e1b2290b61c9186Brian Wellington return 1;
3fcf6b956f47405750724bd84e1b2290b61c9186Brian Wellington }
3fcf6b956f47405750724bd84e1b2290b61c9186Brian Wellington
5f9e583552f53de12062bfff12e47250abce378fBrian Wellington try
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews {
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews directoryServer.initializeConfiguration(configClass.getValue(),
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews configFile.getValue());
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews }
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews catch (Exception e)
5f9e583552f53de12062bfff12e47250abce378fBrian Wellington {
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews int msgID = MSGID_LDIFSEARCH_CANNOT_INITIALIZE_CONFIG;
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson String message = getMessage(msgID,
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson String.valueOf(configFile.getValue()),
68f72235f8f41fa949823551d8e6476057ec5bd6Andreas Gustafsson e.getMessage());
68f72235f8f41fa949823551d8e6476057ec5bd6Andreas Gustafsson System.err.println(message);
68f72235f8f41fa949823551d8e6476057ec5bd6Andreas Gustafsson return 1;
68f72235f8f41fa949823551d8e6476057ec5bd6Andreas Gustafsson }
68f72235f8f41fa949823551d8e6476057ec5bd6Andreas Gustafsson
68f72235f8f41fa949823551d8e6476057ec5bd6Andreas Gustafsson try
68f72235f8f41fa949823551d8e6476057ec5bd6Andreas Gustafsson {
68f72235f8f41fa949823551d8e6476057ec5bd6Andreas Gustafsson directoryServer.initializeSchema();
68f72235f8f41fa949823551d8e6476057ec5bd6Andreas Gustafsson }
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson catch (Exception e)
68f72235f8f41fa949823551d8e6476057ec5bd6Andreas Gustafsson {
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson int msgID = MSGID_LDIFSEARCH_CANNOT_INITIALIZE_SCHEMA;
80f323528ac699026a609a5e3b765dc6e88fe37cAndreas Gustafsson String message = getMessage(msgID,
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson String.valueOf(configFile.getValue()),
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson e.getMessage());
3fcf6b956f47405750724bd84e1b2290b61c9186Brian Wellington System.err.println(message);
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews return 1;
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews }
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews }
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews // Choose the desired search scope.
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews SearchScope searchScope;
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews if (scopeString.isPresent())
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews {
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews String scopeStr = toLowerCase(scopeString.getValue());
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews if (scopeStr.equals(SCOPE_STRING_BASE))
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews {
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews searchScope = SearchScope.BASE_OBJECT;
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews }
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews else if (scopeStr.equals(SCOPE_STRING_ONE))
5f9e583552f53de12062bfff12e47250abce378fBrian Wellington {
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson searchScope = SearchScope.SINGLE_LEVEL;
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson }
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson else if (scopeStr.equals(SCOPE_STRING_SUBORDINATE))
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson {
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson searchScope = SearchScope.SUBORDINATE_SUBTREE;
bc53aacc6e9302b1f8d01467fc39585584652782Andreas Gustafsson }
bc53aacc6e9302b1f8d01467fc39585584652782Andreas Gustafsson else
bc53aacc6e9302b1f8d01467fc39585584652782Andreas Gustafsson {
bc53aacc6e9302b1f8d01467fc39585584652782Andreas Gustafsson searchScope = SearchScope.WHOLE_SUBTREE;
bc53aacc6e9302b1f8d01467fc39585584652782Andreas Gustafsson }
d906600f7d1e86a4315e65a500f806ca1e4caa9bAndreas Gustafsson }
bc53aacc6e9302b1f8d01467fc39585584652782Andreas Gustafsson else
bc53aacc6e9302b1f8d01467fc39585584652782Andreas Gustafsson {
bc53aacc6e9302b1f8d01467fc39585584652782Andreas Gustafsson searchScope = SearchScope.WHOLE_SUBTREE;
bc53aacc6e9302b1f8d01467fc39585584652782Andreas Gustafsson }
2995f8205eaa0d4bc3a57900a413b5cfdb83564fAndreas Gustafsson
2995f8205eaa0d4bc3a57900a413b5cfdb83564fAndreas Gustafsson
2995f8205eaa0d4bc3a57900a413b5cfdb83564fAndreas Gustafsson // Create the list of filters that will be used to process the searches.
2995f8205eaa0d4bc3a57900a413b5cfdb83564fAndreas Gustafsson LinkedList<SearchFilter> searchFilters = new LinkedList<SearchFilter>();
bc53aacc6e9302b1f8d01467fc39585584652782Andreas Gustafsson for (String filterString : filterStrings)
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews {
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews try
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews {
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews searchFilters.add(SearchFilter.createFilterFromString(filterString));
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews }
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews catch (Exception e)
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews {
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews int msgID = MSGID_LDIFSEARCH_CANNOT_PARSE_FILTER;
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews String message = getMessage(msgID, filterString, e.getMessage());
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews System.err.println(message);
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews return 1;
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews }
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews }
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews // Transform the attributes to return from strings to attribute types.
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews LinkedHashSet<AttributeType> userAttributeTypes =
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews new LinkedHashSet<AttributeType>();
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews LinkedHashSet<AttributeType> operationalAttributeTypes =
d73de275987d29627dc11d5bd4a22874a29f7874Mark Andrews new LinkedHashSet<AttributeType>();
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews for (String attributeName : attributeNames)
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews {
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews AttributeType t = DirectoryServer.getAttributeType(attributeName, true);
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews if (t.isOperational())
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews {
bc53aacc6e9302b1f8d01467fc39585584652782Andreas Gustafsson operationalAttributeTypes.add(t);
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson }
919caa020b8f9b856d77b3a72e0c9301dfa495c7Andreas Gustafsson else
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson {
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson userAttributeTypes.add(t);
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews }
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson }
bd1db480f30e025bba719799f910b34848a9a997Mark Andrews
bd1db480f30e025bba719799f910b34848a9a997Mark Andrews for (String objectClassName : objectClassNames)
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews {
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson ObjectClass c = DirectoryServer.getObjectClass(objectClassName, true);
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson for (AttributeType t : c.getRequiredAttributeChain())
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson {
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson if (t.isOperational())
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson {
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews operationalAttributeTypes.add(t);
caa736a754e90f44bbc249e22f96bcbf4e04b849Andreas Gustafsson }
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews else
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews {
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews userAttributeTypes.add(t);
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews }
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews }
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews for (AttributeType t : c.getOptionalAttributeChain())
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews {
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews if (t.isOperational())
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews {
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews operationalAttributeTypes.add(t);
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews }
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews else
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews {
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews userAttributeTypes.add(t);
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews }
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews }
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews }
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews // Set the base DNs for the import config.
7f32428506d55083fe5ac9aa515294bdef7c6e27Mark Andrews LinkedList<DN> baseDNs = new LinkedList<DN>();
c0707105f60934d59321c2fccbc254f9e31ff28aMark Andrews if (baseDNString.isPresent())
c0707105f60934d59321c2fccbc254f9e31ff28aMark Andrews {
c0707105f60934d59321c2fccbc254f9e31ff28aMark Andrews for (String dnString : baseDNString.getValues())
c0707105f60934d59321c2fccbc254f9e31ff28aMark Andrews {
c0707105f60934d59321c2fccbc254f9e31ff28aMark Andrews try
c0707105f60934d59321c2fccbc254f9e31ff28aMark Andrews {
c0707105f60934d59321c2fccbc254f9e31ff28aMark Andrews baseDNs.add(DN.decode(dnString));
c0707105f60934d59321c2fccbc254f9e31ff28aMark Andrews }
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson catch (Exception e)
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson {
5f9e583552f53de12062bfff12e47250abce378fBrian Wellington int msgID = MSGID_LDIFSEARCH_CANNOT_PARSE_BASE_DN;
5f9e583552f53de12062bfff12e47250abce378fBrian Wellington String message = getMessage(msgID, dnString, e.getMessage());
08a768e82ad64ede97f640c88e02984b59122753Michael Graff System.err.println(message);
08a768e82ad64ede97f640c88e02984b59122753Michael Graff return 1;
08a768e82ad64ede97f640c88e02984b59122753Michael Graff }
08a768e82ad64ede97f640c88e02984b59122753Michael Graff }
08a768e82ad64ede97f640c88e02984b59122753Michael Graff }
08a768e82ad64ede97f640c88e02984b59122753Michael Graff else
3fcf6b956f47405750724bd84e1b2290b61c9186Brian Wellington {
0e40083fdd5445703bd30e46e5bfe7d047bced12Brian Wellington baseDNs.add(DN.nullDN());
0e40083fdd5445703bd30e46e5bfe7d047bced12Brian Wellington }
08a768e82ad64ede97f640c88e02984b59122753Michael Graff
3ec6b563d7b6cb11a047f23faa2a0f206ccd93e7Brian Wellington
3ec6b563d7b6cb11a047f23faa2a0f206ccd93e7Brian Wellington // Get the time limit in milliseconds.
3ec6b563d7b6cb11a047f23faa2a0f206ccd93e7Brian Wellington long timeLimitMillis;
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington try
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington {
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington if (timeLimit.isPresent())
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington {
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington timeLimitMillis = 1000L * timeLimit.getIntValue();
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington }
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington else
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington {
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington timeLimitMillis = 0;
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington }
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington }
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington catch (Exception e)
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington {
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington int msgID = MSGID_LDIFSEARCH_CANNOT_PARSE_TIME_LIMIT;
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington String message = getMessage(msgID, String.valueOf(e));
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington System.err.println(message);
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington return 1;
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington }
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington // Convert the size limit to an integer.
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington int sizeLimitValue;
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington try
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington {
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington if (sizeLimit.isPresent())
fee5012c43744322c1785e5c3e0c322443faa304Brian Wellington {
3ec6b563d7b6cb11a047f23faa2a0f206ccd93e7Brian Wellington sizeLimitValue = sizeLimit.getIntValue();
3ec6b563d7b6cb11a047f23faa2a0f206ccd93e7Brian Wellington }
3ec6b563d7b6cb11a047f23faa2a0f206ccd93e7Brian Wellington else
0e40083fdd5445703bd30e46e5bfe7d047bced12Brian Wellington {
0e40083fdd5445703bd30e46e5bfe7d047bced12Brian Wellington sizeLimitValue =0;
0e40083fdd5445703bd30e46e5bfe7d047bced12Brian Wellington }
0e40083fdd5445703bd30e46e5bfe7d047bced12Brian Wellington }
0e40083fdd5445703bd30e46e5bfe7d047bced12Brian Wellington catch (Exception e)
0e40083fdd5445703bd30e46e5bfe7d047bced12Brian Wellington {
0e40083fdd5445703bd30e46e5bfe7d047bced12Brian Wellington int msgID = MSGID_LDIFSEARCH_CANNOT_PARSE_SIZE_LIMIT;
3ec6b563d7b6cb11a047f23faa2a0f206ccd93e7Brian Wellington String message = getMessage(msgID, String.valueOf(e));
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington System.err.println(message);
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington return 1;
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington }
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington // Create the LDIF import configuration that will be used to read the source
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington // data.
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington LDIFImportConfig importConfig;
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington if (ldifFile.isPresent())
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington {
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington importConfig = new LDIFImportConfig(ldifFile.getValues());
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington }
d0fbcfeee1c1dbdb079231545de3a0c58248202fMark Andrews else
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington {
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington importConfig = new LDIFImportConfig(System.in);
af5ad488cbf17988fbd36a25c908737412ccd382Brian Wellington }
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington
b495fd2992c63472b3ad2d9517ffe9b50118840aAndreas Gustafsson // Create the LDIF export configuration that will be used to write the
af5ad488cbf17988fbd36a25c908737412ccd382Brian Wellington // matching entries.
f317c00e0d5978f29285ea062b34ec73dc419095Brian Wellington LDIFExportConfig exportConfig;
f317c00e0d5978f29285ea062b34ec73dc419095Brian Wellington if (outputFile.isPresent())
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington {
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington if (overwriteExisting.isPresent())
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington {
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington exportConfig = new LDIFExportConfig(outputFile.getName(),
dee520f1be8c59e10a55b6995844395e811c310fBrian Wellington ExistingFileBehavior.OVERWRITE);
dee520f1be8c59e10a55b6995844395e811c310fBrian Wellington }
dee520f1be8c59e10a55b6995844395e811c310fBrian Wellington else
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington {
529ff4b4959fb157194f985394951108ff5286e4Brian Wellington exportConfig = new LDIFExportConfig(outputFile.getName(),
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington ExistingFileBehavior.APPEND);
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington }
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington }
a14613fce99dee3cad5bf842fd6be78f8e463582Brian Wellington else
5b76a09697bfc76f5acefd65d5b37b1214d271a8Mark Andrews {
5b76a09697bfc76f5acefd65d5b37b1214d271a8Mark Andrews exportConfig = new LDIFExportConfig(System.out);
5b76a09697bfc76f5acefd65d5b37b1214d271a8Mark Andrews }
5b76a09697bfc76f5acefd65d5b37b1214d271a8Mark Andrews
5b76a09697bfc76f5acefd65d5b37b1214d271a8Mark Andrews if (dontWrap.isPresent())
9738408dcbd4c1f7eb2b105c83388608fafd7808Mark Andrews {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson exportConfig.setWrapColumn(0);
489b76292622f5bc18bf1a18845f8166a73bd797Brian Wellington }
489b76292622f5bc18bf1a18845f8166a73bd797Brian Wellington else
2271edc0b4ba96e69a283eced420b94ffb678beeBrian Wellington {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson exportConfig.setWrapColumn(75);
2271edc0b4ba96e69a283eced420b94ffb678beeBrian Wellington }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson // Create the LDIF reader/writer from the import/export config.
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson LDIFReader reader;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson LDIFWriter writer;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson try
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
7005cfed8cd3296d356883dcb414979f22e06b13Brian Wellington reader = new LDIFReader(importConfig);
489b76292622f5bc18bf1a18845f8166a73bd797Brian Wellington }
489b76292622f5bc18bf1a18845f8166a73bd797Brian Wellington catch (Exception e)
489b76292622f5bc18bf1a18845f8166a73bd797Brian Wellington {
3184ff5e45c8f821e5165ea60d674bfb87faf5b8Mark Andrews int msgID = MSGID_LDIFSEARCH_CANNOT_CREATE_READER;
3184ff5e45c8f821e5165ea60d674bfb87faf5b8Mark Andrews String message = getMessage(msgID, String.valueOf(e));
3184ff5e45c8f821e5165ea60d674bfb87faf5b8Mark Andrews System.err.println(message);
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson return 1;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
9ceaa92a8ca8a0270ba296d44599e94d95033759Andreas Gustafsson try
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson writer = new LDIFWriter(exportConfig);
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson catch (Exception e)
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
70e854766f5304f43e94212dc38ebaefe214148cMark Andrews try
70e854766f5304f43e94212dc38ebaefe214148cMark Andrews {
70e854766f5304f43e94212dc38ebaefe214148cMark Andrews reader.close();
70e854766f5304f43e94212dc38ebaefe214148cMark Andrews } catch (Exception e2) {}
70e854766f5304f43e94212dc38ebaefe214148cMark Andrews
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson int msgID = MSGID_LDIFSEARCH_CANNOT_CREATE_WRITER;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson String message = getMessage(msgID, String.valueOf(e));
fa280ff02ad0c29616a0c3a22ef02cbb3f6db7efDavid Lawrence System.err.println(message);
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson return 1;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
fa280ff02ad0c29616a0c3a22ef02cbb3f6db7efDavid Lawrence
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson // Start reading data from the LDIF reader.
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson long startTime = System.currentTimeMillis();
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson long stopTime = startTime + timeLimitMillis;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson long matchCount = 0;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson int resultCode = LDAPResultCode.SUCCESS;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson while (true)
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson // If the time limit has been reached, then stop now.
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson if ((timeLimitMillis > 0) && (System.currentTimeMillis() > stopTime))
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson resultCode = LDAPResultCode.TIME_LIMIT_EXCEEDED;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson int msgID = MSGID_LDIFSEARCH_TIME_LIMIT_EXCEEDED;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson String message = getMessage(msgID);
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson System.err.println(message);
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson break;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson try
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
3fafd7c0c42134ff2964b74a31500465a96dee90Andreas Gustafsson Entry entry = reader.readEntry(checkSchema);
aa30ee42c4b6da9bab4fb84d6cbbda6036a4d426Mark Andrews if (entry == null)
aa30ee42c4b6da9bab4fb84d6cbbda6036a4d426Mark Andrews {
9ceaa92a8ca8a0270ba296d44599e94d95033759Andreas Gustafsson break;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson // Check to see if the entry has an acceptable base and scope.
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson boolean matchesBaseAndScope = false;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson for (DN baseDN : baseDNs)
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson if (entry.matchesBaseAndScope(baseDN, searchScope))
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson matchesBaseAndScope = true;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson break;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson if (! matchesBaseAndScope)
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson continue;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson // Check to see if the entry matches any of the filters.
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson boolean matchesFilter = false;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson for (SearchFilter filter : searchFilters)
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson if (filter.matchesEntry(entry))
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson matchesFilter = true;
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence break;
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson if (! matchesFilter)
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson continue;
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson }
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson
712bf9b0cc4ed34f4bf33b437f8b0e45853b93ceMark Andrews // Prepare the entry to return to the client.
aa30ee42c4b6da9bab4fb84d6cbbda6036a4d426Mark Andrews if (! allUserAttrs)
aa30ee42c4b6da9bab4fb84d6cbbda6036a4d426Mark Andrews {
aa30ee42c4b6da9bab4fb84d6cbbda6036a4d426Mark Andrews Iterator<AttributeType> iterator =
712bf9b0cc4ed34f4bf33b437f8b0e45853b93ceMark Andrews entry.getUserAttributes().keySet().iterator();
712bf9b0cc4ed34f4bf33b437f8b0e45853b93ceMark Andrews while (iterator.hasNext())
712bf9b0cc4ed34f4bf33b437f8b0e45853b93ceMark Andrews {
712bf9b0cc4ed34f4bf33b437f8b0e45853b93ceMark Andrews if (! userAttributeTypes.contains(iterator.next()))
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson {
a1884b96ef53efc8b4e14be173aaee552ca0213aAndreas Gustafsson iterator.remove();
620de5a4b1f23dc9b4ec30d30c0607ff389be0daBob Halley }
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence }
fafb62400d2f1b1da4f3908447e1f3935fc5155bBrian Wellington }
fafb62400d2f1b1da4f3908447e1f3935fc5155bBrian Wellington
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence if (! allOperationalAttrs)
fafb62400d2f1b1da4f3908447e1f3935fc5155bBrian Wellington {
620de5a4b1f23dc9b4ec30d30c0607ff389be0daBob Halley Iterator<AttributeType> iterator =
9ceaa92a8ca8a0270ba296d44599e94d95033759Andreas Gustafsson entry.getOperationalAttributes().keySet().iterator();
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence while (iterator.hasNext())
620de5a4b1f23dc9b4ec30d30c0607ff389be0daBob Halley {
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence if (! operationalAttributeTypes.contains(iterator.next()))
fafb62400d2f1b1da4f3908447e1f3935fc5155bBrian Wellington {
fafb62400d2f1b1da4f3908447e1f3935fc5155bBrian Wellington iterator.remove();
fafb62400d2f1b1da4f3908447e1f3935fc5155bBrian Wellington }
23ac30603a7639bea1d331537634b079b046b122Mark Andrews }
23ac30603a7639bea1d331537634b079b046b122Mark Andrews }
23ac30603a7639bea1d331537634b079b046b122Mark Andrews
23ac30603a7639bea1d331537634b079b046b122Mark Andrews
23ac30603a7639bea1d331537634b079b046b122Mark Andrews // Write the entry to the client and increase the count.
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington // FIXME -- Should we include a comment about which base+filter matched?
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington writer.writeEntry(entry);
64b92523f9333ba053f4b2860335583be455b0b3Brian Wellington writer.flush();
64b92523f9333ba053f4b2860335583be455b0b3Brian Wellington
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington matchCount++;
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington if ((sizeLimitValue > 0) && (matchCount > sizeLimitValue))
64b92523f9333ba053f4b2860335583be455b0b3Brian Wellington {
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington resultCode = LDAPResultCode.SIZE_LIMIT_EXCEEDED;
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence int msgID = MSGID_LDIFSEARCH_SIZE_LIMIT_EXCEEDED;
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence String message = getMessage(msgID);
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence System.err.println(message);
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence break;
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence }
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence }
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence catch (LDIFException le)
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence {
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence if (le.canContinueReading())
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence {
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence int msgID = MSGID_LDIFSEARCH_CANNOT_READ_ENTRY_RECOVERABLE;
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence String message = getMessage(msgID, le.getMessage());
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence System.err.println(message);
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley }
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley else
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley {
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley int msgID = MSGID_LDIFSEARCH_CANNOT_READ_ENTRY_FATAL;
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley String message = getMessage(msgID, le.getMessage());
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley System.err.println(message);
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley resultCode = LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley break;
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley }
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley }
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley catch (Exception e)
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley {
03f4c76f95f75e2b0d1206e784e35bed6041305cBob Halley int msgID = MSGID_LDIFSEARCH_ERROR_DURING_PROCESSING;
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence String message = getMessage(msgID, String.valueOf(e));
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence System.err.println(message);
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence resultCode = LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence break;
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence }
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence }
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence
53f1312c61fa8618852584bcdf9f35530282eb08Mark Andrews // Close the reader and writer.
3ea6d4dc33482a752553c59ed94bcecd23d254b0Mark Andrews try
3ea6d4dc33482a752553c59ed94bcecd23d254b0Mark Andrews {
3ea6d4dc33482a752553c59ed94bcecd23d254b0Mark Andrews reader.close();
3ea6d4dc33482a752553c59ed94bcecd23d254b0Mark Andrews } catch (Exception e) {}
3ea6d4dc33482a752553c59ed94bcecd23d254b0Mark Andrews
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence try
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence {
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence writer.close();
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence } catch (Exception e) {}
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence return resultCode;
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence }
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence}
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence
9a2574531e3d2ced31072200b416467fdee0c29cDavid Lawrence