From: Ken Hornstein Date: Tue, 25 Oct 2005 20:08:02 +0000 (+0000) Subject: integrate-asetkey-20051029 X-Git-Tag: openafs-devel-1_5_0~218 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=6b042d4edb7f26358523da9dcdb565ed023e00da integrate-asetkey-20051029 Add asetkey to the OpenAFS tree. --- diff --git a/src/aklog/Makefile.in b/src/aklog/Makefile.in index 6e40f4f..a52bc2c 100644 --- a/src/aklog/Makefile.in +++ b/src/aklog/Makefile.in @@ -16,31 +16,42 @@ AFSLIBS = ${TOP_LIBDIR}/libprot.a ${TOP_LIBDIR}/libubik.a \ SRCS= aklog.c aklog_main.c krb_util.c linked_list.c OBJS= aklog.o aklog_main.o krb_util.o linked_list.o -all: aklog +all: aklog asetkey aklog: ${OBJS} ${AFSLIBS} ${CC} -o $@ ${CFLAGS} ${OBJS} ${AKLIBS} ${AFSLIBS} ${XLIBS} +asetkey: asetkey.o ${AFSLIBS} + ${CC} -o $@ ${CFLAGS} asetkey.o ${AKLIBS} ${AFSLIBS} ${XLIBS} + # # Installation targets # install: \ ${DESTDIR}${bindir}/aklog + ${DESTDIR}${afssrvbindir}/asetkey ${DESTDIR}${bindir}/aklog: aklog ${INSTALL} $? $@ +${DESTDIR}${afssrvbindir}/asetkey: asetkey + ${INSTALL} $? $@ + dest: \ ${DEST}/bin/aklog + ${DEST}/root.server/usr/afs/bin/asetkey ${DEST}/bin/aklog: aklog ${INSTALL} $? $@ +${DEST}/root.server/usr/afs/bin/asetkey: asetkey + ${INSTALL} $? $@ + # # Misc. targets # clean: - $(RM) -f *.o ${OBJS} aklog + $(RM) -f *.o ${OBJS} aklog asetkey include ../config/Makefile.version diff --git a/src/aklog/asetkey.c b/src/aklog/asetkey.c new file mode 100644 index 0000000..3664222 --- /dev/null +++ b/src/aklog/asetkey.c @@ -0,0 +1,138 @@ +/* + * $Id$ + * + * asetkey - Manipulates an AFS KeyFile + * + * Updated for Kerberos 5 + */ + +#include +#include +#include +#include +#ifdef HAVE_MEMORY_H +#include +#endif /* HAVE_MEMORY_H */ +#ifdef HAVE_STRING_H +#include +#else /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H +#include +#endif /* HAVE_STRINGS_H */ +#endif /* HAVE_STRING_H */ + +#include +#include + +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + struct afsconf_dir *tdir; + register long code; + const char *confdir; + + if (argc == 1) { + fprintf(stderr, "%s: usage is '%s options, e.g.\n", + argv[0], argv[0]); + fprintf(stderr, "\t%s add \n", argv[0]); + fprintf(stderr, "\t%s delete \n", argv[0]); + fprintf(stderr, "\t%s list\n", argv[0]); + exit(1); + } + + confdir = AFSDIR_SERVER_ETC_DIRPATH; + + tdir = afsconf_Open(confdir); + if (!tdir) { + fprintf(stderr, "%s: can't initialize conf dir '%s'\n", argv[0], + confdir); + exit(1); + } + if (strcmp(argv[1], "add")==0) { + krb5_context context; + krb5_principal principal; + krb5_keyblock *key; + krb5_error_code retval; + int kvno; + + if (argc != 5) { + fprintf(stderr, "%s add: usage is '%s add " + "\n", argv[0], argv[0]); + exit(1); + } + + krb5_init_context(&context); + + kvno = atoi(argv[2]); + retval = krb5_parse_name(context, argv[4], &principal); + if (retval != 0) { + com_err(argv[0], retval, "while parsing AFS principal"); + exit(1); + } + retval = krb5_kt_read_service_key(context, argv[3], principal, kvno, + ENCTYPE_DES_CBC_CRC, &key); + if (retval != 0) { + com_err(argv[0], retval, "while extracting AFS service key"); + exit(1); + } + + if (key->length != 8) { + fprintf(stderr, "Key length should be 8, but is really %d!\n", + key->length); + exit(1); + } + + code = afsconf_AddKey(tdir, kvno, (char *) key->contents, 1); + if (code) { + fprintf(stderr, "%s: failed to set key, code %d.\n", argv[0], code); + exit(1); + } + krb5_free_principal(context, principal); + krb5_free_keyblock(context, key); + } + else if (strcmp(argv[1], "delete")==0) { + long kvno; + if (argc != 3) { + fprintf(stderr, "%s delete: usage is '%s delete \n", + argv[0], argv[0]); + exit(1); + } + kvno = atoi(argv[2]); + code = afsconf_DeleteKey(tdir, kvno); + if (code) { + fprintf(stderr, "%s: failed to delete key %d, (code %d)\n", + argv[0], kvno, code); + exit(1); + } + } + else if (strcmp(argv[1], "list") == 0) { + struct afsconf_keys tkeys; + register int i, j; + + code = afsconf_GetKeys(tdir, &tkeys); + if (code) { + fprintf(stderr, "%s: failed to get keys, code %d\n", argv[0], code); + exit(1); + } + for(i=0;i