update for 0.1e
[heimdal.git] / lib / gssapi / krb5 / display_status.c
blobcdccdced47d090f6e36cf41579e2d2e8104ff3f3
1 /*
2 * Copyright (c) 1998, 1999 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. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Kungliga Tekniska
20 * Högskolan and its contributors.
22 * 4. Neither the name of the Institute nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
39 #include "gssapi_locl.h"
41 RCSID("$Id$");
43 static char *
44 calling_error(OM_uint32 v)
46 static char *msgs[] = {
47 NULL, /* 0 */
48 "A required input parameter could not be read.", /* */
49 "A required output parameter could not be written.", /* */
50 "A parameter was malformed"
53 if (v == 0)
54 return "";
55 else if (v >= sizeof(msgs)/sizeof(*msgs))
56 return "unknown calling error";
57 else
58 return msgs[v];
61 static char *
62 routine_error(OM_uint32 v)
64 static char *msgs[] = {
65 NULL, /* 0 */
66 "An unsupported mechanism was requested",
67 "An invalid name was supplied",
68 "A supplied name was of an unsupported type",
69 "Incorrect channel bindings were supplied",
70 "An invalid status code was supplied",
71 "A token had an invalid MIC",
72 "No credentials were supplied, "
73 "or the credentials were unavailable or inaccessible.",
74 "No context has been established",
75 "A token was invalid",
76 "A credential was invalid",
77 "The referenced credentials have expired",
78 "The context has expired",
79 "Miscellaneous failure (see text)",
80 "The quality-of-protection requested could not be provide",
81 "The operation is forbidden by local security policy",
82 "The operation or option is not available",
83 "The requested credential element already exists",
84 "The provided name was not a mechanism name.",
87 if (v == 0)
88 return "";
89 else if (v >= sizeof(msgs)/sizeof(*msgs))
90 return "unknown routine error";
91 else
92 return msgs[v];
95 OM_uint32 gss_display_status
96 (OM_uint32 *minor_status,
97 OM_uint32 status_value,
98 int status_type,
99 const gss_OID mech_type,
100 OM_uint32 *message_context,
101 gss_buffer_t status_string)
103 char *buf;
105 gssapi_krb5_init ();
107 *minor_status = 0;
109 if (mech_type != GSS_C_NO_OID &&
110 mech_type != GSS_KRB5_MECHANISM)
111 return GSS_S_BAD_MECH;
113 if (status_type == GSS_C_GSS_CODE) {
114 asprintf (&buf, "%s %s",
115 calling_error(GSS_CALLING_ERROR(status_value)),
116 routine_error(GSS_ROUTINE_ERROR(status_value)));
117 if (buf == NULL) {
118 *minor_status = ENOMEM;
119 return GSS_S_FAILURE;
121 } else if (status_type == GSS_C_MECH_CODE) {
122 buf = strdup(krb5_get_err_text (gssapi_krb5_context, status_value));
123 if (buf == NULL) {
124 *minor_status = ENOMEM;
125 return GSS_S_FAILURE;
127 } else
128 return GSS_S_BAD_STATUS;
130 *message_context = 0;
132 status_string->length = strlen(buf);
133 status_string->value = buf;
135 return GSS_S_COMPLETE;