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
: \
28 echo -ne "$name --out <keytabfile> --princ <principal> --pass <password>|*\n"
29 echo -ne " [--host hostname] [--enc <encryption>]\n"
30 echo -ne " [--ptype <type>] [--path-to-ldbsearch <path>]\n"
31 echo -ne "\nEncoding should be one of:\n"
32 echo -ne " * des-cbc-crc\n"
33 echo -ne " * des-cbc-md5\n"
34 echo -ne " * rc4-hmac (default)\n"
35 echo -ne " * aes128-cts\n"
36 echo -ne " * aes256-cts\n"
72 echo "Internal error!"
77 #RC4-HMAC-NT|AES256-SHA1|AES128-SHA
78 if [ -z "$enc" ]; then
81 if [ -z "$path" ]; then
82 path
=$
(dirname $0)/..
/bin
/
83 if [ ! -f ${path}ldbsearch
]; then
84 path
=$
(dirname $0)/..
/..
/bin
/
87 if [ -z "$outfile" -o -z "$princ" -o -z "$pass" ]; then
88 echo "At least one mandatory parameter (--out, --princ, --pass) was not specified"
95 kvno
=$
(${path}ldbsearch
-H ldap
://$host "(|(samaccountname=$princ)(serviceprincipalname=$princ)(userprincipalname=$princ))" msds-keyversionnumber
-k 1 -N 2>/dev
/null |
grep -i msds-keyversionnumber
)
96 if [ x
"$kvno" = x
"" ]; then
97 echo -ne "Unable to find kvno for principal $princ\n"
98 echo -ne " check that you are authentified with kerberos\n"
101 kvno
=$
(echo $kvno |
sed 's/^.*: //')
104 if [ "$pass" = "*" ]; then
105 echo -n "Enter password for $princ: "
112 ktutil
>/dev
/null
<<EOF
113 add_entry -password -p $princ -k $kvno -e $enc
118 if [ $?
-eq 0 ]; then
119 echo "Keytab file $outfile created with success"
121 echo "Error while creating the keytab file $outfile"