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