2 * Copyright (c) 1997 - 2005 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
36 __RCSID("$Heimdal: hprop.c 21745 2007-07-31 16:11:25Z lha $"
39 static int version_flag
;
41 static const char *ktname
= HPROP_KEYTAB
;
42 static const char *database
;
43 static char *mkeyfile
;
45 static int verbose_flag
;
46 static int encrypt_flag
;
47 static int decrypt_flag
;
48 static hdb_master_key mkey5
;
50 static char *source_type
;
52 static char *afs_cell
;
53 static char *v4_realm
;
55 static int kaspecials_flag
;
56 static int ka_use_null_salt
;
58 static char *local_realm
=NULL
;
61 open_socket(krb5_context context
, const char *hostname
, const char *port
)
63 struct addrinfo
*ai
, *a
;
64 struct addrinfo hints
;
67 memset (&hints
, 0, sizeof(hints
));
68 hints
.ai_socktype
= SOCK_STREAM
;
69 hints
.ai_protocol
= IPPROTO_TCP
;
71 error
= getaddrinfo (hostname
, port
, &hints
, &ai
);
73 warnx ("%s: %s", hostname
, gai_strerror(error
));
77 for (a
= ai
; a
!= NULL
; a
= a
->ai_next
) {
80 s
= socket (a
->ai_family
, a
->ai_socktype
, a
->ai_protocol
);
83 if (connect (s
, a
->ai_addr
, a
->ai_addrlen
) < 0) {
84 warn ("connect(%s)", hostname
);
91 warnx ("failed to contact %s", hostname
);
97 v5_prop(krb5_context context
, HDB
*db
, hdb_entry_ex
*entry
, void *appdata
)
100 struct prop_data
*pd
= appdata
;
104 ret
= hdb_seal_keys_mkey(context
, &entry
->entry
, mkey5
);
106 krb5_warn(context
, ret
, "hdb_seal_keys_mkey");
111 ret
= hdb_unseal_keys_mkey(context
, &entry
->entry
, mkey5
);
113 krb5_warn(context
, ret
, "hdb_unseal_keys_mkey");
118 ret
= hdb_entry2value(context
, &entry
->entry
, &data
);
120 krb5_warn(context
, ret
, "hdb_entry2value");
125 ret
= krb5_write_message(context
, &pd
->sock
, &data
);
127 ret
= krb5_write_priv_message(context
, pd
->auth_context
,
129 krb5_data_free(&data
);
134 v4_prop(void *arg
, struct v4_principal
*p
)
136 struct prop_data
*pd
= arg
;
140 memset(&ent
, 0, sizeof(ent
));
142 ret
= krb5_425_conv_principal(pd
->context
, p
->name
, p
->instance
, v4_realm
,
143 &ent
.entry
.principal
);
145 krb5_warn(pd
->context
, ret
,
146 "krb5_425_conv_principal %s.%s@%s",
147 p
->name
, p
->instance
, v4_realm
);
153 krb5_unparse_name_short(pd
->context
, ent
.entry
.principal
, &s
);
154 krb5_warnx(pd
->context
, "%s.%s -> %s", p
->name
, p
->instance
, s
);
158 ent
.entry
.kvno
= p
->kvno
;
159 ent
.entry
.keys
.len
= 3;
160 ent
.entry
.keys
.val
= malloc(ent
.entry
.keys
.len
* sizeof(*ent
.entry
.keys
.val
));
161 if (ent
.entry
.keys
.val
== NULL
)
162 krb5_errx(pd
->context
, ENOMEM
, "malloc");
164 ent
.entry
.keys
.val
[0].mkvno
= malloc (sizeof(*ent
.entry
.keys
.val
[0].mkvno
));
165 if (ent
.entry
.keys
.val
[0].mkvno
== NULL
)
166 krb5_errx(pd
->context
, ENOMEM
, "malloc");
167 *(ent
.entry
.keys
.val
[0].mkvno
) = p
->mkvno
;
169 ent
.entry
.keys
.val
[0].mkvno
= NULL
;
170 ent
.entry
.keys
.val
[0].salt
= calloc(1, sizeof(*ent
.entry
.keys
.val
[0].salt
));
171 if (ent
.entry
.keys
.val
[0].salt
== NULL
)
172 krb5_errx(pd
->context
, ENOMEM
, "calloc");
173 ent
.entry
.keys
.val
[0].salt
->type
= KRB5_PADATA_PW_SALT
;
174 ent
.entry
.keys
.val
[0].key
.keytype
= ETYPE_DES_CBC_MD5
;
175 krb5_data_alloc(&ent
.entry
.keys
.val
[0].key
.keyvalue
, DES_KEY_SZ
);
176 memcpy(ent
.entry
.keys
.val
[0].key
.keyvalue
.data
, p
->key
, 8);
178 copy_Key(&ent
.entry
.keys
.val
[0], &ent
.entry
.keys
.val
[1]);
179 ent
.entry
.keys
.val
[1].key
.keytype
= ETYPE_DES_CBC_MD4
;
180 copy_Key(&ent
.entry
.keys
.val
[0], &ent
.entry
.keys
.val
[2]);
181 ent
.entry
.keys
.val
[2].key
.keytype
= ETYPE_DES_CBC_CRC
;
184 int life
= _krb5_krb_life_to_time(0, p
->max_life
);
185 if(life
== NEVERDATE
){
186 ent
.entry
.max_life
= NULL
;
188 /* clean up lifetime a bit */
190 life
= (life
+ 86399) / 86400 * 86400;
192 life
= (life
+ 3599) / 3600 * 3600;
193 ALLOC(ent
.entry
.max_life
);
194 *ent
.entry
.max_life
= life
;
198 ALLOC(ent
.entry
.valid_end
);
199 *ent
.entry
.valid_end
= p
->exp_date
;
201 ret
= krb5_make_principal(pd
->context
, &ent
.entry
.created_by
.principal
,
207 krb5_warn(pd
->context
, ret
, "krb5_make_principal");
211 ent
.entry
.created_by
.time
= time(NULL
);
212 ALLOC(ent
.entry
.modified_by
);
213 ret
= krb5_425_conv_principal(pd
->context
, p
->mod_name
, p
->mod_instance
,
214 v4_realm
, &ent
.entry
.modified_by
->principal
);
216 krb5_warn(pd
->context
, ret
, "%s.%s@%s", p
->name
, p
->instance
, v4_realm
);
217 ent
.entry
.modified_by
->principal
= NULL
;
221 ent
.entry
.modified_by
->time
= p
->mod_date
;
223 ent
.entry
.flags
.forwardable
= 1;
224 ent
.entry
.flags
.renewable
= 1;
225 ent
.entry
.flags
.proxiable
= 1;
226 ent
.entry
.flags
.postdate
= 1;
227 ent
.entry
.flags
.client
= 1;
228 ent
.entry
.flags
.server
= 1;
230 /* special case password changing service */
231 if(strcmp(p
->name
, "changepw") == 0 &&
232 strcmp(p
->instance
, "kerberos") == 0) {
233 ent
.entry
.flags
.forwardable
= 0;
234 ent
.entry
.flags
.renewable
= 0;
235 ent
.entry
.flags
.proxiable
= 0;
236 ent
.entry
.flags
.postdate
= 0;
237 ent
.entry
.flags
.initial
= 1;
238 ent
.entry
.flags
.change_pw
= 1;
241 ret
= v5_prop(pd
->context
, NULL
, &ent
, pd
);
243 if (strcmp (p
->name
, "krbtgt") == 0
244 && strcmp (v4_realm
, p
->instance
) != 0) {
245 krb5_free_principal (pd
->context
, ent
.entry
.principal
);
246 ret
= krb5_425_conv_principal (pd
->context
, p
->name
,
247 v4_realm
, p
->instance
,
248 &ent
.entry
.principal
);
250 ret
= v5_prop (pd
->context
, NULL
, &ent
, pd
);
254 hdb_free_entry(pd
->context
, &ent
);
260 /* read a `ka_entry' from `fd' at offset `pos' */
262 read_block(krb5_context context
, int fd
, int32_t pos
, void *buf
, size_t len
)
266 if((ret
= pread(fd
, buf
, len
, 64 + pos
)) < 0)
267 krb5_err(context
, 1, errno
, "pread(%u)", 64 + pos
);
269 if(lseek(fd
, 64 + pos
, SEEK_SET
) == (off_t
)-1)
270 krb5_err(context
, 1, errno
, "lseek(%u)", 64 + pos
);
271 ret
= read(fd
, buf
, len
);
273 krb5_err(context
, 1, errno
, "read(%lu)", (unsigned long)len
);
276 krb5_errx(context
, 1, "read(%lu) = %u", (unsigned long)len
, ret
);
280 ka_convert(struct prop_data
*pd
, int fd
, struct ka_entry
*ent
)
282 int32_t flags
= ntohl(ent
->flags
);
287 && (flags
& KAFNORMAL
) == 0) /* remove special entries */
289 memset(&hdb
, 0, sizeof(hdb
));
290 ret
= krb5_425_conv_principal(pd
->context
, ent
->name
, ent
->instance
,
291 v4_realm
, &hdb
.entry
.principal
);
293 krb5_warn(pd
->context
, ret
,
294 "krb5_425_conv_principal (%s.%s@%s)",
295 ent
->name
, ent
->instance
, v4_realm
);
298 hdb
.entry
.kvno
= ntohl(ent
->kvno
);
299 hdb
.entry
.keys
.len
= 3;
301 malloc(hdb
.entry
.keys
.len
* sizeof(*hdb
.entry
.keys
.val
));
302 if (hdb
.entry
.keys
.val
== NULL
)
303 krb5_errx(pd
->context
, ENOMEM
, "malloc");
304 hdb
.entry
.keys
.val
[0].mkvno
= NULL
;
305 hdb
.entry
.keys
.val
[0].salt
= calloc(1, sizeof(*hdb
.entry
.keys
.val
[0].salt
));
306 if (hdb
.entry
.keys
.val
[0].salt
== NULL
)
307 krb5_errx(pd
->context
, ENOMEM
, "calloc");
308 if (ka_use_null_salt
) {
309 hdb
.entry
.keys
.val
[0].salt
->type
= hdb_pw_salt
;
310 hdb
.entry
.keys
.val
[0].salt
->salt
.data
= NULL
;
311 hdb
.entry
.keys
.val
[0].salt
->salt
.length
= 0;
313 hdb
.entry
.keys
.val
[0].salt
->type
= hdb_afs3_salt
;
314 hdb
.entry
.keys
.val
[0].salt
->salt
.data
= strdup(afs_cell
);
315 if (hdb
.entry
.keys
.val
[0].salt
->salt
.data
== NULL
)
316 krb5_errx(pd
->context
, ENOMEM
, "strdup");
317 hdb
.entry
.keys
.val
[0].salt
->salt
.length
= strlen(afs_cell
);
320 hdb
.entry
.keys
.val
[0].key
.keytype
= ETYPE_DES_CBC_MD5
;
321 krb5_data_copy(&hdb
.entry
.keys
.val
[0].key
.keyvalue
,
324 copy_Key(&hdb
.entry
.keys
.val
[0], &hdb
.entry
.keys
.val
[1]);
325 hdb
.entry
.keys
.val
[1].key
.keytype
= ETYPE_DES_CBC_MD4
;
326 copy_Key(&hdb
.entry
.keys
.val
[0], &hdb
.entry
.keys
.val
[2]);
327 hdb
.entry
.keys
.val
[2].key
.keytype
= ETYPE_DES_CBC_CRC
;
329 ALLOC(hdb
.entry
.max_life
);
330 *hdb
.entry
.max_life
= ntohl(ent
->max_life
);
332 if(ntohl(ent
->valid_end
) != NEVERDATE
&& ntohl(ent
->valid_end
) != 0xffffffff) {
333 ALLOC(hdb
.entry
.valid_end
);
334 *hdb
.entry
.valid_end
= ntohl(ent
->valid_end
);
337 if (ntohl(ent
->pw_change
) != NEVERDATE
&&
338 ent
->pw_expire
!= 255 &&
339 ent
->pw_expire
!= 0) {
340 ALLOC(hdb
.entry
.pw_end
);
341 *hdb
.entry
.pw_end
= ntohl(ent
->pw_change
)
342 + 24 * 60 * 60 * ent
->pw_expire
;
345 ret
= krb5_make_principal(pd
->context
, &hdb
.entry
.created_by
.principal
,
350 hdb
.entry
.created_by
.time
= time(NULL
);
354 ALLOC(hdb
.entry
.modified_by
);
355 read_block(pd
->context
, fd
, ntohl(ent
->mod_ptr
), &mod
, sizeof(mod
));
357 krb5_425_conv_principal(pd
->context
, mod
.name
, mod
.instance
, v4_realm
,
358 &hdb
.entry
.modified_by
->principal
);
359 hdb
.entry
.modified_by
->time
= ntohl(ent
->mod_time
);
360 memset(&mod
, 0, sizeof(mod
));
363 hdb
.entry
.flags
.forwardable
= 1;
364 hdb
.entry
.flags
.renewable
= 1;
365 hdb
.entry
.flags
.proxiable
= 1;
366 hdb
.entry
.flags
.postdate
= 1;
367 /* XXX - AFS 3.4a creates krbtgt.REALMOFCELL as NOTGS+NOSEAL */
368 if (strcmp(ent
->name
, "krbtgt") == 0 &&
369 (flags
& (KAFNOTGS
|KAFNOSEAL
)) == (KAFNOTGS
|KAFNOSEAL
))
370 flags
&= ~(KAFNOTGS
|KAFNOSEAL
);
372 hdb
.entry
.flags
.client
= (flags
& KAFNOTGS
) == 0;
373 hdb
.entry
.flags
.server
= (flags
& KAFNOSEAL
) == 0;
375 ret
= v5_prop(pd
->context
, NULL
, &hdb
, pd
);
376 hdb_free_entry(pd
->context
, &hdb
);
381 ka_dump(struct prop_data
*pd
, const char *file
)
383 struct ka_header header
;
385 int fd
= open(file
, O_RDONLY
);
388 krb5_err(pd
->context
, 1, errno
, "open(%s)", file
);
389 read_block(pd
->context
, fd
, 0, &header
, sizeof(header
));
390 if(header
.version1
!= header
.version2
)
391 krb5_errx(pd
->context
, 1, "Version mismatch in header: %ld/%ld",
392 (long)ntohl(header
.version1
), (long)ntohl(header
.version2
));
393 if(ntohl(header
.version1
) != 5)
394 krb5_errx(pd
->context
, 1, "Unknown database version %ld (expected 5)",
395 (long)ntohl(header
.version1
));
396 for(i
= 0; i
< ntohl(header
.hashsize
); i
++){
397 int32_t pos
= ntohl(header
.hash
[i
]);
400 read_block(pd
->context
, fd
, pos
, &ent
, sizeof(ent
));
401 ka_convert(pd
, fd
, &ent
);
402 pos
= ntohl(ent
.next
);
410 struct getargs args
[] = {
411 { "master-key", 'm', arg_string
, &mkeyfile
, "v5 master key file", "file" },
412 { "database", 'd', arg_string
, &database
, "database", "file" },
413 { "source", 0, arg_string
, &source_type
, "type of database to read",
420 { "v4-realm", 'r', arg_string
, &v4_realm
, "v4 realm to use" },
421 { "cell", 'c', arg_string
, &afs_cell
, "name of AFS cell" },
422 { "kaspecials", 'S', arg_flag
, &kaspecials_flag
, "dump KASPECIAL keys"},
423 { "keytab", 'k', arg_string
, &ktname
, "keytab to use for authentication", "keytab" },
424 { "v5-realm", 'R', arg_string
, &local_realm
, "v5 realm to use" },
425 { "decrypt", 'D', arg_flag
, &decrypt_flag
, "decrypt keys" },
426 { "encrypt", 'E', arg_flag
, &encrypt_flag
, "encrypt keys" },
427 { "stdout", 'n', arg_flag
, &to_stdout
, "dump to stdout" },
428 { "verbose", 'v', arg_flag
, &verbose_flag
},
429 { "version", 0, arg_flag
, &version_flag
},
430 { "help", 'h', arg_flag
, &help_flag
}
433 static int num_args
= sizeof(args
) / sizeof(args
[0]);
438 arg_printusage (args
, num_args
, NULL
, "[host[:port]] ...");
443 get_creds(krb5_context context
, krb5_ccache
*cache
)
446 krb5_principal client
;
448 krb5_get_init_creds_opt
*init_opts
;
449 krb5_preauthtype preauth
= KRB5_PADATA_ENC_TIMESTAMP
;
452 ret
= krb5_kt_register(context
, &hdb_kt_ops
);
453 if(ret
) krb5_err(context
, 1, ret
, "krb5_kt_register");
455 ret
= krb5_kt_resolve(context
, ktname
, &keytab
);
456 if(ret
) krb5_err(context
, 1, ret
, "krb5_kt_resolve");
458 ret
= krb5_make_principal(context
, &client
, NULL
,
459 "kadmin", HPROP_NAME
, NULL
);
460 if(ret
) krb5_err(context
, 1, ret
, "krb5_make_principal");
462 ret
= krb5_get_init_creds_opt_alloc(context
, &init_opts
);
463 if(ret
) krb5_err(context
, 1, ret
, "krb5_get_init_creds_opt_alloc");
464 krb5_get_init_creds_opt_set_preauth_list(init_opts
, &preauth
, 1);
466 ret
= krb5_get_init_creds_keytab(context
, &creds
, client
, keytab
, 0, NULL
, init_opts
);
467 if(ret
) krb5_err(context
, 1, ret
, "krb5_get_init_creds");
469 krb5_get_init_creds_opt_free(context
, init_opts
);
471 ret
= krb5_kt_close(context
, keytab
);
472 if(ret
) krb5_err(context
, 1, ret
, "krb5_kt_close");
474 ret
= krb5_cc_gen_new(context
, &krb5_mcc_ops
, cache
);
475 if(ret
) krb5_err(context
, 1, ret
, "krb5_cc_gen_new");
477 ret
= krb5_cc_initialize(context
, *cache
, client
);
478 if(ret
) krb5_err(context
, 1, ret
, "krb5_cc_initialize");
480 krb5_free_principal(context
, client
);
482 ret
= krb5_cc_store_cred(context
, *cache
, &creds
);
483 if(ret
) krb5_err(context
, 1, ret
, "krb5_cc_store_cred");
485 krb5_free_cred_contents(context
, &creds
);
495 #define IS_TYPE_V4(X) ((X) == HPROP_KRB4_DUMP || (X) == HPROP_KASERVER)
501 { HPROP_HEIMDAL
, "heimdal" },
502 { HPROP_KRB4_DUMP
, "krb4-dump" },
503 { HPROP_KASERVER
, "kaserver" },
504 { HPROP_MIT_DUMP
, "mit-dump" }
508 parse_source_type(const char *s
)
511 for(i
= 0; i
< sizeof(types
) / sizeof(types
[0]); i
++) {
512 if(strstr(types
[i
].name
, s
) == types
[i
].name
)
513 return types
[i
].type
;
519 iterate (krb5_context context
,
520 const char *database_name
,
523 struct prop_data
*pd
)
528 case HPROP_KRB4_DUMP
:
529 ret
= v4_prop_dump(pd
, database_name
);
531 krb5_warnx(context
, "v4_prop_dump: %s",
532 krb5_get_err_text(context
, ret
));
535 ret
= ka_dump(pd
, database_name
);
537 krb5_warn(context
, ret
, "ka_dump");
540 ret
= mit_prop_dump(pd
, database_name
);
542 krb5_warnx(context
, "mit_prop_dump: %s",
543 krb5_get_err_text(context
, ret
));
546 ret
= hdb_foreach(context
, db
, HDB_F_DECRYPT
, v5_prop
, pd
);
548 krb5_warn(context
, ret
, "hdb_foreach");
551 krb5_errx(context
, 1, "unknown prop type: %d", type
);
557 dump_database (krb5_context context
, int type
,
558 const char *database_name
, HDB
*db
)
564 pd
.context
= context
;
565 pd
.auth_context
= NULL
;
566 pd
.sock
= STDOUT_FILENO
;
568 ret
= iterate (context
, database_name
, db
, type
, &pd
);
570 krb5_errx(context
, 1, "iterate failure");
571 krb5_data_zero (&data
);
572 ret
= krb5_write_message (context
, &pd
.sock
, &data
);
574 krb5_err(context
, 1, ret
, "krb5_write_message");
580 propagate_database (krb5_context context
, int type
,
581 const char *database_name
,
582 HDB
*db
, krb5_ccache ccache
,
583 int optidx
, int argc
, char **argv
)
585 krb5_principal server
;
589 for(i
= optidx
; i
< argc
; i
++){
590 krb5_auth_context auth_context
;
595 char *port
, portstr
[NI_MAXSERV
];
596 char *host
= argv
[i
];
598 port
= strchr(host
, ':');
600 snprintf(portstr
, sizeof(portstr
), "%u",
601 ntohs(krb5_getportbyname (context
, "hprop", "tcp",
607 fd
= open_socket(context
, host
, port
);
610 krb5_warn (context
, errno
, "connect %s", host
);
614 ret
= krb5_sname_to_principal(context
, argv
[i
],
615 HPROP_NAME
, KRB5_NT_SRV_HST
, &server
);
618 krb5_warn(context
, ret
, "krb5_sname_to_principal(%s)", host
);
625 krb5_get_default_realm(context
,&my_realm
);
627 free (*krb5_princ_realm(context
, server
));
628 krb5_princ_set_realm(context
,server
,&my_realm
);
632 ret
= krb5_sendauth(context
,
638 AP_OPTS_MUTUAL_REQUIRED
| AP_OPTS_USE_SUBKEY
,
646 krb5_free_principal(context
, server
);
650 krb5_warn(context
, ret
, "krb5_sendauth (%s)", host
);
655 pd
.context
= context
;
656 pd
.auth_context
= auth_context
;
659 ret
= iterate (context
, database_name
, db
, type
, &pd
);
661 krb5_warnx(context
, "iterate to host %s failed", host
);
666 krb5_data_zero (&data
);
667 ret
= krb5_write_priv_message(context
, auth_context
, &fd
, &data
);
669 krb5_warn(context
, ret
, "krb5_write_priv_message");
674 ret
= krb5_read_priv_message(context
, auth_context
, &fd
, &data
);
676 krb5_warn(context
, ret
, "krb5_read_priv_message: %s", host
);
680 krb5_data_free (&data
);
683 krb5_auth_con_free(context
, auth_context
);
692 main(int argc
, char **argv
)
695 krb5_context context
;
696 krb5_ccache ccache
= NULL
;
702 setprogname(argv
[0]);
704 if(getarg(args
, num_args
, argc
, argv
, &optidx
))
715 ret
= krb5_init_context(&context
);
720 krb5_set_default_realm(context
, local_realm
);
722 if(v4_realm
== NULL
) {
723 ret
= krb5_get_default_realm(context
, &v4_realm
);
725 krb5_err(context
, 1, ret
, "krb5_get_default_realm");
728 if(afs_cell
== NULL
) {
729 afs_cell
= strdup(v4_realm
);
731 krb5_errx(context
, 1, "out of memory");
736 if(encrypt_flag
&& decrypt_flag
)
737 krb5_errx(context
, 1,
738 "only one of `--encrypt' and `--decrypt' is meaningful");
740 if(source_type
!= NULL
) {
741 type
= parse_source_type(source_type
);
743 krb5_errx(context
, 1, "unknown source type `%s'", source_type
);
745 type
= HPROP_HEIMDAL
;
748 get_creds(context
, &ccache
);
750 if(decrypt_flag
|| encrypt_flag
) {
751 ret
= hdb_read_master_key(context
, mkeyfile
, &mkey5
);
752 if(ret
&& ret
!= ENOENT
)
753 krb5_err(context
, 1, ret
, "hdb_read_master_key");
755 krb5_errx(context
, 1, "No master key file found");
758 if (IS_TYPE_V4(type
) && v4_realm
== NULL
)
759 krb5_errx(context
, 1, "Its a Kerberos 4 database "
760 "but no realm configured");
764 if (database
== NULL
)
765 database
= DEFAULT_DATABASE
;
766 ka_use_null_salt
= krb5_config_get_bool_default(context
, NULL
, FALSE
,
768 "afs_uses_null_salt",
772 case HPROP_KRB4_DUMP
:
773 if (database
== NULL
)
774 krb5_errx(context
, 1, "no dump file specified");
778 if (database
== NULL
)
779 krb5_errx(context
, 1, "no dump file specified");
782 ret
= hdb_create (context
, &db
, database
);
784 krb5_err(context
, 1, ret
, "hdb_create: %s", database
);
785 ret
= db
->hdb_open(context
, db
, O_RDONLY
, 0);
787 krb5_err(context
, 1, ret
, "db->hdb_open");
790 krb5_errx(context
, 1, "unknown dump type `%d'", type
);
795 exit_code
= dump_database (context
, type
, database
, db
);
797 exit_code
= propagate_database (context
, type
, database
,
798 db
, ccache
, optidx
, argc
, argv
);
801 krb5_cc_destroy(context
, ccache
);
804 (*db
->hdb_destroy
)(context
, db
);
806 krb5_free_context(context
);