Skip to content

Instantly share code, notes, and snippets.

@Higgs1
Created August 19, 2020 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Higgs1/e1e3ed6251d278ab2557cc9ac4a92b40 to your computer and use it in GitHub Desktop.
Save Higgs1/e1e3ed6251d278ab2557cc9ac4a92b40 to your computer and use it in GitHub Desktop.
# Requires the "kinit" command
# Fedora: krb5-workstation
# OpenSUSE: krb5-client
# Ubuntu: krb5-user
# TODO: allow use of environment variables
USERN="$USER"
while (( "$#" )); do
case "$1" in
-D|--domain)
REALM=$2
shift 2
;;
-U|--user*)
USERN=$2
shift 2
;;
-P|--pass*)
PASSW=$2
shift 2
;;
-V|--verbose)
export KRB5_TRACE=/dev/stdout
shift 1
;;
-H|--help)
echo 'TODO: help'
shift 1
exit
;;
*)
break
;;
esac
done
if [ -z "$REALM" ]; then
if [[ "$USERN" =~ @ ]]; then
REALM="${USERN#*@}"
elif [[ "$USERN" =~ \\ ]]; then
REALM="${USERN%\\*}".local
USERN="${USERN#*\\}"
fi
fi
if [ -z "$*" ]; then
set -- $(xargs -0 < /proc/$$/cmdline)
fi
if [ ! -z "$REALM" ]; then
export KRB5_CONFIG="$(mktemp)"
trap "rm -f \"$KRB5_CONFIG\"" EXIT
echo $'[libdefaults]\ndefault_realm='"${REALM^^}" > "$KRB5_CONFIG"
fi
export KRB5CCNAME="$(mktemp)"
trap "rm -f \"$KRB5CCNAME\"" EXIT
(
if [ ! -z "$PASSW" ]; then
echo "$PASSW" | kinit -fVApE "$USERN" > /dev/null
else
kinit -fVApE "$USERN"
fi
) 2> /dev/null && $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment