set_dbinfo.c revision 178825
1139825Simp/* 2110285Snyan * Copyright (c) 1997-2007 Kungliga Tekniska H�gskolan 3110333Snyan * (Royal Institute of Technology, Stockholm, Sweden). 4110285Snyan * 5110285Snyan * All rights reserved. 6110285Snyan * 7110285Snyan * Redistribution and use in source and binary forms, with or without 8110285Snyan * modification, are permitted provided that the following conditions 9110285Snyan * are met: 10110285Snyan * 11110285Snyan * 1. Redistributions of source code must retain the above copyright 12110285Snyan * notice, this list of conditions and the following disclaimer. 13110285Snyan * 14110285Snyan * 2. Redistributions in binary form must reproduce the above copyright 15110285Snyan * notice, this list of conditions and the following disclaimer in the 16110285Snyan * documentation and/or other materials provided with the distribution. 17110285Snyan * 18110285Snyan * 3. Neither the name of the Institute nor the names of its contributors 19110285Snyan * may be used to endorse or promote products derived from this software 20110285Snyan * without specific prior written permission. 21110285Snyan * 22110285Snyan * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 23110285Snyan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24110285Snyan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25110285Snyan * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 26110285Snyan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27110285Snyan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28110285Snyan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29110285Snyan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30110285Snyan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31110285Snyan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32110285Snyan * SUCH DAMAGE. 33110285Snyan */ 34110285Snyan 35110285Snyan#include "kdc_locl.h" 36110285Snyan 37110285SnyanRCSID("$Id: default_config.c 21296 2007-06-25 14:49:11Z lha $"); 38110285Snyan 39110285Snyankrb5_error_code 40110285Snyankrb5_kdc_set_dbinfo(krb5_context context, struct krb5_kdc_configuration *c) 41110285Snyan{ 42110285Snyan struct hdb_dbinfo *info, *d; 43110285Snyan krb5_error_code ret; 44110285Snyan int i; 45110285Snyan 46110285Snyan /* fetch the databases */ 47110285Snyan ret = hdb_get_dbinfo(context, &info); 48110285Snyan if (ret) 49110285Snyan return ret; 50110285Snyan 51110285Snyan d = NULL; 52110285Snyan while ((d = hdb_dbinfo_get_next(info, d)) != NULL) { 53110285Snyan void *ptr; 54110285Snyan 55110285Snyan ptr = realloc(c->db, (c->num_db + 1) * sizeof(*c->db)); 56110285Snyan if (ptr == NULL) { 57110285Snyan ret = ENOMEM; 58110285Snyan krb5_set_error_string(context, "out of memory"); 59110285Snyan goto out; 60110285Snyan } 61110285Snyan c->db = ptr; 62110285Snyan 63110285Snyan ret = hdb_create(context, &c->db[c->num_db], 64110285Snyan hdb_dbinfo_get_dbname(context, d)); 65110285Snyan if(ret) 66110285Snyan goto out; 67110285Snyan 68110285Snyan ret = hdb_set_master_keyfile(context, c->db[c->num_db], 69110285Snyan hdb_dbinfo_get_mkey_file(context, d)); 70 if (ret) 71 goto out; 72 73 c->num_db++; 74 75 kdc_log(context, c, 0, "label: %s", 76 hdb_dbinfo_get_label(context, d)); 77 kdc_log(context, c, 0, "\tdbname: %s", 78 hdb_dbinfo_get_dbname(context, d)); 79 kdc_log(context, c, 0, "\tmkey_file: %s", 80 hdb_dbinfo_get_mkey_file(context, d)); 81 kdc_log(context, c, 0, "\tacl_file: %s", 82 hdb_dbinfo_get_acl_file(context, d)); 83 } 84 hdb_free_dbinfo(context, &info); 85 86 return 0; 87out: 88 for (i = 0; i < c->num_db; i++) 89 if (c->db[i] && c->db[i]->hdb_destroy) 90 (*c->db[i]->hdb_destroy)(context, c->db[i]); 91 c->num_db = 0; 92 free(c->db); 93 c->db = NULL; 94 95 hdb_free_dbinfo(context, &info); 96 97 return ret; 98} 99 100 101