From d9b2b9b7578edb367174b1a516f38feb6eb028ae Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Fri, 10 Nov 2006 23:45:06 +0000
Subject: [PATCH] Make a number of changes to administrative tools provided with OpenDS. These are all made under the umbrella of issue #994, but there are individual issues for each change.
---
opends/src/server/org/opends/server/tools/LDAPModify.java | 372 ++++++++++++++++++++++++++++++++---------------------
1 files changed, 224 insertions(+), 148 deletions(-)
diff --git a/opends/src/server/org/opends/server/tools/LDAPModify.java b/opends/src/server/org/opends/server/tools/LDAPModify.java
index 0c40f4b..d578a2d 100644
--- a/opends/src/server/org/opends/server/tools/LDAPModify.java
+++ b/opends/src/server/org/opends/server/tools/LDAPModify.java
@@ -80,6 +80,7 @@
import static org.opends.server.messages.ToolMessages.*;
import static org.opends.server.protocols.ldap.LDAPResultCode.*;
import static org.opends.server.util.ServerConstants.*;
+import static org.opends.server.util.StaticUtils.*;
@@ -195,7 +196,7 @@
int msgID = MSGID_LDIF_FILE_INVALID_LDIF_ENTRY;
String message = getMessage(msgID, le.getLineNumber(), fileName,
String.valueOf(le));
- err.println(message);
+ err.println(wrapText(message, MAX_LINE_WIDTH));
continue;
}
} catch (Exception e)
@@ -220,7 +221,7 @@
{
int msgID = MSGID_LDIF_FILE_READ_ERROR;
String message = getMessage(msgID, fileName, String.valueOf(e));
- err.println(message);
+ err.println(wrapText(message, MAX_LINE_WIDTH));
continue;
}
}
@@ -318,8 +319,9 @@
{
assert debugException(CLASS_NAME, "readAndExecute", ae);
msgID = MSGID_OPERATION_FAILED;
- err.println(getMessage(msgID, operationType, asn1OctetStr,
- ae.getMessage()));
+ String message = getMessage(msgID, operationType, asn1OctetStr,
+ ae.getMessage());
+ err.println(wrapText(message, MAX_LINE_WIDTH));
if(!modifyOptions.continueOnError())
{
throw new IOException(ae.getMessage());
@@ -389,7 +391,7 @@
if (errorMessage != null)
{
- out.println(errorMessage);
+ out.println(wrapText(errorMessage, MAX_LINE_WIDTH));
}
if (referralURLs != null)
@@ -408,7 +410,7 @@
if (controlValue == null)
{
msgID = MSGID_LDAPMODIFY_PREREAD_NO_VALUE;
- err.println(getMessage(msgID));
+ err.println(wrapText(getMessage(msgID), MAX_LINE_WIDTH));
continue;
}
@@ -423,13 +425,15 @@
catch (ASN1Exception ae)
{
msgID = MSGID_LDAPMODIFY_PREREAD_CANNOT_DECODE_VALUE;
- err.println(getMessage(msgID, ae.getMessage()));
+ err.println(wrapText(getMessage(msgID, ae.getMessage()),
+ MAX_LINE_WIDTH));
continue;
}
catch (LDAPException le)
{
msgID = MSGID_LDAPMODIFY_PREREAD_CANNOT_DECODE_VALUE;
- err.println(getMessage(msgID, le.getMessage()));
+ err.println(wrapText(getMessage(msgID, le.getMessage()),
+ MAX_LINE_WIDTH));
continue;
}
@@ -444,7 +448,7 @@
if (controlValue == null)
{
msgID = MSGID_LDAPMODIFY_POSTREAD_NO_VALUE;
- err.println(getMessage(msgID));
+ err.println(wrapText(getMessage(msgID), MAX_LINE_WIDTH));
continue;
}
@@ -459,13 +463,15 @@
catch (ASN1Exception ae)
{
msgID = MSGID_LDAPMODIFY_POSTREAD_CANNOT_DECODE_VALUE;
- err.println(getMessage(msgID, ae.getMessage()));
+ err.println(wrapText(getMessage(msgID, ae.getMessage()),
+ MAX_LINE_WIDTH));
continue;
}
catch (LDAPException le)
{
msgID = MSGID_LDAPMODIFY_POSTREAD_CANNOT_DECODE_VALUE;
- err.println(getMessage(msgID, le.getMessage()));
+ err.println(wrapText(getMessage(msgID, le.getMessage()),
+ MAX_LINE_WIDTH));
continue;
}
@@ -557,163 +563,208 @@
LDAPModifyOptions modifyOptions = new LDAPModifyOptions();
LDAPConnection connection = null;
- BooleanArgument trustAll = null;
- StringArgument assertionFilter = null;
- StringArgument bindDN = null;
- StringArgument bindPassword = null;
- FileBasedArgument bindPasswordFile = null;
- StringArgument proxyAuthzID = null;
- BooleanArgument reportAuthzID = null;
- StringArgument encodingStr = null;
- StringArgument keyStorePath = null;
- StringArgument keyStorePassword = null;
- StringArgument trustStorePath = null;
-// StringArgument trustStorePassword = null;
- StringArgument hostName = null;
- IntegerArgument port = null;
- BooleanArgument showUsage = null;
- StringArgument controlStr = null;
- BooleanArgument verbose = null;
- BooleanArgument continueOnError = null;
- BooleanArgument useSSL = null;
- BooleanArgument startTLS = null;
- BooleanArgument saslExternal = null;
- BooleanArgument defaultAdd = null;
- StringArgument filename = null;
- StringArgument saslOptions = null;
- StringArgument preReadAttributes = null;
- StringArgument postReadAttributes = null;
- IntegerArgument version = null;
- BooleanArgument noop = null;
+ BooleanArgument continueOnError = null;
+ BooleanArgument defaultAdd = null;
+ BooleanArgument noop = null;
+ BooleanArgument reportAuthzID = null;
+ BooleanArgument saslExternal = null;
+ BooleanArgument showUsage = null;
+ BooleanArgument startTLS = null;
+ BooleanArgument trustAll = null;
+ BooleanArgument useSSL = null;
+ BooleanArgument verbose = null;
+ FileBasedArgument bindPasswordFile = null;
+ FileBasedArgument keyStorePasswordFile = null;
+ FileBasedArgument trustStorePasswordFile = null;
+ IntegerArgument port = null;
+ IntegerArgument version = null;
+ StringArgument assertionFilter = null;
+ StringArgument bindDN = null;
+ StringArgument bindPassword = null;
+ StringArgument controlStr = null;
+ StringArgument encodingStr = null;
+ StringArgument filename = null;
+ StringArgument hostName = null;
+ StringArgument keyStorePath = null;
+ StringArgument keyStorePassword = null;
+ StringArgument postReadAttributes = null;
+ StringArgument preReadAttributes = null;
+ StringArgument proxyAuthzID = null;
+ StringArgument saslOptions = null;
+ StringArgument trustStorePath = null;
+ StringArgument trustStorePassword = null;
// Create the command-line argument parser for use with this program.
- ArgumentParser argParser = new ArgumentParser(CLASS_NAME, false);
+ String toolDescription = getMessage(MSGID_LDAPMODIFY_TOOL_DESCRIPTION);
+ ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
+ false);
try
{
- trustAll = new BooleanArgument("trustAll", 'X', "trustAll",
- MSGID_DESCRIPTION_TRUSTALL);
- argParser.addArgument(trustAll);
- bindDN = new StringArgument("bindDN", 'D', "bindDN", false, false,
- true, "{bindDN}", null, null,
+ hostName = new StringArgument("host", 'h', "host", false, false, true,
+ "{host}", "localhost", null,
+ MSGID_DESCRIPTION_HOST);
+ argParser.addArgument(hostName);
+
+ port = new IntegerArgument("port", 'p', "port", false, false, true,
+ "{port}", 389, null, MSGID_DESCRIPTION_PORT);
+ argParser.addArgument(port);
+
+ useSSL = new BooleanArgument("useSSL", 'Z', "useSSL",
+ MSGID_DESCRIPTION_USE_SSL);
+ argParser.addArgument(useSSL);
+
+ startTLS = new BooleanArgument("startTLS", 'q', "startTLS",
+ MSGID_DESCRIPTION_START_TLS);
+ argParser.addArgument(startTLS);
+
+ bindDN = new StringArgument("bindDN", 'D', "bindDN", false, false, true,
+ "{bindDN}", null, null,
MSGID_DESCRIPTION_BINDDN);
argParser.addArgument(bindDN);
+
bindPassword = new StringArgument("bindPassword", 'w', "bindPassword",
- false, false,
- true, "{bindPassword}", null, null,
- MSGID_DESCRIPTION_BINDPASSWORD);
+ false, false, true, "{bindPassword}",
+ null, null,
+ MSGID_DESCRIPTION_BINDPASSWORD);
argParser.addArgument(bindPassword);
- bindPasswordFile = new FileBasedArgument("bindPasswordFile", 'j',
- "bindPasswordFile", false, false,
- "{bindPasswordFilename}", null, null,
- MSGID_DESCRIPTION_BINDPASSWORDFILE);
+
+ bindPasswordFile =
+ new FileBasedArgument("bindPasswordFile", 'j', "bindPasswordFile",
+ false, false, "{bindPasswordFilename}", null,
+ null, MSGID_DESCRIPTION_BINDPASSWORDFILE);
argParser.addArgument(bindPasswordFile);
- proxyAuthzID = new StringArgument("proxy_authzid", 'Y', "proxyAs", false,
- false, true, "{authzID}", null, null,
- MSGID_DESCRIPTION_PROXY_AUTHZID);
- argParser.addArgument(proxyAuthzID);
- reportAuthzID = new BooleanArgument("reportauthzid", 'E',
- "reportAuthzID",
- MSGID_DESCRIPTION_REPORT_AUTHZID);
- argParser.addArgument(reportAuthzID);
- encodingStr = new StringArgument("encoding", 'i', "encoding",
- false, false,
- true, "{encoding}", null, null,
- MSGID_DESCRIPTION_ENCODING);
- argParser.addArgument(encodingStr);
- keyStorePath = new StringArgument("keyStorePath", 'K',
- "keyStorePath", false, false, true,
- "{keyStorePath}", null, null,
- MSGID_DESCRIPTION_KEYSTOREPATH);
- argParser.addArgument(keyStorePath);
- trustStorePath = new StringArgument("trustStorePath", 'P',
- "trustStorePath", false, false, true,
- "{trustStorePath}", null, null,
- MSGID_DESCRIPTION_TRUSTSTOREPATH);
- argParser.addArgument(trustStorePath);
- keyStorePassword = new StringArgument("keyStorePassword", 'W',
- "keyStorePassword", false, false,
- true, "{keyStorePassword}", null, null,
- MSGID_DESCRIPTION_KEYSTOREPASSWORD);
- argParser.addArgument(keyStorePassword);
- hostName = new StringArgument("host", 'h', "host",
- false, false,
- true, "{host}", "localhost", null,
- MSGID_DESCRIPTION_HOST);
- argParser.addArgument(hostName);
- port = new IntegerArgument("port", 'p', "port",
- false, false, true, "{port}", 389, null,
- MSGID_DESCRIPTION_PORT);
- argParser.addArgument(port);
- version = new IntegerArgument("version", 'V', "version",
- false, false, true, "{version}", 3, null,
- MSGID_DESCRIPTION_VERSION);
- argParser.addArgument(version);
- filename = new StringArgument("filename", 'f',
- "filename", false, false, true,
- "{filename}", null, null,
- MSGID_DELETE_DESCRIPTION_FILENAME);
- argParser.addArgument(filename);
- showUsage = new BooleanArgument("showUsage", 'H', "help",
- MSGID_DESCRIPTION_SHOWUSAGE);
- argParser.addArgument(showUsage);
- argParser.setUsageArgument(showUsage, out);
- controlStr = new StringArgument("controls", 'J', "controls", false,
- false, true,
- "{controloid[:criticality[:value|::b64value|:<fileurl]]}",
- null, null, MSGID_DESCRIPTION_CONTROLS);
- argParser.addArgument(controlStr);
- verbose = new BooleanArgument("verbose", 'v', "verbose",
- MSGID_DESCRIPTION_VERBOSE);
- argParser.addArgument(verbose);
- continueOnError = new BooleanArgument("continueOnError", 'c',
- "continueOnError",
- MSGID_DESCRIPTION_CONTINUE_ON_ERROR);
- argParser.addArgument(continueOnError);
- useSSL = new BooleanArgument("useSSL", 'Z',
- "useSSL",
- MSGID_DESCRIPTION_USE_SSL);
- argParser.addArgument(useSSL);
- startTLS = new BooleanArgument("startTLS", 'q',
- "startTLS",
- MSGID_DESCRIPTION_START_TLS);
- argParser.addArgument(startTLS);
- saslExternal = new BooleanArgument("useSASLExternal", 'r',
- "useSASLExternal",
- MSGID_DESCRIPTION_USE_SASL_EXTERNAL);
- argParser.addArgument(saslExternal);
- defaultAdd = new BooleanArgument("defaultAdd", 'a',
- "defaultAdd",
- MSGID_MODIFY_DESCRIPTION_DEFAULT_ADD);
+
+ defaultAdd = new BooleanArgument("defaultAdd", 'a', "defaultAdd",
+ MSGID_MODIFY_DESCRIPTION_DEFAULT_ADD);
argParser.addArgument(defaultAdd);
+
+ filename = new StringArgument("filename", 'f', "filename", false, false,
+ true, "{filename}", null, null,
+ MSGID_DELETE_DESCRIPTION_FILENAME);
+ argParser.addArgument(filename);
+
+ saslExternal = new BooleanArgument("useSASLExternal", 'r',
+ "useSASLExternal",
+ MSGID_DESCRIPTION_USE_SASL_EXTERNAL);
+ argParser.addArgument(saslExternal);
+
saslOptions = new StringArgument("saslOptions", 'o', "saslOptions", false,
true, true, "{name=value}", null, null,
MSGID_DESCRIPTION_SASL_PROPERTIES);
argParser.addArgument(saslOptions);
+
+ trustAll = new BooleanArgument("trustAll", 'X', "trustAll",
+ MSGID_DESCRIPTION_TRUSTALL);
+ argParser.addArgument(trustAll);
+
+ keyStorePath = new StringArgument("keyStorePath", 'K', "keyStorePath",
+ false, false, true, "{keyStorePath}",
+ null, null,
+ MSGID_DESCRIPTION_KEYSTOREPATH);
+ argParser.addArgument(keyStorePath);
+
+ keyStorePassword = new StringArgument("keyStorePassword", 'W',
+ "keyStorePassword", false, false,
+ true, "{keyStorePassword}", null,
+ null,
+ MSGID_DESCRIPTION_KEYSTOREPASSWORD);
+ argParser.addArgument(keyStorePassword);
+
+ keyStorePasswordFile =
+ new FileBasedArgument("keystorepasswordfile", null,
+ "keyStorePasswordFile", false, false, "{path}",
+ null, null,
+ MSGID_DESCRIPTION_KEYSTOREPASSWORD_FILE);
+ argParser.addArgument(keyStorePasswordFile);
+
+ trustStorePath = new StringArgument("trustStorePath", 'P',
+ "trustStorePath", false, false, true,
+ "{trustStorePath}", null, null,
+ MSGID_DESCRIPTION_TRUSTSTOREPATH);
+ argParser.addArgument(trustStorePath);
+
+ trustStorePassword =
+ new StringArgument("trustStorePassword", null, "trustStorePassword",
+ false, false, true, "{trustStorePassword}", null,
+ null, MSGID_DESCRIPTION_TRUSTSTOREPASSWORD);
+ argParser.addArgument(trustStorePassword);
+
+ trustStorePasswordFile =
+ new FileBasedArgument("truststorepasswordfile", null,
+ "trustStorePasswordFile", false, false,
+ "{path}", null, null,
+ MSGID_DESCRIPTION_TRUSTSTOREPASSWORD_FILE);
+ argParser.addArgument(trustStorePasswordFile);
+
+ proxyAuthzID = new StringArgument("proxy_authzid", 'Y', "proxyAs", false,
+ false, true, "{authzID}", null, null,
+ MSGID_DESCRIPTION_PROXY_AUTHZID);
+ argParser.addArgument(proxyAuthzID);
+
+ reportAuthzID = new BooleanArgument("reportauthzid", 'E',
+ "reportAuthzID",
+ MSGID_DESCRIPTION_REPORT_AUTHZID);
+ argParser.addArgument(reportAuthzID);
+
assertionFilter = new StringArgument("assertionfilter", null,
"assertionFilter", false, false,
true, "{filter}", null, null,
MSGID_DESCRIPTION_ASSERTION_FILTER);
argParser.addArgument(assertionFilter);
+
preReadAttributes = new StringArgument("prereadattrs", null,
"preReadAttributes", false, false,
true, "{attrList}", null, null,
MSGID_DESCRIPTION_PREREAD_ATTRS);
argParser.addArgument(preReadAttributes);
+
postReadAttributes = new StringArgument("postreadattrs", null,
"postReadAttributes", false,
false, true, "{attrList}", null,
null,
MSGID_DESCRIPTION_POSTREAD_ATTRS);
argParser.addArgument(postReadAttributes);
+
+ controlStr =
+ new StringArgument("controls", 'J', "controls", false, false, true,
+ "{controloid[:criticality[:value|::b64value|:<fileurl]]}",
+ null, null, MSGID_DESCRIPTION_CONTROLS);
+ argParser.addArgument(controlStr);
+
+ version = new IntegerArgument("version", 'V', "version",
+ false, false, true, "{version}", 3, null,
+ MSGID_DESCRIPTION_VERSION);
+ argParser.addArgument(version);
+
+ encodingStr = new StringArgument("encoding", 'i', "encoding",
+ false, false,
+ true, "{encoding}", null, null,
+ MSGID_DESCRIPTION_ENCODING);
+ argParser.addArgument(encodingStr);
+
+ continueOnError = new BooleanArgument("continueOnError", 'c',
+ "continueOnError",
+ MSGID_DESCRIPTION_CONTINUE_ON_ERROR);
+ argParser.addArgument(continueOnError);
+
noop = new BooleanArgument("no-op", 'n', "noop",
MSGID_DESCRIPTION_NOOP);
argParser.addArgument(noop);
+
+ verbose = new BooleanArgument("verbose", 'v', "verbose",
+ MSGID_DESCRIPTION_VERBOSE);
+ argParser.addArgument(verbose);
+
+ showUsage = new BooleanArgument("showUsage", 'H', "help",
+ MSGID_DESCRIPTION_SHOWUSAGE);
+ argParser.addArgument(showUsage);
+ argParser.setUsageArgument(showUsage, out);
} catch (ArgumentException ae)
{
int msgID = MSGID_ENCPW_CANNOT_INITIALIZE_ARGS;
String message = getMessage(msgID, ae.getMessage());
- err.println(message);
+ err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
@@ -727,7 +778,7 @@
int msgID = MSGID_ENCPW_ERROR_PARSING_ARGS;
String message = getMessage(msgID, ae.getMessage());
- err.println(message);
+ err.println(wrapText(message, MAX_LINE_WIDTH));
err.println(argParser.getUsage());
return 1;
}
@@ -740,8 +791,10 @@
if(bindPassword.isPresent() && bindPasswordFile.isPresent())
{
- err.println("ERROR: Both -w and -j flags specified. " +
- "Please specify one.");
+ int msgID = MSGID_TOOL_CONFLICTING_ARGS;
+ String message = getMessage(msgID, bindPassword.getLongIdentifier(),
+ bindPasswordFile.getLongIdentifier());
+ err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
@@ -753,7 +806,7 @@
} catch(ArgumentException ae)
{
assert debugException(CLASS_NAME, "main", ae);
- err.println(ae.getMessage());
+ err.println(wrapText(ae.getMessage(), MAX_LINE_WIDTH));
return 1;
}
@@ -763,14 +816,14 @@
if(versionNumber != 2 && versionNumber != 3)
{
int msgID = MSGID_DESCRIPTION_INVALID_VERSION;
- err.println(getMessage(msgID, versionNumber));
+ err.println(wrapText(getMessage(msgID, versionNumber), MAX_LINE_WIDTH));
return 1;
}
connectionOptions.setVersionNumber(versionNumber);
} catch(ArgumentException ae)
{
assert debugException(CLASS_NAME, "main", ae);
- err.println(ae.getMessage());
+ err.println(wrapText(ae.getMessage(), MAX_LINE_WIDTH));
return 1;
}
@@ -788,7 +841,7 @@
} catch(Exception ex)
{
assert debugException(CLASS_NAME, "main", ex);
- err.println(ex.getMessage());
+ err.println(wrapText(ex.getMessage(), MAX_LINE_WIDTH));
return 1;
}
} else if(bindPasswordValue == null)
@@ -798,9 +851,27 @@
}
String keyStorePathValue = keyStorePath.getValue();
- String keyStorePasswordValue = keyStorePassword.getValue();
String trustStorePathValue = trustStorePath.getValue();
+
+ String keyStorePasswordValue = null;
+ if (keyStorePassword.isPresent())
+ {
+ keyStorePasswordValue = keyStorePassword.getValue();
+ }
+ else if (keyStorePasswordFile.isPresent())
+ {
+ keyStorePasswordValue = keyStorePasswordFile.getValue();
+ }
+
String trustStorePasswordValue = null;
+ if (trustStorePassword.isPresent())
+ {
+ trustStorePasswordValue = trustStorePassword.getValue();
+ }
+ else if (trustStorePasswordFile.isPresent())
+ {
+ trustStorePasswordValue = trustStorePasswordFile.getValue();
+ }
modifyOptions.setShowOperations(noop.isPresent());
modifyOptions.setVerbose(verbose.isPresent());
@@ -813,7 +884,9 @@
LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
if(ctrl == null)
{
- err.println("Invalid control specified:" + ctrlString);
+ int msgID = MSGID_TOOL_INVALID_CONTROL_STRING;
+ String message = getMessage(msgID, ctrlString);
+ err.println(wrapText(message, MAX_LINE_WIDTH));
err.println(argParser.getUsage());
return 1;
}
@@ -844,8 +917,9 @@
}
catch (LDAPException le)
{
- err.println(getMessage(MSGID_LDAP_ASSERTION_INVALID_FILTER,
- le.getMessage()));
+ int msgID = MSGID_LDAP_ASSERTION_INVALID_FILTER;
+ String message = getMessage(msgID, le.getMessage());
+ err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
}
@@ -919,14 +993,16 @@
{
if(!connectionOptions.useSSL() && !connectionOptions.useStartTLS())
{
- err.println("SASL External requires either SSL or StartTLS " +
- "options to be requested.");
+ int msgID = MSGID_TOOL_SASLEXTERNAL_NEEDS_SSL_OR_TLS;
+ String message = getMessage(msgID);
+ err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
if(keyStorePathValue == null)
{
- err.println("SASL External requires a path to the SSL " +
- "client certificate keystore.");
+ int msgID = MSGID_TOOL_SASLEXTERNAL_NEEDS_KEYSTORE;
+ String message = getMessage(msgID);
+ err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
}
@@ -966,19 +1042,19 @@
} catch(LDAPException le)
{
assert debugException(CLASS_NAME, "main", le);
- err.println(le.getMessage());
+ err.println(wrapText(le.getMessage(), MAX_LINE_WIDTH));
int code = le.getResultCode();
return code;
} catch(LDAPConnectionException lce)
{
assert debugException(CLASS_NAME, "main", lce);
- err.println(lce.getMessage());
+ err.println(wrapText(lce.getMessage(), MAX_LINE_WIDTH));
int code = lce.getErrorCode();
return code;
} catch(Exception e)
{
assert debugException(CLASS_NAME, "main", e);
- err.println(e.getMessage());
+ err.println(wrapText(e.getMessage(), MAX_LINE_WIDTH));
return 1;
} finally
{
--
Gitblit v1.10.0