113394Swpaul/*
213394Swpaul * Copyright (c) 1997, 1998, 2002 Kungliga Tekniska H��gskolan
313394Swpaul * (Royal Institute of Technology, Stockholm, Sweden).
413394Swpaul * All rights reserved.
513394Swpaul *
613394Swpaul * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
713394Swpaul *
813394Swpaul * Redistribution and use in source and binary forms, with or without
913394Swpaul * modification, are permitted provided that the following conditions
1013394Swpaul * are met:
1113394Swpaul *
1213394Swpaul * 1. Redistributions of source code must retain the above copyright
1313394Swpaul *    notice, this list of conditions and the following disclaimer.
1413394Swpaul *
1513394Swpaul * 2. Redistributions in binary form must reproduce the above copyright
1613394Swpaul *    notice, this list of conditions and the following disclaimer in the
1713394Swpaul *    documentation and/or other materials provided with the distribution.
1813394Swpaul *
1913394Swpaul * 3. Neither the name of the Institute nor the names of its contributors
2013394Swpaul *    may be used to endorse or promote products derived from this software
2113394Swpaul *    without specific prior written permission.
2213394Swpaul *
2313394Swpaul * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
2413394Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2513394Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2613394Swpaul * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
2713394Swpaul * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2813394Swpaul * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2913394Swpaul * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3013394Swpaul * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3113394Swpaul * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3213394Swpaul * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33114601Sobrien * SUCH DAMAGE.
34114601Sobrien */
3530911Scharnier
3630911Scharnier#include "kdc_locl.h"
3730911Scharnier
3813394Swpaulvoid
3913394Swpaulkdc_openlog(krb5_context context,
4013394Swpaul	    const char *service,
41161262Sru	    krb5_kdc_configuration *config)
4213394Swpaul{
4330911Scharnier    char **s = NULL, **p;
4413394Swpaul    krb5_initlog(context, "kdc", &config->logf);
4513394Swpaul    s = krb5_config_get_strings(context, NULL, service, "logging", NULL);
4613394Swpaul    if(s == NULL)
4713394Swpaul	s = krb5_config_get_strings(context, NULL, "logging", service, NULL);
4813394Swpaul    if(s){
4913394Swpaul	for(p = s; *p; p++)
5013394Swpaul	    krb5_addlog_dest(context, config->logf, *p);
5113394Swpaul	krb5_config_free_strings(s);
5213394Swpaul    }else {
5313394Swpaul	char *ss;
5413394Swpaul	if (asprintf(&ss, "0-1/FILE:%s/%s", hdb_db_dir(context),
5513394Swpaul	    KDC_LOG_FILE) < 0)
5613394Swpaul	    err(1, NULL);
5713394Swpaul	krb5_addlog_dest(context, config->logf, ss);
5813394Swpaul	free(ss);
5913394Swpaul    }
6013394Swpaul    krb5_set_warn_dest(context, config->logf);
6113394Swpaul}
6213394Swpaul
6313394Swpaulchar*
64161262Srukdc_log_msg_va(krb5_context context,
6513394Swpaul	       krb5_kdc_configuration *config,
6613394Swpaul	       int level, const char *fmt, va_list ap)
6713394Swpaul{
68161359Sthomas    char *msg;
6913394Swpaul    krb5_vlog_msg(context, config->logf, &msg, level, fmt, ap);
7013394Swpaul    return msg;
7113394Swpaul}
7213394Swpaul
7313394Swpaulchar*
7413394Swpaulkdc_log_msg(krb5_context context,
7513394Swpaul	    krb5_kdc_configuration *config,
7613394Swpaul	    int level, const char *fmt, ...)
7713394Swpaul{
7813394Swpaul    va_list ap;
7913394Swpaul    char *s;
8013394Swpaul    va_start(ap, fmt);
8113394Swpaul    s = kdc_log_msg_va(context, config, level, fmt, ap);
8213394Swpaul    va_end(ap);
8313394Swpaul    return s;
8413394Swpaul}
85161359Sthomas
86161359Sthomasvoid
8713394Swpaulkdc_log(krb5_context context,
8813394Swpaul	krb5_kdc_configuration *config,
8913394Swpaul	int level, const char *fmt, ...)
9094887Sdes{
9190298Sdes    va_list ap;
9213394Swpaul    char *s;
9390297Sdes    va_start(ap, fmt);
9494887Sdes    s = kdc_log_msg_va(context, config, level, fmt, ap);
9594887Sdes    if(s) free(s);
9694887Sdes    va_end(ap);
9794887Sdes}
9894887Sdes