From 8e474971d3d44dd006f873288c854887648d33a1 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Thu, 4 Aug 2016 08:11:00 +0000 Subject: [PATCH] #1240: use sshpass on all posix platforms (except centos..) so we can supply the password from the launcher dialog git-svn-id: https://xpra.org/svn/Xpra/trunk@13201 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- debian/control | 2 ++ osx/Helpers/SSH_ASKPASS | 3 --- osx/Xpra.bundle | 3 +++ osx/jhbuild/xpra.modules | 10 ++++++++++ osx/make-app.sh | 2 +- rpmbuild/xpra.spec | 5 +++++ src/xpra/client/gtk_base/client_launcher.py | 14 +++++++++++--- src/xpra/platform/darwin/paths.py | 9 +++++++++ src/xpra/platform/paths.py | 16 ++++++++++++++++ src/xpra/scripts/main.py | 15 +++++++++++++-- 10 files changed, 70 insertions(+), 9 deletions(-) delete mode 100755 osx/Helpers/SSH_ASKPASS diff --git a/debian/control b/debian/control index 5a91c2f4c9..588f115895 100644 --- a/debian/control +++ b/debian/control @@ -132,6 +132,8 @@ Recommends: ,websockify # we cannot do versionned recommends but we need keyboard-configuration (>= 1.82) ,keyboard-configuration +#for using SSH passwords from the GUI launcher: + ,sshpass Suggests: openssh-server # optional - only really useful with GPU opencl implementations: ,python-pyopencl diff --git a/osx/Helpers/SSH_ASKPASS b/osx/Helpers/SSH_ASKPASS deleted file mode 100755 index 2329e4947d..0000000000 --- a/osx/Helpers/SSH_ASKPASS +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -echo ${XPRA_SSH_PASS} \ No newline at end of file diff --git a/osx/Xpra.bundle b/osx/Xpra.bundle index 27f6f04a0e..f193bcb7f2 100644 --- a/osx/Xpra.bundle +++ b/osx/Xpra.bundle @@ -119,6 +119,9 @@ ${prefix}/bin/gst-inspect-1.0 + + ${prefix}/bin/sshpass + ${project}/dist/Xpra.app/Contents/Resources/ diff --git a/osx/jhbuild/xpra.modules b/osx/jhbuild/xpra.modules index 9aebbe0179..6e25ec953e 100644 --- a/osx/jhbuild/xpra.modules +++ b/osx/jhbuild/xpra.modules @@ -50,6 +50,15 @@ + + + + version="1.05" + hash="sha256:c6324fcee608b99a58f9870157dfa754837f8c48be3df0f5e2f3accf145dee60" + repo="ftp.gnu.org"/> + + + + diff --git a/osx/make-app.sh b/osx/make-app.sh index d97fd5d5d7..6185afcaf0 100755 --- a/osx/make-app.sh +++ b/osx/make-app.sh @@ -118,7 +118,7 @@ rm "${MACOS_DIR}/Xpra_Launcher-bin" #ensure that every wrapper has a "python" executable to match: #(see PythonExecWrapper for why we need this "exec -a" workaround) python_executable="$RSCDIR/bin/python" -for x in `ls "$HELPERS_DIR" | egrep -v "Python|SSH_ASKPASS|gst-plugin-scanner"`; do +for x in `ls "$HELPERS_DIR" | egrep -v "Python|gst-plugin-scanner"`; do #replace underscore with space in actual binary filename: target="$RSCDIR/bin/`echo $x | sed 's+_+ +g'`" if [ ! -e "$target" ]; then diff --git a/rpmbuild/xpra.spec b/rpmbuild/xpra.spec index 79b3b746b6..e9b990eca8 100644 --- a/rpmbuild/xpra.spec +++ b/rpmbuild/xpra.spec @@ -185,6 +185,11 @@ Requires: xvidcore Requires: ffmpeg-xpra Requires: %{numpy} Requires: xpra-common = %{version}-%{build_no}%{dist} +%if 0%{?el6}%{?el7} +#sshpass is not available! +%else +Requires: sshpass +%endif %if 0%{?suse_version} #only use recommends because these are not in the standard repos: Recommends: python-gstreamer diff --git a/src/xpra/client/gtk_base/client_launcher.py b/src/xpra/client/gtk_base/client_launcher.py index 5203e4b613..b1f38a23cb 100755 --- a/src/xpra/client/gtk_base/client_launcher.py +++ b/src/xpra/client/gtk_base/client_launcher.py @@ -400,9 +400,17 @@ def mode_changed(self, *args): self.username_label.hide() if self.config.port>0: self.port_entry.set_text("%s" % self.config.port) - if not ssh or sys.platform.startswith("win") or sys.platform.startswith("darwin"): - #password cannot be used with ssh - #(except on win32 with plink, and on osx via the SSH_ASKPASS hack) + can_use_password = not ssh + if ssh: + if sys.platform.startswith("win"): + #plink can use password + pass + else: + #can use password if sshpass is installed: + from xpra.platform.paths import get_sshpass_command + sshpass = get_sshpass_command() + can_use_password = bool(sshpass) + if can_use_password: self.password_label.show() self.password_entry.show() else: diff --git a/src/xpra/platform/darwin/paths.py b/src/xpra/platform/darwin/paths.py index c5b9fcea33..84468e4d6a 100644 --- a/src/xpra/platform/darwin/paths.py +++ b/src/xpra/platform/darwin/paths.py @@ -125,6 +125,15 @@ def do_get_download_dir(): return d +def do_get_ssh_askpass_script(): + from xpra.platform.paths import get_app_dir + base = get_app_dir() + p = os.path.join(base, "Resources", "bin", "sshpass") + if os.path.exists(p): + return p + return None + + def do_get_sound_command(): #try to use the subapp: from xpra.platform.paths import get_app_dir diff --git a/src/xpra/platform/paths.py b/src/xpra/platform/paths.py index f94381847e..b5ba05fa65 100755 --- a/src/xpra/platform/paths.py +++ b/src/xpra/platform/paths.py @@ -89,6 +89,20 @@ def do_get_remote_run_xpra_scripts(): return ["~/.xpra/run-xpra", "$XDG_RUNTIME_DIR/xpra/run-xpra", "xpra"] +def get_sshpass_command(): + return env_or_delegate("XPRA_SSHPASS", do_get_sshpass_command) +def do_get_sshpass_command(): + import os.path + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, "sshpass") + if is_exe(exe_file): + return exe_file + return None + + #overriden in platform code: def get_app_dir(): return env_or_delegate("XPRA_APP_DIR", do_get_app_dir) @@ -199,6 +213,7 @@ def do_get_sound_command(): "do_get_app_dir", "do_get_icon_dir") platform_import(globals(), "paths", False, + "do_get_ssh_askpass_script", "do_get_sound_command", "do_get_install_prefix", "do_get_default_conf_dirs", @@ -224,6 +239,7 @@ def get_info(): "icons" : get_icon_dir(), "home" : os.path.expanduser("~"), "sound_command" : get_sound_command(), + "sshpass_command" : get_sshpass_command(), } diff --git a/src/xpra/scripts/main.py b/src/xpra/scripts/main.py index fc51385308..b7416324a9 100755 --- a/src/xpra/scripts/main.py +++ b/src/xpra/scripts/main.py @@ -1436,8 +1436,6 @@ def connect_to(display_desc, opts=None, debug_cb=None, ssh_fail_cb=ssh_connect_f cmd += [INITENV_COMMAND+";"+remote_cmd] else: cmd += [remote_cmd] - if env: - kwargs["env"] = env if debug_cb: debug_cb("starting %s tunnel" % str(cmd[0])) #debug_cb("starting ssh: %s with kwargs=%s" % (str(cmd), kwargs)) @@ -1446,6 +1444,19 @@ def connect_to(display_desc, opts=None, debug_cb=None, ssh_fail_cb=ssh_connect_f for x in cmd: if type(x)!=str: raise InitException("argument is not a string: %s (%s), found in command: %s" % (x, type(x), cmd)) + password = display_desc.get("password") + if password: + from xpra.platform.paths import get_sshpass_command + sshpass = get_sshpass_command() + if sshpass: + #sshpass -e ssh ... + cmd.insert(0, sshpass) + cmd.insert(1, "-e") + if env is None: + env = os.environ.copy() + env["SSHPASS"] = password + if env: + kwargs["env"] = env child = Popen(cmd, stdin=PIPE, stdout=PIPE, **kwargs) except OSError as e: raise InitException("Error running ssh program '%s': %s" % (cmd, e))