2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <WINNT/afsreg.h>
17 #include <WINNT/afsevent.h>
21 #include "cellconfig.h"
23 #include <afs/afsutil.h>
25 #include "AFS_component_version_number.c"
26 static int char2hex(char c);
27 static int hex2char(char c);
30 main(int argc, char **argv)
32 struct afsconf_dir *tdir;
38 printf("setkey: usage is 'setkey <opcode> options, e.g.\n");
39 printf(" setkey add <kvno> <key>\n");
40 printf(" note: <key> should be an 8byte hex representation \n");
41 printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n");
42 printf(" setkey delete <kvno>\n");
43 printf(" setkey list\n");
47 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
49 printf("setkey: can't initialize conf dir '%s'\n",
50 AFSDIR_SERVER_ETC_DIRPATH);
53 if (strcmp(argv[1], "add") == 0) {
56 printf("setkey add: usage is 'setkey add <kvno> <key>\n");
59 if (strlen(argv[3]) != 16) {
60 printf("key %s is not in right format\n", argv[3]);
61 printf(" <key> should be an 8byte hex representation \n");
62 printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n");
65 memset(tkey, 0, sizeof(tkey));
66 for (i = 7, cp = argv[3] + 15; i >= 0; i--, cp -= 2)
67 tkey[i] = char2hex(*cp) + char2hex(*(cp - 1)) * 16;
69 code = afsconf_AddKey(tdir, atoi(argv[2]), tkey, 1);
71 printf("setkey: failed to set key, code %d.\n", (int)code);
74 } else if (strcmp(argv[1], "delete") == 0) {
77 printf("setkey delete: usage is 'setkey delete <kvno>\n");
81 code = afsconf_DeleteKey(tdir, kvno);
83 printf("setkey: failed to delete key %d, (code %d)\n", (int)kvno,
87 } else if (strcmp(argv[1], "list") == 0) {
88 struct afsconf_keys tkeys;
92 code = afsconf_GetKeys(tdir, &tkeys);
94 printf("setkey: failed to get keys, code %d\n", (int)code);
97 for (i = 0; i < tkeys.nkeys; i++) {
98 if (tkeys.key[i].kvno != -1) {
102 memcpy(tbuffer, tkeys.key[i].key, 8);
104 for (j = 0; j < 8; j++) {
106 hexbuf[j * 2] = hex2char(c / 16);
107 hexbuf[j * 2 + 1] = hex2char(c % 16);
110 printf("kvno %4d: key is '%s' (0x%s)\n",
111 (int)tkeys.key[i].kvno, tbuffer, hexbuf);
114 printf("All done.\n");
117 ("setkey: unknown operation '%s', type 'setkey' for assistance\n",
127 if (c >= '0' && c <= '9')
129 if ((c >= 'a') && (c <= 'f'))
130 return (c - 'a' + 10);
132 if ((c >= 'A') && (c <= 'F'))
133 return (c - 'A' + 10);
144 return (c - 10 + 'a');