/src/samba/third_party/heimdal/lib/krb5/log.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 1997-2006 Kungliga Tekniska Högskolan |
3 | | * (Royal Institute of Technology, Stockholm, Sweden). |
4 | | * All rights reserved. |
5 | | * |
6 | | * Portions Copyright (c) 2009 Apple Inc. All rights reserved. |
7 | | * |
8 | | * Redistribution and use in source and binary forms, with or without |
9 | | * modification, are permitted provided that the following conditions |
10 | | * are met: |
11 | | * |
12 | | * 1. Redistributions of source code must retain the above copyright |
13 | | * notice, this list of conditions and the following disclaimer. |
14 | | * |
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. |
18 | | * |
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. |
22 | | * |
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 |
33 | | * SUCH DAMAGE. |
34 | | */ |
35 | | |
36 | | #include "krb5_locl.h" |
37 | | #include <assert.h> |
38 | | #include <vis.h> |
39 | | |
40 | | KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL |
41 | | krb5_initlog(krb5_context context, |
42 | | const char *program, |
43 | | krb5_log_facility **fac) |
44 | 0 | { |
45 | 0 | return heim_initlog(context->hcontext, program, fac); |
46 | 0 | } |
47 | | |
48 | | struct krb5_addlog_func_wrapper { |
49 | | krb5_context context; |
50 | | krb5_log_log_func_t log_func; |
51 | | krb5_log_close_func_t close_func; |
52 | | void *data; |
53 | | }; |
54 | | |
55 | | static void HEIM_CALLCONV |
56 | | krb5_addlog_func_wrapper_log(heim_context hcontext, |
57 | | const char *prefix, |
58 | | const char *msg, |
59 | | void *data) |
60 | 0 | { |
61 | 0 | struct krb5_addlog_func_wrapper *w = data; |
62 | |
|
63 | 0 | w->log_func(w->context, |
64 | 0 | prefix, |
65 | 0 | msg, |
66 | 0 | w->data); |
67 | 0 | } |
68 | | |
69 | | static void HEIM_CALLCONV |
70 | | krb5_addlog_func_wrapper_close(void *data) |
71 | 0 | { |
72 | 0 | struct krb5_addlog_func_wrapper *w = data; |
73 | |
|
74 | 0 | w->close_func(w->data); |
75 | 0 | free(w); |
76 | 0 | } |
77 | | |
78 | | KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL |
79 | | krb5_addlog_func(krb5_context context, |
80 | | krb5_log_facility *fac, |
81 | | int min, |
82 | | int max, |
83 | | krb5_log_log_func_t log_func, |
84 | | krb5_log_close_func_t close_func, |
85 | | void *data) |
86 | 0 | { |
87 | 0 | struct krb5_addlog_func_wrapper *w = NULL; |
88 | |
|
89 | 0 | w = calloc(1, sizeof(*w)); |
90 | 0 | if (w == NULL) |
91 | 0 | return krb5_enomem(context); |
92 | | |
93 | 0 | w->context = context; |
94 | 0 | w->log_func = log_func; |
95 | 0 | w->close_func = close_func; |
96 | 0 | w->data = data; |
97 | |
|
98 | 0 | return heim_addlog_func(context->hcontext, fac, min, max, |
99 | 0 | krb5_addlog_func_wrapper_log, |
100 | 0 | krb5_addlog_func_wrapper_close, |
101 | 0 | w); |
102 | 0 | } |
103 | | |
104 | | KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL |
105 | | krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *orig) |
106 | 0 | { |
107 | 0 | return heim_addlog_dest(context->hcontext, f, orig); |
108 | 0 | } |
109 | | |
110 | | |
111 | | KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL |
112 | | krb5_openlog(krb5_context context, |
113 | | const char *program, |
114 | | krb5_log_facility **fac) |
115 | 0 | { |
116 | 0 | krb5_error_code ret; |
117 | 0 | char **p; |
118 | |
|
119 | 0 | p = krb5_config_get_strings(context, NULL, "logging", program, NULL); |
120 | 0 | if (p == NULL) |
121 | 0 | p = krb5_config_get_strings(context, NULL, "logging", "default", NULL); |
122 | 0 | ret = heim_openlog(context->hcontext, program, (const char **)p, fac); |
123 | 0 | krb5_config_free_strings(p); |
124 | 0 | return ret; |
125 | 0 | } |
126 | | |
127 | | KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL |
128 | | krb5_closelog(krb5_context context, |
129 | | krb5_log_facility *fac) |
130 | 0 | { |
131 | 0 | heim_closelog(context->hcontext, fac); |
132 | 0 | return 0; |
133 | 0 | } |
134 | | |
135 | | #undef __attribute__ |
136 | | #define __attribute__(X) |
137 | | |
138 | | KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL |
139 | | krb5_vlog_msg(krb5_context context, |
140 | | krb5_log_facility *fac, |
141 | | char **reply, |
142 | | int level, |
143 | | const char *fmt, |
144 | | va_list ap) |
145 | | __attribute__ ((__format__ (__printf__, 5, 0))) |
146 | 0 | { |
147 | 0 | return heim_vlog_msg(context->hcontext, fac, reply, level, fmt, ap); |
148 | 0 | } |
149 | | |
150 | | KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL |
151 | | krb5_vlog(krb5_context context, |
152 | | krb5_log_facility *fac, |
153 | | int level, |
154 | | const char *fmt, |
155 | | va_list ap) |
156 | | __attribute__ ((__format__ (__printf__, 4, 0))) |
157 | 0 | { |
158 | 0 | return heim_vlog_msg(context->hcontext, fac, NULL, level, fmt, ap); |
159 | 0 | } |
160 | | |
161 | | KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL |
162 | | krb5_log_msg(krb5_context context, |
163 | | krb5_log_facility *fac, |
164 | | int level, |
165 | | char **reply, |
166 | | const char *fmt, |
167 | | ...) |
168 | | __attribute__ ((__format__ (__printf__, 5, 6))) |
169 | 0 | { |
170 | 0 | va_list ap; |
171 | 0 | krb5_error_code ret; |
172 | |
|
173 | 0 | va_start(ap, fmt); |
174 | 0 | ret = heim_vlog_msg(context->hcontext, fac, reply, level, fmt, ap); |
175 | 0 | va_end(ap); |
176 | 0 | return ret; |
177 | 0 | } |
178 | | |
179 | | |
180 | | KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL |
181 | | krb5_log(krb5_context context, |
182 | | krb5_log_facility *fac, |
183 | | int level, |
184 | | const char *fmt, |
185 | | ...) |
186 | | __attribute__ ((__format__ (__printf__, 4, 5))) |
187 | 0 | { |
188 | 0 | va_list ap; |
189 | 0 | krb5_error_code ret; |
190 | |
|
191 | 0 | va_start(ap, fmt); |
192 | 0 | ret = heim_vlog(context->hcontext, fac, level, fmt, ap); |
193 | 0 | va_end(ap); |
194 | 0 | return ret; |
195 | 0 | } |
196 | | |
197 | | void KRB5_LIB_FUNCTION |
198 | | _krb5_debug(krb5_context context, |
199 | | int level, |
200 | | const char *fmt, |
201 | | ...) |
202 | | __attribute__ ((__format__ (__printf__, 3, 4))) |
203 | 0 | { |
204 | 0 | va_list ap; |
205 | |
|
206 | 0 | va_start(ap, fmt); |
207 | 0 | if (context && context->hcontext) |
208 | 0 | heim_vdebug(context->hcontext, level, fmt, ap); |
209 | 0 | va_end(ap); |
210 | 0 | } |
211 | | |
212 | | void KRB5_LIB_FUNCTION |
213 | | krb5_debug(krb5_context context, |
214 | | int level, |
215 | | const char *fmt, |
216 | | ...) |
217 | | __attribute__ ((__format__ (__printf__, 3, 4))) |
218 | 0 | { |
219 | 0 | va_list ap; |
220 | |
|
221 | 0 | va_start(ap, fmt); |
222 | 0 | if (context && context->hcontext) |
223 | 0 | heim_vdebug(context->hcontext, level, fmt, ap); |
224 | 0 | va_end(ap); |
225 | 0 | } |
226 | | |
227 | | KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL |
228 | | _krb5_have_debug(krb5_context context, int level) |
229 | 0 | { |
230 | 0 | if (context == NULL || context->hcontext == NULL) |
231 | 0 | return 0; |
232 | 0 | return heim_have_debug(context->hcontext, level); |
233 | 0 | } |
234 | | |
235 | | KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL |
236 | | krb5_have_debug(krb5_context context, int level) |
237 | 0 | { |
238 | 0 | return _krb5_have_debug(context, level); |
239 | 0 | } |
240 | | |
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) |
244 | 0 | { |
245 | 0 | return heim_add_debug_dest(context->hcontext, program, log_spec); |
246 | 0 | } |
247 | | |
248 | | KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL |
249 | | krb5_set_log_dest(krb5_context context, krb5_log_facility *fac) |
250 | 0 | { |
251 | 0 | return heim_set_log_dest(context->hcontext, fac); |
252 | 0 | } |