Verify that the LDAP ports are available during installation.

This commit is contained in:
Rob Crittenden 2007-10-15 13:27:05 -04:00
parent 95f0c52013
commit af0a1d989b

View File

@ -31,6 +31,7 @@ sys.path.append("/usr/share/ipa")
import os
import socket
import errno
import logging
import pwd
import getpass
@ -138,6 +139,18 @@ def check_existing_installation():
if serverid:
erase_ds_instance_data(serverid)
def check_ports():
ds_unsecure = port_available(389)
ds_secure = port_available(636)
if not ds_unsecure or not ds_secure:
print "IPA requires ports 389 and 636 for the Directory Server."
print "These are currently in use:"
if not ds_unsecure:
print "\t389"
if not ds_secure:
print "\t636"
sys.exit(1)
def get_fqdn():
fqdn = ""
try:
@ -234,6 +247,36 @@ def read_ip_address():
hosts_fd.close()
askip = False
def port_available(port):
"""Try to bind to a port on the wildcard host
Return 1 if the port is available
Return 0 if the port is in use
"""
rv = 1
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', port))
s.shutdown(0)
s.close()
except socket.error, e:
if e[0] == errno.EADDRINUSE:
rv = 0
if rv:
try:
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', port))
s.shutdown(0)
s.close()
except socket.error, e:
if e[0] == errno.EADDRINUSE:
rv = 0
return rv
def read_ds_user():
print "The server must run as a specific user in a specific group."
print "It is strongly recommended that this user should have no privileges"
@ -344,6 +387,7 @@ def main():
print "To accept the default shown in brackets, press the Enter key."
print ""
check_ports()
check_existing_installation()
options = parse_options()