1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* kadmin/dbutil/kdb5_destroy.c - Destroy a KDC database */ 3 /* 4 * Copyright 1990, 2008 by the Massachusetts Institute of Technology. 5 * All Rights Reserved. 6 * 7 * Export of this software from the United States of America may 8 * require a specific license from the United States Government. 9 * It is the responsibility of any person or organization contemplating 10 * export to obtain such a license before exporting. 11 * 12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 13 * distribute this software and its documentation for any purpose and 14 * without fee is hereby granted, provided that the above copyright 15 * notice appear in all copies and that both that copyright notice and 16 * this permission notice appear in supporting documentation, and that 17 * the name of M.I.T. not be used in advertising or publicity pertaining 18 * to distribution of the software without specific, written prior 19 * permission. Furthermore if you modify this software you must label 20 * your software as modified software and not distribute it in such a 21 * fashion that it might be confused with the original M.I.T. software. 22 * M.I.T. makes no representations about the suitability of 23 * this software for any purpose. It is provided "as is" without express 24 * or implied warranty. 25 */ 26 27 #include "k5-int.h" 28 #include <stdio.h> 29 #include "com_err.h" 30 #include <kadm5/admin.h> 31 #include <kdb.h> 32 #include "kdb5_util.h" 33 34 extern int exit_status; 35 extern krb5_boolean dbactive; 36 extern kadm5_config_params global_params; 37 38 char *yes = "yes\n"; /* \n to compare against result of 39 fgets */ 40 41 void 42 kdb5_destroy(argc, argv) 43 int argc; 44 char *argv[]; 45 { 46 extern int optind; 47 int optchar; 48 char *dbname; 49 char buf[5]; 50 krb5_error_code retval1; 51 int force = 0; 52 53 dbname = global_params.dbname; 54 55 optind = 1; 56 while ((optchar = getopt(argc, argv, "f")) != -1) { 57 switch(optchar) { 58 case 'f': 59 force++; 60 break; 61 case '?': 62 default: 63 usage(); 64 return; 65 /*NOTREACHED*/ 66 } 67 } 68 if (!force) { 69 printf(_("Deleting KDC database stored in '%s', are you sure?\n"), 70 dbname); 71 printf(_("(type 'yes' to confirm)? ")); 72 if (fgets(buf, sizeof(buf), stdin) == NULL) { 73 exit_status++; return; 74 } 75 if (strcmp(buf, yes)) { 76 exit_status++; return; 77 } 78 printf(_("OK, deleting database '%s'...\n"), dbname); 79 } 80 81 retval1 = krb5_db_destroy(util_context, db5util_db_args); 82 if (retval1) { 83 com_err(progname, retval1, _("deleting database '%s'"), dbname); 84 exit_status++; return; 85 } 86 87 if (global_params.iprop_enabled) { 88 (void) unlink(global_params.iprop_logfile); 89 } 90 91 dbactive = FALSE; 92 printf(_("** Database '%s' destroyed.\n"), dbname); 93 return; 94 } 95