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 <hcrypto/ui.h>
28 #include <hcrypto/des.h>
31 #include <afs/afsutil.h>
33 #include <afs/cellconfig.h>
34 #include <afs/kautils.h>
37 main(int argc
, char **argv
)
39 struct afsconf_dir
*tdir
;
43 printf("bos_util: usage is 'bos_util <opcode> options, e.g.\n");
44 printf(" bos_util add <kvno>\n");
45 printf(" bos_util adddes <kvno>\n");
47 printf(" bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
49 printf(" bos_util delete <kvno>\n");
50 printf(" bos_util list\n");
54 tdir
= afsconf_Open(AFSDIR_SERVER_ETC_DIR
);
56 printf("bos_util: can't initialize conf dir '%s'\n",
57 AFSDIR_SERVER_ETC_DIR
);
60 if (strcmp(argv
[1], "add") == 0) {
61 struct ktc_encryptionKey tkey
;
63 char buf
[BUFSIZ
], ver
[BUFSIZ
];
67 printf("bos_util add: usage is 'bos_util add <kvno>\n");
71 memset(&tkey
, 0, sizeof(struct ktc_encryptionKey
));
74 code
= UI_UTIL_read_pw_string(buf
, sizeof(buf
), "input key: ", 0);
75 if (code
|| strlen(buf
) == 0) {
76 printf("Bad key: \n");
79 code
= UI_UTIL_read_pw_string(ver
, sizeof(ver
), "Retype input key: ", 0);
80 if (code
|| strlen(ver
) == 0) {
81 printf("Bad key: \n");
84 if (strcmp(ver
, buf
) != 0) {
85 printf("\nInput key mismatch\n");
88 ka_StringToKey(buf
, tcell
, &tkey
);
89 code
= afsconf_AddKey(tdir
, kvno
, (char *)&tkey
, 0);
91 printf("bos_util: failed to set key, code %d.\n", code
);
94 } else if (strcmp(argv
[1], "adddes") == 0) {
98 char buf
[BUFSIZ
], ver
[BUFSIZ
];
101 printf("bos_util adddes: usage is 'bos_util adddes <kvno>\n");
104 kvno
= atoi(argv
[2]);
105 memset(&tkey
, 0, sizeof(struct ktc_encryptionKey
));
108 code
= UI_UTIL_read_pw_string(buf
, sizeof(buf
), "input key: ", 0);
109 if (code
|| strlen(buf
) == 0) {
110 printf("Bad key: \n");
113 code
= UI_UTIL_read_pw_string(ver
, sizeof(ver
), "Retype input key: ", 0);
114 if (code
|| strlen(ver
) == 0) {
115 printf("Bad key: \n");
118 if (strcmp(ver
, buf
) != 0) {
119 printf("\nInput key mismatch\n");
122 DES_string_to_key(buf
, &tkey
);
123 code
= afsconf_AddKey(tdir
, kvno
, (char *) &tkey
, 0);
125 printf("bos_util: failed to set key, code %d.\n", code
);
130 else if (strcmp(argv
[1], "srvtab2keyfile") == 0) {
131 char tkey
[8], name
[255], inst
[255], realm
[255];
135 ("bos_util add: usage is 'bos_util srvtab2keyfile <kvno> <keyfile> <princ>\n");
138 kvno
= atoi(argv
[2]);
139 bzero(tkey
, sizeof(tkey
));
140 code
= kname_parse(name
, inst
, realm
, argv
[4]);
142 printf("Invalid kerberos name\n");
145 code
= read_service_key(name
, inst
, realm
, kvno
, argv
[3], tkey
);
147 printf("Can't find key in %s\n", argv
[3]);
150 code
= afsconf_AddKey(tdir
, kvno
, tkey
, 0);
152 printf("bos_util: failed to set key, code %d.\n", code
);
157 else if (strcmp(argv
[1], "delete") == 0) {
160 printf("bos_util delete: usage is 'bos_util delete <kvno>\n");
163 kvno
= atoi(argv
[2]);
164 code
= afsconf_DeleteKey(tdir
, kvno
);
166 printf("bos_util: failed to delete key %ld, (code %d)\n", kvno
,
170 } else if (strcmp(argv
[1], "list") == 0) {
171 struct afsconf_keys tkeys
;
173 unsigned char tbuffer
[9];
175 code
= afsconf_GetKeys(tdir
, &tkeys
);
177 printf("bos_util: failed to get keys, code %d\n", code
);
180 for (i
= 0; i
< tkeys
.nkeys
; i
++) {
181 if (tkeys
.key
[i
].kvno
!= -1) {
183 memcpy(tbuffer
, tkeys
.key
[i
].key
, 8);
185 printf("kvno %4d: key is '%s' '", tkeys
.key
[i
].kvno
, tbuffer
);
186 for (count
= 0; count
< 8; count
++)
187 printf("\\%03o", tbuffer
[count
]);
191 printf("All done.\n");
194 ("bos_util: unknown operation '%s', type 'bos_util' for assistance\n",