Created
November 17, 2011 11:09
-
-
Save taylor/1372925 to your computer and use it in GitHub Desktop.
Revisions
-
taylor revised this gist
Nov 18, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #!/bin/bash # Name: ssh-srv-wrapper # # Purpose: Check DNS SRV records and use the entry when possible. @@ -21,7 +21,7 @@ if [ "$me" = "ssh" -a "$0" = "${SSH}" ] ; then SSH=`PATH=${PATH/$mydir:} which ssh` fi usage() { #echo "usage: $me [args] [user@<host>] [args]" #echo "See man ssh (1)" $SSH -
taylor revised this gist
Nov 18, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ DEBUG_ME=0 me=`basename $0` mydir=$(dirname $0) _dmsg() { if [ "${DEBUG_ME}" = 1 ] ; then echo $* ; fi ; } SSH=`which ssh` if [ "$me" = "ssh" -a "$0" = "${SSH}" ] ; then -
taylor revised this gist
Nov 18, 2011 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,8 +22,9 @@ if [ "$me" = "ssh" -a "$0" = "${SSH}" ] ; then fi function usage() { #echo "usage: $me [args] [user@<host>] [args]" #echo "See man ssh (1)" $SSH } if [ "$1" = "" ] ; then -
taylor revised this gist
Nov 17, 2011 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -87,7 +87,6 @@ if [ "$check_srv" = "true" ] ; then if [ $? = 0 ] ; then srv=$(host -s -W 1 -t SRV _ssh._tcp.${host}|grep "has SRV") if [ $? = 0 ] ; then shost=${srv##* } host=${shost%*.} sport=${srv%* $host.} -
taylor revised this gist
Nov 17, 2011 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -83,7 +83,6 @@ user=${userhost%%@*} [ "$user" = "$host" ] && user= if [ "$check_srv" = "true" ] ; then echo $host | grep '[A-Za-z]' > /dev/null if [ $? = 0 ] ; then srv=$(host -s -W 1 -t SRV _ssh._tcp.${host}|grep "has SRV") @@ -108,5 +107,5 @@ fi args=("${preargs[@]}" "${userat}${host}" "${postargs[@]}") _dmsg Executing $SSH ${args[@]} exec $SSH ${args[@]} -
taylor revised this gist
Nov 17, 2011 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,8 +9,6 @@ # Taylor Carpenter <[email protected]> DEBUG_ME=0 me=`basename $0` -
taylor revised this gist
Nov 17, 2011 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,10 +16,7 @@ Run the script directly or feel free to rename or symlink to the name ssh. It w * Fork the project. * Make your feature addition or bug fix. * Send me a pull request -- not sure if that will work in a Gist... # Copyright -
taylor revised this gist
Nov 17, 2011 . 1 changed file with 26 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ # Introduction *ssh-srv-wrapper* is bash shell script which tries to find a SSH SRV record for the first host and uses what is found rather than what was passed (if a valid record is found). # Install Run the script directly or feel free to rename or symlink to the name ssh. It will look for another ssh in your path to execute. # TODO * Validate host found in DNS. Potential security risk if DNS server returned shell esacpe sequences, etc. # Note on Patches/Pull Requests * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * Commit, do not mess with rakefile, version, or history. * If you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull * Send me a pull request. Bonus points for topic branches. # Copyright Released into the public domain. -
taylor renamed this gist
Nov 17, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
taylor revised this gist
Nov 17, 2011 . No changes.There are no files selected for viewing
-
taylor revised this gist
Nov 17, 2011 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,9 @@ # # Taylor Carpenter <[email protected]> #echo $* > /tmp/fooo #exit DEBUG_ME=0 me=`basename $0` @@ -82,10 +85,12 @@ user=${userhost%%@*} [ "$user" = "$host" ] && user= if [ "$check_srv" = "true" ] ; then _dmsg "Checking SRV" echo $host | grep '[A-Za-z]' > /dev/null if [ $? = 0 ] ; then srv=$(host -s -W 1 -t SRV _ssh._tcp.${host}|grep "has SRV") if [ $? = 0 ] ; then echo "srv: '$srv'" shost=${srv##* } host=${shost%*.} sport=${srv%* $host.} -
taylor revised this gist
Nov 17, 2011 . 1 changed file with 5 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,26 +44,26 @@ i=0 # Only parse args up to [user@]host for (( i=0; i<${#args[*]}; i++ )) ; do case ${args[i]} in -[$nao]|-[$nao]*[$nao]) preargs[${#preargs[*]}]="${args[i]}" args[i]= ;; -*p) preargs[${#preargs[*]}]="${args[i]}" args[i]= ((i++)) preargs[${#preargs[*]}]="${args[i]}" args[i]= check_srv=false # ignore SRV record ;; -*) preargs[${#preargs[*]}]="${args[i]}" args[i]= ((i++)) preargs[${#preargs[*]}]="${args[i]}" args[i]= ;; *) userhost="${args[i]}" args[i]= postargs=($(echo "${args[@]}")) @@ -77,21 +77,15 @@ if [ -z "$userhost" ] ; then exit 1 fi host=${userhost##*@} user=${userhost%%@*} [ "$user" = "$host" ] && user= if [ "$check_srv" = "true" ] ; then echo $host | grep '[A-Za-z]' > /dev/null if [ $? = 0 ] ; then srv=$(host -s -W 1 -t SRV _ssh._tcp.${host}) if [ $? = 0 ] ; then shost=${srv##* } host=${shost%*.} sport=${srv%* $host.} @@ -100,25 +94,16 @@ if [ "$check_srv" = "true" ] ; then if [ -z "$host" ] ; then echo "Could not figure out hostname in SRV record" exit 1 fi fi fi [ "$port" != "" ] && preargs[${#preargs[*]}]="-p ${port}" _dmsg "After SRV lookup -- HOST: $host PORT: $port" fi [ "$user" != "" ] && userat="${user}@" || userat="" args=("${preargs[@]}" "${userat}${host}" "${postargs[@]}") _dmsg $SSH ${args[@]} exec $SSH ${args[@]} -
taylor revised this gist
Nov 17, 2011 . 1 changed file with 36 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,27 @@ #!/bin/sh # Name: ssh-srv-wrapper # # Purpose: Check DNS SRV records and use the entry when possible. # # This code is hereby released to the public domain and may be used for any # purpose whatsoever without permission or acknowledgment. # # Taylor Carpenter <[email protected]> DEBUG_ME=0 me=`basename $0` mydir=$(dirname $0) function _dmsg() { if [ "${DEBUG_ME}" = 1 ] ; then echo $* ; fi ; } SSH=`which ssh` if [ "$me" = "ssh" -a "$0" = "${SSH}" ] ; then SSH=`PATH=${PATH/$mydir:} which ssh` fi function usage() { echo "usage: $me [args] [user@<host>] [args]" echo "See man ssh (1)" } @@ -33,30 +44,29 @@ i=0 # Only parse args up to [user@]host for (( i=0; i<${#args[*]}; i++ )) ; do case ${args[i]} in -[$nao]|-[$nao]*[$nao]) _dmsg "arg with out opts '${args[i]}'" preargs[${#preargs[*]}]="${args[i]}" args[i]= ;; -*p) _dmsg "ignoring SRV" preargs[${#preargs[*]}]="${args[i]}" args[i]= ((i++)) preargs[${#preargs[*]}]="${args[i]}" args[i]= check_srv=false # ignore SRV record ;; -*) _dmsg "option that takes arg" preargs[${#preargs[*]}]="${args[i]}" args[i]= ((i++)) preargs[${#preargs[*]}]="${args[i]}" args[i]= ;; *) _dmsg "arg should be host '${args[i]}'" userhost="${args[i]}" args[i]= postargs=($(echo "${args[@]}")) break ;; esac @@ -67,21 +77,21 @@ if [ -z "$userhost" ] ; then exit 1 fi _dmsg Should be good _dmsg ${newargs[@]} host=${userhost##*@} user=${userhost%%@*} [ "$user" = "$host" ] && user= _dmsg "host: $host" _dmsg "user: $user" if [ "$check_srv" = "true" ] ; then echo $host | grep '[A-Za-z]' > /dev/null if [ $? = 0 ] ; then srv=$(host -s -W 1 -t SRV _ssh._tcp.${host}) if [ $? = 0 ] ; then #_dmsg SRV: $srv shost=${srv##* } host=${shost%*.} sport=${srv%* $host.} @@ -90,17 +100,25 @@ if [ "$check_srv" = "true" ] ; then if [ -z "$host" ] ; then echo "Could not figure out hostname in SRV record" exit 1 #else #echo "HOST: $host PORT: $port" fi fi fi #[ "$port" != "" ] && portopt="-p ${port}" || portopt="" [ "$port" != "" ] && preargs[${#preargs[*]}]="-p ${port}" fi [ "$user" != "" ] && userat="${user}@" || userat="" _dmsg "srv done" _dmsg "preargs '${preargs[@]}'" _dmsg "user@host: ${userat}${host}" _dmsg "postargs '${postargs[@]}'" args=("${preargs[@]}" "${userat}${host}" "${postargs[@]}") #echo $SSH ${portopt} ${userat}${host} $@ #exec $SSH ${portopt} ${userat}${host} $@ _dmsg $SSH ${args[@]} exec $SSH ${args[@]} -
taylor revised this gist
Nov 17, 2011 . 1 changed file with 81 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,39 +8,99 @@ if [ "$me" = "ssh" -a "$0" = "${SSH}" ] ; then SSH=`PATH=${PATH/$mydir:} which ssh` fi function usage() { echo "usage: $me [args] [user@<host>] [args]" #echo "usage: $me [user@<host>] [args]" echo "See man ssh (1)" } if [ "$1" = "" ] ; then usage exit 1 elif [ "$1" = "-V" -o "$1" = "-version" ] ; then exec $SSH -V else args=("$@") fi preargs=() postargs=() nao=1246AaCfgKkMNnqsTtVvXxYy userhost= check_srv=true i=0 # Only parse args up to [user@]host for (( i=0; i<${#args[*]}; i++ )) ; do case ${args[i]} in -[$nao]|-[$nao]*[$nao]) echo "arg with out opts '${args[i]}'" preargs[${#preargs[*]}]="${args[i]}" args[i]= ;; -*p) echo "ignoring SRV" #preargs=("$preargs" "${args[i]}" ${args[i+1]}) preargs[${#preargs[*]}]="${args[i]}" args[i]= ((i++)) preargs[${#preargs[*]}]="${args[i]}" args[i]= check_srv=false # ignore SRV record ;; -*) echo "option that takes arg" preargs[${#preargs[*]}]="${args[i]}" args[i]= ((i++)) preargs[${#preargs[*]}]="${args[i]}" args[i]= ;; *) echo "arg should be host '${args[i]}'" userhost="${args[i]}" args[i]= preargs[${#preargs[*]}]="${args[@]}" break ;; esac done if [ -z "$userhost" ] ; then usage exit 1 fi echo Should be good echo ${newargs[@]} host=${userhost##*@} user=${userhost%%@*} [ "$user" = "$host" ] && user= echo "host: $host" echo "user: $user" if [ "$check_srv" = "true" ] ; then echo $host | grep '[A-Za-z]' > /dev/null if [ $? = 0 ] ; then srv=$(host -s -W 1 -t SRV _ssh._tcp.${host}) if [ $? = 0 ] ; then #echo SRV: $srv shost=${srv##* } host=${shost%*.} sport=${srv%* $host.} port=${sport##* } if [ -z "$host" ] ; then echo "Could not figure out hostname in SRV record" exit 1 else echo "HOST: $host PORT: $port" fi fi fi fi echo "srv done" exit [ "$port" != "" ] && portopt="-p ${port}" || portopt="" [ "$user" != "" ] && userat="${user}@" || userat="" #echo $SSH ${portopt} ${userat}${host} $@ exec $SSH ${portopt} ${userat}${host} $@ -
taylor revised this gist
Nov 17, 2011 . No changes.There are no files selected for viewing
-
taylor revised this gist
Nov 17, 2011 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,11 @@ #!/bin/sh me=`basename $0` mydir=$(dirname $0) SSH=`which ssh` if [ "$me" = "ssh" -a "$0" = "${SSH}" ] ; then SSH=`PATH=${PATH/$mydir:} which ssh` fi if [ "$1" = "" ] ; then @@ -44,4 +43,4 @@ fi [ "$user" != "" ] && userat="${user}@" || userat="" echo $SSH ${portopt} ${userat}${host} $@ exec $SSH ${portopt} ${userat}${host} $@ -
taylor created this gist
Nov 17, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #!/bin/sh me=`basename $0` mefull="$0" mydir=$(dirname $0) SSH=`which ssh` if [ "$me" = "ssh" -a "${mefull}" = "${SSH}" ] ; then SSH=`PATH=${PATH/:$mydir} which ssh` fi if [ "$1" = "" ] ; then echo "usage: $me [user@<host>] [args]" exit 1 fi host=${1##*@} user=${1%%@*} [ "$user" = "$host" ] && user="" echo "host = '$host'" shift echo $host | grep '[A-Za-z]' > /dev/null if [ $? = 0 ] ; then srv=$(host -s -W 1 -t SRV _ssh._tcp.${host}) if [ $? = 0 ] ; then echo SRV: $srv shost=${srv##* } host=${shost%*.} sport=${srv%* $host.} port=${sport##* } if [ -z "$host" ] ; then echo "Could not figure out hostname in SRV record" exit 1 else echo "HOST: $host PORT: $port" fi fi fi [ "$port" != "" ] && portopt="-p ${port}" || portopt="" [ "$user" != "" ] && userat="${user}@" || userat="" echo $SSH ${portopt} ${userat}${host} $@ exec $SSH ${portopt} ${userat}${host} $@