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 <sys/types.h>
21 #include <WINNT/afsreg.h>
22 #include <WINNT/afsevent.h>
25 #ifdef HAVE_NETINET_IN_H
26 #include <netinet/in.h>
31 #include "cellconfig.h"
33 #include <afs/afsutil.h>
35 #include "AFS_component_version_number.c"
36 static int char2hex(char c);
37 static int hex2char(char c);
44 struct afsconf_dir *tdir;
45 register afs_int32 code;
50 printf("setkey: usage is 'setkey <opcode> options, e.g.\n");
51 printf(" setkey add <kvno> <key>\n");
52 printf(" note: <key> should be an 8byte hex representation \n");
53 printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n");
54 printf(" setkey delete <kvno>\n");
55 printf(" setkey list\n");
59 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
61 printf("setkey: can't initialize conf dir '%s'\n",
62 AFSDIR_SERVER_ETC_DIRPATH);
65 if (strcmp(argv[1], "add") == 0) {
68 printf("setkey add: usage is 'setkey add <kvno> <key>\n");
71 if (strlen(argv[3]) != 16) {
72 printf("key %s is not in right format\n", argv[3]);
73 printf(" <key> should be an 8byte hex representation \n");
74 printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n");
77 memset(tkey, 0, sizeof(tkey));
78 for (i = 7, cp = argv[3] + 15; i >= 0; i--, cp -= 2)
79 tkey[i] = char2hex(*cp) + char2hex(*(cp - 1)) * 16;
81 code = afsconf_AddKey(tdir, atoi(argv[2]), tkey, 1);
83 printf("setkey: failed to set key, code %d.\n", (int)code);
86 } else if (strcmp(argv[1], "delete") == 0) {
89 printf("setkey delete: usage is 'setkey delete <kvno>\n");
93 code = afsconf_DeleteKey(tdir, kvno);
95 printf("setkey: failed to delete key %d, (code %d)\n", (int)kvno,
99 } else if (strcmp(argv[1], "list") == 0) {
100 struct afsconf_keys tkeys;
104 code = afsconf_GetKeys(tdir, &tkeys);
106 printf("setkey: failed to get keys, code %d\n", (int)code);
109 for (i = 0; i < tkeys.nkeys; i++) {
110 if (tkeys.key[i].kvno != -1) {
114 memcpy(tbuffer, tkeys.key[i].key, 8);
116 for (j = 0; j < 8; j++) {
118 hexbuf[j * 2] = hex2char(c / 16);
119 hexbuf[j * 2 + 1] = hex2char(c % 16);
122 printf("kvno %4d: key is '%s' (0x%s)\n",
123 (int)tkeys.key[i].kvno, tbuffer, hexbuf);
126 printf("All done.\n");
129 ("setkey: unknown operation '%s', type 'setkey' for assistance\n",
139 if (c >= '0' && c <= '9')
141 if ((c >= 'a') && (c <= 'f'))
142 return (c - 'a' + 10);
144 if ((c >= 'A') && (c <= 'F'))
145 return (c - 'A' + 10);
156 return (c - 10 + 'a');