Created
August 19, 2020 15:41
-
-
Save Higgs1/e1e3ed6251d278ab2557cc9ac4a92b40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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