Skip to content

Commit

Permalink
Improves Kerberos ktstrip shell script. (#35)
Browse files Browse the repository at this point in the history
Improves Kerberos ktstrip shell script.
  • Loading branch information
JumpingYang001 authored and Yash-Khatri committed Aug 9, 2022
1 parent a9ed233 commit 1704cd0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Unix/tools/ktstrip
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ fi
list=$(mktemp)
delete_list=$(mktemp)
cmd=$(mktemp)
tmp_kt="/tmp/tmp.kt"
# Generate random string.
rand_str=`cat /dev/urandom | tr -cd 'a-zA-Z0-9' | head -c 10`
tmp_kt="/tmp/tmp.$rand_str"

# clean temp files
CleanTempFiles()
Expand Down Expand Up @@ -86,12 +88,22 @@ cat $list | awk '/^[ ]*[0-9]/{ print " "$1" " $2" "$3 }' | awk '{ if ( $3 !~ /ho

# Build the final command file adding commands at the front and back
printf "read_kt $SRC_KT \n" | cat - $delete_list >$cmd
printf "write_kt $tmp_kt\n" >>$cmd
printf "write_kt $tmp_kt\nquit\n" >>$cmd

# The command file will now ready to delete all unneeded entries.
printf "Creating $DST_KT\n"
cat $cmd | ktutil

# Make sure tmp_kt keytab content is valid.
klist -k $tmp_kt >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "The keytab $tmp_kt is invalid." 2>&1
CleanTempFiles
rm -f $tmp_kt
exit 1
fi

CleanTempFiles

if [ ! -f $tmp_kt ]
Expand Down

0 comments on commit 1704cd0

Please sign in to comment.