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>
14 #include <sys/types.h>
19 #include <WINNT/afsreg.h>
20 #include <WINNT/afsevent.h>
23 #ifdef HAVE_NETINET_IN_H
24 #include <netinet/in.h>
30 #include "cellconfig.h"
32 #include <afs/afsutil.h>
34 #include "AFS_component_version_number.c"
35 static int char2hex(char c);
36 static int hex2char(char c);
39 main(int argc, char **argv)
41 struct afsconf_dir *tdir;
47 printf("setkey: usage is 'setkey <opcode> options, e.g.\n");
48 printf(" setkey add <kvno> <key>\n");
49 printf(" note: <key> should be an 8byte hex representation \n");
50 printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n");
51 printf(" setkey delete <kvno>\n");
52 printf(" setkey list\n");
56 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
58 printf("setkey: can't initialize conf dir '%s'\n",
59 AFSDIR_SERVER_ETC_DIRPATH);
62 if (strcmp(argv[1], "add") == 0) {
65 printf("setkey add: usage is 'setkey add <kvno> <key>\n");
68 if (strlen(argv[3]) != 16) {
69 printf("key %s is not in right format\n", argv[3]);
70 printf(" <key> should be an 8byte hex representation \n");
71 printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n");
74 memset(tkey, 0, sizeof(tkey));
75 for (i = 7, cp = argv[3] + 15; i >= 0; i--, cp -= 2)
76 tkey[i] = char2hex(*cp) + char2hex(*(cp - 1)) * 16;
78 code = afsconf_AddKey(tdir, atoi(argv[2]), tkey, 1);
80 printf("setkey: failed to set key, code %d.\n", (int)code);
83 } else if (strcmp(argv[1], "delete") == 0) {
86 printf("setkey delete: usage is 'setkey delete <kvno>\n");
90 code = afsconf_DeleteKey(tdir, kvno);
92 printf("setkey: failed to delete key %d, (code %d)\n", (int)kvno,
96 } else if (strcmp(argv[1], "list") == 0) {
97 struct afsconf_keys tkeys;
101 code = afsconf_GetKeys(tdir, &tkeys);
103 printf("setkey: failed to get keys, code %d\n", (int)code);
106 for (i = 0; i < tkeys.nkeys; i++) {
107 if (tkeys.key[i].kvno != -1) {
111 memcpy(tbuffer, tkeys.key[i].key, 8);
113 for (j = 0; j < 8; j++) {
115 hexbuf[j * 2] = hex2char(c / 16);
116 hexbuf[j * 2 + 1] = hex2char(c % 16);
119 printf("kvno %4d: key is '%s' (0x%s)\n",
120 (int)tkeys.key[i].kvno, tbuffer, hexbuf);
123 printf("All done.\n");
126 ("setkey: unknown operation '%s', type 'setkey' for assistance\n",
136 if (c >= '0' && c <= '9')
138 if ((c >= 'a') && (c <= 'f'))
139 return (c - 'a' + 10);
141 if ((c >= 'A') && (c <= 'F'))
142 return (c - 'A' + 10);
153 return (c - 10 + 'a');