1 /* -*- mode: c; indent-tabs-mode: nil -*- */
3 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
6 * Copyright 1993 by OpenVision Technologies, Inc.
8 * Permission to use, copy, modify, distribute, and sell this software
9 * and its documentation for any purpose is hereby granted without fee,
10 * provided that the above copyright notice appears in all copies and
11 * that both that copyright notice and this permission notice appear in
12 * supporting documentation, and that the name of OpenVision not be used
13 * in advertising or publicity pertaining to distribution of the software
14 * without specific, written prior permission. OpenVision makes no
15 * representations about the suitability of this software for any
16 * purpose. It is provided "as is" without express or implied warranty.
18 * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
22 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24 * PERFORMANCE OF THIS SOFTWARE.
27 #include "gssapiP_krb5.h"
30 /* XXXX internationalization!! */
33 compare_OM_uint32 (OM_uint32 a
, OM_uint32 b
)
47 #include "error_map.h"
50 * AKA krb5_gss_get_error_message. See #define in gssapiP_krb5.h.
52 char *get_error_message(OM_uint32 minor_code
)
54 gsserrmap
*p
= k5_getspecific(K5_KEY_GSS_KRB5_ERROR_MESSAGE
);
58 fprintf(stderr
, "%s(%lu, p=%p)", __func__
, (unsigned long) minor_code
,
62 char **v
= gsserrmap_find(p
, minor_code
);
66 fprintf(stderr
, " FOUND!");
71 msg
= (char *)error_message((krb5_error_code
)minor_code
);
73 fprintf(stderr
, " -> %p/%s\n", (void *) msg
, msg
);
78 #define save_error_string_nocopy gss_krb5_save_error_string_nocopy
79 static int save_error_string_nocopy(OM_uint32 minor_code
, char *msg
)
85 fprintf(stderr
, "%s(%lu, %s)", __func__
, (unsigned long) minor_code
, msg
);
87 p
= k5_getspecific(K5_KEY_GSS_KRB5_ERROR_MESSAGE
);
89 p
= malloc(sizeof(*p
));
94 if (gsserrmap_init(p
) != 0) {
100 if (k5_setspecific(K5_KEY_GSS_KRB5_ERROR_MESSAGE
, p
) != 0) {
101 gsserrmap_destroy(p
);
108 ret
= gsserrmap_replace_or_insert(p
, minor_code
, msg
);
109 /* Solaris Kerberos */
111 gsserrmap_destroy(p
);
118 fprintf(stderr
, " p=%p %s\n", (void *)p
, ret
? "FAIL" : "SUCCESS");
122 void save_error_string(OM_uint32 minor_code
, char *msg
)
124 char *s
= strdup(msg
);
126 if (save_error_string_nocopy(minor_code
, s
) != 0)
130 void save_error_message(OM_uint32 minor_code
, const char *format
, ...)
136 va_start(ap
, format
);
137 n
= vasprintf(&s
, format
, ap
);
140 if (save_error_string_nocopy(minor_code
, s
) != 0)
144 void krb5_gss_save_error_info(OM_uint32 minor_code
, krb5_context ctx
)
149 fprintf(stderr
, "%s(%lu, ctx=%p)\n", __func__
,
150 (unsigned long) minor_code
, (void *)ctx
);
152 s
= (char *)krb5_get_error_message(ctx
, (krb5_error_code
)minor_code
);
154 fprintf(stderr
, "%s(%lu, ctx=%p) saving: %s\n", __func__
,
155 (unsigned long) minor_code
, (void *)ctx
, s
);
157 save_error_string(minor_code
, s
);
158 /* The get_error_message call above resets the error message in
159 ctx. Put it back, in case we make this call again *sigh*. */
160 krb5_set_error_message(ctx
, (krb5_error_code
)minor_code
, "%s", s
);
161 krb5_free_error_message(ctx
, s
);
163 void krb5_gss_delete_error_info(void *p
)
165 gsserrmap_destroy(p
);
171 krb5_gss_display_status(minor_status
, status_value
, status_type
,
172 mech_type
, message_context
, status_string
)
173 OM_uint32
*minor_status
;
174 OM_uint32 status_value
;
177 OM_uint32
*message_context
;
178 gss_buffer_t status_string
;
180 status_string
->length
= 0;
181 status_string
->value
= NULL
;
183 if ((mech_type
!= GSS_C_NULL_OID
) &&
184 !g_OID_equal(gss_mech_krb5
, mech_type
) &&
185 !g_OID_equal(gss_mech_krb5_old
, mech_type
)) {
187 return(GSS_S_BAD_MECH
);
190 if (status_type
== GSS_C_GSS_CODE
) {
191 return(g_display_major_status(minor_status
, status_value
,
192 message_context
, status_string
));
193 } else if (status_type
== GSS_C_MECH_CODE
) {
194 (void) gss_krb5int_initialize_library();
196 if (*message_context
) {
197 *minor_status
= (OM_uint32
) G_BAD_MSG_CTX
;
198 return(GSS_S_FAILURE
);
201 /* If this fails, there's not much we can do... */
202 /* Solaris Kerberos - cleaned-up/fixed the return checks/values here */
203 if (!g_make_string_buffer(krb5_gss_get_error_message(status_value
),
205 *minor_status
= ENOMEM
;
206 return(GSS_S_FAILURE
);
209 return(GSS_S_COMPLETE
);
212 return(GSS_S_BAD_STATUS
);
218 * Hack alert: workaround obfusicated func name issues for mech_spnego.so.
221 krb5_gss_display_status2(minor_status
, status_value
, status_type
,
222 mech_type
, message_context
, status_string
)
223 OM_uint32
*minor_status
;
224 OM_uint32 status_value
;
227 OM_uint32
*message_context
;
228 gss_buffer_t status_string
;
230 return(krb5_gss_display_status(minor_status
, status_value
,
231 status_type
, mech_type
, message_context
,