2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
9 * Openvision retains the copyright to derivative works of
10 * this source code. Do *NOT* create a derivative of this
11 * source code before consulting with your legal department.
12 * Do *NOT* integrate *ANY* of this source code into another
13 * product before consulting with your legal department.
15 * For further information, read the top-level Openvision
16 * copyright which is contained in the top-level MIT Kerberos
19 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
25 * admin/destroy/kdb5_destroy.c
27 * Copyright 1990 by the Massachusetts Institute of Technology.
28 * All Rights Reserved.
30 * Export of this software from the United States of America may
31 * require a specific license from the United States Government.
32 * It is the responsibility of any person or organization contemplating
33 * export to obtain such a license before exporting.
35 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
36 * distribute this software and its documentation for any purpose and
37 * without fee is hereby granted, provided that the above copyright
38 * notice appear in all copies and that both that copyright notice and
39 * this permission notice appear in supporting documentation, and that
40 * the name of M.I.T. not be used in advertising or publicity pertaining
41 * to distribution of the software without specific, written prior
42 * permission. Furthermore if you modify this software you must label
43 * your software as modified software and not distribute it in such a
44 * fashion that it might be confused with the original M.I.T. software.
45 * M.I.T. makes no representations about the suitability of
46 * this software for any purpose. It is provided "as is" without express
47 * or implied warranty.
50 * kdb_dest(roy): destroy the named database.
52 * This version knows about DBM format databases.
58 #include <kadm5/admin.h>
61 #include "kdb5_util.h"
63 extern int exit_status
;
64 extern krb5_boolean dbactive
;
65 extern kadm5_config_params global_params
;
68 kdb5_destroy(argc
, argv
)
77 krb5_error_code retval1
;
80 char ufilename
[MAX_FILENAME
];
82 retval1
= kadm5_init_krb5_context(&context
);
85 /* Solaris Kerberos */
86 com_err(progname
, retval1
, "while initializing krb5_context");
90 if ((retval1
= krb5_set_default_realm(context
,
91 util_context
->default_realm
))) {
92 /* Solaris Kerberos */
93 com_err(progname
, retval1
, "while setting default realm name");
97 /* Solaris Kerberos */
99 if (strrchr(argv
[0], '/'))
100 argv
[0] = strrchr(argv
[0], '/')+1;
102 dbname
= global_params
.dbname
;
105 while ((optchar
= getopt(argc
, argv
, "f")) != -1) {
118 printf(gettext("Deleting KDC database stored in '%s', "
119 "are you sure?\n"), dbname
);
120 printf(gettext("(type 'yes' or 'y' to confirm)? "));
121 if (fgets(buf
, sizeof(buf
), stdin
) == NULL
) {
122 exit_status
++; return;
124 if ((strncmp(buf
, gettext("yes\n"),
125 strlen(gettext("yes\n"))) != 0) &&
126 (strncmp(buf
, gettext("y\n"),
127 strlen(gettext("y\n"))) != 0)) {
128 printf(gettext("database not deleted !! '%s'...\n"),
131 exit_status
++; return;
133 printf(gettext("OK, deleting database '%s'...\n"), dbname
);
136 retval1
= krb5_db_destroy(context
, db5util_db_args
);
138 /* check for a stash file and delete it if necessary */
139 if (global_params
.stash_file
== NULL
) {
140 char stash
[MAXPATHLEN
+1];
141 extern krb5_principal master_princ
;
142 krb5_data
*realm
= krb5_princ_realm(context
, master_princ
);
143 (void) strlcpy(stash
, DEFAULT_KEYFILE_STUB
, sizeof (stash
));
145 * realm->data is not necessarily NULL terminated so be
146 * careful how much data is copied here. Don't overrun
147 * the "stash" buffer and dont overrun the realm->data buffer,
148 * copy the smaller of the 2 lengths.
150 (void) strncat(stash
, realm
->data
,
151 (realm
->length
< (MAXPATHLEN
-strlen(stash
)) ? realm
->length
:
152 MAXPATHLEN
-strlen(stash
)));
153 global_params
.stash_file
= (char *)strdup(stash
);
155 if (!access(global_params
.stash_file
, F_OK
))
156 (void)unlink(global_params
.stash_file
);
159 /* Solaris Kerberos */
160 com_err(progname
, retval1
,
161 gettext("deleting database '%s'"), dbname
);
162 exit_status
++; return;
165 if (global_params
.iprop_enabled
) {
166 if (strlcpy(ufilename
, dbname
, MAX_FILENAME
) >= MAX_FILENAME
) {
170 if (strlcat(ufilename
, ".ulog", MAX_FILENAME
) >= MAX_FILENAME
) {
175 (void) unlink(ufilename
);
179 printf(gettext("** Database '%s' destroyed.\n"), dbname
);