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" 62RCSID("$Id: gss_display_status.c,v 1.1.1.1 2011/06/10 09:34:42 andrew Exp $"); 63 64static const char * 65calling_error(OM_uint32 v) 66{ 67 static const char *msgs[] = { 68 NULL, /* 0 */ 69 "A required input parameter could not be read.", /* */ 70 "A required output parameter could not be written.", /* */ 71 "A parameter was malformed" 72 }; 73 74 v >>= GSS_C_CALLING_ERROR_OFFSET; 75 76 if (v == 0) 77 return ""; 78 else if (v >= sizeof(msgs)/sizeof(*msgs)) 79 return "unknown calling error"; 80 else 81 return msgs[v]; 82} 83 84static const char * 85routine_error(OM_uint32 v) 86{ 87 static const char *msgs[] = { 88 "Function completed successfully", /* 0 */ 89 "An unsupported mechanism was requested", 90 "An invalid name was supplied", 91 "A supplied name was of an unsupported type", 92 "Incorrect channel bindings were supplied", 93 "An invalid status code was supplied", 94 "A token had an invalid MIC", 95 "No credentials were supplied, " 96 "or the credentials were unavailable or inaccessible.", 97 "No context has been established", 98 "A token was invalid", 99 "A credential was invalid", 100 "The referenced credentials have expired", 101 "The context has expired", 102 "Miscellaneous failure (see text)", 103 "The quality-of-protection requested could not be provide", 104 "The operation is forbidden by local security policy", 105 "The operation or option is not available", 106 "The requested credential element already exists", 107 "The provided name was not a mechanism name.", 108 }; 109 110 v >>= GSS_C_ROUTINE_ERROR_OFFSET; 111 112 if (v >= sizeof(msgs)/sizeof(*msgs)) 113 return "unknown routine error"; 114 else 115 return msgs[v]; 116} 117 118static const char * 119supplementary_error(OM_uint32 v) 120{ 121 static const char *msgs[] = { 122 "normal completion", 123 "continuation call to routine required", 124 "duplicate per-message token detected", 125 "timed-out per-message token detected", 126 "reordered (early) per-message token detected", 127 "skipped predecessor token(s) detected" 128 }; 129 130 v >>= GSS_C_SUPPLEMENTARY_OFFSET; 131 132 if (v >= sizeof(msgs)/sizeof(*msgs)) 133 return "unknown routine error"; 134 else 135 return msgs[v]; 136} 137 138 139OM_uint32 GSSAPI_LIB_FUNCTION 140gss_display_status(OM_uint32 *minor_status, 141 OM_uint32 status_value, 142 int status_type, 143 const gss_OID mech_type, 144 OM_uint32 *message_content, 145 gss_buffer_t status_string) 146{ 147 OM_uint32 major_status; 148 149 _mg_buffer_zero(status_string); 150 *message_content = 0; 151 152 major_status = _gss_mg_get_error(mech_type, status_type, 153 status_value, status_string); 154 if (major_status == GSS_S_COMPLETE) { 155 156 *message_content = 0; 157 *minor_status = 0; 158 return GSS_S_COMPLETE; 159 } 160 161 *minor_status = 0; 162 switch (status_type) { 163 case GSS_C_GSS_CODE: { 164 char *buf; 165 166 if (GSS_SUPPLEMENTARY_INFO(status_value)) 167 asprintf(&buf, "%s", supplementary_error( 168 GSS_SUPPLEMENTARY_INFO(status_value))); 169 else 170 asprintf (&buf, "%s %s", 171 calling_error(GSS_CALLING_ERROR(status_value)), 172 routine_error(GSS_ROUTINE_ERROR(status_value))); 173 174 if (buf == NULL) 175 break; 176 177 status_string->length = strlen(buf); 178 status_string->value = buf; 179 180 return GSS_S_COMPLETE; 181 } 182 case GSS_C_MECH_CODE: { 183 OM_uint32 maj_junk, min_junk; 184 gss_buffer_desc oid; 185 char *buf; 186 187 maj_junk = gss_oid_to_str(&min_junk, mech_type, &oid); 188 if (maj_junk != GSS_S_COMPLETE) { 189 oid.value = rk_UNCONST("unknown"); 190 oid.length = 7; 191 } 192 193 asprintf (&buf, "unknown mech-code %lu for mech %.*s", 194 (unsigned long)status_value, 195 (int)oid.length, (char *)oid.value); 196 if (maj_junk == GSS_S_COMPLETE) 197 gss_release_buffer(&min_junk, &oid); 198 199 if (buf == NULL) 200 break; 201 202 status_string->length = strlen(buf); 203 status_string->value = buf; 204 205 return GSS_S_COMPLETE; 206 } 207 } 208 _mg_buffer_zero(status_string); 209 return (GSS_S_BAD_STATUS); 210} 211