LDAPPasswordModify.java revision 29fa222166e7cbd6b5823421555aa647108eb00f
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley/*
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * CDDL HEADER START
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley *
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * The contents of this file are subject to the terms of the
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * Common Development and Distribution License, Version 1.0 only
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * (the "License"). You may not use this file except in compliance
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * with the License.
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley *
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * You can obtain a copy of the license at
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * trunk/opends/resource/legal-notices/OpenDS.LICENSE
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * See the License for the specific language governing permissions
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * and limitations under the License.
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley *
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * When distributing Covered Code, include this CDDL HEADER in each
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington * file and include the License file at
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley * add the following below this CDDL HEADER, with the fields enclosed
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * by brackets "[]" replaced with your own identifying * information:
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * Portions Copyright [yyyy] [name of copyright owner]
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley *
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * CDDL HEADER END
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley *
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley *
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff * Portions Copyright 2006 Sun Microsystems, Inc.
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff */
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffpackage org.opends.server.tools;
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport java.io.OutputStream;
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport java.io.PrintStream;
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport java.util.ArrayList;
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport java.util.concurrent.atomic.AtomicInteger;
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.core.DirectoryServer;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.asn1.ASN1Element;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.asn1.ASN1OctetString;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.asn1.ASN1Reader;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.asn1.ASN1Sequence;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.asn1.ASN1Writer;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.ldap.LDAPMessage;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.ldap.LDAPResultCode;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.ldap.UnbindRequestProtocolOp;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.types.DN;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.types.NullOutputStream;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.ArgumentException;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.ArgumentParser;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.BooleanArgument;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.FileBasedArgument;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.IntegerArgument;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.StringArgument;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport static org.opends.server.extensions.ExtensionsConstants.*;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport static org.opends.server.messages.MessageHandler.*;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport static org.opends.server.messages.ToolMessages.*;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport static org.opends.server.util.ServerConstants.*;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport static org.opends.server.util.StaticUtils.*;
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson/**
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * This program provides a utility that uses the LDAP password modify extended
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * operation to change the password for a user. It exposes the three primary
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * options available for this operation, which are:
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson *
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * <UL>
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * <LI>The user identity whose password should be changed.</LI>
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * <LI>The current password for the user.</LI>
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * <LI>The new password for the user.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * </UL>
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson *
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * All of these are optional components that may be included or omitted from the
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * request.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson */
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafssonpublic class LDAPPasswordModify
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson{
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson /**
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * The fully-qualified name of this class for debugging purposes.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson */
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson private static final String CLASS_NAME =
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson "org.opends.server.tools.LDAPPasswordModify";
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson /**
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * Parses the command-line arguments, establishes a connection to the
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * Directory Server, sends the password modify request, and reads the
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * response.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson *
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * @param args The command-line arguments provided to this program.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson */
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson public static void main(String[] args)
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson {
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson int returnCode = mainPasswordModify(args, true, System.out, System.err);
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson if (returnCode != 0)
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson {
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson System.exit(returnCode);
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson }
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson }
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson /**
2c7e99b941c3f1ffa29f9034c710f358c09f13c9Michael Graff * Parses the command-line arguments, establishes a connection to the
2c7e99b941c3f1ffa29f9034c710f358c09f13c9Michael Graff * Directory Server, sends the password modify request, and reads the
2c7e99b941c3f1ffa29f9034c710f358c09f13c9Michael Graff * response.
2c7e99b941c3f1ffa29f9034c710f358c09f13c9Michael Graff *
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * @param args The command-line arguments provided to this program.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson *
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * @return An integer value of zero if everything completed successfully, or
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * a nonzero value if an error occurred.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson */
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson public static int mainPasswordModify(String[] args)
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson {
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson return mainPasswordModify(args, true, System.out, System.err);
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson }
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson /**
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * Parses the command-line arguments, establishes a connection to the
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * Directory Server, sends the password modify request, and reads the
13494a4d4bead37f22eb6c4779c73310109f7e4aJames Brister * response.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley *
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @param args The command-line arguments provided to this
5b36207657107b48295534c51d5f6f070d6f689eBob Halley * program.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @param initializeServer Indicates whether to initialize the server.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @param outStream The output stream to use for standard output.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @param errStream The output stream to use for standard error.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley *
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @return An integer value of zero if everything completed successfully, or
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * a nonzero value if an error occurred.
a2171e092382f8f8a72b1f73436ddf93918c7719Bob Halley */
a2171e092382f8f8a72b1f73436ddf93918c7719Bob Halley public static int mainPasswordModify(String[] args, boolean initializeServer,
7c0876aa42e6abaa8779bcb83962ccf20a9f4da3Bob Halley OutputStream outStream,
a2171e092382f8f8a72b1f73436ddf93918c7719Bob Halley OutputStream errStream)
491b48ec3f3ef014312688776ddbd4eab8a2c10cMichael Graff {
13494a4d4bead37f22eb6c4779c73310109f7e4aJames Brister PrintStream out;
13494a4d4bead37f22eb6c4779c73310109f7e4aJames Brister if (outStream == null)
13494a4d4bead37f22eb6c4779c73310109f7e4aJames Brister {
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley out = NullOutputStream.printStream();
13494a4d4bead37f22eb6c4779c73310109f7e4aJames Brister }
13494a4d4bead37f22eb6c4779c73310109f7e4aJames Brister else
13494a4d4bead37f22eb6c4779c73310109f7e4aJames Brister {
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley out = new PrintStream(outStream);
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley }
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley PrintStream err;
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley if (errStream == null)
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley {
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley err = NullOutputStream.printStream();
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley }
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley else
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley {
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley err = new PrintStream(errStream);
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley }
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley // Create the arguments that will be used by this program.
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley BooleanArgument provideDNForAuthzID;
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley BooleanArgument showUsage;
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley BooleanArgument sslBlindTrust;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley BooleanArgument useSSL;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley BooleanArgument useStartTLS;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley FileBasedArgument bindPWFile;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley FileBasedArgument currentPWFile;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley FileBasedArgument newPWFile;
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley FileBasedArgument sslKeyStorePINFile;
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley FileBasedArgument sslTrustStorePINFile;
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley IntegerArgument ldapPort;
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley StringArgument authzID;
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley StringArgument bindDN;
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley StringArgument bindPW;
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley StringArgument currentPW;
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley StringArgument ldapHost;
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley StringArgument newPW;
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley StringArgument sslKeyStore;
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley StringArgument sslTrustStore;
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley // Initialize the argument parser.
491b48ec3f3ef014312688776ddbd4eab8a2c10cMichael Graff String toolDescription = getMessage(MSGID_LDAPPWMOD_TOOL_DESCRIPTION);
13494a4d4bead37f22eb6c4779c73310109f7e4aJames Brister ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
ffea097efa5b9d6a0d5e8ed43d98c29de3fa5b8dMichael Graff false);
491b48ec3f3ef014312688776ddbd4eab8a2c10cMichael Graff
ffea097efa5b9d6a0d5e8ed43d98c29de3fa5b8dMichael Graff try
ffea097efa5b9d6a0d5e8ed43d98c29de3fa5b8dMichael Graff {
ffea097efa5b9d6a0d5e8ed43d98c29de3fa5b8dMichael Graff ldapHost = new StringArgument("ldaphost", 'h', "ldapHost", false, false,
ffea097efa5b9d6a0d5e8ed43d98c29de3fa5b8dMichael Graff true, "{host}", "127.0.0.1", null,
491b48ec3f3ef014312688776ddbd4eab8a2c10cMichael Graff MSGID_LDAPPWMOD_DESCRIPTION_HOST);
ffea097efa5b9d6a0d5e8ed43d98c29de3fa5b8dMichael Graff argParser.addArgument(ldapHost);
ffea097efa5b9d6a0d5e8ed43d98c29de3fa5b8dMichael Graff
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff ldapPort = new IntegerArgument("ldapport", 'p', "ldapPort", false, false,
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff true, "{port}", 389, null, true, 1, true,
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff 65535, MSGID_LDAPPWMOD_DESCRIPTION_PORT);
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff argParser.addArgument(ldapPort);
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff useSSL = new BooleanArgument("usessl", 'Z', "useSSL",
64ba6e4cc3a0ccf8c8c6349fa75b937ca9bad9a6Michael Graff MSGID_LDAPPWMOD_DESCRIPTION_USE_SSL);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley argParser.addArgument(useSSL);
491b48ec3f3ef014312688776ddbd4eab8a2c10cMichael Graff
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley useStartTLS = new BooleanArgument("usestarttls", 'q', "useStartTLS",
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_USE_STARTTLS);
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley argParser.addArgument(useStartTLS);
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley bindDN = new StringArgument("binddn", 'D', "bindDN", false, false, true,
a2171e092382f8f8a72b1f73436ddf93918c7719Bob Halley "{bindDN}", null, null,
61ca07caec2c7d58e1da52055c1aa1e1fb8c67d9Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_BIND_DN);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley argParser.addArgument(bindDN);
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley bindPW = new StringArgument("bindpw", 'w', "bindPassword", false, false,
7c0876aa42e6abaa8779bcb83962ccf20a9f4da3Bob Halley true, "{bindDN}", null, null,
7c0876aa42e6abaa8779bcb83962ccf20a9f4da3Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_BIND_PW);
7c0876aa42e6abaa8779bcb83962ccf20a9f4da3Bob Halley argParser.addArgument(bindPW);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
491b48ec3f3ef014312688776ddbd4eab8a2c10cMichael Graff bindPWFile =
491b48ec3f3ef014312688776ddbd4eab8a2c10cMichael Graff new FileBasedArgument("bindpwfile", 'j', "bindPasswordFile", false,
491b48ec3f3ef014312688776ddbd4eab8a2c10cMichael Graff false, "{file}", null, null,
491b48ec3f3ef014312688776ddbd4eab8a2c10cMichael Graff MSGID_LDAPPWMOD_DESCRIPTION_BIND_PW_FILE);
28ed3013196c373745dbde87b75a490148dab840Bob Halley argParser.addArgument(bindPWFile);
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson
820ad97db480f58e1e4d0d3eeae73b2fb27b4f91Andreas Gustafsson
820ad97db480f58e1e4d0d3eeae73b2fb27b4f91Andreas Gustafsson authzID = new StringArgument("authzid", 'a', "authzID", false, false,
820ad97db480f58e1e4d0d3eeae73b2fb27b4f91Andreas Gustafsson true, "{authzID}", null, null,
820ad97db480f58e1e4d0d3eeae73b2fb27b4f91Andreas Gustafsson MSGID_LDAPPWMOD_DESCRIPTION_AUTHZID);
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson argParser.addArgument(authzID);
28ed3013196c373745dbde87b75a490148dab840Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley provideDNForAuthzID =
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson new BooleanArgument("providednforauthzid", 'A',"provideDNForAuthzID",
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_PROVIDE_DN_FOR_AUTHZID);
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson argParser.addArgument(provideDNForAuthzID);
1922518d7f7b5e3e77b8e1c92569c98268b9c192Andreas Gustafsson
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley newPW = new StringArgument("newpw", 'n', "newPassword", false, false,
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley true, "{newPassword}", null, null,
70eb7879553eaa57c391f07e439911bfdaff7124Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_NEWPW);
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley argParser.addArgument(newPW);
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley newPWFile = new FileBasedArgument("newpwfile", 'N', "newPasswordFile",
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley false, false, "{file}", null, null,
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_NEWPWFILE);
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley argParser.addArgument(newPWFile);
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley currentPW =
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley new StringArgument("currentpw", 'c', "currentPassword", false, false,
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley true, "{currentPassword}", null, null,
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_CURRENTPW);
70eb7879553eaa57c391f07e439911bfdaff7124Bob Halley argParser.addArgument(currentPW);
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley currentPWFile =
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley new FileBasedArgument("currentpwfile", 'C', "currentPasswordFile",
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley false, false, "{file}", null, null,
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_CURRENTPWFILE);
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley argParser.addArgument(currentPWFile);
c768c47e59194578c7c605a28c112ba0a4e9af53Bob Halley
c768c47e59194578c7c605a28c112ba0a4e9af53Bob Halley
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley sslBlindTrust =
70eb7879553eaa57c391f07e439911bfdaff7124Bob Halley new BooleanArgument("blindtrust", 'X', "trustAllCertificates",
1922518d7f7b5e3e77b8e1c92569c98268b9c192Andreas Gustafsson MSGID_LDAPPWMOD_DESCRIPTION_BLIND_TRUST);
868f13e9490474f8f9f3ceb5494e704f5719dce1Bob Halley argParser.addArgument(sslBlindTrust);
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley
868f13e9490474f8f9f3ceb5494e704f5719dce1Bob Halley
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley sslKeyStore =
868f13e9490474f8f9f3ceb5494e704f5719dce1Bob Halley new StringArgument("sslkeystore", 'k', "sslKeyStore", false, false,
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley true, "{file}", null, null,
1922518d7f7b5e3e77b8e1c92569c98268b9c192Andreas Gustafsson MSGID_LDAPPWMOD_DESCRIPTION_KEYSTORE);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley argParser.addArgument(sslKeyStore);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley sslKeyStorePINFile =
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley new FileBasedArgument("sslkeystorepin", 'K', "sslKeyStorePINFile",
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley false, false, "{file}", null, null,
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_KEYSTORE_PINFILE);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley argParser.addArgument(sslKeyStorePINFile);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley sslTrustStore =
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley new StringArgument("ssltruststore", 't', "sslTrustStore", false,
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley false, true, "{file}", null, null,
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_TRUSTSTORE);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley argParser.addArgument(sslTrustStore);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley sslTrustStorePINFile =
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley new FileBasedArgument("ssltruststorepin", 'T',
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley "sslTrustStorePINFile", false, false, "{file}", null, null,
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_TRUSTSTORE_PINFILE);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley argParser.addArgument(sslTrustStorePINFile);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley showUsage = new BooleanArgument("help", 'H', "help",
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_USAGE);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley argParser.addArgument(showUsage);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley argParser.setUsageArgument(showUsage, out);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley }
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley catch (ArgumentException ae)
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley {
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley int msgID = MSGID_LDAPPWMOD_CANNOT_INITIALIZE_ARGS;
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley String message = getMessage(msgID, ae.getMessage());
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley err.println(wrapText(message, MAX_LINE_WIDTH));
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley return 1;
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley }
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley // Parse the command-line arguments provided to this program.
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley try
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley {
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley argParser.parseArguments(args);
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley }
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley catch (ArgumentException ae)
6d5dcd0dc9bdbd679282b1ffc47987d24c3a1346Bob Halley {
6d5dcd0dc9bdbd679282b1ffc47987d24c3a1346Bob Halley int msgID = MSGID_LDAPPWMOD_ERROR_PARSING_ARGS;
6d5dcd0dc9bdbd679282b1ffc47987d24c3a1346Bob Halley String message = getMessage(msgID, ae.getMessage());
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
6d5dcd0dc9bdbd679282b1ffc47987d24c3a1346Bob Halley err.println(wrapText(message, MAX_LINE_WIDTH));
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley err.println(argParser.getUsage());
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley return 1;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley }
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley // If the usage argument was provided, then we don't need to do anything
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley // else.
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley if (showUsage.isPresent())
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley {
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley return 0;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley }
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley // Make sure that the user didn't specify any conflicting arguments.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley if (bindPW.isPresent() && bindPWFile.isPresent())
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley {
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley int msgID = MSGID_LDAPPWMOD_CONFLICTING_ARGS;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley String message = getMessage(msgID, bindPW.getLongIdentifier(),
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley bindPWFile.getLongIdentifier());
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley err.println(wrapText(message, MAX_LINE_WIDTH));
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley return 1;
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley }
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley if (newPW.isPresent() && newPWFile.isPresent())
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley {
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley int msgID = MSGID_LDAPPWMOD_CONFLICTING_ARGS;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley String message = getMessage(msgID, newPW.getLongIdentifier(),
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley newPWFile.getLongIdentifier());
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley err.println(wrapText(message, MAX_LINE_WIDTH));
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington return 1;
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington }
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington if (currentPW.isPresent() && currentPWFile.isPresent())
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington {
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington int msgID = MSGID_LDAPPWMOD_CONFLICTING_ARGS;
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington String message = getMessage(msgID, currentPW.getLongIdentifier(),
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington currentPWFile.getLongIdentifier());
44aae046c38e796e581110b7ecdf4478167d684dBob Halley err.println(wrapText(message, MAX_LINE_WIDTH));
44aae046c38e796e581110b7ecdf4478167d684dBob Halley return 1;
44aae046c38e796e581110b7ecdf4478167d684dBob Halley }
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
690a68b8112039e633e26f9216c0d463751e011aMichael Graff if (useSSL.isPresent() && useStartTLS.isPresent())
44aae046c38e796e581110b7ecdf4478167d684dBob Halley {
44aae046c38e796e581110b7ecdf4478167d684dBob Halley int msgID = MSGID_LDAPPWMOD_CONFLICTING_ARGS;
44aae046c38e796e581110b7ecdf4478167d684dBob Halley String message = getMessage(msgID, useSSL.getLongIdentifier(),
44aae046c38e796e581110b7ecdf4478167d684dBob Halley useStartTLS.getLongIdentifier());
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington err.println(wrapText(message, MAX_LINE_WIDTH));
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley return 1;
}
// If a bind DN was provided, make sure that a password was given. If a
// password was given, make sure a bind DN was provided. If neither were
// given, then make sure that an authorization ID and the current password
// were provided.
if (bindDN.isPresent())
{
if (! (bindPW.isPresent() || bindPWFile.isPresent()))
{
int msgID = MSGID_LDAPPWMOD_BIND_DN_AND_PW_MUST_BE_TOGETHER;
String message = getMessage(msgID);
err.println(wrapText(message, MAX_LINE_WIDTH));
err.println(argParser.getUsage());
return 1;
}
}
else if (bindPW.isPresent() || bindPWFile.isPresent())
{
int msgID = MSGID_LDAPPWMOD_BIND_DN_AND_PW_MUST_BE_TOGETHER;
String message = getMessage(msgID);
err.println(wrapText(message, MAX_LINE_WIDTH));
err.println(argParser.getUsage());
return 1;
}
else
{
if (provideDNForAuthzID.isPresent())
{
int msgID = MSGID_LDAPPWMOD_DEPENDENT_ARGS;
String message = getMessage(msgID,
provideDNForAuthzID.getLongIdentifier(),
bindDN.getLongIdentifier());
err.println(wrapText(message, MAX_LINE_WIDTH));
err.println(argParser.getUsage());
return 1;
}
if (! (authzID.isPresent() &&
(currentPW.isPresent() || currentPWFile.isPresent())))
{
int msgID = MSGID_LDAPPWMOD_ANON_REQUIRES_AUTHZID_AND_CURRENTPW;
String message = getMessage(msgID);
err.println(wrapText(message, MAX_LINE_WIDTH));
err.println(argParser.getUsage());
return 1;
}
}
// Get the host and port.
String host = ldapHost.getValue();
int port;
try
{
port = ldapPort.getIntValue();
}
catch (Exception e)
{
// This should never happen.
err.println(e);
return 1;
}
// Perform a basic Directory Server bootstrap if appropriate.
if (initializeServer)
{
DirectoryServer.bootstrapClient();
}
// Establish a connection to the Directory Server.
AtomicInteger nextMessageID = new AtomicInteger(1);
LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions();
connectionOptions.setUseSSL(useSSL.isPresent());
connectionOptions.setStartTLS(useStartTLS.isPresent());
connectionOptions.setVersionNumber(3);
if(connectionOptions.useSSL() || connectionOptions.useStartTLS())
{
try
{
SSLConnectionFactory sslConnectionFactory = new SSLConnectionFactory();
sslConnectionFactory.init(sslBlindTrust.isPresent(),
sslKeyStore.getValue(),
sslKeyStorePINFile.getValue(),
sslTrustStore.getValue(),
sslTrustStorePINFile.getValue());
connectionOptions.setSSLConnectionFactory(sslConnectionFactory);
}
catch (Exception e)
{
int msgID = MSGID_LDAPPWMOD_ERROR_INITIALIZING_SSL;
String message = getMessage(msgID, String.valueOf(e));
err.println(wrapText(message, MAX_LINE_WIDTH));
return 1;
}
}
LDAPConnection connection = new LDAPConnection(host, port,
connectionOptions, out, err);
String dn;
String pw;
if (bindPW.isPresent())
{
dn = bindDN.getValue();
pw = bindPW.getValue();
}
else if (bindPWFile.isPresent())
{
dn = bindDN.getValue();
pw = bindPWFile.getValue();
}
else
{
dn = null;
pw = null;
}
try
{
connection.connectToHost(dn, pw, nextMessageID);
}
catch (LDAPConnectionException lce)
{
int msgID = MSGID_LDAPPWMOD_CANNOT_CONNECT;
String message = getMessage(msgID, lce.getMessage());
err.println(wrapText(message, MAX_LINE_WIDTH));
return lce.getErrorCode();
}
ASN1Reader reader = connection.getASN1Reader();
ASN1Writer writer = connection.getASN1Writer();
// Construct the password modify request.
ArrayList<ASN1Element> requestElements = new ArrayList<ASN1Element>(3);
if (authzID.isPresent())
{
requestElements.add(new ASN1OctetString(TYPE_PASSWORD_MODIFY_USER_ID,
authzID.getValue()));
}
else if (provideDNForAuthzID.isPresent())
{
requestElements.add(new ASN1OctetString(TYPE_PASSWORD_MODIFY_USER_ID,
"dn:" + dn));
}
if (currentPW.isPresent())
{
requestElements.add(new ASN1OctetString(TYPE_PASSWORD_MODIFY_OLD_PASSWORD,
currentPW.getValue()));
}
else if (provideDNForAuthzID.isPresent())
{
requestElements.add(new ASN1OctetString(TYPE_PASSWORD_MODIFY_OLD_PASSWORD,
pw));
}
if (newPW.isPresent())
{
requestElements.add(new ASN1OctetString(TYPE_PASSWORD_MODIFY_NEW_PASSWORD,
newPW.getValue()));
}
ASN1OctetString requestValue =
new ASN1OctetString(new ASN1Sequence(requestElements).encode());
ExtendedRequestProtocolOp extendedRequest =
new ExtendedRequestProtocolOp(OID_PASSWORD_MODIFY_REQUEST,
requestValue);
LDAPMessage requestMessage =
new LDAPMessage(nextMessageID.getAndIncrement(), extendedRequest);
// Send the request to the server and read the response.
try
{
writer.writeElement(requestMessage.encode());
}
catch (Exception e)
{
int msgID = MSGID_LDAPPWMOD_CANNOT_SEND_PWMOD_REQUEST;
String message = getMessage(msgID, String.valueOf(e));
err.println(wrapText(message, MAX_LINE_WIDTH));
try
{
requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(),
new UnbindRequestProtocolOp());
writer.writeElement(requestMessage.encode());
}
catch (Exception e2) {}
try
{
reader.close();
writer.close();
} catch (Exception e2) {}
return 1;
}
// Read the response from the server.
LDAPMessage responseMessage = null;
try
{
ASN1Sequence responseSequence = reader.readElement().decodeAsSequence();
responseMessage = LDAPMessage.decode(responseSequence);
}
catch (Exception e)
{
int msgID = MSGID_LDAPPWMOD_CANNOT_READ_PWMOD_RESPONSE;
String message = getMessage(msgID, String.valueOf(e));
err.println(wrapText(message, MAX_LINE_WIDTH));
try
{
requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(),
new UnbindRequestProtocolOp());
writer.writeElement(requestMessage.encode());
}
catch (Exception e2) {}
try
{
reader.close();
writer.close();
} catch (Exception e2) {}
return 1;
}
// Make sure that the response was acceptable.
ExtendedResponseProtocolOp extendedResponse =
responseMessage.getExtendedResponseProtocolOp();
int resultCode = extendedResponse.getResultCode();
if (resultCode != LDAPResultCode.SUCCESS)
{
int msgID = MSGID_LDAPPWMOD_FAILED;
String message = getMessage(msgID, resultCode);
err.println(wrapText(message, MAX_LINE_WIDTH));
String errorMessage = extendedResponse.getErrorMessage();
if ((errorMessage != null) && (errorMessage.length() > 0))
{
msgID = MSGID_LDAPPWMOD_FAILURE_ERROR_MESSAGE;
message = getMessage(msgID, errorMessage);
err.println(wrapText(message, MAX_LINE_WIDTH));
}
DN matchedDN = extendedResponse.getMatchedDN();
if (matchedDN != null)
{
msgID = MSGID_LDAPPWMOD_FAILURE_MATCHED_DN;
message = getMessage(msgID, matchedDN.toString());
err.println(wrapText(message, MAX_LINE_WIDTH));
}
try
{
requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(),
new UnbindRequestProtocolOp());
writer.writeElement(requestMessage.encode());
}
catch (Exception e) {}
try
{
reader.close();
writer.close();
} catch (Exception e) {}
return resultCode;
}
else
{
int msgID = MSGID_LDAPPWMOD_SUCCESSFUL;
String message = getMessage(msgID);
out.println(wrapText(message, MAX_LINE_WIDTH));
String additionalInfo = extendedResponse.getErrorMessage();
if ((additionalInfo != null) && (additionalInfo.length() > 0))
{
msgID = MSGID_LDAPPWMOD_ADDITIONAL_INFO;
message = getMessage(msgID, additionalInfo);
out.println(wrapText(message, MAX_LINE_WIDTH));
}
}
// See if the response included a generated password.
ASN1OctetString responseValue = extendedResponse.getValue();
if (responseValue != null)
{
try
{
ASN1Sequence responseSequence =
ASN1Sequence.decodeAsSequence(responseValue.value());
for (ASN1Element e : responseSequence.elements())
{
if (e.getType() == TYPE_PASSWORD_MODIFY_GENERATED_PASSWORD)
{
int msgID = MSGID_LDAPPWMOD_GENERATED_PASSWORD;
String message = getMessage(msgID,
e.decodeAsOctetString().stringValue());
out.println(wrapText(message, MAX_LINE_WIDTH));
}
else
{
int msgID = MSGID_LDAPPWMOD_UNRECOGNIZED_VALUE_TYPE;
String message = getMessage(msgID, byteToHex(e.getType()));
err.println(wrapText(message, MAX_LINE_WIDTH));
}
}
}
catch (Exception e)
{
int msgID = MSGID_LDAPPWMOD_COULD_NOT_DECODE_RESPONSE_VALUE;
String message = getMessage(msgID, String.valueOf(e));
err.println(wrapText(message, MAX_LINE_WIDTH));
try
{
requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(),
new UnbindRequestProtocolOp());
writer.writeElement(requestMessage.encode());
}
catch (Exception e2) {}
try
{
reader.close();
writer.close();
} catch (Exception e2) {}
return 1;
}
}
// Unbind from the server and close the connection.
try
{
requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(),
new UnbindRequestProtocolOp());
writer.writeElement(requestMessage.encode());
}
catch (Exception e) {}
try
{
reader.close();
writer.close();
} catch (Exception e) {}
return 0;
}
}