Commit d6ebe595 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Fix SSH Match fallback

parent b9e46030
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ make_config() {
	cat ~/.ssh/config ~/.ssh/config.local 2>/dev/null |
		awk >"$SSH_CONFIG" "
			function remove_line() { sub(/^/, \"\#\"); }
			/^$/ || /^#/ { print \$0; next }
			/^$/ || /^#[^@]/ { print \$0; next }

			`rule_match`
			`rule_unix_sockets`
@@ -74,9 +74,14 @@ rule_match() {
	[ $SSH_MAJOR -eq 6 ] && [ $SSH_MINOR -ge 5 ] && return

	cat <<-'END_AWK'
		BEGIN { is_match=0 }
		BEGIN { is_match=0; match_fallback=false }
		match($1, /^#@fallback:$/) {
		  sub(/.*#@fallback:[[:space:]]*/, "")
		  match_fallback=$0
		  next
		}
		match($1, /^Match$/) {
		  if ( match($0, /#default:[[:space:]]*match-all/) ) {
		  if ( ! system(match_fallback) ) {
		    sub(/^.*$/, "Host *")
		  } else {
		    is_match=1
@@ -84,6 +89,7 @@ rule_match() {
		}
		match($1, /^Host$/) { is_match=0 }
		is_match { remove_line() }
		!match($1, /^#fallback:$/) { match_fallback=false }
	END_AWK
}

+2 −1
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@ Host 192.168.* 10.* *.lan *.local localhost
## REQUIRES: (Match exec) 6.5
## REQUIRES: (ControlMaster, ControlPath) 3.9
## REQUIRES: (ControlPersist) 5.6
Match exec "test ${PLATFORM:-unknown} != windows" #default: match-all
#@fallback: test ${PLATFORM:-unknown} != windows
Match exec "test ${PLATFORM:-unknown} != windows"
	ControlMaster auto
	ControlPath %d/.ssh/socks:%l/%r@%h:%p
	ControlPersist 2h