Initial import from FreeBSD RELENG_4:
[dragonfly.git] / crypto / kerberosIV / admin / kstash.c
1 /*
2  * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
3  * of Technology 
4  *
5  * For copying and distribution information, please see the file
6  * <mit-copyright.h>.
7  *
8  * Description.
9  */
10
11 #include "adm_locl.h"
12
13 RCSID("$Id: kstash.c,v 1.10 1997/03/30 17:35:37 assar Exp $");
14
15 /* change this later, but krblib_dbm needs it for now */
16
17 static des_cblock master_key;
18 static des_key_schedule master_key_schedule;
19
20 static void 
21 clear_secrets(void)
22 {
23     memset(master_key_schedule, 0, sizeof(master_key_schedule));
24     memset(master_key, 0, sizeof(master_key));
25 }
26
27 int
28 main(int argc, char **argv)
29 {
30     long    n;
31     int ret = 0;
32     set_progname (argv[0]);
33
34     if ((n = kerb_init()))
35         errx(1, "Kerberos db and cache init failed = %ld\n", n);
36
37     if (kdb_get_master_key (KDB_GET_PROMPT, &master_key,
38                             master_key_schedule) != 0) {
39         clear_secrets();
40         errx(1, "Couldn't read master key.");
41     }
42
43     if (kdb_verify_master_key (&master_key, master_key_schedule, stderr) < 0) {
44         clear_secrets();
45         return 1;
46     }
47
48     ret = kdb_kstash(&master_key, MKEYFILE);
49     if(ret < 0)
50         warn("writing master key");
51     else
52         fprintf(stderr, "Wrote master key to %s\n", MKEYFILE);
53     
54     clear_secrets();
55     return ret;
56 }