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 __RCSID("$Heimdal: warn.c 19086 2006-11-21 08:06:40Z lha $"
40 static krb5_error_code
_warnerr(krb5_context context
, int do_errtext
,
41 krb5_error_code code
, int level
, const char *fmt
, va_list ap
)
42 __attribute__((__format__(__printf__
, 5, 0)));
44 static krb5_error_code
45 _warnerr(krb5_context context
, int do_errtext
,
46 krb5_error_code code
, int level
, const char *fmt
, va_list ap
)
49 const char *args
[2], **arg
;
53 args
[0] = args
[1] = NULL
;
56 strlcat(xfmt
, "%s", sizeof(xfmt
));
58 strlcat(xfmt
, ": ", sizeof(xfmt
));
59 vasprintf(&msg
, fmt
, ap
);
64 if(context
&& do_errtext
){
67 strlcat(xfmt
, "%s", sizeof(xfmt
));
69 err_str
= krb5_get_error_string(context
);
70 if (err_str
!= NULL
) {
73 err_msg
= krb5_get_err_text(context
, code
);
77 *arg
++ = "<unknown error>";
81 if(context
&& context
->warn_dest
)
82 krb5_log(context
, context
->warn_dest
, level
, xfmt
, args
[0], args
[1]);
84 warnx(xfmt
, args
[0], args
[1]);
90 #define FUNC(ETEXT, CODE, LEVEL) \
91 krb5_error_code ret; \
94 ret = _warnerr(context, ETEXT, CODE, LEVEL, fmt, ap); \
98 #define __attribute__(X)
100 krb5_error_code KRB5_LIB_FUNCTION
101 krb5_vwarn(krb5_context context
, krb5_error_code code
,
102 const char *fmt
, va_list ap
)
103 __attribute__ ((format (printf
, 3, 0)))
105 return _warnerr(context
, 1, code
, 1, fmt
, ap
);
109 krb5_error_code KRB5_LIB_FUNCTION
110 krb5_warn(krb5_context context
, krb5_error_code code
, const char *fmt
, ...)
111 __attribute__ ((format (printf
, 3, 4)))
117 krb5_error_code KRB5_LIB_FUNCTION
118 krb5_vwarnx(krb5_context context
, const char *fmt
, va_list ap
)
119 __attribute__ ((format (printf
, 2, 0)))
121 return _warnerr(context
, 0, 0, 1, fmt
, ap
);
124 krb5_error_code KRB5_LIB_FUNCTION
125 krb5_warnx(krb5_context context
, const char *fmt
, ...)
126 __attribute__ ((format (printf
, 2, 3)))
132 krb5_error_code KRB5_LIB_FUNCTION
133 krb5_verr(krb5_context context
, int eval
, krb5_error_code code
,
134 const char *fmt
, va_list ap
)
135 __attribute__ ((noreturn
, format (printf
, 4, 0)))
137 _warnerr(context
, 1, code
, 0, fmt
, ap
);
142 krb5_error_code KRB5_LIB_FUNCTION
143 krb5_err(krb5_context context
, int eval
, krb5_error_code code
,
144 const char *fmt
, ...)
145 __attribute__ ((noreturn
, format (printf
, 4, 5)))
151 krb5_error_code KRB5_LIB_FUNCTION
152 krb5_verrx(krb5_context context
, int eval
, const char *fmt
, va_list ap
)
153 __attribute__ ((noreturn
, format (printf
, 3, 0)))
155 _warnerr(context
, 0, 0, 0, fmt
, ap
);
159 krb5_error_code KRB5_LIB_FUNCTION
160 krb5_errx(krb5_context context
, int eval
, const char *fmt
, ...)
161 __attribute__ ((noreturn
, format (printf
, 3, 4)))
167 krb5_error_code KRB5_LIB_FUNCTION
168 krb5_vabort(krb5_context context
, krb5_error_code code
,
169 const char *fmt
, va_list ap
)
170 __attribute__ ((noreturn
, format (printf
, 3, 0)))
172 _warnerr(context
, 1, code
, 0, fmt
, ap
);
177 krb5_error_code KRB5_LIB_FUNCTION
178 krb5_abort(krb5_context context
, krb5_error_code code
, const char *fmt
, ...)
179 __attribute__ ((noreturn
, format (printf
, 3, 4)))
185 krb5_error_code KRB5_LIB_FUNCTION
186 krb5_vabortx(krb5_context context
, const char *fmt
, va_list ap
)
187 __attribute__ ((noreturn
, format (printf
, 2, 0)))
189 _warnerr(context
, 0, 0, 0, fmt
, ap
);
193 krb5_error_code KRB5_LIB_FUNCTION
194 krb5_abortx(krb5_context context
, const char *fmt
, ...)
195 __attribute__ ((noreturn
, format (printf
, 2, 3)))
201 krb5_error_code KRB5_LIB_FUNCTION
202 krb5_set_warn_dest(krb5_context context
, krb5_log_facility
*fac
)
204 context
->warn_dest
= fac
;
208 krb5_log_facility
* KRB5_LIB_FUNCTION
209 krb5_get_warn_dest(krb5_context context
)
211 return context
->warn_dest
;