> i2013-02-08 17:59:56 DEBUG executing openssh: ['ssh',
> '-oForwardX11=no', '-oForwardAgent=no', '-oClearAllForwardings=yes',
> '-oProtocol=2', '-p', '22', '-l', 'root', '-s', '-o',
> 'UserKnownHostsFile=/root/.ssh/known_hosts', 'mahler', 'sftp']
> 
> The problem with this is that it makes it impossible to set such
> things as the username and port via ~/.ssh/config. I consider this a
> bug because it is highly unexpected behaviour.

Michael,

I also thought it was strange when I saw it doing that as well.  I
think it is reasonable and a good idea to set/disable the first
options -oForwardX11=no -oForwardAgent=no -oClearAllForwardings=yes
-oProtocol=2 any reason you can think of these being enabled?

The user and port I agree with, and here's a patch to let ssh pick the
default if none was given.  

What about the known hosts file?  Should that also fall back to ssh
for the default?

---
 NEWS                            |    2 ++
 obnamlib/plugins/sftp_plugin.py |   24 +++++++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/NEWS b/NEWS
index 24f79da..2252841 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,8 @@ Version X.Y, released UNRELEASED
 * SSHChannelAdapter now reports the number of bytes send and received
   (before ssh encryption), from David Fries
 * new option 'ssh-options' to pass additional options to ssh from David Fries
+* Only set ssh user/port if explicitily requested, otherwise let ssh
+  select them.  Reported by Michael Goetze, fixed by David Fries.
 
 Bug fixes:
 
diff --git a/obnamlib/plugins/sftp_plugin.py b/obnamlib/plugins/sftp_plugin.py
index f57c577..e715937 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.
     
@@ -169,9 +166,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:
             if self.settings['ssh-key']:
                 args += ['-i', self.settings['ssh-key']]
@@ -202,7 +202,11 @@ class SftpFS(obnamlib.VirtualFileSystem):
 
     def _connect_paramiko(self):
         logging.debug('connect_paramiko: host=%s port=%s' % (self.host, 
self.port))
-        self.transport = paramiko.Transport((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:
@@ -249,6 +253,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)
@@ -298,12 +304,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)
@@ -314,7 +320,7 @@ class SftpFS(obnamlib.VirtualFileSystem):
                     raise morphlib.Error(msg)
         else:
             host = netloc
-            port = DEFAULT_SSH_PORT
+            port = None
 
         if path.startswith('/~/'):
             path = path[3:]
-- 
1.7.10.4


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to