1# SYNOPSIS
2#
3#   AMANDA_SSH_SECURITY
4#
5# OVERVIEW
6#
7#   Handle configuration for SSH security, implementing the --with-ssh-security
8#   option and checking for the relevant programs and options.  Defines and substitutes
9#   SSH_SECURITY, searches for and defines SSH, and defines SSH_OPTIONS.
10#
11AC_DEFUN([AMANDA_SSH_SECURITY],
12[
13    SSH_SECURITY=yes
14    AC_ARG_WITH(ssh-security,
15        AS_HELP_STRING([--with-ssh-security],
16                [include SSH authentication]),
17        [
18            case "$withval" in
19                n | no) SSH_SECURITY=no ;;
20                y |  ye | yes) SSH_SECURITY=yes ;;
21                *) AC_MSG_ERROR([*** You must not supply an argument to --with-ssh-security.])
22              ;;
23            esac
24        ],
25    )
26
27    if test "x$SSH_SECURITY" = "xyes"; then
28        # find the SSH binary
29        AMANDA_PROG_SSH
30
31        # see what options we should use
32        AC_ARG_WITH(ssh-options,
33            AS_HELP_STRING([ --with-ssh-options=@<:@OPTIONS@:>@],
34               [Use these ssh options for ssh security; the default should work]),
35            [ SSH_OPTIONS="$withval" ],
36            [ SSH_OPTIONS='' ]
37        )
38
39        case "$SSH_OPTIONS" in
40            y | ye | yes | n | no)
41                AC_MSG_ERROR([*** You must supply an argument to --with-ssh-options.]);;
42            *) : ;;
43        esac
44
45        AC_MSG_CHECKING([SSH options])
46        # if we didn't get SSH options from the user, figure them out for ourselves
47        if test -z "$SSH_OPTIONS"; then
48            case `$SSH -V 2>&1` in
49                OpenSSH*) SSH_OPTIONS='-x -o BatchMode=yes -o PreferredAuthentications=publickey';;
50                *) SSH_OPTIONS='-x -o BatchMode=yes' ;;
51            esac
52        fi
53
54        # now convert that to a comma-separated list of C strings
55        eval "set dummy ${SSH_OPTIONS}"; shift
56        SSH_OPTIONS=''
57	for i in "${@}"; do
58	    quoted="\"`echo "$i" | sed -e 's/\"/\\\"/'`\""
59	    SSH_OPTIONS="${SSH_OPTIONS}${SSH_OPTIONS:+, }$quoted";
60	done
61        AC_MSG_RESULT($SSH_OPTIONS)
62
63        # finally, make the various outputs for all of this
64        AC_DEFINE(SSH_SECURITY,1,
65                [Define if SSH transport should be enabled. ])
66        AC_DEFINE_UNQUOTED(SSH, "$SSH",
67                [Path to the SSH binary])
68        AC_DEFINE_UNQUOTED(SSH_OPTIONS, $SSH_OPTIONS,
69                [Arguments to ssh])
70    fi
71    AM_CONDITIONAL(WANT_SSH_SECURITY, test x"$SSH_SECURITY" = x"yes")
72
73    AC_SUBST(SSH_SECURITY)
74    # (note -- don't just substitute SSH_OPTIONS -- shell quoting will break)
75])
76