mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
18.37.2006 074d48992964d0a8cf3462f1d9960ace90c2d68d
Update the CLI setup utility to perform a more reliable port-in-use check.  It
now uses both a server socket and a client socket, and will reject the port
number if the server socket can't bind to the requested port, or if the client
socket can bind to that port.

OpenDS Issue Number: 1112
2 files modified
50 ■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/messages/ToolMessages.java 11 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java 39 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/messages/ToolMessages.java
@@ -9089,12 +9089,13 @@
                    "On which port would you like the Directory Server to " +
                    "accept connections from LDAP clients?");
    registerMessage(MSGID_INSTALLDS_CANNOT_BIND_TO_PRIVILEGED_PORT,
                    "ERROR:  Unable to bind to port %d:  %s.  This port may " +
                    "already be in use, or if you are a nonroot user then " +
                    "you may not be allowed to use port numbers 1024 or " +
                    "below.");
                    "ERROR:  Unable to bind to port %d.  This port may " +
                    "already be in use, or you may not have permission to " +
                    "bind to it.  On UNIX-based operating systems, non-root " +
                    "users may not be allowed to bind to ports 1 through " +
                    "1024.");
    registerMessage(MSGID_INSTALLDS_CANNOT_BIND_TO_PORT,
                    "ERROR:  Unable to bind to port %d:  %s.  This port may " +
                    "ERROR:  Unable to bind to port %d.  This port may " +
                    "already be in use, or you may not have permission to " +
                    "bind to it.");
    registerMessage(MSGID_INSTALLDS_PROMPT_ROOT_DN,
opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java
@@ -32,6 +32,7 @@
import java.io.File;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
@@ -448,22 +449,48 @@
            serverSocket.setReuseAddress(true);
            serverSocket.bind(socketAddress);
            serverSocket.close();
            break;
          }
          catch (Exception e)
            try
          {
            if (ldapPortNumber <= 1024)
              Socket socket = new Socket("127.0.0.1", ldapPortNumber);
              socket.close();
              if ((ldapPortNumber <= 1024) && (! isWindows))
            {
              msgID   = MSGID_INSTALLDS_CANNOT_BIND_TO_PRIVILEGED_PORT;
              message = getMessage(msgID, ldapPortNumber, e.getMessage());
                message = getMessage(msgID, ldapPortNumber);
              System.err.println(wrapText(message, MAX_LINE_WIDTH));
            }
            else
            {
              msgID   = MSGID_INSTALLDS_CANNOT_BIND_TO_PORT;
              message = getMessage(msgID, ldapPortNumber, e.getMessage());
                message = getMessage(msgID, ldapPortNumber);
              System.err.println(wrapText(message, MAX_LINE_WIDTH));
            }
              continue;
            }
            catch (Exception e)
            {
              // This is expected, so no action should be taken.
              break;
            }
          }
          catch (Exception e)
          {
            if ((ldapPortNumber <= 1024) && (! isWindows))
            {
              msgID   = MSGID_INSTALLDS_CANNOT_BIND_TO_PRIVILEGED_PORT;
              message = getMessage(msgID, ldapPortNumber);
              System.err.println(wrapText(message, MAX_LINE_WIDTH));
            }
            else
            {
              msgID   = MSGID_INSTALLDS_CANNOT_BIND_TO_PORT;
              message = getMessage(msgID, ldapPortNumber);
              System.err.println(wrapText(message, MAX_LINE_WIDTH));
            }
            continue;
          }
        }
      }