Path: blob/main/crypto/krb5/src/kadmin/dbutil/kdb5_stash.c
34889 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* kadmin/dbutil/kdb5_stash.c - Store the master database key in a file */2/*3* Copyright 1990 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*/25/*26* Copyright (C) 1998 by the FundsXpress, INC.27*28* All rights reserved.29*30* Export of this software from the United States of America may require31* a specific license from the United States Government. It is the32* responsibility of any person or organization contemplating export to33* obtain such a license before exporting.34*35* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and36* distribute this software and its documentation for any purpose and37* without fee is hereby granted, provided that the above copyright38* notice appear in all copies and that both that copyright notice and39* this permission notice appear in supporting documentation, and that40* the name of FundsXpress. not be used in advertising or publicity pertaining41* to distribution of the software without specific, written prior42* permission. FundsXpress makes no representations about the suitability of43* this software for any purpose. It is provided "as is" without express44* or implied warranty.45*46* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR47* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED48* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.49*/5051#include "k5-int.h"52#include "com_err.h"53#include <kadm5/admin.h>54#include <stdio.h>55#include "kdb5_util.h"5657extern krb5_keyblock master_keyblock;58extern krb5_principal master_princ;59extern kadm5_config_params global_params;6061extern int exit_status;62extern int close_policy_db;6364void65kdb5_stash(int argc, char *argv[])66{67extern char *optarg;68extern int optind;69int optchar;70krb5_error_code retval;71char *keyfile = 0;72krb5_kvno mkey_kvno;7374keyfile = global_params.stash_file;7576optind = 1;77while ((optchar = getopt(argc, argv, "f:")) != -1) {78switch(optchar) {79case 'f':80keyfile = optarg;81break;82case '?':83default:84usage();85return;86}87}8889if (!krb5_c_valid_enctype(master_keyblock.enctype)) {90char tmp[32];91if (krb5_enctype_to_name(master_keyblock.enctype, FALSE,92tmp, sizeof(tmp)))93com_err(progname, KRB5_PROG_KEYTYPE_NOSUPP,94_("while setting up enctype %d"), master_keyblock.enctype);95else96com_err(progname, KRB5_PROG_KEYTYPE_NOSUPP, "%s", tmp);97exit_status++; return;98}99100if (global_params.mask & KADM5_CONFIG_KVNO)101mkey_kvno = global_params.kvno; /* user specified */102else103mkey_kvno = IGNORE_VNO; /* use whatever krb5_db_fetch_mkey finds */104105if (!valid_master_key) {106/* TRUE here means read the keyboard, but only once */107retval = krb5_db_fetch_mkey(util_context, master_princ,108master_keyblock.enctype,109TRUE, FALSE, (char *) NULL,110&mkey_kvno,111NULL, &master_keyblock);112if (retval) {113com_err(progname, retval, _("while reading master key"));114exit_status++; return;115}116117retval = krb5_db_fetch_mkey_list(util_context, master_princ,118&master_keyblock);119if (retval) {120com_err(progname, retval, _("while getting master key list"));121exit_status++; return;122}123} else {124printf(_("Using existing stashed keys to update stash file.\n"));125}126127retval = krb5_db_store_master_key_list(util_context, keyfile, master_princ,128NULL);129if (retval) {130com_err(progname, retval, _("while storing key"));131exit_status++; return;132}133134exit_status = 0;135return;136}137138139