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>
33 #include <afs/afsutil.h>
36 #include <afs/cellconfig.h>
37 #include <afs/kautils.h>
39 #include <des_prototypes.h>
42 main(int argc, char **argv)
44 struct afsconf_dir *tdir;
48 printf("bos_util: usage is 'bos_util <opcode> options, e.g.\n");
49 printf(" bos_util add <kvno>\n");
50 printf(" bos_util adddes <kvno>\n");
52 printf(" bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
54 printf(" bos_util delete <kvno>\n");
55 printf(" bos_util list\n");
59 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIR);
61 printf("bos_util: can't initialize conf dir '%s'\n",
62 AFSDIR_SERVER_ETC_DIR);
65 if (strcmp(argv[1], "add") == 0) {
66 struct ktc_encryptionKey tkey;
68 char buf[BUFSIZ], ver[BUFSIZ];
72 printf("bos_util add: usage is 'bos_util add <kvno>\n");
76 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
79 code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
80 if (code || strlen(buf) == 0) {
81 printf("Bad key: \n");
84 code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
85 if (code || strlen(ver) == 0) {
86 printf("Bad key: \n");
89 if (strcmp(ver, buf) != 0) {
90 printf("\nInput key mismatch\n");
93 ka_StringToKey(buf, tcell, &tkey);
94 code = afsconf_AddKey(tdir, kvno, ktc_to_charptr(&tkey), 0);
96 printf("bos_util: failed to set key, code %d.\n", code);
99 } else if (strcmp(argv[1], "adddes") == 0) {
100 struct ktc_encryptionKey tkey;
103 char buf[BUFSIZ], ver[BUFSIZ];
106 printf("bos_util adddes: usage is 'bos_util adddes <kvno>\n");
109 kvno = atoi(argv[2]);
110 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
113 code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
114 if (code || strlen(buf) == 0) {
115 printf("Bad key: \n");
118 code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
119 if (code || strlen(ver) == 0) {
120 printf("Bad key: \n");
123 if (strcmp(ver, buf) != 0) {
124 printf("\nInput key mismatch\n");
127 des_string_to_key(buf, ktc_to_cblockptr(&tkey));
128 code = afsconf_AddKey(tdir, kvno, ktc_to_charptr(&tkey), 0);
130 printf("bos_util: failed to set key, code %d.\n", code);
135 else if (strcmp(argv[1], "srvtab2keyfile") == 0) {
136 char tkey[8], name[255], inst[255], realm[255];
140 ("bos_util add: usage is 'bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
143 kvno = atoi(argv[2]);
144 bzero(tkey, sizeof(tkey));
145 code = kname_parse(name, inst, realm, argv[4]);
147 printf("Invalid kerberos name\n");
150 code = read_service_key(name, inst, realm, kvno, argv[3], tkey);
152 printf("Can't find key in %s\n", argv[3]);
155 code = afsconf_AddKey(tdir, kvno, tkey, 0);
157 printf("bos_util: failed to set key, code %d.\n", code);
162 else if (strcmp(argv[1], "delete") == 0) {
165 printf("bos_util delete: usage is 'bos_util delete <kvno>\n");
168 kvno = atoi(argv[2]);
169 code = afsconf_DeleteKey(tdir, kvno);
171 printf("bos_util: failed to delete key %ld, (code %d)\n", kvno,
175 } else if (strcmp(argv[1], "list") == 0) {
176 struct afsconf_keys tkeys;
178 unsigned char tbuffer[9];
180 code = afsconf_GetKeys(tdir, &tkeys);
182 printf("bos_util: failed to get keys, code %d\n", code);
185 for (i = 0; i < tkeys.nkeys; i++) {
186 if (tkeys.key[i].kvno != -1) {
189 memcpy(tbuffer, tkeys.key[i].key, 8);
191 printf("kvno %4d: key is '%s' '", tkeys.key[i].kvno, tbuffer);
192 strcpy((char *)x, (char *)tbuffer);
193 for (count = 0; count < 8; count++)
194 printf("\\%03o", x[count]);
198 printf("All done.\n");
201 ("bos_util: unknown operation '%s', type 'bos_util' for assistance\n",