Path: blob/main/crypto/krb5/src/kadmin/dbutil/kdb5_destroy.c
34889 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* kadmin/dbutil/kdb5_destroy.c - Destroy a KDC database */2/*3* Copyright 1990, 2008 by the Massachusetts Institute of Technology.4* All Rights Reserved.5*6* Export of this software from the United States of America may7* require a specific license from the United States Government.8* It is the responsibility of any person or organization contemplating9* export to obtain such a license before exporting.10*11* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and12* distribute this software and its documentation for any purpose and13* without fee is hereby granted, provided that the above copyright14* notice appear in all copies and that both that copyright notice and15* this permission notice appear in supporting documentation, and that16* the name of M.I.T. not be used in advertising or publicity pertaining17* to distribution of the software without specific, written prior18* permission. Furthermore if you modify this software you must label19* your software as modified software and not distribute it in such a20* fashion that it might be confused with the original M.I.T. software.21* M.I.T. makes no representations about the suitability of22* this software for any purpose. It is provided "as is" without express23* or implied warranty.24*/2526#include "k5-int.h"27#include <stdio.h>28#include "com_err.h"29#include <kadm5/admin.h>30#include <kdb.h>31#include "kdb5_util.h"3233extern int exit_status;34extern krb5_boolean dbactive;35extern kadm5_config_params global_params;3637char *yes = "yes\n"; /* \n to compare against result of38fgets */3940void41kdb5_destroy(int argc, char *argv[])42{43extern int optind;44int optchar;45char *dbname;46char buf[5];47krb5_error_code retval1;48int force = 0;4950dbname = global_params.dbname;5152optind = 1;53while ((optchar = getopt(argc, argv, "f")) != -1) {54switch(optchar) {55case 'f':56force++;57break;58case '?':59default:60usage();61return;62/*NOTREACHED*/63}64}65if (!force) {66printf(_("Deleting KDC database stored in '%s', are you sure?\n"),67dbname);68printf(_("(type 'yes' to confirm)? "));69if (fgets(buf, sizeof(buf), stdin) == NULL) {70exit_status++; return;71}72if (strcmp(buf, yes)) {73exit_status++; return;74}75printf(_("OK, deleting database '%s'...\n"), dbname);76}7778retval1 = krb5_db_destroy(util_context, db5util_db_args);79if (retval1) {80com_err(progname, retval1, _("deleting database '%s'"), dbname);81exit_status++; return;82}8384if (global_params.iprop_enabled) {85(void) unlink(global_params.iprop_logfile);86}8788dbactive = FALSE;89printf(_("** Database '%s' destroyed.\n"), dbname);90return;91}929394