Skip to content

Commit

Permalink
Fixes cleanup and removes trap on INT signal
Browse files Browse the repository at this point in the history
  • Loading branch information
leshniak committed Sep 14, 2022
1 parent 147a8a4 commit 6b5ed19
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions usr/local/bin/ttyd-login
Original file line number Diff line number Diff line change
@@ -1,4 1,5 @@
#!/bin/sh
set -e

script_name=$(basename "$0")
remote_addr="$1"
Expand All @@ -7,17 8,20 @@ error_pipe="${TMPDIR:-/tmp}/$script_name.$$.pipe"
error_log="${TMPDIR:-/tmp}/$script_name.$$.stderr"

cleanup() {
trap - TERM
rm -f -- "$error_pipe" "$error_log"
kill -- -$$
}

trap cleanup INT TERM EXIT
trap cleanup TERM EXIT

[ ! -z "$remote_addr" ] && echo "Connecting to $hostname from $remote_addr."

read -rp "$hostname login: " ssh_user
touch "$error_log"
mkfifo "$error_pipe"
tee -a "$error_log" < "$error_pipe" >&2 &
ssh -o PreferredAuthentications=password -l "$ssh_user" "$hostname" 2>"$error_pipe"
ssh -o PreferredAuthentications=password -l "$ssh_user" "$hostname" 2>"$error_pipe" || true

failures=$(grep -ic "too many authentication failures" "$error_log")

Expand Down

0 comments on commit 6b5ed19

Please sign in to comment.