/* * Copyright 2000, International Business Machines Corporation and others. * All Rights Reserved. * * This software has been released under the terms of the IBM Public * License. For details, see the LICENSE file in the top-level source * directory or online at http://www.openafs.org/dl/license10.html */ #include #include #ifdef AFS_NT40_ENV #include #include #include #include #else #include #include #endif #include "cellconfig.h" #include "keys.h" #include #include "AFS_component_version_number.c" int char2hex(char c); int hex2char(char c); main(argc, argv) int argc; char **argv; { struct afsconf_dir *tdir; register afs_int32 code; int i; char *cp; if (argc == 1) { printf("setkey: usage is 'setkey options, e.g.\n"); printf(" setkey add \n"); printf(" note: should be an 8byte hex representation \n"); printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n"); printf(" setkey delete \n"); printf(" setkey list\n"); exit(1); } tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH); if (!tdir) { printf("setkey: can't initialize conf dir '%s'\n", AFSDIR_SERVER_ETC_DIRPATH); exit(1); } if (strcmp(argv[1], "add")==0) { char tkey[8]; if (argc != 4) { printf("setkey add: usage is 'setkey add \n"); exit(1); } if (strlen(argv[3]) != 16) { printf("key %s is not in right format\n", argv[3]); printf(" should be an 8byte hex representation \n"); printf(" Ex: setkey add 0 \"80b6a7cd7a9dadb6\"\n"); exit(1); } bzero(tkey, sizeof(tkey)); for(i=7, cp = argv[3] + 15;i>=0; i--,cp-=2) tkey[i] = char2hex(*cp) + char2hex(*(cp-1))*16; code = afsconf_AddKey(tdir, atoi(argv[2]), tkey, 1); if (code) { printf("setkey: failed to set key, code %d.\n", code); exit(1); } } else if (strcmp(argv[1], "delete")==0) { afs_int32 kvno; if (argc != 3) { printf("setkey delete: usage is 'setkey delete \n"); exit(1); } kvno = atoi(argv[2]); code = afsconf_DeleteKey(tdir, kvno); if (code) { printf("setkey: failed to delete key %d, (code %d)\n", kvno, code); exit(1); } } else if (strcmp(argv[1], "list") == 0) { struct afsconf_keys tkeys; register int i; char tbuffer[9]; code = afsconf_GetKeys(tdir, &tkeys); if (code) { printf("setkey: failed to get keys, code %d\n", code); exit(1); } for(i=0;i= '0' && c <='9') return ( c - 48); if ( (c >= 'a') && (c <= 'f') ) return (c-'a' + 10); if ( (c >= 'A') && (c <='F') ) return (c-'A' + 10); return -1; } int hex2char(char c) { if (c <=9) return (c+48); return (c - 10 + 'a'); }