1 /* $NetBSD: gss_display_status.c,v 1.1.1.2 2014/04/24 12:45:29 pettai Exp $ */
4 * Copyright (c) 2005 Doug Rabson
7 * Redistribution and use in source and binary forms, with or without
8 * 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.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * $FreeBSD: src/lib/libgssapi/gss_display_status.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
31 * Copyright (c) 1998 - 2005 Kungliga Tekniska Högskolan
32 * (Royal Institute of Technology, Stockholm, Sweden).
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
46 * 3. Neither the name of the Institute nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 #include "mech_locl.h"
66 calling_error(OM_uint32 v
)
68 static const char *msgs
[] = {
70 "A required input parameter could not be read.", /* */
71 "A required output parameter could not be written.", /* */
72 "A parameter was malformed"
75 v
>>= GSS_C_CALLING_ERROR_OFFSET
;
79 else if (v
>= sizeof(msgs
)/sizeof(*msgs
))
80 return "unknown calling error";
86 routine_error(OM_uint32 v
)
88 static const char *msgs
[] = {
89 "Function completed successfully", /* 0 */
90 "An unsupported mechanism was requested",
91 "An invalid name was supplied",
92 "A supplied name was of an unsupported type",
93 "Incorrect channel bindings were supplied",
94 "An invalid status code was supplied",
95 "A token had an invalid MIC",
96 "No credentials were supplied, "
97 "or the credentials were unavailable or inaccessible.",
98 "No context has been established",
99 "A token was invalid",
100 "A credential was invalid",
101 "The referenced credentials have expired",
102 "The context has expired",
103 "Miscellaneous failure (see text)",
104 "The quality-of-protection requested could not be provide",
105 "The operation is forbidden by local security policy",
106 "The operation or option is not available",
107 "The requested credential element already exists",
108 "The provided name was not a mechanism name.",
111 v
>>= GSS_C_ROUTINE_ERROR_OFFSET
;
113 if (v
>= sizeof(msgs
)/sizeof(*msgs
))
114 return "unknown routine error";
120 supplementary_error(OM_uint32 v
)
122 static const char *msgs
[] = {
124 "continuation call to routine required",
125 "duplicate per-message token detected",
126 "timed-out per-message token detected",
127 "reordered (early) per-message token detected",
128 "skipped predecessor token(s) detected"
131 v
>>= GSS_C_SUPPLEMENTARY_OFFSET
;
133 if (v
>= sizeof(msgs
)/sizeof(*msgs
))
134 return "unknown routine error";
140 GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
141 gss_display_status(OM_uint32
*minor_status
,
142 OM_uint32 status_value
,
144 const gss_OID mech_type
,
145 OM_uint32
*message_content
,
146 gss_buffer_t status_string
)
148 OM_uint32 major_status
;
150 _mg_buffer_zero(status_string
);
151 *message_content
= 0;
153 major_status
= _gss_mg_get_error(mech_type
, status_type
,
154 status_value
, status_string
);
155 if (major_status
== GSS_S_COMPLETE
) {
157 *message_content
= 0;
159 return GSS_S_COMPLETE
;
163 switch (status_type
) {
164 case GSS_C_GSS_CODE
: {
168 if (GSS_SUPPLEMENTARY_INFO(status_value
))
169 e
= asprintf(&buf
, "%s", supplementary_error(
170 GSS_SUPPLEMENTARY_INFO(status_value
)));
172 e
= asprintf (&buf
, "%s %s",
173 calling_error(GSS_CALLING_ERROR(status_value
)),
174 routine_error(GSS_ROUTINE_ERROR(status_value
)));
176 if (e
< 0 || buf
== NULL
)
179 status_string
->length
= strlen(buf
);
180 status_string
->value
= buf
;
182 return GSS_S_COMPLETE
;
184 case GSS_C_MECH_CODE
: {
185 OM_uint32 maj_junk
, min_junk
;
190 maj_junk
= gss_oid_to_str(&min_junk
, mech_type
, &oid
);
191 if (maj_junk
!= GSS_S_COMPLETE
) {
192 oid
.value
= rk_UNCONST("unknown");
196 e
= asprintf (&buf
, "unknown mech-code %lu for mech %.*s",
197 (unsigned long)status_value
,
198 (int)oid
.length
, (char *)oid
.value
);
199 if (maj_junk
== GSS_S_COMPLETE
)
200 gss_release_buffer(&min_junk
, &oid
);
202 if (e
< 0 || buf
== NULL
)
205 status_string
->length
= strlen(buf
);
206 status_string
->value
= buf
;
208 return GSS_S_COMPLETE
;
211 _mg_buffer_zero(status_string
);
212 return (GSS_S_BAD_STATUS
);