2 * Copyright (c) 1997, 1998, 1999 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "ktutil_locl.h"
38 /* convert a version 4 srvtab to a version 5 keytab */
41 #define KEYFILE "/etc/srvtab"
44 static char *srvtab
= KEYFILE
;
48 static struct getargs args
[] = {
49 { "srvtab", 's', arg_string
, &srvtab
, "srvtab to convert", "file" },
50 { "help", 'h', arg_flag
, &help_flag
},
51 { "verbose", 'v', arg_flag
, &verbose
},
54 static int num_args
= sizeof(args
) / sizeof(args
[0]);
57 srvconv(int argc
, char **argv
)
64 if(getarg(args
, num_args
, argc
, argv
, &optind
)){
65 arg_printusage(args
, num_args
, "ktutil srvconvert", "");
69 arg_printusage(args
, num_args
, "ktutil srvconvert", "");
77 arg_printusage(args
, num_args
, "ktutil srvconvert", "");
81 fd
= open(srvtab
, O_RDONLY
);
83 krb5_warn(context
, errno
, "%s", srvtab
);
86 sp
= krb5_storage_from_fd(fd
);
92 char *service
, *instance
, *realm
;
95 krb5_keytab_entry entry
;
97 ret
= krb5_ret_stringz(sp
, &service
);
98 if(ret
== KRB5_CC_END
) {
103 krb5_warn(context
, ret
, "reading service");
106 ret
= krb5_ret_stringz(sp
, &instance
);
108 krb5_warn(context
, ret
, "reading instance");
112 ret
= krb5_ret_stringz(sp
, &realm
);
114 krb5_warn(context
, ret
, "reading realm");
119 ret
= krb5_425_conv_principal(context
, service
, instance
, realm
,
125 krb5_warn(context
, ret
, "krb5_425_conv_principal (%s.%s@%s)",
126 service
, instance
, realm
);
130 ret
= krb5_ret_int8(sp
, &kvno
);
132 krb5_warn(context
, ret
, "reading kvno");
133 krb5_free_principal(context
, entry
.principal
);
136 ret
= sp
->fetch(sp
, key
, 8);
138 krb5_warn(context
, errno
, "reading key");
139 krb5_free_principal(context
, entry
.principal
);
143 krb5_warn(context
, errno
, "end of file while reading key");
144 krb5_free_principal(context
, entry
.principal
);
149 entry
.timestamp
= time (NULL
);
150 entry
.keyblock
.keyvalue
.data
= key
;
151 entry
.keyblock
.keyvalue
.length
= 8;
155 ret
= krb5_unparse_name(context
, entry
.principal
, &p
);
157 krb5_warn(context
, ret
, "krb5_unparse_name");
158 krb5_free_principal(context
, entry
.principal
);
161 fprintf(stderr
, "Storing keytab for %s\n", p
);
166 entry
.keyblock
.keytype
= ETYPE_DES_CBC_MD5
;
167 ret
= krb5_kt_add_entry(context
, keytab
, &entry
);
168 entry
.keyblock
.keytype
= ETYPE_DES_CBC_MD4
;
169 ret
= krb5_kt_add_entry(context
, keytab
, &entry
);
170 entry
.keyblock
.keytype
= ETYPE_DES_CBC_CRC
;
171 ret
= krb5_kt_add_entry(context
, keytab
, &entry
);
172 krb5_free_principal(context
, entry
.principal
);
174 krb5_warn(context
, ret
, "krb5_kt_add_entry");
178 krb5_storage_free(sp
);