166458Sdfr/* 266458Sdfr * Copyright (c) 1997-2004 Kungliga Tekniska H��gskolan 366458Sdfr * (Royal Institute of Technology, Stockholm, Sweden). 466458Sdfr * All rights reserved. 566458Sdfr * 666458Sdfr * Redistribution and use in source and binary forms, with or without 766458Sdfr * modification, are permitted provided that the following conditions 866458Sdfr * are met: 966458Sdfr * 1066458Sdfr * 1. Redistributions of source code must retain the above copyright 1166458Sdfr * notice, this list of conditions and the following disclaimer. 1266458Sdfr * 1366458Sdfr * 2. Redistributions in binary form must reproduce the above copyright 1466458Sdfr * notice, this list of conditions and the following disclaimer in the 1566458Sdfr * documentation and/or other materials provided with the distribution. 1666458Sdfr * 1766458Sdfr * 3. Neither the name of the Institute nor the names of its contributors 1866458Sdfr * may be used to endorse or promote products derived from this software 1966458Sdfr * without specific prior written permission. 2066458Sdfr * 2166458Sdfr * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 2266458Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2366458Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2466458Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 2566458Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2666458Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2766458Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2866458Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2966458Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3066458Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3166458Sdfr * SUCH DAMAGE. 3266458Sdfr */ 3366458Sdfr 3466458Sdfr#include "kadmin_locl.h" 3566458Sdfr#include "kadmin-commands.h" 3666458Sdfr#include <kadm5/private.h> 3766458Sdfr 3866458Sdfrextern int local_flag; 3966458Sdfr 4066458Sdfrint 4166458Sdfrdump(struct dump_options *opt, int argc, char **argv) 4266458Sdfr{ 4366458Sdfr krb5_error_code ret; 4466458Sdfr FILE *f; 4566458Sdfr HDB *db = NULL; 4666458Sdfr 4766458Sdfr if(!local_flag) { 4866458Sdfr krb5_warnx(context, "dump is only available in local (-l) mode"); 4966458Sdfr return 0; 5066458Sdfr } 5166458Sdfr 52115084Smarcel db = _kadm5_s_get_db(kadm_handle); 53115084Smarcel 5466458Sdfr if(argc == 0) 5566458Sdfr f = stdout; 56115084Smarcel else 5766458Sdfr f = fopen(argv[0], "w"); 58115084Smarcel 59119159Smarcel if(f == NULL) { 60120222Smarcel krb5_warn(context, errno, "open: %s", argv[0]); 61115084Smarcel goto out; 62115084Smarcel } 63115913Smarcel ret = db->hdb_open(context, db, O_RDONLY, 0600); 64120222Smarcel if(ret) { 6572892Sjhb krb5_warn(context, ret, "hdb_open"); 6666458Sdfr goto out; 6766458Sdfr } 6866458Sdfr 6966458Sdfr hdb_foreach(context, db, opt->decrypt_flag ? HDB_F_DECRYPT : 0, 70118414Smarcel hdb_print_entry, f); 71118414Smarcel 72118414Smarcel db->hdb_close(context, db); 73118414Smarcelout: 7466458Sdfr if(f && f != stdout) 7566458Sdfr fclose(f); 7666458Sdfr return 0; 7766458Sdfr} 7866458Sdfr