|
|
1.1 root 1: /*
2: * $Source: /mit/kerberos/src/admin/RCS/ext_srvtab.c,v $
3: * $Header: ext_srvtab.c,v 4.1 89/07/18 16:49:30 jtkohl Exp $
4: *
5: * Copyright 1987, 1988 by the Massachusetts Institute of Technology.
6: *
7: * For copying and distribution information, please see the file
8: * <mit-copyright.h>.
9: *
10: * Description
11: */
12:
13: #ifndef lint
14: static char rcsid_ext_srvtab_c[] =
15: "$Header: ext_srvtab.c,v 4.1 89/07/18 16:49:30 jtkohl Exp $";
16: #endif lint
17:
18: #include <mit-copyright.h>
19:
20: #include <stdio.h>
21: #include <sys/file.h>
22: #include <sys/types.h>
23: #include <sys/time.h>
24: #include <sys/stat.h>
25: #include <sys/wait.h>
26: #include <signal.h>
27: #include <des.h>
28: #include <krb.h>
29: #include <krb_db.h>
30:
31: #define TRUE 1
32: #define FALSE 0
33:
34: static C_Block master_key;
35: static C_Block session_key;
36: static Key_schedule master_key_schedule;
37: char progname[] = "ext_srvtab";
38: char realm[REALM_SZ];
39:
40: main(argc, argv)
41: int argc;
42: char *argv[];
43: {
44: FILE *fout;
45: char fname[1024];
46: int fopen_errs = 0;
47: int arg;
48: Principal princs[40];
49: int more;
50: int prompt = TRUE;
51: register int n, i;
52:
53: bzero(realm, sizeof(realm));
54:
55: /* Parse commandline arguments */
56: if (argc < 2)
57: usage();
58: else {
59: for (i = 1; i < argc; i++) {
60: if (strcmp(argv[i], "-n") == 0)
61: prompt = FALSE;
62: else if (strcmp(argv[i], "-r") == 0) {
63: if (++i >= argc)
64: usage();
65: else {
66: strcpy(realm, argv[i]);
67: /*
68: * This is to humor the broken way commandline
69: * argument parsing is done. Later, this
70: * program ignores everything that starts with -.
71: */
72: argv[i][0] = '-';
73: }
74: }
75: else if (argv[i][0] == '-')
76: usage();
77: else
78: if (!k_isinst(argv[i])) {
79: fprintf(stderr, "%s: bad instance name: %s\n",
80: progname, argv[i]);
81: usage();
82: }
83: }
84: }
85:
86: if (kdb_get_master_key (prompt, master_key, master_key_schedule) != 0) {
87: fprintf (stderr, "Couldn't read master key.\n");
88: fflush (stderr);
89: exit(1);
90: }
91:
92: if (kdb_verify_master_key (master_key, master_key_schedule, stderr) < 0) {
93: exit(1);
94: }
95:
96: /* For each arg, search for instances of arg, and produce */
97: /* srvtab file */
98: if (!realm[0])
99: if (krb_get_lrealm(realm, 1) != KSUCCESS) {
100: fprintf(stderr, "%s: couldn't get local realm\n", progname);
101: exit(1);
102: }
103: (void) umask(077);
104:
105: for (arg = 1; arg < argc; arg++) {
106: if (argv[arg][0] == '-')
107: continue;
108: sprintf(fname, "%s-new-srvtab", argv[arg]);
109: if ((fout = fopen(fname, "w")) == NULL) {
110: fprintf(stderr, "Couldn't create file '%s'.\n", fname);
111: fopen_errs++;
112: continue;
113: }
114: printf("Generating '%s'....\n", fname);
115: n = kerb_get_principal("*", argv[arg], &princs[0], 40, &more);
116: if (more)
117: fprintf(stderr, "More than 40 found...\n");
118: for (i = 0; i < n; i++) {
119: FWrite(princs[i].name, strlen(princs[i].name) + 1, 1, fout);
120: FWrite(princs[i].instance, strlen(princs[i].instance) + 1,
121: 1, fout);
122: FWrite(realm, strlen(realm) + 1, 1, fout);
123: FWrite(&princs[i].key_version,
124: sizeof(princs[i].key_version), 1, fout);
125: bcopy(&princs[i].key_low, session_key, sizeof(long));
126: bcopy(&princs[i].key_high, session_key + sizeof(long),
127: sizeof(long));
128: kdb_encrypt_key (session_key, session_key,
129: master_key, master_key_schedule, DES_DECRYPT);
130: FWrite(session_key, sizeof session_key, 1, fout);
131: }
132: fclose(fout);
133: }
134:
135: StampOutSecrets();
136:
137: exit(fopen_errs); /* 0 errors if successful */
138:
139: }
140:
141: Die()
142: {
143: StampOutSecrets();
144: exit(1);
145: }
146:
147: FWrite(p, size, n, f)
148: char *p;
149: int size;
150: int n;
151: FILE *f;
152: {
153: if (fwrite(p, size, n, f) != n) {
154: printf("Error writing output file. Terminating.\n");
155: Die();
156: }
157: }
158:
159: StampOutSecrets()
160: {
161: bzero(master_key, sizeof master_key);
162: bzero(session_key, sizeof session_key);
163: bzero(master_key_schedule, sizeof master_key_schedule);
164: }
165:
166: usage()
167: {
168: fprintf(stderr,
169: "Usage: %s [-n] [-r realm] instance [instance ...]\n", progname);
170: exit(1);
171: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.