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