4 # Copyright (C) Matthieu Patou <mat@matws.net> 2010
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 TEMP=`getopt -o h --long princ:,pass:,out:,host:,ptype:,enc:,path-to-ldbsearch: \
27 echo -ne "$name --out <keytabfile> --princ <principal> --pass <password>|*\n"
28 echo -ne " [--host hostname] [--enc <encryption>]\n"
29 echo -ne " [--ptype <type>] [--path-to-ldbsearch <path>]\n"
30 echo -ne "\nEncoding should be one of:\n"
31 echo -ne " * des-cbc-crc\n"
32 echo -ne " * des-cbc-md5\n"
33 echo -ne " * rc4-hmac (default)\n"
34 echo -ne " * aes128-cts\n"
35 echo -ne " * aes256-cts\n"
40 --out) outfile=$2 ; shift 2 ;;
41 --princ) princ=$2 ; shift 2 ;;
42 --pass) pass=$2 ; shift 2 ;;
43 --host) host=$2 ; shift 2 ;;
45 --enc) enc=$2; shift 2;;
46 --path-to-ldbsearch) path="$2/"; shift 2;;
49 *) echo "Internal error!" ; exit 1 ;;
52 #RC4-HMAC-NT|AES256-SHA1|AES128-SHA
53 if [ -z "$enc" ]; then
56 if [ -z "$path" ]; then
57 path=`dirname $0`/../bin/
59 if [ -z "$outfile" -o -z "$princ" -o -z "$pass" ]; then
60 echo "At least one mandatory parameter (--out, --princ, --pass) was not specified"
66 kvno=`${path}ldbsearch -H ldap://$host "(|(samaccountname=$princ)(serviceprincipalname=$princ))" msds-keyversionnumber -k 1 -N 2>/dev/null| grep -i msds-keyversionnumber`
67 if [ "$kvno" == "" ]; then
68 echo -ne "Unable to find kvno for principal $princ\n"
69 echo -ne " check that you are authentified with kerberos\n"
72 kvno=`echo $kvno | sed 's/^.*: //'`
75 if [ "$pass" == "*" ]; then
76 echo -n "Enter password for $princ: "
83 ktutil >/dev/null <<EOF
84 add_entry -password -p $princ -k $kvno -e $enc
90 echo "Keytab file $outfile created with success"
92 echo "Error while creating the keytab file $outfile"