diff options
author | Lars Wirzenius <liw@liw.fi> | 2013-02-23 19:07:20 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2013-02-23 19:07:20 +0000 |
commit | 00c58746fe0f2f69858907038c573e540d484f83 (patch) | |
tree | de273728dd822d71746dd74709aa10a39af87d6d | |
parent | b64418d388610bf86922481226cbbc641d4395db (diff) | |
parent | 036337ffcce5d4ae6a84671cba7af1c76539de90 (diff) | |
download | obnam-00c58746fe0f2f69858907038c573e540d484f83.tar.gz |
Merge bugfix for ssh user/port
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | obnamlib/plugins/sftp_plugin.py | 27 |
2 files changed, 19 insertions, 10 deletions
@@ -41,6 +41,8 @@ Bug fixes: `add-key` and `remove-key` subcommands. Reported by Lars Kruse. * Restoring symlinks as root would fail. Reported and fixed by David Fries. +* Only set ssh user/port if explicitily requested, otherwise let ssh + select them. Reported by Michael Goetze, fixed by David Fries. Version 1.3, released 2012-12-16 -------------------------------- diff --git a/obnamlib/plugins/sftp_plugin.py b/obnamlib/plugins/sftp_plugin.py index c648063a..1241a26f 100644 --- a/obnamlib/plugins/sftp_plugin.py +++ b/obnamlib/plugins/sftp_plugin.py @@ -41,9 +41,6 @@ with warnings.catch_warnings(): import obnamlib -DEFAULT_SSH_PORT = 22 - - def ioerror_to_oserror(method): '''Decorator to convert an IOError exception to OSError. @@ -158,9 +155,12 @@ class SftpFS(obnamlib.VirtualFileSystem): args = ['ssh', '-oForwardX11=no', '-oForwardAgent=no', '-oClearAllForwardings=yes', '-oProtocol=2', - '-p', str(self.port), - '-l', self.user, '-s'] + # default user/port from ssh (could be a per host configuration) + if self.port: + args += ['-p', str(self.port)] + if self.user: + args += ['-l', self.user] if self.settings and self.settings['ssh-key']: args += ['-i', self.settings['ssh-key']] if self.settings and self.settings['strict-ssh-host-keys']: @@ -185,8 +185,13 @@ class SftpFS(obnamlib.VirtualFileSystem): return True def _connect_paramiko(self): - logging.debug('connect_paramiko: host=%s port=%s' % (self.host, self.port)) - self.transport = paramiko.Transport((self.host, self.port)) + logging.debug( + 'connect_paramiko: host=%s port=%s' % (self.host, self.port)) + if self.port: + remote = (self.host, self.port) + else: + remote = (self.host) + self.transport = paramiko.Transport(remote) self.transport.connect() logging.debug('connect_paramiko: connected') try: @@ -233,6 +238,8 @@ class SftpFS(obnamlib.VirtualFileSystem): logging.debug('Host key for %s OK' % hostname) def _authenticate(self, username): + if not username: + username = self._get_username() for key in self._find_auth_keys(): try: self.transport.auth_publickey(username, key) @@ -280,12 +287,12 @@ class SftpFS(obnamlib.VirtualFileSystem): if '@' in netloc: user, netloc = netloc.split('@', 1) else: - user = self._get_username() + user = None if ':' in netloc: host, port = netloc.split(':', 1) if port == '': - port = DEFAULT_SSH_PORT + port = None else: try: port = int(port) @@ -296,7 +303,7 @@ class SftpFS(obnamlib.VirtualFileSystem): raise morphlib.Error(msg) else: host = netloc - port = DEFAULT_SSH_PORT + port = None if path.startswith('/~/'): path = path[3:] |