Implement support for parsing proxycommand.

This commit is contained in:
Olle Lundberg 2012-10-16 16:38:38 +02:00
parent b3d5156019
commit ac1310c4a1
1 changed files with 42 additions and 24 deletions

View File

@ -82,6 +82,7 @@ class SSHConfig (object):
""" """
Create a new OpenSSH config object. Create a new OpenSSH config object.
""" """
self._proxyregex = re.compile(r"^(proxycommand)\s*=*\s*(.*)", re.I)
self._config = [] self._config = []
def parse(self, file_obj): def parse(self, file_obj):
@ -97,6 +98,7 @@ class SSHConfig (object):
if (line == '') or (line[0] == '#'): if (line == '') or (line[0] == '#'):
continue continue
if '=' in line: if '=' in line:
<<<<<<< HEAD
# Ensure ProxyCommand gets properly split # Ensure ProxyCommand gets properly split
if line.lower().strip().startswith('proxycommand'): if line.lower().strip().startswith('proxycommand'):
match = proxy_re.match(line) match = proxy_re.match(line)
@ -104,6 +106,20 @@ class SSHConfig (object):
else: else:
key, value = line.split('=', 1) key, value = line.split('=', 1)
key = key.strip().lower() key = key.strip().lower()
||||||| merged common ancestors
key, value = line.split('=', 1)
key = key.strip().lower()
=======
if not line.lower().startswith('proxycommand'):
key, value = line.split('=', 1)
key = key.strip().lower()
else:
#ProxyCommand have been specified with an equal
# sign. Eat that and split in two groups.
match = self._proxyregex.match(line)
key = match.group(1).lower()
value = match.group(2)
>>>>>>> Implement support for parsing proxycommand.
else: else:
# find first whitespace, and split there # find first whitespace, and split there
i = 0 i = 0
@ -209,30 +225,32 @@ class SSHConfig (object):
host = socket.gethostname().split('.')[0] host = socket.gethostname().split('.')[0]
fqdn = LazyFqdn(self) fqdn = LazyFqdn(self)
homedir = os.path.expanduser('~') homedir = os.path.expanduser('~')
replacements = { replacements = {'controlpath':
'controlpath': [ [
('%h', config['hostname']), ('%h', config['hostname']),
('%l', fqdn), ('%l', fqdn),
('%L', host), ('%L', host),
('%n', hostname), ('%n', hostname),
('%p', port), ('%p', port),
('%r', remoteuser), ('%r', remoteuser),
('%u', user) ('%u', user)
], ],
'identityfile': [ 'identityfile':
('~', homedir), [
('%d', homedir), ('~', homedir),
('%h', config['hostname']), ('%d', homedir),
('%l', fqdn), ('%h', config['hostname']),
('%u', user), ('%l', fqdn),
('%r', remoteuser) ('%u', user),
], ('%r', remoteuser)
'proxycommand': [ ],
('%h', config['hostname']), 'proxycommand':
('%p', port), [
('%r', remoteuser), ('%h', config['hostname']),
], ('%p', port),
} ('%r', remoteuser)
]
}
for k in config: for k in config:
if k in replacements: if k in replacements: