2 # This must be called as (note the trailing dot):
4 # rsync-ssl-rsh HOSTNAME rsync --server --daemon .
6 # ... which is typically done via the rsync-ssl script, which results in something like this:
8 # rsync --rsh=rsync-ssl-rsh -aiv HOSTNAME::module [ARGS]
10 # This SSL setup based on the files by: http://dozzie.jarowit.net/trac/wiki/RsyncSSL
11 # Note that an stunnel connection requires at least version 4.x of stunnel.
13 # The environment can override our defaults using RSYNC_SSL_* variables
15 function path_search
{
18 for prog
in "${@}"; do
20 [[ -z "$dir" ]] && dir
=.
21 if [[ -f "$dir/$prog" && -x "$dir/$prog" ]]; then
30 echo "Failed to find on your path: $*" 1>&2
31 echo "See the rsync-ssl manpage for configuration assistance." 1>&2
35 if [[ -z "$RSYNC_SSL_TYPE" ]]; then
36 found
=`path_search stunnel4 stunnel openssl` ||
exit 1
37 if [[ "$found" == */openssl
]]; then
38 RSYNC_SSL_TYPE
=openssl
39 RSYNC_SSL_OPENSSL
="$found"
41 RSYNC_SSL_TYPE
=stunnel
42 RSYNC_SSL_STUNNEL
="$found"
46 case "$RSYNC_SSL_TYPE" in
48 if [[ -z "$RSYNC_SSL_OPENSSL" ]]; then
49 RSYNC_SSL_OPENSSL
=`path_search openssl` ||
exit 1
54 if [[ -z "$RSYNC_SSL_STUNNEL" ]]; then
55 RSYNC_SSL_STUNNEL
=`path_search stunnel4 stunnel` ||
exit 1
60 echo "The RSYNC_SSL_TYPE specifies an unknown type: $RSYNC_SSL_TYPE" 1>&2
65 if [[ -z "$RSYNC_SSL_CERT" ]]; then
68 certopt
="cert$optsep$RSYNC_SSL_CERT"
71 if [[ -z ${RSYNC_SSL_CA_CERT+x} ]]; then
72 # RSYNC_SSL_CA_CERT unset - default CA set AND verify:
74 caopt
="-verify_return_error -verify 4"
78 elif [[ "$RSYNC_SSL_CA_CERT" == "" ]]; then
79 # RSYNC_SSL_CA_CERT set but empty -do NO verifications:
86 # RSYNC_SSL_CA_CERT set - use CA AND verify:
88 caopt
="-CAfile $RSYNC_SSL_CA_CERT -verify_return_error -verify 4"
90 cafile
="CAfile = $RSYNC_SSL_CA_CERT"
94 port
="${RSYNC_PORT:-0}"
95 if [[ "$port" == 0 ]]; then
96 port
="${RSYNC_SSL_PORT:-874}"
99 # If the user specified USER@HOSTNAME::module, then rsync passes us
100 # the -l USER option too, so we must be prepared to ignore it.
101 if [[ "$1" == "-l" ]]; then
108 if [[ -z "$hostname" ||
"$1" != rsync ||
"$2" != --server ||
"$3" != --daemon ]]; then
109 echo "Usage: rsync-ssl-helper HOSTNAME rsync --server --daemon ." 1>&2
113 if [[ $RSYNC_SSL_TYPE == openssl
]]; then
114 exec $RSYNC_SSL_OPENSSL s_client
$caopt $certopt -quiet -verify_quiet -servername $hostname -connect $hostname:$port
116 # devzero@web.de came up with this no-tmpfile calling syntax:
117 exec $RSYNC_SSL_STUNNEL -fd 10 11<&0 <<EOF 10<&0 0<&11 11<&-
120 connect = $hostname:$port