2 * Copyright (c) 1997-2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "krb5_locl.h"
40 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
41 krb5_initlog(krb5_context context
,
43 krb5_log_facility
**fac
)
45 return heim_initlog(context
->hcontext
, program
, fac
);
48 struct krb5_addlog_func_wrapper
{
50 krb5_log_log_func_t log_func
;
51 krb5_log_close_func_t close_func
;
55 static void HEIM_CALLCONV
56 krb5_addlog_func_wrapper_log(heim_context hcontext
,
61 struct krb5_addlog_func_wrapper
*w
= data
;
63 w
->log_func(w
->context
,
69 static void HEIM_CALLCONV
70 krb5_addlog_func_wrapper_close(void *data
)
72 struct krb5_addlog_func_wrapper
*w
= data
;
74 w
->close_func(w
->data
);
78 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
79 krb5_addlog_func(krb5_context context
,
80 krb5_log_facility
*fac
,
83 krb5_log_log_func_t log_func
,
84 krb5_log_close_func_t close_func
,
87 struct krb5_addlog_func_wrapper
*w
= NULL
;
89 w
= calloc(1, sizeof(*w
));
91 return krb5_enomem(context
);
94 w
->log_func
= log_func
;
95 w
->close_func
= close_func
;
98 return heim_addlog_func(context
->hcontext
, fac
, min
, max
,
99 krb5_addlog_func_wrapper_log
,
100 krb5_addlog_func_wrapper_close
,
104 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
105 krb5_addlog_dest(krb5_context context
, krb5_log_facility
*f
, const char *orig
)
107 return heim_addlog_dest(context
->hcontext
, f
, orig
);
111 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
112 krb5_openlog(krb5_context context
,
114 krb5_log_facility
**fac
)
119 p
= krb5_config_get_strings(context
, NULL
, "logging", program
, NULL
);
121 p
= krb5_config_get_strings(context
, NULL
, "logging", "default", NULL
);
122 ret
= heim_openlog(context
->hcontext
, program
, (const char **)p
, fac
);
123 krb5_config_free_strings(p
);
127 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
128 krb5_closelog(krb5_context context
,
129 krb5_log_facility
*fac
)
131 heim_closelog(context
->hcontext
, fac
);
136 #define __attribute__(X)
138 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
139 krb5_vlog_msg(krb5_context context
,
140 krb5_log_facility
*fac
,
145 __attribute__ ((__format__ (__printf__
, 5, 0)))
147 return heim_vlog_msg(context
->hcontext
, fac
, reply
, level
, fmt
, ap
);
150 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
151 krb5_vlog(krb5_context context
,
152 krb5_log_facility
*fac
,
156 __attribute__ ((__format__ (__printf__
, 4, 0)))
158 return heim_vlog_msg(context
->hcontext
, fac
, NULL
, level
, fmt
, ap
);
161 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
162 krb5_log_msg(krb5_context context
,
163 krb5_log_facility
*fac
,
168 __attribute__ ((__format__ (__printf__
, 5, 6)))
174 ret
= heim_vlog_msg(context
->hcontext
, fac
, reply
, level
, fmt
, ap
);
180 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
181 krb5_log(krb5_context context
,
182 krb5_log_facility
*fac
,
186 __attribute__ ((__format__ (__printf__
, 4, 5)))
192 ret
= heim_vlog(context
->hcontext
, fac
, level
, fmt
, ap
);
197 void KRB5_LIB_FUNCTION
198 _krb5_debug(krb5_context context
,
202 __attribute__ ((__format__ (__printf__
, 3, 4)))
207 if (context
&& context
->hcontext
)
208 heim_vdebug(context
->hcontext
, level
, fmt
, ap
);
212 void KRB5_LIB_FUNCTION
213 krb5_debug(krb5_context context
,
217 __attribute__ ((__format__ (__printf__
, 3, 4)))
222 if (context
&& context
->hcontext
)
223 heim_vdebug(context
->hcontext
, level
, fmt
, ap
);
227 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
228 _krb5_have_debug(krb5_context context
, int level
)
230 if (context
== NULL
|| context
->hcontext
== NULL
)
232 return heim_have_debug(context
->hcontext
, level
);
235 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
236 krb5_have_debug(krb5_context context
, int level
)
238 return _krb5_have_debug(context
, level
);
241 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
242 krb5_set_debug_dest(krb5_context context
, const char *program
,
243 const char *log_spec
)
245 return heim_add_debug_dest(context
->hcontext
, program
, log_spec
);
248 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
249 krb5_set_log_dest(krb5_context context
, krb5_log_facility
*fac
)
251 return heim_set_log_dest(context
->hcontext
, fac
);