The branch, build-main has been updated via 15598f15f512d67222a5d2b4f1b4bb277b29f520 (commit) via 77a00fac353b65ab845e1eba91a9e0a4f5df150a (commit) via 470dda06432bcaaa0989b6961700ec4e71c5a194 (commit) from 6d9eef295e1a3386d07015e00e4292400f8c4d7f (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- ----------------------------------------------------------------------- Summary of changes: debian/changelog | 3 ++ x2go/client.py | 16 ++++++++++++ x2go/forward.py | 72 +++++++++++++++++++++++++++++------------------------ x2go/session.py | 37 +++++++++++++++++++++++++++- x2go/sshproxy.py | 12 ++++++-- 5 files changed, 103 insertions(+), 37 deletions(-) The diff of changes is: diff --git a/debian/changelog b/debian/changelog index 0805825..a6a731a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,9 @@ python-x2go (0.1.1.2-0~x2go1) UNRELEASED; urgency=low - Use X2goRegistryException for session query for non-existing sessions. - Catch this exception in X2goClient. - Fix desktop sharing. + - Improve error handling / logging in forward.py. + - Add X2goSession method that detects if auto-connecting a session profile + is probably possible. -- Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Fri, 24 Jun 2011 16:42:20 +0200 diff --git a/x2go/client.py b/x2go/client.py index c4073ca..1327d33 100644 --- a/x2go/client.py +++ b/x2go/client.py @@ -1035,6 +1035,22 @@ class X2goClient(object): return self.session_registry(session_uuid).check_host() __check_session_host = check_session_host + def session_can_auto_connect(self, session_uuid): + """\ + Check if session with unique identifier <session_uuid> is configured adequately + to be able to auto-connect to the X2go server (e.g. public key authentication). + + @param session_uuid: the X2go session's UUID registry hash + @type session_uuid: C{str} + + @return: returns C{True} if the session can auto-connect, C{False} otherwise, C{None} + if no control session has been set up yet. + @rtype: C{bool} + + """ + return self.session_registry(session_uuid).can_auto_connect() + __session_can_auto_connect = session_can_auto_connect + def connect_session(self, session_uuid, username='', password='', diff --git a/x2go/forward.py b/x2go/forward.py index 34466d0..f12666b 100644 --- a/x2go/forward.py +++ b/x2go/forward.py @@ -103,7 +103,6 @@ class X2goFwServer(StreamServer): # it is recommended here to have passed on the session instance to this object... if self.session_instance: if not self.session_instance.is_connected(): - print 'HALLO' break _count += 1 @@ -117,45 +116,52 @@ class X2goFwServer(StreamServer): self.logger('incoming request to %s:%d failed on attempt %d: %s' % (self.chain_host, self.chain_port, _count, - repr(e)), - loglevel=log.loglevel_ERROR) + repr(e)), + loglevel=log.loglevel_WARN) gevent.sleep(.4) - # once we are here, we can presume the tunnel to be active... - self.is_active = True - if self.chan is None: - self.logger('incoming request to [%s]:%d was rejected by the SSH server.' % - (self.chain_host, self.chain_port), loglevel=log.loglevel_ERROR) - if self.session_instance: - self.session_instance.HOOK_forwarding_tunnel_setup_failed(chain_host=self.chain_host, chain_port=self.chain_port) - return + if not _success: + self.logger('incoming request to %s:%d failed after %d attempts' % (self.chain_host, + self.chain_port, + _count), + loglevel=log.loglevel_ERROR) else: - self.logger('connected! Tunnel open %r -> %r -> %r' % (self.fw_socket.getpeername(), + # once we are here, we can presume the tunnel to be active... + self.is_active = True + + if self.chan is None: + self.logger('incoming request to [%s]:%d was rejected by the SSH server.' % + (self.chain_host, self.chain_port), loglevel=log.loglevel_ERROR) + if self.session_instance: + self.session_instance.HOOK_forwarding_tunnel_setup_failed(chain_host=self.chain_host, chain_port=self.chain_port) + return + else: + self.logger('connected! Tunnel open %r -> %r -> %r' % (self.fw_socket.getpeername(), chan_peername, (self.chain_host, self.chain_port)), loglevel=log.loglevel_INFO) - self.keepalive = True - try: - while self.keepalive: - r, w, x = select.select([self.fw_socket, self.chan], [], []) - if fw_socket in r: - data = fw_socket.recv(1024) - if len(data) == 0: - break - self.chan.send(data) - if self.chan in r: - data = self.chan.recv(1024) - if len(data) == 0: - break - fw_socket.send(data) - self.close_channel() - self.close_socket() - except socket.error: - pass + self.keepalive = True + try: + while self.keepalive: + r, w, x = select.select([self.fw_socket, self.chan], [], []) + if fw_socket in r: + data = fw_socket.recv(1024) + if len(data) == 0: + break + self.chan.send(data) + if self.chan in r: + data = self.chan.recv(1024) + if len(data) == 0: + break + fw_socket.send(data) + self.close_channel() + self.close_socket() + except socket.error: + pass - self.is_active = False - self.logger('Tunnel closed from %r' % (chan_peername,), - loglevel=log.loglevel_INFO) + self.is_active = False + self.logger('Tunnel closed from %r' % (chan_peername,), + loglevel=log.loglevel_INFO) def close_channel(self): """\ diff --git a/x2go/session.py b/x2go/session.py index 9439477..ead7b93 100644 --- a/x2go/session.py +++ b/x2go/session.py @@ -75,7 +75,7 @@ _X2GO_SESSION_PARAMS = ('geometry', 'depth', 'link', 'pack', ) """A list of allowed X2go session parameters.""" _X2GO_SSHPROXY_PARAMS = ('sshproxy_host', 'sshproxy_user', 'sshproxy_password', - 'sshproxy_key_filename', 'sshproxy_tunnel', + 'sshproxy_key_filename', 'sshproxy_pkey', 'sshproxy_tunnel', ) """A list of allowed X2go SSH proxy parameters.""" @@ -665,6 +665,41 @@ class X2goSession(object): return _valid or self.HOOK_check_host_dialog(host=_host, port=_port, fingerprint=_fingerprint, fingerprint_type=_fingerprint_type) __check_host = check_host + def can_auto_connect(self): + """\ + Check if a session is configured adequately to be able to auto-connect to the X2go + server (e.g. public key authentication). + + @return: returns C{True} if the session can auto-connect, C{False} otherwise, C{None} + if no control session has been set up yet. + @rtype: C{bool} + + """ + + def _can_sshproxy_autoconnect(): + + if self.use_sshproxy: + if self.sshproxy_params.has_key('sshproxy_key_filename') and self.sshproxy_params['sshproxy_key_filename'] and os.path.exists(os.path.normpath(self.sshproxy_params['sshproxy_key_filename'])): + return True + elif self.sshproxy_params.has_key('sshproxy_pkey') and self.sshproxy_params['sshproxy_pkey']: + return True + else: + return False + else: + return True + + # do we have a key file passed as control parameter? + if self.control_params.has_key('key_filename') and self.control_params['key_filename'] and os.path.exists(os.path.normpath(self.control_params['key_filename'])): + return _can_sshproxy_autoconnect() + + # or a private key? + elif self.control_params.has_key('pkey') and self.control_params['pkey']: + return _can_sshproxy_autoconnect() + + else: + return False + __can_auto_connect = can_auto_connect + def connect(self, username='', password='', add_to_known_hosts=False, force_password_auth=False, use_sshproxy=False, sshproxy_user='', sshproxy_password=''): """\ diff --git a/x2go/sshproxy.py b/x2go/sshproxy.py index e59d430..3d08a35 100644 --- a/x2go/sshproxy.py +++ b/x2go/sshproxy.py @@ -55,9 +55,9 @@ class X2goSSHProxy(paramiko.SSHClient, threading.Thread): def __init__(self, hostname=None, port=22, username=None, password=None, key_filename=None, local_host='localhost', local_port=22022, remote_host='localhost', remote_port=22, - known_hosts=None, add_to_known_hosts=False, + known_hosts=None, add_to_known_hosts=False, pkey=None, sshproxy_host=None, sshproxy_port=22, sshproxy_user=None, - sshproxy_password=None, sshproxy_key_filename=None, + sshproxy_password=None, sshproxy_key_filename=None, sshproxy_pkey=None, sshproxy_tunnel=None, ssh_rootdir=os.path.join(_LOCAL_HOME, _X2GO_SSH_ROOTDIR), session_instance=None, @@ -73,6 +73,8 @@ class X2goSSHProxy(paramiko.SSHClient, threading.Thread): @type password: C{str} @param key_filename: name of a SSH private key file @type key_filename: C{str} + @param pkey: a private DSA/RSA key object (as provided by Paramiko/SSH) + @type pkey: C{RSA/DSA key instance} @param local_host: bind SSH tunnel to the C{local_host} IP socket address (default: localhost) @type local_host: C{str} @param local_port: IP socket port to bind the SSH tunnel to (default; 22022) @@ -99,6 +101,8 @@ class X2goSSHProxy(paramiko.SSHClient, threading.Thread): @type sshproxy_password: C{str} @param sshproxy_key_filename: alias for C{key_filename} @type sshproxy_key_filename: C{str} + @param sshproxy_pkey: alias for C{pkey} + @type sshproxy_pkey: C{RSA/DSA key instance} (Paramiko) @param sshproxy_tunnel: a string of the format <local_host>:<local_port>:<remote_host>:<remote_port> which will override---if used---the options: C{local_host}, C{local_port}, C{remote_host} and C{remote_port} @@ -135,6 +139,7 @@ class X2goSSHProxy(paramiko.SSHClient, threading.Thread): if sshproxy_user: self.username = sshproxy_user if sshproxy_password: password = sshproxy_password if sshproxy_key_filename: key_filename = sshproxy_key_filename + if sshproxy_pkey: pkey = sshproxy_pkey if sshproxy_tunnel: self.local_host, self.local_port, self.remote_host, self.remote_port = sshproxy_tunnel.split(':') self.local_port = int(self.local_port) @@ -164,11 +169,12 @@ class X2goSSHProxy(paramiko.SSHClient, threading.Thread): self.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: - if key_filename and os.path.exists(os.path.normpath(key_filename)): + if (key_filename and os.path.exists(os.path.normpath(key_filename))) or pkey: try: self.connect(self.hostname, port=self.port, username=self.username, key_filename=key_filename, + pkey=pkey, look_for_keys=False, allow_agent=False, ) hooks/post-receive -- python-x2go.git (Python X2go Client API) This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "python-x2go.git" (Python X2go Client API).