154925bf6Swillf /*
254925bf6Swillf  * lib/krb5/krb/kerrs.c
354925bf6Swillf  *
454925bf6Swillf  * Copyright 2006 Massachusetts Institute of Technology.
554925bf6Swillf  * All Rights Reserved.
654925bf6Swillf  *
754925bf6Swillf  * Export of this software from the United States of America may
854925bf6Swillf  *   require a specific license from the United States Government.
954925bf6Swillf  *   It is the responsibility of any person or organization contemplating
1054925bf6Swillf  *   export to obtain such a license before exporting.
11*1da57d55SToomas Soome  *
1254925bf6Swillf  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
1354925bf6Swillf  * distribute this software and its documentation for any purpose and
1454925bf6Swillf  * without fee is hereby granted, provided that the above copyright
1554925bf6Swillf  * notice appear in all copies and that both that copyright notice and
1654925bf6Swillf  * this permission notice appear in supporting documentation, and that
1754925bf6Swillf  * the name of M.I.T. not be used in advertising or publicity pertaining
1854925bf6Swillf  * to distribution of the software without specific, written prior
1954925bf6Swillf  * permission.  Furthermore if you modify this software you must label
2054925bf6Swillf  * your software as modified software and not distribute it in such a
2154925bf6Swillf  * fashion that it might be confused with the original M.I.T. software.
2254925bf6Swillf  * M.I.T. makes no representations about the suitability of
2354925bf6Swillf  * this software for any purpose.  It is provided "as is" without express
2454925bf6Swillf  * or implied warranty.
2554925bf6Swillf  *
2654925bf6Swillf  * error-message functions
2754925bf6Swillf  */
2854925bf6Swillf #include <stdarg.h>
2954925bf6Swillf #include "k5-int.h"
3054925bf6Swillf 
3154925bf6Swillf #ifdef DEBUG
3254925bf6Swillf static int error_message_debug = 0;
3354925bf6Swillf #ifndef ERROR_MESSAGE_DEBUG
3454925bf6Swillf #define ERROR_MESSAGE_DEBUG() (error_message_debug != 0)
3554925bf6Swillf #endif
3654925bf6Swillf #endif
3754925bf6Swillf 
3854925bf6Swillf void KRB5_CALLCONV_C
krb5_set_error_message(krb5_context ctx,krb5_error_code code,const char * fmt,...)3954925bf6Swillf krb5_set_error_message (krb5_context ctx, krb5_error_code code,
4054925bf6Swillf 			const char *fmt, ...)
4154925bf6Swillf {
4254925bf6Swillf     va_list args;
4354925bf6Swillf     if (ctx == NULL)
4454925bf6Swillf 	return;
4554925bf6Swillf     va_start (args, fmt);
4654925bf6Swillf #ifdef DEBUG
4754925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
4854925bf6Swillf 	fprintf(stderr,
4954925bf6Swillf 		"krb5_set_error_message(ctx=%p/err=%p, code=%ld, ...)\n",
5054925bf6Swillf 		ctx, &ctx->err, (long) code);
5154925bf6Swillf #endif
5254925bf6Swillf     krb5int_vset_error (&ctx->err, code, fmt, args);
5354925bf6Swillf #ifdef DEBUG
5454925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
5554925bf6Swillf 	fprintf(stderr, "->%s\n", ctx->err.msg);
5654925bf6Swillf #endif
5754925bf6Swillf     va_end (args);
5854925bf6Swillf }
5954925bf6Swillf 
6054925bf6Swillf void KRB5_CALLCONV
krb5_vset_error_message(krb5_context ctx,krb5_error_code code,const char * fmt,va_list args)6154925bf6Swillf krb5_vset_error_message (krb5_context ctx, krb5_error_code code,
6254925bf6Swillf 			 const char *fmt, va_list args)
6354925bf6Swillf {
6454925bf6Swillf #ifdef DEBUG
6554925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
6654925bf6Swillf 	fprintf(stderr, "krb5_vset_error_message(ctx=%p, code=%ld, ...)\n",
6754925bf6Swillf 		ctx, (long) code);
6854925bf6Swillf #endif
6954925bf6Swillf     if (ctx == NULL)
7054925bf6Swillf 	return;
7154925bf6Swillf     krb5int_vset_error (&ctx->err, code, fmt, args);
7254925bf6Swillf #ifdef DEBUG
7354925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
7454925bf6Swillf 	fprintf(stderr, "->%s\n", ctx->err.msg);
7554925bf6Swillf #endif
7654925bf6Swillf }
7754925bf6Swillf 
7854925bf6Swillf const char * KRB5_CALLCONV
krb5_get_error_message(krb5_context ctx,krb5_error_code code)7954925bf6Swillf krb5_get_error_message (krb5_context ctx, krb5_error_code code)
8054925bf6Swillf {
8154925bf6Swillf #ifdef DEBUG
8254925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
8354925bf6Swillf 	fprintf(stderr, "krb5_get_error_message(%p, %ld)\n", ctx, (long) code);
8454925bf6Swillf #endif
8554925bf6Swillf     if (ctx == NULL)
8654925bf6Swillf 	return error_message(code);
8754925bf6Swillf     return krb5int_get_error (&ctx->err, code);
8854925bf6Swillf }
8954925bf6Swillf 
9054925bf6Swillf void KRB5_CALLCONV
krb5_free_error_message(krb5_context ctx,const char * msg)9154925bf6Swillf krb5_free_error_message (krb5_context ctx, const char *msg)
9254925bf6Swillf {
9354925bf6Swillf #ifdef DEBUG
9454925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
9554925bf6Swillf 	fprintf(stderr, "krb5_free_error_message(%p, %p)\n", ctx, msg);
9654925bf6Swillf #endif
9754925bf6Swillf     if (ctx == NULL)
9854925bf6Swillf 	return;
9954925bf6Swillf     krb5int_free_error (&ctx->err, msg);
10054925bf6Swillf }
10154925bf6Swillf 
10254925bf6Swillf void KRB5_CALLCONV
krb5_clear_error_message(krb5_context ctx)10354925bf6Swillf krb5_clear_error_message (krb5_context ctx)
10454925bf6Swillf {
10554925bf6Swillf #ifdef DEBUG
10654925bf6Swillf     if (ERROR_MESSAGE_DEBUG())
10754925bf6Swillf 	fprintf(stderr, "krb5_clear_error_message(%p)\n", ctx);
10854925bf6Swillf #endif
10954925bf6Swillf     if (ctx == NULL)
11054925bf6Swillf 	return;
11154925bf6Swillf     krb5int_clear_error (&ctx->err);
11254925bf6Swillf }
113