2013-03-20 06:21:16 +01:00
|
|
|
#!/bin/sh
|
2014-05-05 05:20:26 +02:00
|
|
|
|
2016-03-05 00:28:56 +01:00
|
|
|
# write stderr to both calling party and local log; be very careful about
|
|
|
|
# closing file descriptors here - if either stdout or stderr will not be closed
|
|
|
|
# when service process does the same - service call will hang (waiting for EOF
|
|
|
|
# on stdout/stderr)
|
|
|
|
stderr_pipe=/tmp/qrexec-rpc-stderr.$$
|
|
|
|
mkfifo $stderr_pipe
|
|
|
|
# tee can't write to file descriptor, nor /proc/self/fd/2 (EXIO on open)
|
|
|
|
return_stderr_pipe=/tmp/qrexec-rpc-stderr-return.$$
|
|
|
|
mkfifo $return_stderr_pipe
|
|
|
|
{ cat <$return_stderr_pipe >&2 2>/dev/null; rm -f $return_stderr_pipe; } &
|
|
|
|
{ tee $return_stderr_pipe 2>/dev/null <$stderr_pipe |\
|
|
|
|
logger -t "$1-$2" >/dev/null 2>&1; rm -f $stderr_pipe; } &
|
|
|
|
exec 2>$stderr_pipe
|
2014-05-05 05:20:26 +02:00
|
|
|
|
2013-03-20 06:21:16 +01:00
|
|
|
QUBES_RPC=/etc/qubes-rpc
|
2015-02-06 19:47:13 +01:00
|
|
|
LOCAL_QUBES_RPC=/usr/local/etc/qubes-rpc
|
|
|
|
|
2013-03-20 06:21:16 +01:00
|
|
|
if ! [ $# = 2 ] ; then
|
2017-09-30 04:45:31 +02:00
|
|
|
echo "$0: bad argument count, usage: $0 SERVICE-NAME REMOTE-DOMAIN-NAME" >&2
|
2013-03-20 06:21:16 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
export QREXEC_REMOTE_DOMAIN="$2"
|
2016-03-27 04:30:44 +02:00
|
|
|
export QREXEC_SERVICE_FULL_NAME="$1"
|
|
|
|
SERVICE_WITHOUT_ARGUMENT="${1%%+*}"
|
|
|
|
if [ "${QREXEC_SERVICE_FULL_NAME}" != "${SERVICE_WITHOUT_ARGUMENT}" ]; then
|
|
|
|
export QREXEC_SERVICE_ARGUMENT="${QREXEC_SERVICE_FULL_NAME#*+}"
|
|
|
|
fi
|
2015-03-17 14:47:29 +01:00
|
|
|
|
2016-03-27 04:30:44 +02:00
|
|
|
for CFG_FILE in $LOCAL_QUBES_RPC/"$1" $QUBES_RPC/"$1" \
|
|
|
|
$LOCAL_QUBES_RPC/"${SERVICE_WITHOUT_ARGUMENT}" \
|
|
|
|
$QUBES_RPC/"${SERVICE_WITHOUT_ARGUMENT}"; do
|
2015-02-06 19:47:13 +01:00
|
|
|
if [ -s "$CFG_FILE" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2015-03-17 14:47:29 +01:00
|
|
|
|
|
|
|
if [ -x "$CFG_FILE" ] ; then
|
2017-09-30 04:55:24 +02:00
|
|
|
# shellcheck disable=SC2086
|
2016-03-27 04:30:44 +02:00
|
|
|
exec "$CFG_FILE" ${QREXEC_SERVICE_ARGUMENT}
|
2013-03-20 06:21:16 +01:00
|
|
|
echo "$0: failed to execute handler for" "$1" >&2
|
|
|
|
exit 1
|
2015-03-17 14:47:29 +01:00
|
|
|
else
|
2017-09-30 04:55:24 +02:00
|
|
|
# shellcheck disable=SC2086
|
2016-03-27 04:30:44 +02:00
|
|
|
exec /bin/sh -- "$CFG_FILE" ${QREXEC_SERVICE_ARGUMENT}
|
2013-03-20 06:21:16 +01:00
|
|
|
echo "$0: failed to execute handler for" "$1" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|