X-Git-Url: https://snippets.scripts.mit.edu/gitweb.cgi/Scripts/git/.git/blobdiff_plain/28e020a821e1be0eadfcd29478c1de01e8a6f353..ad89b8cabe0677c0023ee2bda00c23ca761b29e8:/kerberos/kdo diff --git a/kerberos/kdo b/kerberos/kdo index 51a5d9b..e06910f 100644 --- a/kerberos/kdo +++ b/kerberos/kdo @@ -1,6 +1,9 @@ +# -*- mode: sh -*- # kdo is a shell function for interacting with multiple Kerberos # credential caches. # +# To use kdo, add this snippet to your .bashrc or .bashrc.mine file. +# # To run a command with a different set of credentials from your # default, run # @@ -21,7 +24,7 @@ # interface to multiple credential caches by defining two functions: # # - kcaches:: -# Print one line per current credential cache of the form " " +# Print one line per current credential cache of the form " " # - knewcache:: # Without changing the current credentials cache, get credentials # for the principal in $1, passing the remaining arguments to @@ -40,12 +43,13 @@ kdo_args=(-l15m -r60m -F) # CC interface for OS X if [ "Darwin" = "$(uname)" ]; then kcaches () { - klist -A | awk '/^Kerberos 5 ticket cache:/ {cache = $5; princline=NR+1} NR==princline {print substr(cache, 2, length(cache)-2), $3}' + klist -A | perl -ne '$cache = $1 if /^Kerberos 5 ticket cache: '\''(.*)'\''/; print "$1 $cache\n" if /^Default principal: (.*)$/' } knewcache () { princ="$1"; shift local oldcache="$(klist | grep 'Kerberos 5 ticket cache' | cut -f 2 -d "'")" + # " # <-- emacs thinks there's an unbalanced " on the previous line. kinit "$@" "$princ" || return 1 cache="$(kfindcache "$princ")" # On OS X, kinit will switch your default credential cache to @@ -62,7 +66,7 @@ fi # setup kdo. Otherwise, add a helpful error. if hash kcaches &>/dev/null && hash knewcache &>/dev/null; then kfindcache () { - kcaches | fgrep "$1" | awk '{print $1}' + kcaches | fgrep "$1" | cut -d' ' -f2- } kdo () { @@ -86,7 +90,7 @@ if hash kcaches &>/dev/null && hash knewcache &>/dev/null; then local cur COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" - opts="$(kcaches | awk '{ print $2 }')" + opts="$(kcaches | awk '{ print $1 }')" case $COMP_CWORD in 1) COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))