From e8292927e355e6d5499ff5691482923ffc576202 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Tue, 14 Aug 2018 07:01:14 +0100 Subject: added check of nc implementation --- gosher | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/gosher b/gosher index 16d2d83..73f5255 100755 --- a/gosher +++ b/gosher @@ -51,7 +51,7 @@ NETCAT="nc" ## ## NETCAT_OPTS: any additional options to netcat ## -NETCAT_OPTS="" +NETCAT_OPTS="-v" ## ## STYLE: The way in which netcat will talk to gosher_serve @@ -94,20 +94,36 @@ if [ -z "${MYNAME#gosher}" ]; then echo "Wrong NETCAT -- Exiting" >&2 exit 2 } + is_openbsd=$(echo "${NETCAT}" | grep -i "certfile") if [ -f "${MYDIR}/gosher_serve" ] || [ -h "${MYDIR}/gosher_serve" ]; then GOSHER_SERVE="${MYDIR}/gosher_serve" trap cleanup 0 HUP INT TRAP TERM QUIT INF="${IPREFIX}$$" - [ "$STYLE" = "pipe" ] && { + [ "$STYLE" = "pipe" -a -n "${is_openbsd}" ] && { + echo "Genuine OpenBSD nc detected" >&2 mkfifo -m 600 "$INF" # shellcheck disable=SC2050 while :; do # shellcheck disable=SC2094 ${GOSHER_SERVE} "${GOPHERDIR}" \ "${HOSTNAME}" "${PORT}" <"$INF" |\ - ${NETCAT} -vvvvv -l "${HOSTNAME}" "${PORT}" >"$INF" + ${NETCAT} ${NETCAT_OPTS} -l "${HOSTNAME}" "${PORT}" >"$INF" + sleep 1 + done + rm -f $INF + exit 0 + } + [ "$STYLE" = "pipe" -a -z "${is_openbsd}" ] && { + echo "Other nc implementation detected" >&2 + mkfifo -m 600 "$INF" +# shellcheck disable=SC2050 + while :; do +# shellcheck disable=SC2094 + ${GOSHER_SERVE} "${GOPHERDIR}" \ + "${HOSTNAME}" "${PORT}" <"$INF" |\ + ${NETCAT} ${NETCAT_OPTS} -l -p "${PORT}" >"$INF" sleep 1 done rm -f $INF @@ -116,7 +132,7 @@ if [ -z "${MYNAME#gosher}" ]; then [ "$STYLE" = 'fork' ] && { # shellcheck disable=SC2050 while :; do - ${NETCAT} -vv -l -p "$PORT" -c \ + ${NETCAT} ${NETCAT_OPTS} -l -p "$PORT" -c \ "${GOSHER_SERVE} ${GOPHERDIR} ${HOSTNAME} ${PORT}" sleep 1 done -- cgit v1.2.3