2023-11-13 14:33:28 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-07-09 17:42:07 +02:00
|
|
|
# SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
2023-11-13 14:33:28 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2024-07-09 17:42:07 +02:00
|
|
|
die(){
|
2024-08-06 18:15:24 +02:00
|
|
|
printf '%s\n' "error: ${1}" >&2
|
2024-07-09 17:42:07 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2024-07-10 14:36:05 +02:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
untrusted_agent="${QREXEC_SERVICE_ARGUMENT}"
|
2023-11-21 14:57:47 +00:00
|
|
|
|
|
|
|
if test -z "${untrusted_agent}"; then
|
2024-07-09 17:42:07 +02:00
|
|
|
die "Agent name is empty"
|
2023-11-21 14:57:47 +00:00
|
|
|
fi
|
|
|
|
|
2024-08-06 18:15:24 +02:00
|
|
|
if ! (printf '%s\n' "${untrusted_agent}" | \
|
|
|
|
grep -q -e "^[A-Za-z0-9][A-Za-z0-9_.-]\+$")
|
2023-11-21 14:57:47 +00:00
|
|
|
then
|
2024-07-09 17:42:07 +02:00
|
|
|
msg="Forbidden characters in agent name."
|
|
|
|
msg="${msg} Allowed chars: letters, numbers, hyphen, underscore and dot."
|
|
|
|
msg="${msg} Name cannot begin with hyphen, underscore or dot"
|
|
|
|
die "${msg}"
|
2023-11-21 14:57:47 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
## Length arbitrarily set.
|
|
|
|
if test "${#untrusted_agent}" -gt 128; then
|
|
|
|
die "Repository name is too long: ${#untrusted_agent}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
agent="${untrusted_agent}"
|
2024-06-25 22:16:26 +02:00
|
|
|
socket="/tmp/qusal-ssh-agent/${agent}.sock"
|
2023-11-13 14:33:28 +00:00
|
|
|
|
|
|
|
qvm-ssh-agent add "${agent}" >/dev/null
|
2023-11-21 14:57:47 +00:00
|
|
|
exec socat STDIO UNIX-CLIENT:"${socket}"
|