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>
27 #include <sys/types.h>
28 #include <netinet/in.h>
40 #include <afs/afsutil.h>
43 #include <afs/cellconfig.h>
46 main(int argc, char **argv)
48 struct afsconf_dir *tdir;
49 register afs_int32 code;
52 printf("bos_util: usage is 'bos_util <opcode> options, e.g.\n");
53 printf(" bos_util add <kvno>\n");
54 printf(" bos_util adddes <kvno>\n");
56 printf(" bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
58 printf(" bos_util delete <kvno>\n");
59 printf(" bos_util list\n");
63 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIR);
65 printf("bos_util: can't initialize conf dir '%s'\n", AFSDIR_SERVER_ETC_DIR);
68 if (strcmp(argv[1], "add")==0) {
69 struct ktc_encryptionKey tkey;
71 char buf[BUFSIZ], ver[BUFSIZ];
75 printf("bos_util add: usage is 'bos_util add <kvno>\n");
79 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
82 code=des_read_pw_string(buf,sizeof(buf),"input key: ",0);
83 if(code || strlen(buf)==0) {
84 printf("Bad key: \n");
87 code=des_read_pw_string(ver,sizeof(ver),"Retype input key: ",0);
88 if(code || strlen(ver)==0) {
89 printf("Bad key: \n");
92 if (strcmp (ver, buf) != 0) {
93 printf ("\nInput key mismatch\n");
96 ka_StringToKey(buf,tcell,&tkey);
97 code = afsconf_AddKey(tdir, kvno, &tkey, 0);
99 printf("bos_util: failed to set key, code %d.\n", code);
103 else if (strcmp(argv[1], "adddes")==0) {
104 struct ktc_encryptionKey tkey;
106 register afs_int32 code;
107 char buf[BUFSIZ], ver[BUFSIZ];
111 printf("bos_util adddes: usage is 'bos_util adddes <kvno>\n");
114 kvno = atoi(argv[2]);
115 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
118 code=des_read_pw_string(buf,sizeof(buf),"input key: ",0);
119 if(code || strlen(buf)==0) {
120 printf("Bad key: \n");
123 code=des_read_pw_string(ver,sizeof(ver),"Retype input key: ",0);
124 if(code || strlen(ver)==0) {
125 printf("Bad key: \n");
128 if (strcmp (ver, buf) != 0) {
129 printf ("\nInput key mismatch\n");
132 des_string_to_key(buf,&tkey);
133 code = afsconf_AddKey(tdir, kvno, &tkey, 0);
135 printf("bos_util: failed to set key, code %d.\n", code);
140 else if (strcmp(argv[1], "srvtab2keyfile")==0) {
141 char tkey[8], name[255], inst[255], realm[255];
144 printf("bos_util add: usage is 'bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
147 kvno = atoi(argv[2]);
148 bzero(tkey, sizeof(tkey));
149 code = kname_parse(name, inst, realm, argv[4]);
151 printf("Invalid kerberos name\n");
154 code = read_service_key(name, inst, realm, kvno, argv[3], tkey);
156 printf("Can't find key in %s\n", argv[3]);
159 code = afsconf_AddKey(tdir, kvno, tkey, 0);
161 printf("bos_util: failed to set key, code %d.\n", code);
166 else if (strcmp(argv[1], "delete")==0) {
169 printf("bos_util delete: usage is 'bos_util delete <kvno>\n");
172 kvno = atoi(argv[2]);
173 code = afsconf_DeleteKey(tdir, kvno);
175 printf("bos_util: failed to delete key %d, (code %d)\n", kvno, code);
179 else if (strcmp(argv[1], "list") == 0) {
180 struct afsconf_keys tkeys;
182 unsigned char tbuffer[9];
184 code = afsconf_GetKeys(tdir, &tkeys);
186 printf("bos_util: failed to get keys, code %d\n", code);
189 for(i=0;i<tkeys.nkeys;i++) {
190 if (tkeys.key[i].kvno != -1) {
193 memcpy(tbuffer, tkeys.key[i].key, 8);
195 printf("kvno %4d: key is '%s' '", tkeys.key[i].kvno, tbuffer);
196 strcpy(x,(char *)tbuffer);
197 for(count=0;count<8;count++)
198 printf("\\%03o",(unsigned char *)x[count]);
202 printf("All done.\n");
205 printf("bos_util: unknown operation '%s', type 'bos_util' for assistance\n", argv[1]);