2 * Copyright (c) 1998 - 2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "krb5/gsskrb5_locl.h"
36 RCSID("$Id: display_status.c,v 1.17 2006/11/13 18:01:38 lha Exp $");
39 calling_error(OM_uint32 v
)
41 static const char *msgs
[] = {
43 "A required input parameter could not be read.", /* */
44 "A required output parameter could not be written.", /* */
45 "A parameter was malformed"
48 v
>>= GSS_C_CALLING_ERROR_OFFSET
;
52 else if (v
>= sizeof(msgs
)/sizeof(*msgs
))
53 return "unknown calling error";
59 routine_error(OM_uint32 v
)
61 static const char *msgs
[] = {
63 "An unsupported mechanism was requested",
64 "An invalid name was supplied",
65 "A supplied name was of an unsupported type",
66 "Incorrect channel bindings were supplied",
67 "An invalid status code was supplied",
68 "A token had an invalid MIC",
69 "No credentials were supplied, "
70 "or the credentials were unavailable or inaccessible.",
71 "No context has been established",
72 "A token was invalid",
73 "A credential was invalid",
74 "The referenced credentials have expired",
75 "The context has expired",
76 "Miscellaneous failure (see text)",
77 "The quality-of-protection requested could not be provide",
78 "The operation is forbidden by local security policy",
79 "The operation or option is not available",
80 "The requested credential element already exists",
81 "The provided name was not a mechanism name.",
84 v
>>= GSS_C_ROUTINE_ERROR_OFFSET
;
88 else if (v
>= sizeof(msgs
)/sizeof(*msgs
))
89 return "unknown routine error";
95 supplementary_error(OM_uint32 v
)
97 static const char *msgs
[] = {
99 "continuation call to routine required",
100 "duplicate per-message token detected",
101 "timed-out per-message token detected",
102 "reordered (early) per-message token detected",
103 "skipped predecessor token(s) detected"
106 v
>>= GSS_C_SUPPLEMENTARY_OFFSET
;
108 if (v
>= sizeof(msgs
)/sizeof(*msgs
))
109 return "unknown routine error";
115 _gsskrb5_clear_status (void)
117 krb5_context context
;
119 if (_gsskrb5_init (&context
) != 0)
121 krb5_clear_error_string(context
);
125 _gsskrb5_set_status (const char *fmt
, ...)
127 krb5_context context
;
131 if (_gsskrb5_init (&context
) != 0)
135 vasprintf(&str
, fmt
, args
);
138 krb5_set_error_string(context
, str
);
143 OM_uint32 _gsskrb5_display_status
144 (OM_uint32
*minor_status
,
145 OM_uint32 status_value
,
147 const gss_OID mech_type
,
148 OM_uint32
*message_context
,
149 gss_buffer_t status_string
)
151 krb5_context context
;
154 GSSAPI_KRB5_INIT (&context
);
156 status_string
->length
= 0;
157 status_string
->value
= NULL
;
159 if (gss_oid_equal(mech_type
, GSS_C_NO_OID
) == 0 &&
160 gss_oid_equal(mech_type
, GSS_KRB5_MECHANISM
) == 0) {
162 return GSS_C_GSS_CODE
;
165 if (status_type
== GSS_C_GSS_CODE
) {
166 if (GSS_SUPPLEMENTARY_INFO(status_value
))
168 supplementary_error(GSS_SUPPLEMENTARY_INFO(status_value
)));
170 asprintf (&buf
, "%s %s",
171 calling_error(GSS_CALLING_ERROR(status_value
)),
172 routine_error(GSS_ROUTINE_ERROR(status_value
)));
173 } else if (status_type
== GSS_C_MECH_CODE
) {
174 buf
= krb5_get_error_string(context
);
176 const char *tmp
= krb5_get_err_text (context
, status_value
);
178 asprintf(&buf
, "unknown mech error-code %u",
179 (unsigned)status_value
);
184 *minor_status
= EINVAL
;
185 return GSS_S_BAD_STATUS
;
189 *minor_status
= ENOMEM
;
190 return GSS_S_FAILURE
;
193 *message_context
= 0;
196 status_string
->length
= strlen(buf
);
197 status_string
->value
= buf
;
199 return GSS_S_COMPLETE
;