*** empty log message ***
authorJohn Kohl <jtkohl@mit.edu>
Tue, 13 Feb 1990 16:32:12 +0000 (16:32 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Tue, 13 Feb 1990 16:32:12 +0000 (16:32 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@353 dc483132-0cff-0310-8789-dd5450dbe970

src/admin/destroy/kdb5_destroy.c [new file with mode: 0644]

diff --git a/src/admin/destroy/kdb5_destroy.c b/src/admin/destroy/kdb5_destroy.c
new file mode 100644 (file)
index 0000000..936aace
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * 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 <krb5/copyright.h>
+#include <krb5/krb5.h>
+#include <krb5/kdb.h>
+#include <krb5/kdb_dbm.h>
+#include <stdio.h>
+
+#include <com_err.h>
+
+#include <krb5/ext-proto.h>
+
+#include <sys/param.h>                 /* 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);
+}