From 88f98d02aee070c96f3b975ec797754efa3e32d7 Mon Sep 17 00:00:00 2001 From: Jameson Rollins Date: Fri, 29 Oct 2010 20:56:25 -0400 Subject: clean up ssh_proxycommand function (no functional change) --- src/share/m/ssh_proxycommand | 94 +++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/src/share/m/ssh_proxycommand b/src/share/m/ssh_proxycommand index 110309e..3ac70e1 100644 --- a/src/share/m/ssh_proxycommand +++ b/src/share/m/ssh_proxycommand @@ -15,6 +15,55 @@ # established. Can be added to ~/.ssh/config as follows: # ProxyCommand monkeysphere ssh-proxycommand %h %p +# the ssh proxycommand function itself +ssh_proxycommand() { + local connect='true' + local HOST + local PORT + local HOSTP + local URI + + if [[ "$1" == '--no-connect' ]] ; then + connect='false' + shift 1 + fi + + HOST="$1" + PORT="$2" + + if [ -z "$HOST" ] ; then + log error "Host not specified." + usage + exit 255 + fi + if [ -z "$PORT" ] ; then + PORT=22 + fi + + # set the host URI + if [ "$PORT" != '22' ] ; then + HOSTP="${HOST}:${PORT}" + else + HOSTP="${HOST}" + fi + URI="ssh://${HOSTP}" + + # passed HOST/PORT/HOSTP/URI + validate_monkeysphere + + # exec a netcat passthrough to host for the ssh connection + if [[ "$connect" == 'true' ]] ; then + if (type nc &>/dev/null); then + exec nc "$HOST" "$PORT" + elif (type socat &>/dev/null); then + exec socat STDIO "TCP:$HOST:$PORT" + else + echo "Neither netcat nor socat found -- could not complete monkeysphere-ssh-proxycommand connection to $HOST:$PORT" >&2 + exit 255 + fi + fi +} + validate_monkeysphere() { local hostKey @@ -266,48 +315,3 @@ EOF -------------------- ssh continues below -------------------- EOF } - - -# the ssh proxycommand function itself -ssh_proxycommand() { - -if [ "$1" = '--no-connect' ] ; then - NO_CONNECT='true' - shift 1 -fi - -HOST="$1" -PORT="$2" - -if [ -z "$HOST" ] ; then - log error "Host not specified." - usage - exit 255 -fi -if [ -z "$PORT" ] ; then - PORT=22 -fi - -# set the host URI -if [ "$PORT" != '22' ] ; then - HOSTP="${HOST}:${PORT}" -else - HOSTP="${HOST}" -fi -URI="ssh://${HOSTP}" - -validate_monkeysphere - -# exec a netcat passthrough to host for the ssh connection -if [ -z "$NO_CONNECT" ] ; then - if (type nc &>/dev/null); then - exec nc "$HOST" "$PORT" - elif (type socat &>/dev/null); then - exec socat STDIO "TCP:$HOST:$PORT" - else - echo "Neither netcat nor socat found -- could not complete monkeysphere-ssh-proxycommand connection to $HOST:$PORT" >&2 - exit 255 - fi -fi - -} -- cgit v1.2.3