1b528cefcSMark Murray /*
2*ae771770SStanislav Sedov * Copyright (c) 1997, 1998, 2002 Kungliga Tekniska Högskolan
3b528cefcSMark Murray * (Royal Institute of Technology, Stockholm, Sweden).
4b528cefcSMark Murray * All rights reserved.
5b528cefcSMark Murray *
6*ae771770SStanislav Sedov * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
7*ae771770SStanislav Sedov *
8b528cefcSMark Murray * Redistribution and use in source and binary forms, with or without
9b528cefcSMark Murray * modification, are permitted provided that the following conditions
10b528cefcSMark Murray * are met:
11b528cefcSMark Murray *
12b528cefcSMark Murray * 1. Redistributions of source code must retain the above copyright
13b528cefcSMark Murray * notice, this list of conditions and the following disclaimer.
14b528cefcSMark Murray *
15b528cefcSMark Murray * 2. Redistributions in binary form must reproduce the above copyright
16b528cefcSMark Murray * notice, this list of conditions and the following disclaimer in the
17b528cefcSMark Murray * documentation and/or other materials provided with the distribution.
18b528cefcSMark Murray *
19b528cefcSMark Murray * 3. Neither the name of the Institute nor the names of its contributors
20b528cefcSMark Murray * may be used to endorse or promote products derived from this software
21b528cefcSMark Murray * without specific prior written permission.
22b528cefcSMark Murray *
23b528cefcSMark Murray * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24b528cefcSMark Murray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25b528cefcSMark Murray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26b528cefcSMark Murray * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27b528cefcSMark Murray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28b528cefcSMark Murray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29b528cefcSMark Murray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30b528cefcSMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31b528cefcSMark Murray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32b528cefcSMark Murray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33b528cefcSMark Murray * SUCH DAMAGE.
34b528cefcSMark Murray */
35b528cefcSMark Murray
36b528cefcSMark Murray #include "kdc_locl.h"
37b528cefcSMark Murray
38b528cefcSMark Murray void
kdc_openlog(krb5_context context,const char * service,krb5_kdc_configuration * config)39c19800e8SDoug Rabson kdc_openlog(krb5_context context,
40*ae771770SStanislav Sedov const char *service,
41c19800e8SDoug Rabson krb5_kdc_configuration *config)
42b528cefcSMark Murray {
43b528cefcSMark Murray char **s = NULL, **p;
44c19800e8SDoug Rabson krb5_initlog(context, "kdc", &config->logf);
45*ae771770SStanislav Sedov s = krb5_config_get_strings(context, NULL, service, "logging", NULL);
46b528cefcSMark Murray if(s == NULL)
47*ae771770SStanislav Sedov s = krb5_config_get_strings(context, NULL, "logging", service, NULL);
48b528cefcSMark Murray if(s){
49b528cefcSMark Murray for(p = s; *p; p++)
50c19800e8SDoug Rabson krb5_addlog_dest(context, config->logf, *p);
51b528cefcSMark Murray krb5_config_free_strings(s);
52c19800e8SDoug Rabson }else {
53*ae771770SStanislav Sedov char *ss;
54*ae771770SStanislav Sedov if (asprintf(&ss, "0-1/FILE:%s/%s", hdb_db_dir(context),
55*ae771770SStanislav Sedov KDC_LOG_FILE) < 0)
56*ae771770SStanislav Sedov err(1, NULL);
57*ae771770SStanislav Sedov krb5_addlog_dest(context, config->logf, ss);
58*ae771770SStanislav Sedov free(ss);
59c19800e8SDoug Rabson }
60c19800e8SDoug Rabson krb5_set_warn_dest(context, config->logf);
61b528cefcSMark Murray }
62b528cefcSMark Murray
63b528cefcSMark Murray char*
kdc_log_msg_va(krb5_context context,krb5_kdc_configuration * config,int level,const char * fmt,va_list ap)64c19800e8SDoug Rabson kdc_log_msg_va(krb5_context context,
65c19800e8SDoug Rabson krb5_kdc_configuration *config,
66c19800e8SDoug Rabson int level, const char *fmt, va_list ap)
67b528cefcSMark Murray {
68b528cefcSMark Murray char *msg;
69c19800e8SDoug Rabson krb5_vlog_msg(context, config->logf, &msg, level, fmt, ap);
70b528cefcSMark Murray return msg;
71b528cefcSMark Murray }
72b528cefcSMark Murray
73b528cefcSMark Murray char*
kdc_log_msg(krb5_context context,krb5_kdc_configuration * config,int level,const char * fmt,...)74c19800e8SDoug Rabson kdc_log_msg(krb5_context context,
75c19800e8SDoug Rabson krb5_kdc_configuration *config,
76c19800e8SDoug Rabson int level, const char *fmt, ...)
77b528cefcSMark Murray {
78b528cefcSMark Murray va_list ap;
79b528cefcSMark Murray char *s;
80b528cefcSMark Murray va_start(ap, fmt);
81c19800e8SDoug Rabson s = kdc_log_msg_va(context, config, level, fmt, ap);
82b528cefcSMark Murray va_end(ap);
83b528cefcSMark Murray return s;
84b528cefcSMark Murray }
85b528cefcSMark Murray
86b528cefcSMark Murray void
kdc_log(krb5_context context,krb5_kdc_configuration * config,int level,const char * fmt,...)87c19800e8SDoug Rabson kdc_log(krb5_context context,
88c19800e8SDoug Rabson krb5_kdc_configuration *config,
89c19800e8SDoug Rabson int level, const char *fmt, ...)
90b528cefcSMark Murray {
91b528cefcSMark Murray va_list ap;
92b528cefcSMark Murray char *s;
93b528cefcSMark Murray va_start(ap, fmt);
94c19800e8SDoug Rabson s = kdc_log_msg_va(context, config, level, fmt, ap);
95b528cefcSMark Murray if(s) free(s);
96b528cefcSMark Murray va_end(ap);
97b528cefcSMark Murray }
98