2 * Copyright (C) 1989 by the Massachusetts Institute of Technology
4 * Export of software employing encryption from the United States of
5 * America is assumed to require a specific license from the United
6 * States Government. It is the responsibility of any person or
7 * organization contemplating export to obtain such a license before
10 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
11 * distribute this software and its documentation for any purpose and
12 * without fee is hereby granted, provided that the above copyright
13 * notice appear in all copies and that both that copyright notice and
14 * this permission notice appear in supporting documentation, and that
15 * the name of M.I.T. not be used in advertising or publicity pertaining
16 * to distribution of the software without specific, written prior
17 * permission. M.I.T. makes no representations about the suitability of
18 * this software for any purpose. It is provided "as is" without express
19 * or implied warranty.
22 #include <afsconfig.h>
23 #include <afs/param.h>
28 #include <sys/types.h>
29 #include <netinet/in.h>
41 #include <afs/afsutil.h>
44 #include <afs/cellconfig.h>
47 main(int argc, char **argv)
49 struct afsconf_dir *tdir;
50 register afs_int32 code;
53 printf("bos_util: usage is 'bos_util <opcode> options, e.g.\n");
54 printf(" bos_util add <kvno>\n");
55 printf(" bos_util adddes <kvno>\n");
57 printf(" bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
59 printf(" bos_util delete <kvno>\n");
60 printf(" bos_util list\n");
64 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIR);
66 printf("bos_util: can't initialize conf dir '%s'\n",
67 AFSDIR_SERVER_ETC_DIR);
70 if (strcmp(argv[1], "add") == 0) {
71 struct ktc_encryptionKey tkey;
73 char buf[BUFSIZ], ver[BUFSIZ];
77 printf("bos_util add: usage is 'bos_util add <kvno>\n");
81 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
84 code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
85 if (code || strlen(buf) == 0) {
86 printf("Bad key: \n");
89 code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
90 if (code || strlen(ver) == 0) {
91 printf("Bad key: \n");
94 if (strcmp(ver, buf) != 0) {
95 printf("\nInput key mismatch\n");
98 ka_StringToKey(buf, tcell, &tkey);
99 code = afsconf_AddKey(tdir, kvno, &tkey, 0);
101 printf("bos_util: failed to set key, code %d.\n", code);
104 } else if (strcmp(argv[1], "adddes") == 0) {
105 struct ktc_encryptionKey tkey;
107 register afs_int32 code;
108 char buf[BUFSIZ], ver[BUFSIZ];
112 printf("bos_util adddes: usage is 'bos_util adddes <kvno>\n");
115 kvno = atoi(argv[2]);
116 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
119 code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
120 if (code || strlen(buf) == 0) {
121 printf("Bad key: \n");
124 code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
125 if (code || strlen(ver) == 0) {
126 printf("Bad key: \n");
129 if (strcmp(ver, buf) != 0) {
130 printf("\nInput key mismatch\n");
133 des_string_to_key(buf, &tkey);
134 code = afsconf_AddKey(tdir, kvno, &tkey, 0);
136 printf("bos_util: failed to set key, code %d.\n", code);
141 else if (strcmp(argv[1], "srvtab2keyfile") == 0) {
142 char tkey[8], name[255], inst[255], realm[255];
146 ("bos_util add: usage is 'bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
149 kvno = atoi(argv[2]);
150 bzero(tkey, sizeof(tkey));
151 code = kname_parse(name, inst, realm, argv[4]);
153 printf("Invalid kerberos name\n");
156 code = read_service_key(name, inst, realm, kvno, argv[3], tkey);
158 printf("Can't find key in %s\n", argv[3]);
161 code = afsconf_AddKey(tdir, kvno, tkey, 0);
163 printf("bos_util: failed to set key, code %d.\n", code);
168 else if (strcmp(argv[1], "delete") == 0) {
171 printf("bos_util delete: usage is 'bos_util delete <kvno>\n");
174 kvno = atoi(argv[2]);
175 code = afsconf_DeleteKey(tdir, kvno);
177 printf("bos_util: failed to delete key %d, (code %d)\n", kvno,
181 } else if (strcmp(argv[1], "list") == 0) {
182 struct afsconf_keys tkeys;
184 unsigned char tbuffer[9];
186 code = afsconf_GetKeys(tdir, &tkeys);
188 printf("bos_util: failed to get keys, code %d\n", code);
191 for (i = 0; i < tkeys.nkeys; i++) {
192 if (tkeys.key[i].kvno != -1) {
195 memcpy(tbuffer, tkeys.key[i].key, 8);
197 printf("kvno %4d: key is '%s' '", tkeys.key[i].kvno, tbuffer);
198 strcpy(x, (char *)tbuffer);
199 for (count = 0; count < 8; count++)
200 printf("\\%03o", x[count]);
204 printf("All done.\n");
207 ("bos_util: unknown operation '%s', type 'bos_util' for assistance\n",