sshtunnel: simplify command composition
Remove append_params and use shell expressions instead e.g. ${port:+-p $port}. Note that we can't do that with ProxyCommand because it has to be quoted. The order of options was changed from more important like hostname to just static -nN. The CompressionLevel option is removed from SSH2. Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
This commit is contained in:
parent
d1d1bd60c9
commit
28e8daf726
2 changed files with 20 additions and 26 deletions
|
@ -18,16 +18,6 @@ _err() {
|
||||||
logger -p daemon.err -t sshtunnel "$@"
|
logger -p daemon.err -t sshtunnel "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
append_params() {
|
|
||||||
local p v args
|
|
||||||
for p in "$@"; do
|
|
||||||
eval "v=\$$p"
|
|
||||||
[ -n "$v" ] && args="$args -o $p=$v"
|
|
||||||
done
|
|
||||||
|
|
||||||
ARGS_options="${args# *}"
|
|
||||||
}
|
|
||||||
|
|
||||||
append_string() {
|
append_string() {
|
||||||
local varname="$1"; local add="$2"; local separator="${3:- }"; local actual new
|
local varname="$1"; local add="$2"; local separator="${3:- }"; local actual new
|
||||||
eval "actual=\$$varname"
|
eval "actual=\$$varname"
|
||||||
|
@ -45,7 +35,6 @@ validate_server_section() {
|
||||||
'PKCS11Provider:file' \
|
'PKCS11Provider:file' \
|
||||||
'CheckHostIP:or("yes", "no")' \
|
'CheckHostIP:or("yes", "no")' \
|
||||||
'Compression:or("yes", "no")' \
|
'Compression:or("yes", "no")' \
|
||||||
'CompressionLevel:range(1,9)' \
|
|
||||||
'IdentityFile:file' \
|
'IdentityFile:file' \
|
||||||
'LogLevel:or("QUIET", "FATAL", "ERROR", "INFO", "VERBOSE", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3")' \
|
'LogLevel:or("QUIET", "FATAL", "ERROR", "INFO", "VERBOSE", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3")' \
|
||||||
'ServerAliveCountMax:min(1)' \
|
'ServerAliveCountMax:min(1)' \
|
||||||
|
@ -172,8 +161,6 @@ load_server() {
|
||||||
|
|
||||||
[ "$2" = 0 ] || { _err "server $server: validation failed"; return 1; }
|
[ "$2" = 0 ] || { _err "server $server: validation failed"; return 1; }
|
||||||
|
|
||||||
local ARGS=""
|
|
||||||
local ARGS_options=""
|
|
||||||
local ARGS_tunnels=""
|
local ARGS_tunnels=""
|
||||||
local count=0
|
local count=0
|
||||||
|
|
||||||
|
@ -183,19 +170,27 @@ load_server() {
|
||||||
config_foreach validate_tunnelW_section "tunnelW" load_tunnelW
|
config_foreach validate_tunnelW_section "tunnelW" load_tunnelW
|
||||||
[ "$count" -eq 0 ] && { _err "tunnels to $server not started - no tunnels defined"; return 1; }
|
[ "$count" -eq 0 ] && { _err "tunnels to $server not started - no tunnels defined"; return 1; }
|
||||||
|
|
||||||
append_params CheckHostIP Compression CompressionLevel \
|
# old dbclient use -y for StrictHostKeyChecking.
|
||||||
LogLevel PKCS11Provider ServerAliveCountMax ServerAliveInterval \
|
# The -y for OpenSSH means to use syslog but that's ok
|
||||||
StrictHostKeyChecking TCPKeepAlive VerifyHostKeyDNS
|
local db_StrictHostKeyChecking=""
|
||||||
|
[ "$StrictHostKeyChecking" = "accept-new" ] && db_StrictHostKeyChecking="-y"
|
||||||
|
[ "$StrictHostKeyChecking" = "no" ] && db_StrictHostKeyChecking="-yy"
|
||||||
|
|
||||||
# dropbear doesn't support -o IdentityFile so use -i instead
|
local ARGS="$hostname $ARGS_tunnels \
|
||||||
[ -n "$IdentityFile" ] && ARGS_options="$ARGS_options -i $IdentityFile"
|
${port:+-p $port} \
|
||||||
# dbclient doesn't support StrictHostKeyChecking but it has the -y option that works same
|
${user:+-l $user} \
|
||||||
[ "$StrictHostKeyChecking" = "accept-new" ] && ARGS_options="$ARGS_options -y"
|
${IdentityFile:+-i $IdentityFile} \
|
||||||
[ "$StrictHostKeyChecking" = "no" ] && ARGS_options="$ARGS_options -yy"
|
${CheckHostIP:+-o CheckHostIP=$CheckHostIP} \
|
||||||
ARGS="$ARGS_options -o ExitOnForwardFailure=yes -o BatchMode=yes -nN $ARGS_tunnels "
|
${VerifyHostKeyDNS:+-o VerifyHostKeyDNS=$VerifyHostKeyDNS} \
|
||||||
[ -n "$port" ] && ARGS="$ARGS -p $port "
|
${Compression:+-o Compression=$Compression} \
|
||||||
[ -n "$user" ] && ARGS="$ARGS $user@"
|
${LogLevel:+-o LogLevel=$LogLevel} \
|
||||||
ARGS="${ARGS}$hostname"
|
${PKCS11Provider:+-o PKCS11Provider=$PKCS11Provider} \
|
||||||
|
${TCPKeepAlive:+-o TCPKeepAlive=$TCPKeepAlive} \
|
||||||
|
${ServerAliveCountMax:+-o ServerAliveCountMax=$ServerAliveCountMax} \
|
||||||
|
${ServerAliveInterval:+-o ServerAliveInterval=$ServerAliveInterval} \
|
||||||
|
${StrictHostKeyChecking:+-o StrictHostKeyChecking=$StrictHostKeyChecking $db_StrictHostKeyChecking} \
|
||||||
|
-o ExitOnForwardFailure=yes -o BatchMode=yes -nN \
|
||||||
|
"
|
||||||
|
|
||||||
procd_open_instance "$server"
|
procd_open_instance "$server"
|
||||||
procd_set_param command "$PROG" $ARGS
|
procd_set_param command "$PROG" $ARGS
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
# option retrydelay 1
|
# option retrydelay 1
|
||||||
# option CheckHostIP yes
|
# option CheckHostIP yes
|
||||||
# option Compression no
|
# option Compression no
|
||||||
# option CompressionLevel 6
|
|
||||||
# option IdentityFile /root/.ssh/id_rsa
|
# option IdentityFile /root/.ssh/id_rsa
|
||||||
# option LogLevel INFO
|
# option LogLevel INFO
|
||||||
# option PKCS11Provider /lib/pteidpkcs11.so
|
# option PKCS11Provider /lib/pteidpkcs11.so
|
||||||
|
|
Loading…
Reference in a new issue