/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2012-2015 ForgeRock AS.
*/
/**
* This class provides a tool that can be used to issue compare requests to the
* Directory Server.
*/
public class LDAPCompare
{
/** The fully-qualified name of this class. */
"org.opends.server.tools.LDAPCompare";
/** The message ID counter to use for requests. */
/** The print stream to use for standard error. */
/** The print stream to use for standard output. */
/** Tells whether the command-line is being executed in script friendly mode or not. */
private boolean isScriptFriendly;
/**
* Constructor for the LDAPCompare object.
*
* @param nextMessageID The message ID counter to use for requests.
* @param out The print stream to use for standard output.
* @param err The print stream to use for standard error.
*/
{
this.nextMessageID = nextMessageID;
}
/**
* Execute the compare request in the specified list of DNs.
*
* @param connection The connection to execute the request on.
* @param attributeType The attribute type to compare.
* @param attributeVal The attribute value to compare.
* @param lines The list of DNs to compare the attribute in.
* @param compareOptions The constraints for the compare request.
* @return the LDAP result code for the operation
*
* @throws IOException If a problem occurs while communicating with the
* Directory Server.
*
* @throws LDAPException If the server returns an error response.
*/
throws IOException, LDAPException
{
int aggResultCode = SUCCESS;
{
int resultCode =
}
return aggResultCode;
}
/**
* Read the specified DNs from the given reader
* (file or stdin) and execute the given compare request.
*
* @param connection The connection to execute the request on.
* @param attributeType The attribute type to compare.
* @param attributeVal The attribute value to compare.
* @param reader The reader to read the list of DNs from.
* @param compareOptions The constraints for the compare request.
* @return the LDAP result code for the operation
*
* @throws IOException If a problem occurs while communicating with the
* Directory Server.
*
* @throws LDAPException If the server returns an error response.
*/
throws IOException, LDAPException
{
int aggResultCode = 0;
{
int resultCode =
}
return aggResultCode;
}
/**
* Aggregates a new result code to the existing aggregated result codes. This
* method always overwrites the {@link LDAPResultCode#SUCCESS} and
* {@link LDAPResultCode#COMPARE_TRUE} result codes with the new result code.
* Then
*
* @param aggResultCodes
* the aggregated result codes (a.k.a "accumulator")
* @param newResultCode
* the new result code to aggregate
* @return the new aggregated result code
*/
{
{
}
{
}
return aggResultCodes;
}
/**
* Execute the compare request for the specified DN entry.
*
* @param connection The connection to execute the request on.
* @param attributeType The attribute type to compare.
* @param attributeVal The attribute value to compare.
* @param line The DN to compare attribute in.
* @param compareOptions The constraints for the compare request.
* @return the LDAP result code for the operation
*
* @throws IOException If a problem occurs while communicating with the
* Directory Server.
*
* @throws LDAPException If the server returns an error response.
*/
throws IOException, LDAPException
{
if (!isScriptFriendly())
{
}
if(!compareOptions.showOperations())
{
try
{
} catch(DecodeException ae)
{
if (!compareOptions.continueOnError())
{
}
else
{
return OPERATIONS_ERROR;
}
}
&& !compareOptions.continueOnError())
{
} else
{
if(resultCode == COMPARE_FALSE)
{
if (isScriptFriendly())
{
}
else
{
}
} else if(resultCode == COMPARE_TRUE)
{
if (isScriptFriendly())
{
}
else
{
}
} else
{
op.getMatchedDN());
}
}
return resultCode;
}
return SUCCESS;
}
/**
* The main method for LDAPCompare tool.
*
* @param args The command-line arguments provided to this program.
*/
{
if(retCode != 0)
{
}
}
/**
* Parses the provided command-line arguments and uses that information to
* run the ldapcompare tool.
*
* @param args The command-line arguments provided to this program.
*
* @return The error code.
*/
{
}
/**
* Parses the provided command-line arguments and uses that information to
* run the ldapcompare tool.
*
* @param args The command-line arguments provided to this
* program.
* @param initializeServer Indicates whether to initialize the server.
* @param outStream The output stream to use for standard output, or
* <CODE>null</CODE> if standard output is not
* needed.
* @param errStream The output stream to use for standard error, or
* <CODE>null</CODE> if standard error is not
* needed.
*
* @return The error code.
*/
{
byte[] attributeVal = null;
// Create the command-line argument parser for use with this program.
false, true, 1, 0,
" \'attribute:value\' \"DN\" ...");
try
{
"script-friendly",
's',
"script-friendly",
OPTION_LONG_HOST, false, false, true,
null,
OPTION_LONG_PORT, false, false, true,
true, 1, true, 65535,
OPTION_LONG_BINDDN, false, false, true,
false, false, true,
new FileBasedArgument("bindPasswordFile",
false, false,
OPTION_LONG_FILENAME, false, false,
null,
"useSASLExternal",
OPTION_LONG_SASLOPTION, false,
true, true,
null,
false, false, true,
OPTION_LONG_KEYSTORE_PWD, false, false,
true, INFO_KEYSTORE_PWD_PLACEHOLDER.get(),
new FileBasedArgument("keyStorePasswordFile",
false, false,
false, false, true,
new StringArgument("trustStorePath",
false, false, true,
false, false, true,
new FileBasedArgument(
"trustStorePasswordFile",
OPTION_LONG_TRUSTSTORE_PWD_FILE, false, false,
null,
OPTION_LONG_ASSERTION_FILE, false, false, true,
null,
false, false, true,
false, false, true, INFO_TIMEOUT_PLACEHOLDER.get(),
false, false,
true, INFO_ENCODING_PLACEHOLDER.get(),
"continueOnError",
"useCompareResultCode",
} catch (ArgumentException ae)
{
return CLIENT_SIDE_PARAM_ERROR;
}
// Parse the command-line arguments provided to this program.
try
{
}
catch (ArgumentException ae)
{
return CLIENT_SIDE_PARAM_ERROR;
}
// If we should just display usage or version information,
// then print it and exit.
if (argParser.usageOrVersionDisplayed())
{
return SUCCESS;
}
{
err, ERR_TOOL_CONFLICTING_ARGS.get(bindPassword.getLongIdentifier(), bindPasswordFile.getLongIdentifier()));
return CLIENT_SIDE_PARAM_ERROR;
}
if(attrAndDNStrings.isEmpty())
{
return CLIENT_SIDE_PARAM_ERROR;
}
// First element should be an attribute string.
// Rest are DN strings
// If no DNs were provided, then exit with an error.
{
return CLIENT_SIDE_PARAM_ERROR;
}
// If trailing DNs were provided and the filename argument was also
// provided, exit with an error.
{
return CLIENT_SIDE_PARAM_ERROR;
}
// parse the attribute string
if(idx == -1)
{
return CLIENT_SIDE_PARAM_ERROR;
}
{
if(nextChar == ':')
{
try
{
}
catch (ParseException e)
{
return CLIENT_SIDE_PARAM_ERROR;
}
} else if(nextChar == '<')
{
try
{
}
catch (Exception e)
{
return CLIENT_SIDE_PARAM_ERROR;
}
} else
{
}
}
else
{
}
int portNumber = 389;
try
{
} catch (ArgumentException ae)
{
return CLIENT_SIDE_PARAM_ERROR;
}
try
{
{
return CLIENT_SIDE_PARAM_ERROR;
}
} catch(ArgumentException ae)
{
return CLIENT_SIDE_PARAM_ERROR;
}
try
{
}
catch (ClientException ex)
{
return CLIENT_SIDE_PARAM_ERROR;
}
if (keyStorePassword.isPresent())
{
}
else if (keyStorePasswordFile.isPresent())
{
}
if (trustStorePassword.isPresent())
{
}
else if (trustStorePasswordFile.isPresent())
{
}
if(controlStr.isPresent())
{
{
{
return CLIENT_SIDE_PARAM_ERROR;
}
}
}
if (assertionFilter.isPresent())
{
try
{
new LDAPAssertionRequestControl(true, filter);
}
catch (LDAPException le)
{
return CLIENT_SIDE_PARAM_ERROR;
}
}
// Set the connection options.
// Parse the SASL properties.
if(saslOptions.isPresent())
{
{
boolean val;
{
}
else
{
}
if(!val)
{
return CLIENT_SIDE_PARAM_ERROR;
}
}
}
{
{
return CLIENT_SIDE_PARAM_ERROR;
}
if(keyStorePathValue == null)
{
return CLIENT_SIDE_PARAM_ERROR;
}
}
try
{
if (initializeServer)
{
// Bootstrap and initialize directory data structures.
}
// Connect to the specified host with the supplied userDN and password.
{
if (certNickname.isPresent())
{
}
else
{
clientAlias = null;
}
sslConnectionFactory = new SSLConnectionFactory();
}
timeout);
{
// Read from stdin.
} else if(fileNameValue != null)
{
try
{
}
catch (Throwable t)
{
{
}
return CLIENT_SIDE_PARAM_ERROR;
}
}
int resultCode;
{
} else
{
}
if (useCompareResultCode.isPresent())
{
return resultCode;
}
return SUCCESS;
} catch(LDAPException le)
{
le.getResultCode(),
le.getMatchedDN());
return le.getResultCode();
} catch(LDAPConnectionException lce)
{
lce.getResultCode(),
lce.getMatchedDN());
return lce.getResultCode();
} catch(Exception e)
{
return OPERATIONS_ERROR;
} finally
{
if(connection != null)
{
if (ldapCompare != null)
{
}
else
{
}
}
}
}
private boolean isScriptFriendly()
{
return isScriptFriendly;
}
}