2 * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "krb5_locl.h"
37 static krb5_error_code
_warnerr(krb5_context context
, int do_errtext
,
38 krb5_error_code code
, int level
, const char *fmt
, va_list ap
)
39 __attribute__((__format__(__printf__
, 5, 0)));
41 static krb5_error_code
42 _warnerr(krb5_context context
, int do_errtext
,
43 krb5_error_code code
, int level
, const char *fmt
, va_list ap
)
46 const char *args
[2], **arg
;
48 const char *err_str
= NULL
;
50 args
[0] = args
[1] = NULL
;
53 strlcat(xfmt
, "%s", sizeof(xfmt
));
55 strlcat(xfmt
, ": ", sizeof(xfmt
));
56 vasprintf(&msg
, fmt
, ap
);
61 if(context
&& do_errtext
){
64 strlcat(xfmt
, "%s", sizeof(xfmt
));
66 err_str
= krb5_get_error_message(context
, code
);
67 if (err_str
!= NULL
) {
70 *arg
= "<unknown error>";
74 if(context
&& context
->warn_dest
)
75 krb5_log(context
, context
->warn_dest
, level
, xfmt
, args
[0], args
[1]);
77 warnx(xfmt
, args
[0], args
[1]);
79 krb5_free_error_message(context
, err_str
);
83 #define FUNC(ETEXT, CODE, LEVEL) \
84 krb5_error_code ret; \
87 ret = _warnerr(context, ETEXT, CODE, LEVEL, fmt, ap); \
91 #define __attribute__(X)
94 * Log a warning to the log, default stderr, include the error from
97 * @param context A Kerberos 5 context.
98 * @param code error code of the last error
99 * @param fmt message to print
100 * @param ap arguments
102 * @ingroup krb5_error
105 krb5_error_code KRB5_LIB_FUNCTION
106 krb5_vwarn(krb5_context context
, krb5_error_code code
,
107 const char *fmt
, va_list ap
)
108 __attribute__ ((format (printf
, 3, 0)))
110 return _warnerr(context
, 1, code
, 1, fmt
, ap
);
114 * Log a warning to the log, default stderr, include the error from
117 * @param context A Kerberos 5 context.
118 * @param code error code of the last error
119 * @param fmt message to print
121 * @ingroup krb5_error
124 krb5_error_code KRB5_LIB_FUNCTION
125 krb5_warn(krb5_context context
, krb5_error_code code
, const char *fmt
, ...)
126 __attribute__ ((format (printf
, 3, 4)))
133 * Log a warning to the log, default stderr.
135 * @param context A Kerberos 5 context.
136 * @param fmt message to print
137 * @param ap arguments
139 * @ingroup krb5_error
142 krb5_error_code KRB5_LIB_FUNCTION
143 krb5_vwarnx(krb5_context context
, const char *fmt
, va_list ap
)
144 __attribute__ ((format (printf
, 2, 0)))
146 return _warnerr(context
, 0, 0, 1, fmt
, ap
);
150 * Log a warning to the log, default stderr.
152 * @param context A Kerberos 5 context.
153 * @param fmt message to print
155 * @ingroup krb5_error
158 krb5_error_code KRB5_LIB_FUNCTION
159 krb5_warnx(krb5_context context
, const char *fmt
, ...)
160 __attribute__ ((format (printf
, 2, 3)))
167 * Log a warning to the log, default stderr, include bthe error from
168 * the last failure and then exit.
170 * @param context A Kerberos 5 context
171 * @param eval the exit code to exit with
172 * @param code error code of the last error
173 * @param fmt message to print
174 * @param ap arguments
176 * @ingroup krb5_error
179 krb5_error_code KRB5_LIB_FUNCTION
180 krb5_verr(krb5_context context
, int eval
, krb5_error_code code
,
181 const char *fmt
, va_list ap
)
182 __attribute__ ((noreturn
, format (printf
, 4, 0)))
184 _warnerr(context
, 1, code
, 0, fmt
, ap
);
189 * Log a warning to the log, default stderr, include bthe error from
190 * the last failure and then exit.
192 * @param context A Kerberos 5 context
193 * @param eval the exit code to exit with
194 * @param code error code of the last error
195 * @param fmt message to print
197 * @ingroup krb5_error
200 krb5_error_code KRB5_LIB_FUNCTION
201 krb5_err(krb5_context context
, int eval
, krb5_error_code code
,
202 const char *fmt
, ...)
203 __attribute__ ((noreturn
, format (printf
, 4, 5)))
210 * Log a warning to the log, default stderr, and then exit.
212 * @param context A Kerberos 5 context
213 * @param eval the exit code to exit with
214 * @param fmt message to print
215 * @param ap arguments
217 * @ingroup krb5_error
220 krb5_error_code KRB5_LIB_FUNCTION
221 krb5_verrx(krb5_context context
, int eval
, const char *fmt
, va_list ap
)
222 __attribute__ ((noreturn
, format (printf
, 3, 0)))
224 _warnerr(context
, 0, 0, 0, fmt
, ap
);
229 * Log a warning to the log, default stderr, and then exit.
231 * @param context A Kerberos 5 context
232 * @param eval the exit code to exit with
233 * @param fmt message to print
235 * @ingroup krb5_error
238 krb5_error_code KRB5_LIB_FUNCTION
239 krb5_errx(krb5_context context
, int eval
, const char *fmt
, ...)
240 __attribute__ ((noreturn
, format (printf
, 3, 4)))
247 * Log a warning to the log, default stderr, include bthe error from
248 * the last failure and then abort.
250 * @param context A Kerberos 5 context
251 * @param code error code of the last error
252 * @param fmt message to print
253 * @param ap arguments
255 * @ingroup krb5_error
258 krb5_error_code KRB5_LIB_FUNCTION
259 krb5_vabort(krb5_context context
, krb5_error_code code
,
260 const char *fmt
, va_list ap
)
261 __attribute__ ((noreturn
, format (printf
, 3, 0)))
263 _warnerr(context
, 1, code
, 0, fmt
, ap
);
268 * Log a warning to the log, default stderr, include the error from
269 * the last failure and then abort.
271 * @param context A Kerberos 5 context
272 * @param code error code of the last error
273 * @param fmt message to print
275 * @ingroup krb5_error
278 krb5_error_code KRB5_LIB_FUNCTION
279 krb5_abort(krb5_context context
, krb5_error_code code
, const char *fmt
, ...)
280 __attribute__ ((noreturn
, format (printf
, 3, 4)))
286 krb5_error_code KRB5_LIB_FUNCTION
287 krb5_vabortx(krb5_context context
, const char *fmt
, va_list ap
)
288 __attribute__ ((noreturn
, format (printf
, 2, 0)))
290 _warnerr(context
, 0, 0, 0, fmt
, ap
);
295 * Log a warning to the log, default stderr, and then abort.
297 * @param context A Kerberos 5 context
298 * @param code error code of the last error
299 * @param fmt message to print
301 * @ingroup krb5_error
304 krb5_error_code KRB5_LIB_FUNCTION
305 krb5_abortx(krb5_context context
, const char *fmt
, ...)
306 __attribute__ ((noreturn
, format (printf
, 2, 3)))
313 * Set the default logging facility.
315 * @param context A Kerberos 5 context
316 * @param fac Facility to use for logging.
318 * @ingroup krb5_error
321 krb5_error_code KRB5_LIB_FUNCTION
322 krb5_set_warn_dest(krb5_context context
, krb5_log_facility
*fac
)
324 context
->warn_dest
= fac
;
329 * Get the default logging facility.
331 * @param context A Kerberos 5 context
333 * @ingroup krb5_error
336 krb5_log_facility
* KRB5_LIB_FUNCTION
337 krb5_get_warn_dest(krb5_context context
)
339 return context
->warn_dest
;