summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2013-09-27 16:15:31 -0700
committerJeff Forcier <jeff@bitprophet.org>2013-09-27 16:15:31 -0700
commit7243f8fe90097eb3c78db0b31a19104155b9cf89 (patch)
tree6c35749871a7086dfc9182ea041c4650c026dece
parentf783d4d818dba93177ac96b95251e18fcfe190cc (diff)
parent8b983d9d3d9c91f321c3f18ecc8fa2e9343ce661 (diff)
Merge branch '1.10' into 1.11
Conflicts: NEWS
-rw-r--r--NEWS7
-rw-r--r--paramiko/config.py39
-rw-r--r--tests/test_util.py11
3 files changed, 42 insertions, 15 deletions
diff --git a/NEWS b/NEWS
index 8affcd56..e3deb149 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,13 @@ Issues noted as "Fabric #NN" can be found at https://github.com/fabric/fabric/.
Releases
========
+v1.10.4 (27th Sep 2013)
+-----------------------
+
+* #179: Fix a missing variable causing errors when an ssh_config file has a
+ non-default AddressFamily set. Thanks to Ed Marshall & Tomaz Muraus for catch
+ & patch.
+
v1.11.1 (20th Sep 2013)
-----------------------
diff --git a/paramiko/config.py b/paramiko/config.py
index b0be1a8e..520da356 100644
--- a/paramiko/config.py
+++ b/paramiko/config.py
@@ -35,9 +35,10 @@ class LazyFqdn(object):
Returns the host's fqdn on request as string.
"""
- def __init__(self, config):
+ def __init__(self, config, host=None):
self.fqdn = None
self.config = config
+ self.host = host
def __str__(self):
if self.fqdn is None:
@@ -54,19 +55,27 @@ class LazyFqdn(object):
fqdn = None
address_family = self.config.get('addressfamily', 'any').lower()
if address_family != 'any':
- family = socket.AF_INET if address_family == 'inet' \
- else socket.AF_INET6
- results = socket.getaddrinfo(host,
- None,
- family,
- socket.SOCK_DGRAM,
- socket.IPPROTO_IP,
- socket.AI_CANONNAME)
- for res in results:
- af, socktype, proto, canonname, sa = res
- if canonname and '.' in canonname:
- fqdn = canonname
- break
+ try:
+ family = socket.AF_INET if address_family == 'inet' \
+ else socket.AF_INET6
+ results = socket.getaddrinfo(
+ self.host,
+ None,
+ family,
+ socket.SOCK_DGRAM,
+ socket.IPPROTO_IP,
+ socket.AI_CANONNAME
+ )
+ for res in results:
+ af, socktype, proto, canonname, sa = res
+ if canonname and '.' in canonname:
+ fqdn = canonname
+ break
+ # giaerror -> socket.getaddrinfo() can't resolve self.host
+ # (which is from socket.gethostname()). Fall back to the
+ # getfqdn() call below.
+ except socket.gaierror:
+ pass
# Handle 'any' / unspecified
if fqdn is None:
fqdn = socket.getfqdn()
@@ -216,7 +225,7 @@ class SSHConfig (object):
remoteuser = user
host = socket.gethostname().split('.')[0]
- fqdn = LazyFqdn(config)
+ fqdn = LazyFqdn(config, host)
homedir = os.path.expanduser('~')
replacements = {'controlpath':
[
diff --git a/tests/test_util.py b/tests/test_util.py
index efda9b2f..a528224e 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -329,3 +329,14 @@ IdentityFile id_dsa22
paramiko.util.lookup_ssh_host_config(host, config),
values
)
+
+ def test_12_config_addressfamily_and_lazy_fqdn(self):
+ """
+ Ensure the code path honoring non-'all' AddressFamily doesn't asplode
+ """
+ test_config = """
+AddressFamily inet
+IdentityFile something_%l_using_fqdn
+"""
+ config = paramiko.util.parse_ssh_config(cStringIO.StringIO(test_config))
+ assert config.lookup('meh') # will die during lookup() if bug regresses