Line data Source code
1 : /*-
2 : * Copyright (c) 2005 Doug Rabson
3 : * All rights reserved.
4 : *
5 : * Redistribution and use in source and binary forms, with or without
6 : * modification, are permitted provided that the following conditions
7 : * are met:
8 : * 1. Redistributions of source code must retain the above copyright
9 : * notice, this list of conditions and the following disclaimer.
10 : * 2. Redistributions in binary form must reproduce the above copyright
11 : * notice, this list of conditions and the following disclaimer in the
12 : * documentation and/or other materials provided with the distribution.
13 : *
14 : * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 : * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 : * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 : * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 : * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 : * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 : * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 : * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 : * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 : * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 : * SUCH DAMAGE.
25 : *
26 : * $FreeBSD: src/lib/libgssapi/gss_display_status.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
27 : */
28 : /*
29 : * Copyright (c) 1998 - 2005 Kungliga Tekniska Högskolan
30 : * (Royal Institute of Technology, Stockholm, Sweden).
31 : * All rights reserved.
32 : *
33 : * Redistribution and use in source and binary forms, with or without
34 : * modification, are permitted provided that the following conditions
35 : * are met:
36 : *
37 : * 1. Redistributions of source code must retain the above copyright
38 : * notice, this list of conditions and the following disclaimer.
39 : *
40 : * 2. Redistributions in binary form must reproduce the above copyright
41 : * notice, this list of conditions and the following disclaimer in the
42 : * documentation and/or other materials provided with the distribution.
43 : *
44 : * 3. Neither the name of the Institute nor the names of its contributors
45 : * may be used to endorse or promote products derived from this software
46 : * without specific prior written permission.
47 : *
48 : * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
49 : * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 : * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 : * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
52 : * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 : * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 : * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 : * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 : * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 : * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 : * SUCH DAMAGE.
59 : */
60 :
61 : #include "mech_locl.h"
62 :
63 : static const char *
64 56 : calling_error(OM_uint32 v)
65 : {
66 0 : static const char *msgs[] = {
67 : NULL, /* 0 */
68 : "A required input parameter could not be read.", /* */
69 : "A required output parameter could not be written.", /* */
70 : "A parameter was malformed"
71 : };
72 :
73 56 : v >>= GSS_C_CALLING_ERROR_OFFSET;
74 :
75 56 : if (v == 0)
76 56 : return "";
77 0 : else if (v >= sizeof(msgs)/sizeof(*msgs))
78 0 : return "unknown calling error";
79 : else
80 0 : return msgs[v];
81 : }
82 :
83 : static const char *
84 56 : routine_error(OM_uint32 v)
85 : {
86 0 : static const char *msgs[] = {
87 : "Function completed successfully", /* 0 */
88 : "An unsupported mechanism was requested",
89 : "An invalid name was supplied",
90 : "A supplied name was of an unsupported type",
91 : "Incorrect channel bindings were supplied",
92 : "An invalid status code was supplied",
93 : "A token had an invalid MIC",
94 : "No credentials were supplied, or the credentials were unavailable or inaccessible.",
95 : "No context has been established",
96 : "A token was invalid",
97 : "A credential was invalid",
98 : "The referenced credentials have expired",
99 : "The context has expired",
100 : "Miscellaneous failure (see text)",
101 : "The quality-of-protection requested could not be provide",
102 : "The operation is forbidden by local security policy",
103 : "The operation or option is not available",
104 : "The requested credential element already exists",
105 : "The provided name was not a mechanism name.",
106 : };
107 :
108 56 : v >>= GSS_C_ROUTINE_ERROR_OFFSET;
109 :
110 56 : if (v >= sizeof(msgs)/sizeof(*msgs))
111 0 : return "unknown routine error";
112 : else
113 56 : return msgs[v];
114 : }
115 :
116 : static const char *
117 0 : supplementary_error(OM_uint32 v)
118 : {
119 0 : static const char *msgs[] = {
120 : "normal completion",
121 : "continuation call to routine required",
122 : "duplicate per-message token detected",
123 : "timed-out per-message token detected",
124 : "reordered (early) per-message token detected",
125 : "skipped predecessor token(s) detected"
126 : };
127 :
128 0 : v >>= GSS_C_SUPPLEMENTARY_OFFSET;
129 :
130 0 : if (v >= sizeof(msgs)/sizeof(*msgs))
131 0 : return "unknown routine error";
132 : else
133 0 : return msgs[v];
134 : }
135 :
136 : /**
137 : * Convert a GSS-API status code to text
138 : *
139 : * @param minor_status minor status code
140 : * @param status_value status value to convert
141 : * @param status_type One of:
142 : * GSS_C_GSS_CODE - status_value is a GSS status code,
143 : * GSS_C_MECH_CODE - status_value is a mechanism status code
144 : * @param mech_type underlying mechanism. Use GSS_C_NO_OID to obtain the
145 : * system default.
146 : * @param message_context state information to extract further messages from the
147 : * status_value
148 : * @param status_string the allocated text representation. Release with
149 : * gss_release_buffer()
150 : *
151 : * @returns a gss_error code.
152 : *
153 : * @ingroup gssapi
154 : */
155 : GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
156 112 : gss_display_status(OM_uint32 *minor_status,
157 : OM_uint32 status_value,
158 : int status_type,
159 : const gss_OID mech_type,
160 : OM_uint32 *message_context,
161 : gss_buffer_t status_string)
162 : {
163 0 : OM_uint32 major_status;
164 :
165 112 : _mg_buffer_zero(status_string);
166 112 : *message_context = 0;
167 :
168 112 : *minor_status = 0;
169 112 : switch (status_type) {
170 56 : case GSS_C_GSS_CODE: {
171 56 : char *buf = NULL;
172 0 : int e;
173 :
174 56 : if (GSS_SUPPLEMENTARY_INFO(status_value))
175 0 : e = asprintf(&buf, "%s", supplementary_error(
176 : GSS_SUPPLEMENTARY_INFO(status_value)));
177 : else
178 56 : e = asprintf (&buf, "%s %s",
179 : calling_error(GSS_CALLING_ERROR(status_value)),
180 : routine_error(GSS_ROUTINE_ERROR(status_value)));
181 :
182 56 : if (e < 0 || buf == NULL)
183 : break;
184 :
185 56 : status_string->length = strlen(buf);
186 56 : status_string->value = buf;
187 :
188 56 : return GSS_S_COMPLETE;
189 : }
190 56 : case GSS_C_MECH_CODE: {
191 0 : OM_uint32 maj_junk, min_junk;
192 0 : gss_buffer_desc oid;
193 56 : char *buf = NULL;
194 0 : int e;
195 :
196 56 : major_status = _gss_mg_get_error(mech_type, status_value,
197 : status_string);
198 56 : if (major_status == GSS_S_COMPLETE) {
199 35 : *message_context = 0;
200 35 : *minor_status = 0;
201 56 : return GSS_S_COMPLETE;
202 : }
203 :
204 21 : maj_junk = gss_oid_to_str(&min_junk, mech_type, &oid);
205 21 : if (maj_junk != GSS_S_COMPLETE) {
206 0 : oid.value = rk_UNCONST("unknown");
207 0 : oid.length = 7;
208 : }
209 :
210 21 : e = asprintf (&buf, "unknown mech-code %lu for mech %.*s",
211 : (unsigned long)status_value,
212 21 : (int)oid.length, (char *)oid.value);
213 21 : if (maj_junk == GSS_S_COMPLETE)
214 21 : gss_release_buffer(&min_junk, &oid);
215 :
216 21 : if (e < 0 || buf == NULL)
217 : break;
218 :
219 21 : status_string->length = strlen(buf);
220 21 : status_string->value = buf;
221 :
222 21 : return GSS_S_COMPLETE;
223 : }
224 : }
225 0 : _mg_buffer_zero(status_string);
226 0 : return (GSS_S_BAD_STATUS);
227 : }
|