2 * Copyright (c) 2001, 2003, 2005 - 2020 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 #define __attribute__(x)
40 * Clears the error message from the Kerberos 5 context.
42 * @param context The Kerberos 5 context to clear
47 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
48 krb5_clear_error_message(krb5_context context
)
50 heim_clear_error_message(context
->hcontext
);
54 * Set the context full error string for a specific error code.
55 * The error that is stored should be internationalized.
57 * The if context is NULL, no error string is stored.
59 * @param context Kerberos 5 context
60 * @param ret The error code
61 * @param fmt Error string for the error code
62 * @param ... printf(3) style parameters.
67 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
68 krb5_set_error_message(krb5_context context
, krb5_error_code ret
,
70 __attribute__ ((__format__ (__printf__
, 3, 4)))
75 krb5_vset_error_message (context
, ret
, fmt
, ap
);
80 * Set the context full error string for a specific error code.
82 * The if context is NULL, no error string is stored.
84 * @param context Kerberos 5 context
85 * @param ret The error code
86 * @param fmt Error string for the error code
87 * @param args printf(3) style parameters.
93 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
94 krb5_vset_error_message(krb5_context context
, krb5_error_code ret
,
95 const char *fmt
, va_list args
)
96 __attribute__ ((__format__ (__printf__
, 3, 0)))
101 heim_vset_error_message(context
->hcontext
, ret
, fmt
, args
);
102 msg
= heim_get_error_message(context
->hcontext
, ret
);
104 _krb5_debug(context
, 100, "error message: %s: %d", msg
, ret
);
105 heim_free_error_message(context
->hcontext
, msg
);
111 * Prepend the context full error string for a specific error code.
112 * The error that is stored should be internationalized.
114 * The if context is NULL, no error string is stored.
116 * @param context Kerberos 5 context
117 * @param ret The error code
118 * @param fmt Error string for the error code
119 * @param ... printf(3) style parameters.
121 * @ingroup krb5_error
124 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
125 krb5_prepend_error_message(krb5_context context
, krb5_error_code ret
,
126 const char *fmt
, ...)
127 __attribute__ ((__format__ (__printf__
, 3, 4)))
132 krb5_vprepend_error_message(context
, ret
, fmt
, ap
);
137 * Prepend the contexts's full error string for a specific error code.
139 * The if context is NULL, no error string is stored.
141 * @param context Kerberos 5 context
142 * @param ret The error code
143 * @param fmt Error string for the error code
144 * @param args printf(3) style parameters.
146 * @ingroup krb5_error
149 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
150 krb5_vprepend_error_message(krb5_context context
, krb5_error_code ret
,
151 const char *fmt
, va_list args
)
152 __attribute__ ((__format__ (__printf__
, 3, 0)))
155 heim_vprepend_error_message(context
->hcontext
, ret
, fmt
, args
);
159 * Return the error message for `code' in context. On memory
160 * allocation error the function returns NULL.
162 * @param context Kerberos 5 context
163 * @param code Error code related to the error
165 * @return an error string, needs to be freed with
166 * krb5_free_error_message(). The functions return NULL on error.
168 * @ingroup krb5_error
171 KRB5_LIB_FUNCTION
const char * KRB5_LIB_CALL
172 krb5_get_error_message(krb5_context context
, krb5_error_code code
)
174 const char *cstr
= NULL
;
177 return strdup("Success");
180 * The MIT version of this function ignores the krb5_context
181 * and several widely deployed applications call krb5_get_error_message()
182 * with a NULL context in order to translate an error code as a
183 * replacement for error_message(). Another reason a NULL context
184 * might be provided is if the krb5_init_context() call itself
187 if (context
== NULL
&& krb5_init_context(&context
) == 0) {
188 cstr
= heim_get_error_message(context
->hcontext
, code
);
189 krb5_free_context(context
);
190 } else if (context
) {
191 cstr
= heim_get_error_message(context
->hcontext
, code
);
193 cstr
= heim_get_error_message(NULL
, code
);
200 * Free the error message returned by krb5_get_error_message().
202 * @param context Kerberos context
203 * @param msg error message to free, returned byg
204 * krb5_get_error_message().
206 * @ingroup krb5_error
209 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
210 krb5_free_error_message(krb5_context context
, const char *msg
)
212 heim_free_error_message(context
? context
->hcontext
: NULL
, msg
);
217 * Return the error string for the error code. The caller must not
220 * This function is deprecated since its not threadsafe.
222 * @param context Kerberos 5 context.
223 * @param code Kerberos error code.
225 * @return the error message matching code
230 KRB5_LIB_FUNCTION
const char* KRB5_LIB_CALL
231 krb5_get_err_text(krb5_context context
, krb5_error_code code
)
232 KRB5_DEPRECATED_FUNCTION("Use krb5_get_error_message instead")
234 return krb5_get_error_message(context
, code
);