Path: blob/main/crypto/krb5/src/kadmin/cli/k5srvutil.sh
34907 views
#!/bin/sh12# list_princs keytab3# returns a list of principals in the keytab4# sorted and uniquified5list_princs() {6klist -k $keytab | awk '(NR > 3) {print $2}' | sort | uniq7}89set_command() {10if [ x$command != x ] ; then11cmd_error Only one command can be specified12usage13exit 114fi15command=$116}1718#interactive_prompt prompt princ19# If in interactive mode return true if the principal should be acted on20# otherwise return true all the time21interactive_prompt() {22if [ $interactive = 0 ] ; then23return 024fi25printf "%s for %s? [yn]" "$1" "$2"26read ans27case $ans in28n*|N*)29return 130;;31esac32return 033}3435cmd_error() {36echo $@ 2>&137}3839usage() {40echo "Usage: $0 [-i] [-f file] [-e keysalts] list|change|delete|delold"41}42434445change_key() {46princs=`list_princs `47for princ in $princs; do48if interactive_prompt "Change key " $princ; then49kadmin -k -t $keytab -p $princ -q \50"ktadd -k $keytab $keysalts $princ"51fi52done53}5455delete_old_keys() {56princs=`list_princs `57for princ in $princs; do58if interactive_prompt "Delete old keys " $princ; then59kadmin -k -t $keytab -p $princ -q "ktrem -k $keytab $princ old"60fi61done62}6364delete_keys() {65interactive=166princs=`list_princs `67for princ in $princs; do68if interactive_prompt "Delete all keys " $princ; then69kadmin -p $princ -k -t $keytab -q "ktrem -k $keytab $princ all"70fi71done72}737475keytab=/etc/krb5.keytab76interactive=077keysalts=""7879while [ $# -gt 0 ] ; do80opt=$181shift82case $opt in83"-f")84keytab=$185shift86;;87"-i")88interactive=189;;90"-e")91keysalts="$keysalts -e \"$1\""92shift93;;94change|delold|delete|list)95set_command $opt96;;97*)98cmd_error Illegal option: $opt99usage100exit 1101;;102esac103done104105106case $command in107change)108change_key109;;110delold)111delete_old_keys112;;113delete)114delete_keys115;;116list)117klist -k $keytab118;;119*)120usage121;;122esac123124125