155682Smarkm/*
2233294Sstas * Copyright (c) 1997, 1998, 2002 Kungliga Tekniska H��gskolan
3233294Sstas * (Royal Institute of Technology, Stockholm, Sweden).
4233294Sstas * All rights reserved.
555682Smarkm *
6233294Sstas * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
755682Smarkm *
8233294Sstas * Redistribution and use in source and binary forms, with or without
9233294Sstas * modification, are permitted provided that the following conditions
10233294Sstas * are met:
1155682Smarkm *
12233294Sstas * 1. Redistributions of source code must retain the above copyright
13233294Sstas *    notice, this list of conditions and the following disclaimer.
1455682Smarkm *
15233294Sstas * 2. Redistributions in binary form must reproduce the above copyright
16233294Sstas *    notice, this list of conditions and the following disclaimer in the
17233294Sstas *    documentation and/or other materials provided with the distribution.
1855682Smarkm *
19233294Sstas * 3. Neither the name of the Institute nor the names of its contributors
20233294Sstas *    may be used to endorse or promote products derived from this software
21233294Sstas *    without specific prior written permission.
22233294Sstas *
23233294Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24233294Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25233294Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26233294Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27233294Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29233294Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30233294Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31233294Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32233294Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33233294Sstas * SUCH DAMAGE.
3455682Smarkm */
3555682Smarkm
3655682Smarkm#include "kdc_locl.h"
3755682Smarkm
3855682Smarkmvoid
39233294Sstaskdc_openlog(krb5_context context,
40233294Sstas	    const char *service,
41178825Sdfr	    krb5_kdc_configuration *config)
4255682Smarkm{
4355682Smarkm    char **s = NULL, **p;
44178825Sdfr    krb5_initlog(context, "kdc", &config->logf);
45233294Sstas    s = krb5_config_get_strings(context, NULL, service, "logging", NULL);
4655682Smarkm    if(s == NULL)
47233294Sstas	s = krb5_config_get_strings(context, NULL, "logging", service, NULL);
4855682Smarkm    if(s){
4955682Smarkm	for(p = s; *p; p++)
50178825Sdfr	    krb5_addlog_dest(context, config->logf, *p);
5155682Smarkm	krb5_config_free_strings(s);
52178825Sdfr    }else {
53233294Sstas	char *ss;
54233294Sstas	if (asprintf(&ss, "0-1/FILE:%s/%s", hdb_db_dir(context),
55233294Sstas	    KDC_LOG_FILE) < 0)
56233294Sstas	    err(1, NULL);
57233294Sstas	krb5_addlog_dest(context, config->logf, ss);
58233294Sstas	free(ss);
59178825Sdfr    }
60178825Sdfr    krb5_set_warn_dest(context, config->logf);
6155682Smarkm}
6255682Smarkm
6355682Smarkmchar*
64233294Sstaskdc_log_msg_va(krb5_context context,
65178825Sdfr	       krb5_kdc_configuration *config,
66178825Sdfr	       int level, const char *fmt, va_list ap)
6755682Smarkm{
6855682Smarkm    char *msg;
69178825Sdfr    krb5_vlog_msg(context, config->logf, &msg, level, fmt, ap);
7055682Smarkm    return msg;
7155682Smarkm}
7255682Smarkm
7355682Smarkmchar*
74233294Sstaskdc_log_msg(krb5_context context,
75178825Sdfr	    krb5_kdc_configuration *config,
76178825Sdfr	    int level, const char *fmt, ...)
7755682Smarkm{
7855682Smarkm    va_list ap;
7955682Smarkm    char *s;
8055682Smarkm    va_start(ap, fmt);
81178825Sdfr    s = kdc_log_msg_va(context, config, level, fmt, ap);
8255682Smarkm    va_end(ap);
8355682Smarkm    return s;
8455682Smarkm}
8555682Smarkm
8655682Smarkmvoid
87233294Sstaskdc_log(krb5_context context,
88178825Sdfr	krb5_kdc_configuration *config,
89178825Sdfr	int level, const char *fmt, ...)
9055682Smarkm{
9155682Smarkm    va_list ap;
9255682Smarkm    char *s;
9355682Smarkm    va_start(ap, fmt);
94178825Sdfr    s = kdc_log_msg_va(context, config, level, fmt, ap);
9555682Smarkm    if(s) free(s);
9655682Smarkm    va_end(ap);
9755682Smarkm}
98