String.valueOf(e));
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
PasswordStorageScheme storageScheme =
DirectoryServer.getAuthPasswordStorageScheme(scheme);
if (storageScheme == null)
{
Message message = ERR_ENCPW_NO_SUCH_AUTH_SCHEME.get(
scheme);
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
if (clearPW == null)
{
clearPW = getClearPW(out, err, argParser, clearPassword,
clearPasswordFile, interactivePassword);
if (clearPW == null)
{
return 1;
}
}
if (storageScheme.authPasswordMatches(clearPW, authInfo, authValue))
{
Message message = INFO_ENCPW_PASSWORDS_MATCH.get();
out.println(message);
if (useCompareResultCode.isPresent())
{
return LDAPResultCode.COMPARE_TRUE;
}
else
{
return 0;
}
}
else
{
Message message = INFO_ENCPW_PASSWORDS_DO_NOT_MATCH.get();
out.println(message);
if (useCompareResultCode.isPresent())
{
return LDAPResultCode.COMPARE_FALSE;
}
else
{
return 0;
}
}
}
else
{
PasswordStorageScheme storageScheme;
String encodedPWString;
if (UserPasswordSyntax.isEncoded(encodedPW))
{
try
{
String[] userPWElements =
UserPasswordSyntax.decodeUserPassword(encodedPW.toString());
encodedPWString = userPWElements[1];
storageScheme =
DirectoryServer.getPasswordStorageScheme(userPWElements[0]);
if (storageScheme == null)
{
Message message = ERR_ENCPW_NO_SUCH_SCHEME.get(userPWElements[0]);
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
}
catch (DirectoryException de)
{
Message message = ERR_ENCPW_INVALID_ENCODED_USERPW.get(
de.getMessageObject());
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
catch (Exception e)
{
Message message = ERR_ENCPW_INVALID_ENCODED_USERPW.get(
String.valueOf(e));
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
}
else
{
if (! schemeName.isPresent())
{
Message message = ERR_ENCPW_NO_SCHEME.get(
schemeName.getLongIdentifier());
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
encodedPWString = encodedPW.toString();
String scheme = toLowerCase(schemeName.getValue());
storageScheme = DirectoryServer.getPasswordStorageScheme(scheme);
if (storageScheme == null)
{
Message message = ERR_ENCPW_NO_SUCH_SCHEME.get(scheme);
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
}
if (clearPW == null)
{
clearPW = getClearPW(out, err, argParser, clearPassword,
clearPasswordFile, interactivePassword);
if (clearPW == null)
{
return 1;
}
}
if (storageScheme.passwordMatches(clearPW,
ByteString.valueOf(encodedPWString)))
{
Message message = INFO_ENCPW_PASSWORDS_MATCH.get();
out.println(message);
if (useCompareResultCode.isPresent())
{
return LDAPResultCode.COMPARE_TRUE;
}
else
{
return 0;
}
}
else
{
Message message = INFO_ENCPW_PASSWORDS_DO_NOT_MATCH.get();
out.println(message);
if (useCompareResultCode.isPresent())
{
return LDAPResultCode.COMPARE_FALSE;
}
else
{
return 0;
}
}
}
}
else
{
// Try to get a reference to the requested password storage scheme.
PasswordStorageScheme storageScheme;
if (authPasswordSyntax.isPresent())
{
String scheme = schemeName.getValue();
storageScheme = DirectoryServer.getAuthPasswordStorageScheme(scheme);
if (storageScheme == null)
{
Message message = ERR_ENCPW_NO_SUCH_AUTH_SCHEME.get(scheme);
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
}
else
{
String scheme = toLowerCase(schemeName.getValue());
storageScheme = DirectoryServer.getPasswordStorageScheme(scheme);
if (storageScheme == null)
{
Message message = ERR_ENCPW_NO_SUCH_SCHEME.get(scheme);
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
}
if (authPasswordSyntax.isPresent())
{
try
{
if (clearPW == null)
{
clearPW = getClearPW(out, err, argParser, clearPassword,
clearPasswordFile, interactivePassword);
if (clearPW == null)
{
return 1;
}
}
encodedPW = storageScheme.encodeAuthPassword(clearPW);
Message message = ERR_ENCPW_ENCODED_PASSWORD.get(
encodedPW.toString());
out.println(message);
}
catch (DirectoryException de)
{
Message message = ERR_ENCPW_CANNOT_ENCODE.get(de.getMessageObject());
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
catch (Exception e)
{
Message message = ERR_ENCPW_CANNOT_ENCODE.get(getExceptionMessage(e));
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
}
else
{
try
{
if (clearPW == null)
{
clearPW = getClearPW(out, err, argParser, clearPassword,
clearPasswordFile, interactivePassword);
if (clearPW == null)
{
return 1;
}
}
encodedPW = storageScheme.encodePasswordWithScheme(clearPW);
Message message =
ERR_ENCPW_ENCODED_PASSWORD.get(encodedPW.toString());
out.println(message);
}