xref: /illumos-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/krb/kerrs.c (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1*54925bf6Swillf /*
2*54925bf6Swillf  * lib/krb5/krb/kerrs.c
3*54925bf6Swillf  *
4*54925bf6Swillf  * Copyright 2006 Massachusetts Institute of Technology.
5*54925bf6Swillf  * All Rights Reserved.
6*54925bf6Swillf  *
7*54925bf6Swillf  * Export of this software from the United States of America may
8*54925bf6Swillf  *   require a specific license from the United States Government.
9*54925bf6Swillf  *   It is the responsibility of any person or organization contemplating
10*54925bf6Swillf  *   export to obtain such a license before exporting.
11*54925bf6Swillf  *
12*54925bf6Swillf  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13*54925bf6Swillf  * distribute this software and its documentation for any purpose and
14*54925bf6Swillf  * without fee is hereby granted, provided that the above copyright
15*54925bf6Swillf  * notice appear in all copies and that both that copyright notice and
16*54925bf6Swillf  * this permission notice appear in supporting documentation, and that
17*54925bf6Swillf  * the name of M.I.T. not be used in advertising or publicity pertaining
18*54925bf6Swillf  * to distribution of the software without specific, written prior
19*54925bf6Swillf  * permission.  Furthermore if you modify this software you must label
20*54925bf6Swillf  * your software as modified software and not distribute it in such a
21*54925bf6Swillf  * fashion that it might be confused with the original M.I.T. software.
22*54925bf6Swillf  * M.I.T. makes no representations about the suitability of
23*54925bf6Swillf  * this software for any purpose.  It is provided "as is" without express
24*54925bf6Swillf  * or implied warranty.
25*54925bf6Swillf  *
26*54925bf6Swillf  * error-message functions
27*54925bf6Swillf  */
28*54925bf6Swillf #include <stdarg.h>
29*54925bf6Swillf #include "k5-int.h"
30*54925bf6Swillf 
31*54925bf6Swillf #ifdef DEBUG
32*54925bf6Swillf static int error_message_debug = 0;
33*54925bf6Swillf #ifndef ERROR_MESSAGE_DEBUG
34*54925bf6Swillf #define ERROR_MESSAGE_DEBUG() (error_message_debug != 0)
35*54925bf6Swillf #endif
36*54925bf6Swillf #endif
37*54925bf6Swillf 
38*54925bf6Swillf void KRB5_CALLCONV_C
krb5_set_error_message(krb5_context ctx,krb5_error_code code,const char * fmt,...)39*54925bf6Swillf krb5_set_error_message (krb5_context ctx, krb5_error_code code,
40*54925bf6Swillf 			const char *fmt, ...)
41*54925bf6Swillf {
42*54925bf6Swillf     va_list args;
43*54925bf6Swillf     if (ctx == NULL)
44*54925bf6Swillf 	return;
45*54925bf6Swillf     va_start (args, fmt);
46*54925bf6Swillf #ifdef DEBUG
47*54925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
48*54925bf6Swillf 	fprintf(stderr,
49*54925bf6Swillf 		"krb5_set_error_message(ctx=%p/err=%p, code=%ld, ...)\n",
50*54925bf6Swillf 		ctx, &ctx->err, (long) code);
51*54925bf6Swillf #endif
52*54925bf6Swillf     krb5int_vset_error (&ctx->err, code, fmt, args);
53*54925bf6Swillf #ifdef DEBUG
54*54925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
55*54925bf6Swillf 	fprintf(stderr, "->%s\n", ctx->err.msg);
56*54925bf6Swillf #endif
57*54925bf6Swillf     va_end (args);
58*54925bf6Swillf }
59*54925bf6Swillf 
60*54925bf6Swillf void KRB5_CALLCONV
krb5_vset_error_message(krb5_context ctx,krb5_error_code code,const char * fmt,va_list args)61*54925bf6Swillf krb5_vset_error_message (krb5_context ctx, krb5_error_code code,
62*54925bf6Swillf 			 const char *fmt, va_list args)
63*54925bf6Swillf {
64*54925bf6Swillf #ifdef DEBUG
65*54925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
66*54925bf6Swillf 	fprintf(stderr, "krb5_vset_error_message(ctx=%p, code=%ld, ...)\n",
67*54925bf6Swillf 		ctx, (long) code);
68*54925bf6Swillf #endif
69*54925bf6Swillf     if (ctx == NULL)
70*54925bf6Swillf 	return;
71*54925bf6Swillf     krb5int_vset_error (&ctx->err, code, fmt, args);
72*54925bf6Swillf #ifdef DEBUG
73*54925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
74*54925bf6Swillf 	fprintf(stderr, "->%s\n", ctx->err.msg);
75*54925bf6Swillf #endif
76*54925bf6Swillf }
77*54925bf6Swillf 
78*54925bf6Swillf const char * KRB5_CALLCONV
krb5_get_error_message(krb5_context ctx,krb5_error_code code)79*54925bf6Swillf krb5_get_error_message (krb5_context ctx, krb5_error_code code)
80*54925bf6Swillf {
81*54925bf6Swillf #ifdef DEBUG
82*54925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
83*54925bf6Swillf 	fprintf(stderr, "krb5_get_error_message(%p, %ld)\n", ctx, (long) code);
84*54925bf6Swillf #endif
85*54925bf6Swillf     if (ctx == NULL)
86*54925bf6Swillf 	return error_message(code);
87*54925bf6Swillf     return krb5int_get_error (&ctx->err, code);
88*54925bf6Swillf }
89*54925bf6Swillf 
90*54925bf6Swillf void KRB5_CALLCONV
krb5_free_error_message(krb5_context ctx,const char * msg)91*54925bf6Swillf krb5_free_error_message (krb5_context ctx, const char *msg)
92*54925bf6Swillf {
93*54925bf6Swillf #ifdef DEBUG
94*54925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
95*54925bf6Swillf 	fprintf(stderr, "krb5_free_error_message(%p, %p)\n", ctx, msg);
96*54925bf6Swillf #endif
97*54925bf6Swillf     if (ctx == NULL)
98*54925bf6Swillf 	return;
99*54925bf6Swillf     krb5int_free_error (&ctx->err, msg);
100*54925bf6Swillf }
101*54925bf6Swillf 
102*54925bf6Swillf void KRB5_CALLCONV
krb5_clear_error_message(krb5_context ctx)103*54925bf6Swillf krb5_clear_error_message (krb5_context ctx)
104*54925bf6Swillf {
105*54925bf6Swillf #ifdef DEBUG
106*54925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
107*54925bf6Swillf 	fprintf(stderr, "krb5_clear_error_message(%p)\n", ctx);
108*54925bf6Swillf #endif
109*54925bf6Swillf     if (ctx == NULL)
110*54925bf6Swillf 	return;
111*54925bf6Swillf     krb5int_clear_error (&ctx->err);
112*54925bf6Swillf }
113