1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#!/bin/bash
#
# Copyright (C) 2013 Nikos Mavrogiannopoulos
#
# This file is part of ocserv.
#
# ocserv is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# ocserv is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GnuTLS; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
SERV="${SERV:-../src/ocserv}"
srcdir=${srcdir:-.}
NO_NEED_ROOT=1
PIDFILE=ocserv-pid.$$.tmp
PATH=${PATH}:/usr/sbin
HACONFIG=haproxy.conf.$$.tmp
HAPROXY=$(which haproxy)
. `dirname $0`/common.sh
eval "${GETPORT}"
HAPORT=${PORT}
eval "${GETPORT}"
if test -z "${HAPROXY}";then
echo "no haproxy present"
exit 77
fi
echo "Testing ocserv connection via haproxy... "
update_config test-haproxy-auth.config
launch_sr_server -d 1 -p ${PIDFILE} -f -c ${CONFIG} & PID=$!
wait_server ${PID}
sed -e 's|@HAPORT@|'${HAPORT}'|g' -e 's|@PORT@|'${PORT}'|g' -e 's|@ADDRESS@|'${ADDRESS}'|g' ${srcdir}/data/haproxy-auth.cfg >${HACONFIG}
LD_PRELOAD=libsocket_wrapper.so:libuid_wrapper.so UID_WRAPPER=1 UID_WRAPPER_ROOT=1 ${HAPROXY} -f ${HACONFIG} -d & HAPID=$!
wait_server ${HAPID}
echo "Connecting to obtain cookie... "
( echo "test" | LD_PRELOAD=libsocket_wrapper.so ${OPENCONNECT} -q ${ADDRESS}:${HAPORT} -u test --servercert=pin-sha256:xp3scfzy3rOQsv9NcOve/8YVVv+pHr4qNCXEXrNl5s8= --cookieonly )
if test $? != 0;then
kill ${HAPID}
fail ${PID} "Could not receive cookie from server"
fi
# Restart haproxy and reconnect.
kill ${HAPID}
sleep 2
LD_PRELOAD=libsocket_wrapper.so:libuid_wrapper.so UID_WRAPPER=1 UID_WRAPPER_ROOT=1 ${HAPROXY} -f ${HACONFIG} -d & HAPID=$!
wait_server ${HAPID}
echo "Re-connecting to obtain cookie after haproxy restart... "
( echo "test" | LD_PRELOAD=libsocket_wrapper.so ${OPENCONNECT} -q ${ADDRESS}:${HAPORT} -u test --servercert=pin-sha256:xp3scfzy3rOQsv9NcOve/8YVVv+pHr4qNCXEXrNl5s8= --cookieonly )
if test $? != 0;then
kill ${HAPID}
fail ${PID} "Could not receive cookie from server"
fi
kill ${HAPID}
if ! test -f ${PIDFILE};then
fail ${PID} "Could not find pid file ${PIDFILE}"
fi
echo "Cleaning up..."
rm -f ${HACONFIG}
cleanup
exit 0
|