/*1* Copyright (c) 1997-2007 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Portions Copyright (c) 2009 Apple Inc. All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10*11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13*14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* 3. Neither the name of the Institute nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#include "kdc_locl.h"3637static krb5_error_code38add_db(krb5_context context, struct krb5_kdc_configuration *c,39const char *conf, const char *master_key)40{41krb5_error_code ret;42void *ptr;4344ptr = realloc(c->db, (c->num_db + 1) * sizeof(*c->db));45if (ptr == NULL) {46krb5_set_error_message(context, ENOMEM, "malloc: out of memory");47return ENOMEM;48}49c->db = ptr;5051ret = hdb_create(context, &c->db[c->num_db], conf);52if(ret)53return ret;5455c->num_db++;5657if (master_key) {58ret = hdb_set_master_keyfile(context, c->db[c->num_db - 1], master_key);59if (ret)60return ret;61}6263return 0;64}6566krb5_error_code67krb5_kdc_set_dbinfo(krb5_context context, struct krb5_kdc_configuration *c)68{69struct hdb_dbinfo *info, *d;70krb5_error_code ret;71int i;7273/* fetch the databases */74ret = hdb_get_dbinfo(context, &info);75if (ret)76return ret;7778d = NULL;79while ((d = hdb_dbinfo_get_next(info, d)) != NULL) {8081ret = add_db(context, c,82hdb_dbinfo_get_dbname(context, d),83hdb_dbinfo_get_mkey_file(context, d));84if (ret)85goto out;8687kdc_log(context, c, 0, "label: %s",88hdb_dbinfo_get_label(context, d));89kdc_log(context, c, 0, "\tdbname: %s",90hdb_dbinfo_get_dbname(context, d));91kdc_log(context, c, 0, "\tmkey_file: %s",92hdb_dbinfo_get_mkey_file(context, d));93kdc_log(context, c, 0, "\tacl_file: %s",94hdb_dbinfo_get_acl_file(context, d));95}96hdb_free_dbinfo(context, &info);9798return 0;99out:100for (i = 0; i < c->num_db; i++)101if (c->db[i] && c->db[i]->hdb_destroy)102(*c->db[i]->hdb_destroy)(context, c->db[i]);103c->num_db = 0;104free(c->db);105c->db = NULL;106107hdb_free_dbinfo(context, &info);108109return ret;110}111112113114115