15e01956fSGlenn Barry /*
25e01956fSGlenn Barry  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
35e01956fSGlenn Barry  */
45e01956fSGlenn Barry /*
55e01956fSGlenn Barry  * lib/krb5/krb/kerrs.c
65e01956fSGlenn Barry  *
75e01956fSGlenn Barry  * Copyright 2006 Massachusetts Institute of Technology.
85e01956fSGlenn Barry  * All Rights Reserved.
95e01956fSGlenn Barry  *
105e01956fSGlenn Barry  * Export of this software from the United States of America may
115e01956fSGlenn Barry  *   require a specific license from the United States Government.
125e01956fSGlenn Barry  *   It is the responsibility of any person or organization contemplating
135e01956fSGlenn Barry  *   export to obtain such a license before exporting.
14*55fea89dSDan Cross  *
155e01956fSGlenn Barry  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
165e01956fSGlenn Barry  * distribute this software and its documentation for any purpose and
175e01956fSGlenn Barry  * without fee is hereby granted, provided that the above copyright
185e01956fSGlenn Barry  * notice appear in all copies and that both that copyright notice and
195e01956fSGlenn Barry  * this permission notice appear in supporting documentation, and that
205e01956fSGlenn Barry  * the name of M.I.T. not be used in advertising or publicity pertaining
215e01956fSGlenn Barry  * to distribution of the software without specific, written prior
225e01956fSGlenn Barry  * permission.  Furthermore if you modify this software you must label
235e01956fSGlenn Barry  * your software as modified software and not distribute it in such a
245e01956fSGlenn Barry  * fashion that it might be confused with the original M.I.T. software.
255e01956fSGlenn Barry  * M.I.T. makes no representations about the suitability of
265e01956fSGlenn Barry  * this software for any purpose.  It is provided "as is" without express
275e01956fSGlenn Barry  * or implied warranty.
285e01956fSGlenn Barry  *
295e01956fSGlenn Barry  * error-message functions
305e01956fSGlenn Barry  */
315e01956fSGlenn Barry #include        <sys/param.h>
325e01956fSGlenn Barry #include        <unistd.h>
335e01956fSGlenn Barry #include        <assert.h>
345e01956fSGlenn Barry #include        <stdio.h>
355e01956fSGlenn Barry #include        <stdlib.h>
365e01956fSGlenn Barry #include        <string.h>
375e01956fSGlenn Barry #include        <k5-int.h>
385e01956fSGlenn Barry #include        <krb5.h>
395e01956fSGlenn Barry #include        <mglueP.h>
405e01956fSGlenn Barry #include        "gssapiP_spnego.h"
415e01956fSGlenn Barry #include        "gssapiP_generic.h"
425e01956fSGlenn Barry #include        <gssapi_err_generic.h>
435e01956fSGlenn Barry 
445e01956fSGlenn Barry #ifdef DEBUG
455e01956fSGlenn Barry static int error_message_debug = 0;
465e01956fSGlenn Barry #ifndef ERROR_MESSAGE_DEBUG
475e01956fSGlenn Barry #define ERROR_MESSAGE_DEBUG() (error_message_debug != 0)
485e01956fSGlenn Barry #endif
495e01956fSGlenn Barry #endif
505e01956fSGlenn Barry 
515e01956fSGlenn Barry void
spnego_set_error_message(spnego_gss_ctx_id_t ctx,spnego_error_code code,const char * fmt,...)525e01956fSGlenn Barry spnego_set_error_message (spnego_gss_ctx_id_t ctx, spnego_error_code code,
535e01956fSGlenn Barry 			const char *fmt, ...)
545e01956fSGlenn Barry {
555e01956fSGlenn Barry     va_list args;
565e01956fSGlenn Barry     if (ctx == NULL)
575e01956fSGlenn Barry 	return;
585e01956fSGlenn Barry     va_start (args, fmt);
595e01956fSGlenn Barry #ifdef DEBUG
605e01956fSGlenn Barry     if (ERROR_MESSAGE_DEBUG())
615e01956fSGlenn Barry 	fprintf(stderr,
625e01956fSGlenn Barry 		"spnego_set_error_message(ctx=%p/err=%p, code=%ld, ...)\n",
635e01956fSGlenn Barry 		ctx, &ctx->err, (long) code);
645e01956fSGlenn Barry #endif
655e01956fSGlenn Barry     krb5int_vset_error (&ctx->err, code, fmt, args);
665e01956fSGlenn Barry #ifdef DEBUG
675e01956fSGlenn Barry     if (ERROR_MESSAGE_DEBUG())
685e01956fSGlenn Barry 	fprintf(stderr, "->%s\n", ctx->err.msg);
695e01956fSGlenn Barry #endif
705e01956fSGlenn Barry     va_end (args);
715e01956fSGlenn Barry }
725e01956fSGlenn Barry 
735e01956fSGlenn Barry void
spnego_vset_error_message(spnego_gss_ctx_id_t ctx,spnego_error_code code,const char * fmt,va_list args)745e01956fSGlenn Barry spnego_vset_error_message (spnego_gss_ctx_id_t ctx, spnego_error_code code,
755e01956fSGlenn Barry 			 const char *fmt, va_list args)
765e01956fSGlenn Barry {
775e01956fSGlenn Barry #ifdef DEBUG
785e01956fSGlenn Barry     if (ERROR_MESSAGE_DEBUG())
795e01956fSGlenn Barry 	fprintf(stderr, "spnego_vset_error_message(ctx=%p, code=%ld, ...)\n",
805e01956fSGlenn Barry 		ctx, (long) code);
815e01956fSGlenn Barry #endif
825e01956fSGlenn Barry     if (ctx == NULL)
835e01956fSGlenn Barry 	return;
845e01956fSGlenn Barry     krb5int_vset_error (&ctx->err, code, fmt, args);
855e01956fSGlenn Barry #ifdef DEBUG
865e01956fSGlenn Barry     if (ERROR_MESSAGE_DEBUG())
875e01956fSGlenn Barry 	fprintf(stderr, "->%s\n", ctx->err.msg);
885e01956fSGlenn Barry #endif
895e01956fSGlenn Barry }
905e01956fSGlenn Barry 
915e01956fSGlenn Barry const char *
spnego_get_error_message(spnego_gss_ctx_id_t ctx,spnego_error_code code)925e01956fSGlenn Barry spnego_get_error_message (spnego_gss_ctx_id_t ctx, spnego_error_code code)
935e01956fSGlenn Barry {
945e01956fSGlenn Barry #ifdef DEBUG
955e01956fSGlenn Barry     if (ERROR_MESSAGE_DEBUG())
965e01956fSGlenn Barry 	fprintf(stderr, "spnego_get_error_message(%p, %ld)\n", ctx, (long) code);
975e01956fSGlenn Barry #endif
985e01956fSGlenn Barry     if (ctx == NULL)
995e01956fSGlenn Barry 	return error_message(code);
1005e01956fSGlenn Barry     return krb5int_get_error (&ctx->err, code);
1015e01956fSGlenn Barry }
1025e01956fSGlenn Barry 
1035e01956fSGlenn Barry void
spnego_free_error_message(spnego_gss_ctx_id_t ctx,const char * msg)1045e01956fSGlenn Barry spnego_free_error_message (spnego_gss_ctx_id_t ctx, const char *msg)
1055e01956fSGlenn Barry {
1065e01956fSGlenn Barry #ifdef DEBUG
1075e01956fSGlenn Barry     if (ERROR_MESSAGE_DEBUG())
1085e01956fSGlenn Barry 	fprintf(stderr, "spnego_free_error_message(%p, %p)\n", ctx, msg);
1095e01956fSGlenn Barry #endif
1105e01956fSGlenn Barry     if (ctx == NULL)
1115e01956fSGlenn Barry 	return;
1125e01956fSGlenn Barry     krb5int_free_error (&ctx->err, msg);
1135e01956fSGlenn Barry }
1145e01956fSGlenn Barry 
1155e01956fSGlenn Barry void
spnego_clear_error_message(spnego_gss_ctx_id_t ctx)1165e01956fSGlenn Barry spnego_clear_error_message (spnego_gss_ctx_id_t ctx)
1175e01956fSGlenn Barry {
1185e01956fSGlenn Barry #ifdef DEBUG
1195e01956fSGlenn Barry     if (ERROR_MESSAGE_DEBUG())
1205e01956fSGlenn Barry 	fprintf(stderr, "spnego_clear_error_message(%p)\n", ctx);
1215e01956fSGlenn Barry #endif
1225e01956fSGlenn Barry     if (ctx == NULL)
1235e01956fSGlenn Barry 	return;
1245e01956fSGlenn Barry     krb5int_clear_error (&ctx->err);
1255e01956fSGlenn Barry }
126