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