tty_kinit () {
# Provides a retry loop for kinit to handle mistyped passwords.
local upn="$1" # Service principal name with which to kinit, e.g., 'name' or
# 'name@REALM'.
local args='-r7d'
[[ -n $upn ]] && args+=" $upn"
until kinit $args; do
local keypress=
read -rsn 1 -p $'Press c to cancel. Any other key to try again.\n' \
keypress
[[ $keypress != c ]] || return 1
done
}