/*1* Copyright (c) 1997, 1998, 2002 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"3637void38kdc_openlog(krb5_context context,39const char *service,40krb5_kdc_configuration *config)41{42char **s = NULL, **p;43krb5_initlog(context, "kdc", &config->logf);44s = krb5_config_get_strings(context, NULL, service, "logging", NULL);45if(s == NULL)46s = krb5_config_get_strings(context, NULL, "logging", service, NULL);47if(s){48for(p = s; *p; p++)49krb5_addlog_dest(context, config->logf, *p);50krb5_config_free_strings(s);51}else {52char *ss;53if (asprintf(&ss, "0-1/FILE:%s/%s", hdb_db_dir(context),54KDC_LOG_FILE) < 0)55err(1, NULL);56krb5_addlog_dest(context, config->logf, ss);57free(ss);58}59krb5_set_warn_dest(context, config->logf);60}6162char*63kdc_log_msg_va(krb5_context context,64krb5_kdc_configuration *config,65int level, const char *fmt, va_list ap)66{67char *msg;68krb5_vlog_msg(context, config->logf, &msg, level, fmt, ap);69return msg;70}7172char*73kdc_log_msg(krb5_context context,74krb5_kdc_configuration *config,75int level, const char *fmt, ...)76{77va_list ap;78char *s;79va_start(ap, fmt);80s = kdc_log_msg_va(context, config, level, fmt, ap);81va_end(ap);82return s;83}8485void86kdc_log(krb5_context context,87krb5_kdc_configuration *config,88int level, const char *fmt, ...)89{90va_list ap;91char *s;92va_start(ap, fmt);93s = kdc_log_msg_va(context, config, level, fmt, ap);94if(s) free(s);95va_end(ap);96}979899