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>
15 #include <sys/types.h>
20 #include <WINNT/afsreg.h>
21 #include <WINNT/afsevent.h>
30 #ifdef HAVE_NETINET_IN_H
31 #include <netinet/in.h>
36 #include "cellconfig.h"
38 #include <afs/afsutil.h>
40 #include "AFS_component_version_number.c"
41 static int char2hex(char c);
42 static int hex2char(char c);
48 struct afsconf_dir *tdir;
49 register afs_int32 code;
54 printf("setkey: usage is 'setkey <opcode> options, e.g.\n");
55 printf(" setkey add <kvno> <key>\n");
56 printf(" note: <key> should be an 8byte hex representation \n");
57 printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n");
58 printf(" setkey delete <kvno>\n");
59 printf(" setkey list\n");
63 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
65 printf("setkey: can't initialize conf dir '%s'\n", AFSDIR_SERVER_ETC_DIRPATH);
68 if (strcmp(argv[1], "add")==0) {
71 printf("setkey add: usage is 'setkey add <kvno> <key>\n");
74 if (strlen(argv[3]) != 16) {
75 printf("key %s is not in right format\n", argv[3]);
76 printf(" <key> should be an 8byte hex representation \n");
77 printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n");
80 memset(tkey, 0, sizeof(tkey));
81 for(i=7, cp = argv[3] + 15;i>=0; i--,cp-=2)
82 tkey[i] = char2hex(*cp) + char2hex(*(cp-1))*16;
84 code = afsconf_AddKey(tdir, atoi(argv[2]), tkey, 1);
86 printf("setkey: failed to set key, code %d.\n", (int) code);
90 else if (strcmp(argv[1], "delete")==0) {
93 printf("setkey delete: usage is 'setkey delete <kvno>\n");
97 code = afsconf_DeleteKey(tdir, kvno);
99 printf("setkey: failed to delete key %d, (code %d)\n", (int) kvno, (int) code);
103 else if (strcmp(argv[1], "list") == 0) {
104 struct afsconf_keys tkeys;
108 code = afsconf_GetKeys(tdir, &tkeys);
110 printf("setkey: failed to get keys, code %d\n", (int) code);
113 for(i=0;i<tkeys.nkeys;i++) {
114 if (tkeys.key[i].kvno != -1) {
118 memcpy(tbuffer, tkeys.key[i].key, 8);
122 hexbuf[j*2] = hex2char( c / 16 );
123 hexbuf[j*2+1] = hex2char( c % 16);
126 printf("kvno %4d: key is '%s' (0x%s)\n", (int) tkeys.key[i].kvno, tbuffer, hexbuf);
129 printf("All done.\n");
132 printf("setkey: unknown operation '%s', type 'setkey' for assistance\n", argv[1]);
138 static int char2hex(char c)
140 if (c >= '0' && c <='9')
142 if ( (c >= 'a') && (c <= 'f') )
145 if ( (c >= 'A') && (c <='F') )
151 static int hex2char(char c)
156 return (c - 10 + 'a');