Kerberos version 4 from the Net/2 tape.
[unix-history] / kerberosIV / kstash / kstash.c
CommitLineData
fdf53e02
GW
1/*
2 * $Source: /usr/src/kerberosIV/kstash/RCS/kstash.c,v $
3 * $Author: kfall $
4 *
5 * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
6 * of Technology
7 *
8 * For copying and distribution information, please see the file
9 * <mit-copyright.h>.
10 *
11 * Description.
12 */
13
14#ifndef lint
15static char rcsid_kstash_c[] =
16"$Header: /usr/src/kerberosIV/kstash/RCS/kstash.c,v 4.1 90/06/25 21:33:13 kfall Exp $";
17#endif lint
18
19#include <mit-copyright.h>
20
21#include <stdio.h>
22#include <sys/types.h>
23#include <sys/socket.h>
24#include <netinet/in.h>
25#include <netdb.h>
26#include <signal.h>
27#include <sgtty.h>
28#include <sys/ioctl.h>
29#include <sys/time.h>
30#include <sys/file.h>
31
32#include <des.h>
33#include <krb.h>
34#include <klog.h>
35#include <prot.h>
36#include <krb_db.h>
37#include <kdc.h>
38
39extern int errno;
40
41/* change this later, but krblib_dbm needs it for now */
42char *progname;
43
44static C_Block master_key;
45static Key_schedule master_key_schedule;
46static Principal s_name_data; /* for services requested */
47static unsigned char master_key_version;
48int debug;
49static int more;
50static int kfile;
51static void clear_secrets();
52
53main(argc, argv)
54 int argc;
55 char **argv;
56{
57 long n;
58 if (n = kerb_init()) {
59 fprintf(stderr, "Kerberos db and cache init failed = %d\n", n);
60 exit(1);
61 }
62
63 if (kdb_get_master_key (TRUE, master_key, master_key_schedule) != 0) {
64 fprintf (stderr, "%s: Couldn't read master key.\n", argv[0]);
65 fflush (stderr);
66 clear_secrets();
67 exit (-1);
68 }
69
70 if (kdb_verify_master_key (master_key, master_key_schedule, stderr) < 0) {
71 clear_secrets();
72 exit (-1);
73 }
74
75 kfile = open(MKEYFILE, O_TRUNC | O_RDWR | O_CREAT, 0600);
76 if (kfile < 0) {
77 clear_secrets();
78 fprintf(stderr, "\n\07\07%s: Unable to open master key file\n",
79 argv[0]);
80 exit(1);
81 }
82 if (write(kfile, (char *) master_key, 8) < 0) {
83 clear_secrets();
84 fprintf(stderr, "\n%s: Write I/O error on master key file\n",
85 argv[0]);
86 exit(1);
87 }
88 (void) close(kfile);
89 clear_secrets();
90}
91
92static void
93clear_secrets()
94{
95 bzero(master_key_schedule, sizeof(master_key_schedule));
96 bzero(master_key, sizeof(master_key));
97}