| | |
| | | import java.io.FileReader; |
| | | import java.io.InputStreamReader; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | | import java.io.Reader; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedList; |
| | |
| | | import org.opends.server.protocols.ldap.LDAPException; |
| | | import org.opends.server.protocols.ldap.LDAPMessage; |
| | | import org.opends.server.protocols.ldap.ProtocolOp; |
| | | import org.opends.server.types.NullOutputStream; |
| | | import org.opends.server.util.PasswordReader; |
| | | import org.opends.server.util.args.ArgumentException; |
| | | import org.opends.server.util.args.ArgumentParser; |
| | |
| | | // The message ID counter to use for requests. |
| | | private AtomicInteger nextMessageID; |
| | | |
| | | // The print stream to use for standard error. |
| | | private PrintStream err; |
| | | |
| | | // The print stream to use for standard output. |
| | | private PrintStream out; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Constructor for the LDAPDelete object. |
| | | * |
| | | * @param nextMessageID The next message ID to use for requests. |
| | | * @param out The print stream to use for standard output. |
| | | * @param err The print stream to use for standard error. |
| | | */ |
| | | public LDAPDelete(AtomicInteger nextMessageID) |
| | | public LDAPDelete(AtomicInteger nextMessageID, PrintStream out, |
| | | PrintStream err) |
| | | { |
| | | this.nextMessageID = nextMessageID; |
| | | this.out = out; |
| | | this.err = err; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | protocolOp = new DeleteRequestProtocolOp(asn1OctetStr); |
| | | int msgID = MSGID_PROCESSING_OPERATION; |
| | | System.out.println(getMessage(msgID, "DELETE", asn1OctetStr)); |
| | | out.println(getMessage(msgID, "DELETE", asn1OctetStr)); |
| | | if(!deleteOptions.showOperations()) |
| | | { |
| | | LDAPMessage message = new LDAPMessage(nextMessageID.getAndIncrement(), |
| | |
| | | { |
| | | msgID = MSGID_OPERATION_FAILED; |
| | | String msg = getMessage(msgID, "DELETE", line, ae.getMessage()); |
| | | System.err.println(msg); |
| | | err.println(msg); |
| | | return; |
| | | } |
| | | } |
| | |
| | | { |
| | | msgID = MSGID_OPERATION_FAILED; |
| | | String msg = getMessage(msgID, "DELETE", line, errorMessage); |
| | | System.err.println(msg); |
| | | err.println(msg); |
| | | } else |
| | | { |
| | | msgID = MSGID_OPERATION_SUCCESSFUL; |
| | | String msg = getMessage(msgID, "DELETE", line); |
| | | System.out.println(msg); |
| | | out.println(msg); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | public static void main(String[] args) |
| | | { |
| | | int retCode = mainDelete(args); |
| | | int retCode = mainDelete(args, true, System.out, System.err); |
| | | |
| | | if(retCode != 0) |
| | | { |
| | |
| | | |
| | | public static int mainDelete(String[] args) |
| | | { |
| | | return mainDelete(args, true, System.out, System.err); |
| | | } |
| | | |
| | | /** |
| | | * Parses the provided command-line arguments and uses that information to |
| | | * run the ldapdelete 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. |
| | | */ |
| | | |
| | | public static int mainDelete(String[] args, boolean initializeServer, |
| | | OutputStream outStream, OutputStream errStream) |
| | | { |
| | | PrintStream out; |
| | | if (outStream == null) |
| | | { |
| | | out = NullOutputStream.printStream(); |
| | | } |
| | | else |
| | | { |
| | | out = new PrintStream(outStream); |
| | | } |
| | | |
| | | PrintStream err; |
| | | if (errStream == null) |
| | | { |
| | | err = NullOutputStream.printStream(); |
| | | } |
| | | else |
| | | { |
| | | err = new PrintStream(errStream); |
| | | } |
| | | |
| | | |
| | | LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions(); |
| | | LDAPDeleteOptions deleteOptions = new LDAPDeleteOptions(); |
| | | LDAPConnection connection = null; |
| | |
| | | showUsage = new BooleanArgument("showUsage", 'H', "help", |
| | | MSGID_DESCRIPTION_SHOWUSAGE); |
| | | argParser.addArgument(showUsage); |
| | | argParser.setUsageArgument(showUsage); |
| | | argParser.setUsageArgument(showUsage, out); |
| | | controlStr = new StringArgument("controls", 'J', "controls", false, false, |
| | | true, "{controloid[:criticality[:value|::b64value|:<fileurl]]}", |
| | | null, null, MSGID_DESCRIPTION_CONTROLS); |
| | |
| | | int msgID = MSGID_ENCPW_CANNOT_INITIALIZE_ARGS; |
| | | String message = getMessage(msgID, ae.getMessage()); |
| | | |
| | | System.err.println(message); |
| | | err.println(message); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | int msgID = MSGID_ENCPW_ERROR_PARSING_ARGS; |
| | | String message = getMessage(msgID, ae.getMessage()); |
| | | |
| | | System.err.println(message); |
| | | System.err.println(argParser.getUsage()); |
| | | err.println(message); |
| | | err.println(argParser.getUsage()); |
| | | return 1; |
| | | } |
| | | |
| | | // If we should just display usage information, then print it and exit. |
| | | if (showUsage.isPresent()) |
| | | { |
| | | System.out.println(argParser.getUsage()); |
| | | out.println(argParser.getUsage()); |
| | | return 0; |
| | | } |
| | | |
| | | if(bindPassword.isPresent() && bindPasswordFile.isPresent()) |
| | | { |
| | | System.err.println("ERROR: Both -w and -j flags specified. " + |
| | | "Please specify one."); |
| | | err.println("ERROR: Both -w and -j flags specified. " + |
| | | "Please specify one."); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | } catch(ArgumentException ae) |
| | | { |
| | | assert debugException(CLASS_NAME, "main", ae); |
| | | System.err.println(ae.getMessage()); |
| | | err.println(ae.getMessage()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | if(versionNumber != 2 && versionNumber != 3) |
| | | { |
| | | int msgID = MSGID_DESCRIPTION_INVALID_VERSION; |
| | | System.err.println(getMessage(msgID, versionNumber)); |
| | | err.println(getMessage(msgID, versionNumber)); |
| | | return 1; |
| | | } |
| | | connectionOptions.setVersionNumber(versionNumber); |
| | | } catch(ArgumentException ae) |
| | | { |
| | | assert debugException(CLASS_NAME, "main", ae); |
| | | System.err.println(ae.getMessage()); |
| | | err.println(ae.getMessage()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | // read the password from the stdin. |
| | | try |
| | | { |
| | | System.out.print(getMessage(MSGID_LDAPAUTH_PASSWORD_PROMPT, |
| | | bindDNValue)); |
| | | out.print(getMessage(MSGID_LDAPAUTH_PASSWORD_PROMPT, bindDNValue)); |
| | | char[] pwChars = PasswordReader.readPassword(); |
| | | bindPasswordValue = new String(pwChars); |
| | | } catch(Exception ex) |
| | | { |
| | | assert debugException(CLASS_NAME, "main", ex); |
| | | System.err.println(ex.getMessage()); |
| | | err.println(ex.getMessage()); |
| | | return 1; |
| | | } |
| | | } else if(bindPasswordValue == null) |
| | |
| | | LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString); |
| | | if(ctrl == null) |
| | | { |
| | | System.err.println("Invalid control specified:" + ctrlString); |
| | | System.out.println(argParser.getUsage()); |
| | | err.println("Invalid control specified:" + ctrlString); |
| | | err.println(argParser.getUsage()); |
| | | return 1; |
| | | } |
| | | deleteOptions.getControls().add(ctrl); |
| | |
| | | { |
| | | if(!connectionOptions.useSSL() && !connectionOptions.useStartTLS()) |
| | | { |
| | | System.err.println("SASL External requires either SSL or StartTLS " + |
| | | "options to be requested."); |
| | | err.println("SASL External requires either SSL or StartTLS " + |
| | | "options to be requested."); |
| | | return 1; |
| | | } |
| | | if(keyStorePathValue == null) |
| | | { |
| | | System.err.println("SASL External requires a path to the SSL " + |
| | | "client certificate keystore."); |
| | | err.println("SASL External requires a path to the SSL " + |
| | | "client certificate keystore."); |
| | | return 1; |
| | | } |
| | | } |
| | | |
| | | try |
| | | { |
| | | |
| | | // Bootstrap and initialize directory data structures. |
| | | DirectoryServer.bootstrapClient(); |
| | | if (initializeServer) |
| | | { |
| | | // Bootstrap and initialize directory data structures. |
| | | DirectoryServer.bootstrapClient(); |
| | | } |
| | | |
| | | // Connect to the specified host with the supplied userDN and password. |
| | | SSLConnectionFactory sslConnectionFactory = null; |
| | |
| | | |
| | | AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | connection = new LDAPConnection(hostNameValue, portNumber, |
| | | connectionOptions); |
| | | connectionOptions, out, err); |
| | | connection.connectToHost(bindDNValue, bindPasswordValue, nextMessageID); |
| | | |
| | | LDAPDelete ldapDelete = new LDAPDelete(nextMessageID); |
| | | LDAPDelete ldapDelete = new LDAPDelete(nextMessageID, out, err); |
| | | if(fileNameValue == null && dnStrings.isEmpty()) |
| | | { |
| | | // Read from stdin. |
| | |
| | | } catch(LDAPException le) |
| | | { |
| | | assert debugException(CLASS_NAME, "main", le); |
| | | System.err.println(le.getMessage()); |
| | | err.println(le.getMessage()); |
| | | int code = le.getResultCode(); |
| | | return code; |
| | | } catch(LDAPConnectionException lce) |
| | | { |
| | | assert debugException(CLASS_NAME, "main", lce); |
| | | System.err.println(lce.getMessage()); |
| | | err.println(lce.getMessage()); |
| | | int code = lce.getErrorCode(); |
| | | return code; |
| | | } catch(Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "main", e); |
| | | System.err.println(e.getMessage()); |
| | | err.println(e.getMessage()); |
| | | return 1; |
| | | } finally |
| | | { |