From: Derrick Brashear Date: Sat, 12 Jan 2002 21:35:59 +0000 (+0000) Subject: bos-key-utility-20020112 X-Git-Tag: openafs-devel-1_3_0~86 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=907452f2d764b9e6c8e15136f05dd44844d011a3 bos-key-utility-20020112 modification of asetkey to allow manipulation of key files without a running bosserver (asetkey requires krb4; this does not) --- diff --git a/src/bozo/Makefile.in b/src/bozo/Makefile.in index ee65164..656f947 100644 --- a/src/bozo/Makefile.in +++ b/src/bozo/Makefile.in @@ -40,7 +40,7 @@ LIBS=${TOP_LIBDIR}/librx.a \ OBJS=bosserver.o bnode.o ezbnodeops.o fsbnodeops.o bosint.ss.o bosint.xdr.o \ bosoprocs.o cronbnodeops.o -all: bosserver ${TOP_INCDIR}/afs/bosint.h bos ${TOP_LIBDIR}/libbos.a ${TOP_INCDIR}/afs/bnode.h +all: bosserver ${TOP_INCDIR}/afs/bosint.h bos ${TOP_LIBDIR}/libbos.a ${TOP_INCDIR}/afs/bnode.h bos_util $(OBJS) bosint.xdr.o bosint.cs.o boserr.o: $(INCLS) @@ -81,6 +81,11 @@ bos.o: bos.c ${INCLS} AFS_component_version_number.o bos: bos.o $(LIBS) libbos.a ${CC} ${CFLAGS} -o bos bos.o libbos.a $(LIBS) ${XLIBS} +bos_util.o: bos_util.c ${INCLS} AFS_component_version_number.o + +bos_util: bos_util.o $(LIBS) + ${CC} ${CFLAGS} -o bos_util bos_util.o $(LIBS) ${XLIBS} + ezbnodeops.o: ezbnodeops.c ${INCLS} fsbnodeops.o: fsbnodeops.c ${INCLS} @@ -101,6 +106,7 @@ install: \ ${DESTDIR}${includedir}/afs/bosint.h \ ${DESTDIR}${bindir}/bos \ ${DESTDIR}${afssrvbindir}/bos \ + ${DESTDIR}${afssrvsbindir}/bos_util \ ${DESTDIR}${libdir}/afs/libbos.a \ ${DESTDIR}${includedir}/afs/bnode.h @@ -116,6 +122,9 @@ ${DEST}/bin/bos: bos ${DEST}/root.server/usr/afs/bin/bos: bos ${INSTALL} $? $@ +${DEST}/root.server/usr/afs/bin/bos_util: bos_util + ${INSTALL} $? $@ + ${DEST}/lib/afs/libbos.a: libbos.a ${INSTALL} $? $@ @@ -148,6 +157,9 @@ ${DESTDIR}${bindir}/bos: bos ${DESTDIR}${afssrvbindir}/bos: bos ${INSTALL} $? $@ +${DESTDIR}${afssrvbindir}/bos_util: bos_util + ${INSTALL} $? $@ + ${DESTDIR}${libdir}/afs/libbos.a: libbos.a ${INSTALL} $? $@ @@ -165,6 +177,6 @@ dest: \ ${DEST}/include/afs/bosint.h \ ${DEST}/bin/bos \ ${DEST}/root.server/usr/afs/bin/bos \ + ${DEST}/root.server/usr/afs/bin/bos_util \ ${DEST}/lib/afs/libbos.a \ ${DEST}/include/afs/bnode.h - diff --git a/src/bozo/bos_util.c b/src/bozo/bos_util.c new file mode 100644 index 0000000..17152aa --- /dev/null +++ b/src/bozo/bos_util.c @@ -0,0 +1,201 @@ +/* + * Copyright (C) 1989 by the Massachusetts Institute of Technology + * + * Export of software employing encryption from the United States of + * America is assumed to require a specific license from the United + * States Government. It is the responsibility of any person or + * organization contemplating export to obtain such a license before + * exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#include +#include + +RCSID("$Header$"); + +#include +#include +#include + +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + struct afsconf_dir *tdir; + register afs_int32 code; + + if (argc == 1) { + printf("bos_util: usage is 'bos_util options, e.g.\n"); + printf(" bos_util add \n"); + printf(" bos_util adddes \n"); +#ifdef KERBEROS + printf(" bos_util srvtab2keyfile \n"); +#endif + printf(" bos_util delete \n"); + printf(" bos_util list\n"); + exit(1); + } + + tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIR); + if (!tdir) { + printf("bos_util: can't initialize conf dir '%s'\n", AFSDIR_SERVER_ETC_DIR); + exit(1); + } + if (strcmp(argv[1], "add")==0) { + struct ktc_encryptionKey tkey; + int kvno; + char buf[BUFSIZ], ver[BUFSIZ]; + char *tcell = (char *) 0; + + if (argc != 3) { + printf("bos_util add: usage is 'bos_util add \n"); + exit(1); + } + kvno = atoi(argv[2]); + memset(&tkey, 0, sizeof(struct ktc_encryptionKey)); + + /* prompt for key */ + code=des_read_pw_string(buf,sizeof(buf),"input key: ",0); + if(code || strlen(buf)==0) { + printf("Bad key: \n"); + exit(1); + } + code=des_read_pw_string(ver,sizeof(ver),"Retype input key: ",0); + if(code || strlen(ver)==0) { + printf("Bad key: \n"); + exit(1); + } + if (strcmp (ver, buf) != 0) { + printf ("\nInput key mismatch\n"); + exit(1); + } + ka_StringToKey(buf,tcell,&tkey); + code = afsconf_AddKey(tdir, kvno, &tkey); + if (code) { + printf("bos_util: failed to set key, code %d.\n", code); + exit(1); + } + } + else if (strcmp(argv[1], "adddes")==0) { + struct ktc_encryptionKey tkey; + int kvno; + register afs_int32 code; + char buf[BUFSIZ], ver[BUFSIZ]; + char *tcell = (char *) 0; + + if (argc != 3) { + printf("bos_util adddes: usage is 'bos_util adddes \n"); + exit(1); + } + kvno = atoi(argv[2]); + memset(&tkey, 0, sizeof(struct ktc_encryptionKey)); + + /* prompt for key */ + code=des_read_pw_string(buf,sizeof(buf),"input key: ",0); + if(code || strlen(buf)==0) { + printf("Bad key: \n"); + exit(1); + } + code=des_read_pw_string(ver,sizeof(ver),"Retype input key: ",0); + if(code || strlen(ver)==0) { + printf("Bad key: \n"); + exit(1); + } + if (strcmp (ver, buf) != 0) { + printf ("\nInput key mismatch\n"); + exit(1); + } + des_string_to_key(buf,&tkey); + code = afsconf_AddKey(tdir, kvno, &tkey); + if (code) { + printf("bos_util: failed to set key, code %d.\n", code); + exit(1); + } + } +#ifdef KERBEROS + else if (strcmp(argv[1], "srvtab2keyfile")==0) { + char tkey[8], name[255], inst[255], realm[255]; + int kvno; + if (argc != 5) { + printf("bos_util add: usage is 'bos_util srvtab2keyfile \n"); + exit(1); + } + kvno = atoi(argv[2]); + bzero(tkey, sizeof(tkey)); + code = kname_parse(name, inst, realm, argv[4]); + if (code != 0) { + printf("Invalid kerberos name\n"); + exit(1); + } + code = read_service_key(name, inst, realm, kvno, argv[3], tkey); + if (code != 0) { + printf("Can't find key in %s\n", argv[3]); + exit(1); + } + code = afsconf_AddKey(tdir, kvno, tkey); + if (code) { + printf("bos_util: failed to set key, code %d.\n", code); + exit(1); + } + } +#endif + else if (strcmp(argv[1], "delete")==0) { + long kvno; + if (argc != 3) { + printf("bos_util delete: usage is 'bos_util delete \n"); + exit(1); + } + kvno = atoi(argv[2]); + code = afsconf_DeleteKey(tdir, kvno); + if (code) { + printf("bos_util: 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; + unsigned char tbuffer[9]; + + code = afsconf_GetKeys(tdir, &tkeys); + if (code) { + printf("bos_util: failed to get keys, code %d\n", code); + exit(1); + } + for(i=0;i