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>
26 #include <sys/types.h>
27 #include <netinet/in.h>
32 #include <afs/afsutil.h>
35 #include <afs/cellconfig.h>
36 #include <afs/kautils.h>
38 #include <des_prototypes.h>
41 main(int argc, char **argv)
43 struct afsconf_dir *tdir;
44 register afs_int32 code;
47 printf("bos_util: usage is 'bos_util <opcode> options, e.g.\n");
48 printf(" bos_util add <kvno>\n");
49 printf(" bos_util adddes <kvno>\n");
51 printf(" bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
53 printf(" bos_util delete <kvno>\n");
54 printf(" bos_util list\n");
58 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIR);
60 printf("bos_util: can't initialize conf dir '%s'\n",
61 AFSDIR_SERVER_ETC_DIR);
64 if (strcmp(argv[1], "add") == 0) {
65 struct ktc_encryptionKey tkey;
67 char buf[BUFSIZ], ver[BUFSIZ];
71 printf("bos_util add: usage is 'bos_util add <kvno>\n");
75 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
78 code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
79 if (code || strlen(buf) == 0) {
80 printf("Bad key: \n");
83 code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
84 if (code || strlen(ver) == 0) {
85 printf("Bad key: \n");
88 if (strcmp(ver, buf) != 0) {
89 printf("\nInput key mismatch\n");
92 ka_StringToKey(buf, tcell, &tkey);
93 code = afsconf_AddKey(tdir, kvno, &tkey, 0);
95 printf("bos_util: failed to set key, code %d.\n", code);
98 } else if (strcmp(argv[1], "adddes") == 0) {
99 struct ktc_encryptionKey tkey;
101 register afs_int32 code;
102 char buf[BUFSIZ], ver[BUFSIZ];
105 printf("bos_util adddes: usage is 'bos_util adddes <kvno>\n");
108 kvno = atoi(argv[2]);
109 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
112 code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
113 if (code || strlen(buf) == 0) {
114 printf("Bad key: \n");
117 code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
118 if (code || strlen(ver) == 0) {
119 printf("Bad key: \n");
122 if (strcmp(ver, buf) != 0) {
123 printf("\nInput key mismatch\n");
126 des_string_to_key(buf, &tkey);
127 code = afsconf_AddKey(tdir, kvno, &tkey, 0);
129 printf("bos_util: failed to set key, code %d.\n", code);
134 else if (strcmp(argv[1], "srvtab2keyfile") == 0) {
135 char tkey[8], name[255], inst[255], realm[255];
139 ("bos_util add: usage is 'bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
142 kvno = atoi(argv[2]);
143 bzero(tkey, sizeof(tkey));
144 code = kname_parse(name, inst, realm, argv[4]);
146 printf("Invalid kerberos name\n");
149 code = read_service_key(name, inst, realm, kvno, argv[3], tkey);
151 printf("Can't find key in %s\n", argv[3]);
154 code = afsconf_AddKey(tdir, kvno, tkey, 0);
156 printf("bos_util: failed to set key, code %d.\n", code);
161 else if (strcmp(argv[1], "delete") == 0) {
164 printf("bos_util delete: usage is 'bos_util delete <kvno>\n");
167 kvno = atoi(argv[2]);
168 code = afsconf_DeleteKey(tdir, kvno);
170 printf("bos_util: failed to delete key %ld, (code %d)\n", kvno,
174 } else if (strcmp(argv[1], "list") == 0) {
175 struct afsconf_keys tkeys;
177 unsigned char tbuffer[9];
179 code = afsconf_GetKeys(tdir, &tkeys);
181 printf("bos_util: failed to get keys, code %d\n", code);
184 for (i = 0; i < tkeys.nkeys; i++) {
185 if (tkeys.key[i].kvno != -1) {
188 memcpy(tbuffer, tkeys.key[i].key, 8);
190 printf("kvno %4d: key is '%s' '", tkeys.key[i].kvno, tbuffer);
191 strcpy((char *)x, (char *)tbuffer);
192 for (count = 0; count < 8; count++)
193 printf("\\%03o", x[count]);
197 printf("All done.\n");
200 ("bos_util: unknown operation '%s', type 'bos_util' for assistance\n",