summaryrefslogtreecommitdiffstats
path: root/ipaserver/install
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2012-07-03 16:49:10 +0200
committerMartin Kosek <mkosek@redhat.com>2012-07-13 14:25:18 +0200
commit4879c68d68634715b9d08a08a4c7be882634409f (patch)
treef64ca647665df5b40fb5501735d7bb5a9776786c /ipaserver/install
parent5c54dd5b03681428040af51ef3e05c10bec91d3f (diff)
downloadfreeipa.git-4879c68d68634715b9d08a08a4c7be882634409f.tar.gz
freeipa.git-4879c68d68634715b9d08a08a4c7be882634409f.tar.xz
freeipa.git-4879c68d68634715b9d08a08a4c7be882634409f.zip
Improve address family handling in sockets
Many functions use low-level socket interface for connection or various checks. However, most of the time we don't respect automatic address family detection but rather try to force our values. This may cause either redundat connection tries when an address family is disabled on system tries or even crashes when socket exceptions are not properly caught. Instead of forcing address families to socket, rather use getaddrinfo interface to automatically retrieve a list of all relevant address families and other connection settings when connecting to remote/local machine or binding to a local port. Now, we will also fill correctly all connection parameters like flowinfo and scopeid for IPv6 connections which will for example prevent issues with scoped IPv6 addresses. bind_port_responder function was changed to at first try to bind to IPv6 wildcard address before IPv4 as IPv6 socket is able to accept both IPv4 and IPv6 connections (unlike IPv4 socket). nsslib connection was refactored to use nss.io.AddrInfo class to get all the available connections. Socket is now not created by default in NSSConnection class initializer, but rather when the actual connection is being made, becase we do not an address family where connection is successful. https://fedorahosted.org/freeipa/ticket/2913 https://fedorahosted.org/freeipa/ticket/2695
Diffstat (limited to 'ipaserver/install')
-rw-r--r--ipaserver/install/dsinstance.py11
-rw-r--r--ipaserver/install/installutils.py30
2 files changed, 9 insertions, 32 deletions
diff --git a/ipaserver/install/dsinstance.py b/ipaserver/install/dsinstance.py
index 9c137af0..25c449a6 100644
--- a/ipaserver/install/dsinstance.py
+++ b/ipaserver/install/dsinstance.py
@@ -119,8 +119,15 @@ def get_ds_instances():
return instances
def check_ports():
- ds_unsecure = installutils.port_available(389)
- ds_secure = installutils.port_available(636)
+ """
+ Check of Directory server ports are open.
+
+ Returns a tuple with two booleans, one for unsecure port 389 and one for
+ secure port 636. True means that the port is free, False means that the
+ port is taken.
+ """
+ ds_unsecure = not ipautil.host_port_open(None, 389)
+ ds_secure = not ipautil.host_port_open(None, 636)
return (ds_unsecure, ds_secure)
def is_ds_running(server_id=''):
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index b65958ed..903e8f18 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -256,36 +256,6 @@ def read_dns_forwarders():
return addrs
-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)
- fcntl.fcntl(s, fcntl.F_SETFD, fcntl.FD_CLOEXEC)
- s.bind(('', port))
- 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)
- fcntl.fcntl(s, fcntl.F_SETFD, fcntl.FD_CLOEXEC)
- s.bind(('', port))
- s.close()
- except socket.error, e:
- if e[0] == errno.EADDRINUSE:
- rv = 0
-
- return rv
-
def get_password(prompt):
if os.isatty(sys.stdin.fileno()):
return getpass.getpass(prompt)