From: John Kohl Date: Tue, 13 Feb 1990 16:32:12 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: krb5-1.0-alpha2~1031 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6bcad8583d03200c94d60727fe05ea0118a419fa;p=krb5.git *** empty log message *** git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@353 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/admin/destroy/kdb5_destroy.c b/src/admin/destroy/kdb5_destroy.c new file mode 100644 index 000000000..936aaceee --- /dev/null +++ b/src/admin/destroy/kdb5_destroy.c @@ -0,0 +1,98 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * kdb_dest(roy): destroy the named database. + * + * This version knows about DBM format databases. + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_kdb_dest_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include +#include +#include +#include +#include + +#include + +#include + +#include /* XXX */ + +extern int errno; + +char *yes = "yes\n"; /* \n to compare against result of + fgets */ + +static void +usage(who, status) +char *who; +int status; +{ + fprintf(stderr, "usage: %s [-n dbname]\n", who); + exit(status); +} + +main(argc, argv) +int argc; +char *argv[]; +{ + extern char *optarg; + int optchar; + char *dbname = 0; + char buf[5]; + char dbfilename[MAXPATHLEN]; + krb5_error_code retval; + + while ((optchar = getopt(argc, argv, "n:")) != EOF) { + switch(optchar) { + case 'n': /* set db name */ + dbname = optarg; + break; + case '?': + default: + usage(argv[0], 1); + /*NOTREACHED*/ + } + } + if (!dbname) + dbname = DEFAULT_DBM_FILE; /* XXX? */ + + printf("Deleting KDC database stored in '%s', are you sure?\n", dbname); + printf("(type 'yes' to confirm)? "); + if ((fgets(buf, sizeof(buf), stdin) != NULL) && /* typed something */ + !strcmp(buf,yes)) { /* it matches yes */ + printf("OK, deleting database '%s'...\n", dbname); + (void) strcpy(dbfilename, dbname); + (void) strcat(dbfilename, ".dir"); + if (unlink(dbfilename) == -1) { + retval = errno; + com_err(argv[0], retval, "deleting database file '%s'",dbfilename); + goto aborted; + } + (void) strcpy(dbfilename, dbname); + (void) strcat(dbfilename, ".pag"); + if (unlink(dbfilename) == -1) { + retval = errno; + com_err(argv[0], retval, "deleting database file '%s'",dbfilename); + fprintf(stderr, + "Database partially deleted--inspect files manually!\n"); + exit(1); + } + printf("** Database '%s' destroyed.\n", dbname); + exit(0); + } + aborted: + printf("** Destruction aborted--database left intact.\n"); + exit(1); +}