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>
31 #ifdef HAVE_NETINET_IN_H
32 #include <netinet/in.h>
37 #include "cellconfig.h"
39 #include <afs/afsutil.h>
41 #include "AFS_component_version_number.c"
42 static int char2hex(char c);
43 static int hex2char(char c);
50 struct afsconf_dir *tdir;
51 register afs_int32 code;
56 printf("setkey: usage is 'setkey <opcode> options, e.g.\n");
57 printf(" setkey add <kvno> <key>\n");
58 printf(" note: <key> should be an 8byte hex representation \n");
59 printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n");
60 printf(" setkey delete <kvno>\n");
61 printf(" setkey list\n");
65 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
67 printf("setkey: can't initialize conf dir '%s'\n",
68 AFSDIR_SERVER_ETC_DIRPATH);
71 if (strcmp(argv[1], "add") == 0) {
74 printf("setkey add: usage is 'setkey add <kvno> <key>\n");
77 if (strlen(argv[3]) != 16) {
78 printf("key %s is not in right format\n", argv[3]);
79 printf(" <key> should be an 8byte hex representation \n");
80 printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n");
83 memset(tkey, 0, sizeof(tkey));
84 for (i = 7, cp = argv[3] + 15; i >= 0; i--, cp -= 2)
85 tkey[i] = char2hex(*cp) + char2hex(*(cp - 1)) * 16;
87 code = afsconf_AddKey(tdir, atoi(argv[2]), tkey, 1);
89 printf("setkey: failed to set key, code %d.\n", (int)code);
92 } else if (strcmp(argv[1], "delete") == 0) {
95 printf("setkey delete: usage is 'setkey delete <kvno>\n");
99 code = afsconf_DeleteKey(tdir, kvno);
101 printf("setkey: failed to delete key %d, (code %d)\n", (int)kvno,
105 } else if (strcmp(argv[1], "list") == 0) {
106 struct afsconf_keys tkeys;
110 code = afsconf_GetKeys(tdir, &tkeys);
112 printf("setkey: failed to get keys, code %d\n", (int)code);
115 for (i = 0; i < tkeys.nkeys; i++) {
116 if (tkeys.key[i].kvno != -1) {
120 memcpy(tbuffer, tkeys.key[i].key, 8);
122 for (j = 0; j < 8; j++) {
124 hexbuf[j * 2] = hex2char(c / 16);
125 hexbuf[j * 2 + 1] = hex2char(c % 16);
128 printf("kvno %4d: key is '%s' (0x%s)\n",
129 (int)tkeys.key[i].kvno, tbuffer, hexbuf);
132 printf("All done.\n");
135 ("setkey: unknown operation '%s', type 'setkey' for assistance\n",
145 if (c >= '0' && c <= '9')
147 if ((c >= 'a') && (c <= 'f'))
148 return (c - 'a' + 10);
150 if ((c >= 'A') && (c <= 'F'))
151 return (c - 'A' + 10);
162 return (c - 10 + 'a');