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

neil_a_wilson
18.37.2006 deb79786ba32f7e13ad01f4025f06a8031f2b115
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
46 ■■■■ changed files
opends/src/server/org/opends/server/messages/ToolMessages.java 11 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/InstallDS.java 35 ●●●● patch | view | raw | blame | history
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,
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;
            try
            {
              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);
                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;
            }
            catch (Exception e)
            {
              // This is expected, so no action should be taken.
              break;
            }
          }
          catch (Exception e)
          {
            if (ldapPortNumber <= 1024)
            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;
          }
        }
      }