1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* kadmin/dbutil/kdb5_stash.c - Store the master database key in a file */
4 * Copyright 1990 by the Massachusetts Institute of Technology.
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.
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.
27 * Copyright (C) 1998 by the FundsXpress, INC.
29 * All rights reserved.
31 * Export of this software from the United States of America may require
32 * a specific license from the United States Government. It is the
33 * responsibility of any person or organization contemplating export to
34 * obtain such a license before exporting.
36 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
37 * distribute this software and its documentation for any purpose and
38 * without fee is hereby granted, provided that the above copyright
39 * notice appear in all copies and that both that copyright notice and
40 * this permission notice appear in supporting documentation, and that
41 * the name of FundsXpress. not be used in advertising or publicity pertaining
42 * to distribution of the software without specific, written prior
43 * permission. FundsXpress makes no representations about the suitability of
44 * this software for any purpose. It is provided "as is" without express
45 * or implied warranty.
47 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
49 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
54 #include <kadm5/admin.h>
56 #include "kdb5_util.h"
58 extern krb5_keyblock master_keyblock;
59 extern krb5_keylist_node *master_keylist;
60 extern krb5_principal master_princ;
61 extern kadm5_config_params global_params;
63 extern int exit_status;
64 extern int close_policy_db;
67 kdb5_stash(argc, argv)
74 krb5_error_code retval;
78 keyfile = global_params.stash_file;
81 while ((optchar = getopt(argc, argv, "f:")) != -1) {
93 if (!krb5_c_valid_enctype(master_keyblock.enctype)) {
95 if (krb5_enctype_to_name(master_keyblock.enctype, FALSE,
97 com_err(progname, KRB5_PROG_KEYTYPE_NOSUPP,
98 _("while setting up enctype %d"), master_keyblock.enctype);
100 com_err(progname, KRB5_PROG_KEYTYPE_NOSUPP, "%s", tmp);
101 exit_status++; return;
104 if (global_params.mask & KADM5_CONFIG_KVNO)
105 mkey_kvno = global_params.kvno; /* user specified */
107 mkey_kvno = IGNORE_VNO; /* use whatever krb5_db_fetch_mkey finds */
109 if (!valid_master_key) {
110 /* TRUE here means read the keyboard, but only once */
111 retval = krb5_db_fetch_mkey(util_context, master_princ,
112 master_keyblock.enctype,
113 TRUE, FALSE, (char *) NULL,
115 NULL, &master_keyblock);
117 com_err(progname, retval, _("while reading master key"));
118 exit_status++; return;
121 retval = krb5_db_fetch_mkey_list(util_context, master_princ,
122 &master_keyblock, mkey_kvno,
125 com_err(progname, retval, _("while getting master key list"));
126 exit_status++; return;
129 printf(_("Using existing stashed keys to update stash file.\n"));
132 retval = krb5_db_store_master_key_list(util_context, keyfile, master_princ,
133 master_keylist, NULL);
135 com_err(progname, errno, _("while storing key"));
136 exit_status++; return;