Implement gss_wrap_iov, gss_unwrap_iov for CFX type encryption types.
[heimdal.git] / lib / gssapi / krb5 / display_status.c
blobf9d84fc762843eee5fe21bbcb01e0b2ec50beb23
1 /*
2 * Copyright (c) 1998 - 2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
31 * SUCH DAMAGE.
34 #include "gsskrb5_locl.h"
36 static const char *
37 calling_error(OM_uint32 v)
39 static const char *msgs[] = {
40 NULL, /* 0 */
41 "A required input parameter could not be read.", /* */
42 "A required output parameter could not be written.", /* */
43 "A parameter was malformed"
46 v >>= GSS_C_CALLING_ERROR_OFFSET;
48 if (v == 0)
49 return "";
50 else if (v >= sizeof(msgs)/sizeof(*msgs))
51 return "unknown calling error";
52 else
53 return msgs[v];
56 static const char *
57 routine_error(OM_uint32 v)
59 static const char *msgs[] = {
60 NULL, /* 0 */
61 "An unsupported mechanism was requested",
62 "An invalid name was supplied",
63 "A supplied name was of an unsupported type",
64 "Incorrect channel bindings were supplied",
65 "An invalid status code was supplied",
66 "A token had an invalid MIC",
67 "No credentials were supplied, "
68 "or the credentials were unavailable or inaccessible.",
69 "No context has been established",
70 "A token was invalid",
71 "A credential was invalid",
72 "The referenced credentials have expired",
73 "The context has expired",
74 "Miscellaneous failure (see text)",
75 "The quality-of-protection requested could not be provide",
76 "The operation is forbidden by local security policy",
77 "The operation or option is not available",
78 "The requested credential element already exists",
79 "The provided name was not a mechanism name.",
82 v >>= GSS_C_ROUTINE_ERROR_OFFSET;
84 if (v == 0)
85 return "";
86 else if (v >= sizeof(msgs)/sizeof(*msgs))
87 return "unknown routine error";
88 else
89 return msgs[v];
92 static const char *
93 supplementary_error(OM_uint32 v)
95 static const char *msgs[] = {
96 "normal completion",
97 "continuation call to routine required",
98 "duplicate per-message token detected",
99 "timed-out per-message token detected",
100 "reordered (early) per-message token detected",
101 "skipped predecessor token(s) detected"
104 v >>= GSS_C_SUPPLEMENTARY_OFFSET;
106 if (v >= sizeof(msgs)/sizeof(*msgs))
107 return "unknown routine error";
108 else
109 return msgs[v];
112 void
113 _gsskrb5_clear_status (void)
115 krb5_context context;
117 if (_gsskrb5_init (&context) != 0)
118 return;
119 krb5_clear_error_message(context);
122 void
123 _gsskrb5_set_status (int ret, const char *fmt, ...)
125 krb5_context context;
126 va_list args;
127 char *str;
129 if (_gsskrb5_init (&context) != 0)
130 return;
132 va_start(args, fmt);
133 vasprintf(&str, fmt, args);
134 va_end(args);
135 if (str) {
136 krb5_set_error_message(context, ret, "%s", str);
137 free(str);
141 OM_uint32 _gsskrb5_display_status
142 (OM_uint32 *minor_status,
143 OM_uint32 status_value,
144 int status_type,
145 const gss_OID mech_type,
146 OM_uint32 *message_context,
147 gss_buffer_t status_string)
149 krb5_context context;
150 char *buf;
152 GSSAPI_KRB5_INIT (&context);
154 status_string->length = 0;
155 status_string->value = NULL;
157 if (gss_oid_equal(mech_type, GSS_C_NO_OID) == 0 &&
158 gss_oid_equal(mech_type, GSS_KRB5_MECHANISM) == 0) {
159 *minor_status = 0;
160 return GSS_C_GSS_CODE;
163 if (status_type == GSS_C_GSS_CODE) {
164 if (GSS_SUPPLEMENTARY_INFO(status_value))
165 asprintf(&buf, "%s",
166 supplementary_error(GSS_SUPPLEMENTARY_INFO(status_value)));
167 else
168 asprintf (&buf, "%s %s",
169 calling_error(GSS_CALLING_ERROR(status_value)),
170 routine_error(GSS_ROUTINE_ERROR(status_value)));
171 } else if (status_type == GSS_C_MECH_CODE) {
172 const char *buf2 = krb5_get_error_message(context, status_value);
173 if (buf2) {
174 buf = strdup(buf2);
175 krb5_free_error_message(context, buf2);
176 } else {
177 asprintf(&buf, "unknown mech error-code %u",
178 (unsigned)status_value);
180 } else {
181 *minor_status = EINVAL;
182 return GSS_S_BAD_STATUS;
185 if (buf == NULL) {
186 *minor_status = ENOMEM;
187 return GSS_S_FAILURE;
190 *message_context = 0;
191 *minor_status = 0;
193 status_string->length = strlen(buf);
194 status_string->value = buf;
196 return GSS_S_COMPLETE;