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