Path: blob/main/crypto/heimdal/lib/gssapi/mech/gss_display_status.c
34914 views
/*-1* Copyright (c) 2005 Doug Rabson2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*25* $FreeBSD: src/lib/libgssapi/gss_display_status.c,v 1.1 2005/12/29 14:40:20 dfr Exp $26*/27/*28* Copyright (c) 1998 - 2005 Kungliga Tekniska Högskolan29* (Royal Institute of Technology, Stockholm, Sweden).30* All rights reserved.31*32* Redistribution and use in source and binary forms, with or without33* modification, are permitted provided that the following conditions34* are met:35*36* 1. Redistributions of source code must retain the above copyright37* notice, this list of conditions and the following disclaimer.38*39* 2. Redistributions in binary form must reproduce the above copyright40* notice, this list of conditions and the following disclaimer in the41* documentation and/or other materials provided with the distribution.42*43* 3. Neither the name of the Institute nor the names of its contributors44* may be used to endorse or promote products derived from this software45* without specific prior written permission.46*47* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND48* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE49* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE50* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE51* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL52* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS53* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)54* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT55* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY56* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF57* SUCH DAMAGE.58*/5960#include "mech_locl.h"6162static const char *63calling_error(OM_uint32 v)64{65static const char *msgs[] = {66NULL, /* 0 */67"A required input parameter could not be read.", /* */68"A required output parameter could not be written.", /* */69"A parameter was malformed"70};7172v >>= GSS_C_CALLING_ERROR_OFFSET;7374if (v == 0)75return "";76else if (v >= sizeof(msgs)/sizeof(*msgs))77return "unknown calling error";78else79return msgs[v];80}8182static const char *83routine_error(OM_uint32 v)84{85static const char *msgs[] = {86"Function completed successfully", /* 0 */87"An unsupported mechanism was requested",88"An invalid name was supplied",89"A supplied name was of an unsupported type",90"Incorrect channel bindings were supplied",91"An invalid status code was supplied",92"A token had an invalid MIC",93"No credentials were supplied, or the credentials were unavailable or inaccessible.",94"No context has been established",95"A token was invalid",96"A credential was invalid",97"The referenced credentials have expired",98"The context has expired",99"Miscellaneous failure (see text)",100"The quality-of-protection requested could not be provide",101"The operation is forbidden by local security policy",102"The operation or option is not available",103"The requested credential element already exists",104"The provided name was not a mechanism name.",105};106107v >>= GSS_C_ROUTINE_ERROR_OFFSET;108109if (v >= sizeof(msgs)/sizeof(*msgs))110return "unknown routine error";111else112return msgs[v];113}114115static const char *116supplementary_error(OM_uint32 v)117{118static const char *msgs[] = {119"normal completion",120"continuation call to routine required",121"duplicate per-message token detected",122"timed-out per-message token detected",123"reordered (early) per-message token detected",124"skipped predecessor token(s) detected"125};126127v >>= GSS_C_SUPPLEMENTARY_OFFSET;128129if (v >= sizeof(msgs)/sizeof(*msgs))130return "unknown routine error";131else132return msgs[v];133}134135136GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL137gss_display_status(OM_uint32 *minor_status,138OM_uint32 status_value,139int status_type,140const gss_OID mech_type,141OM_uint32 *message_content,142gss_buffer_t status_string)143{144OM_uint32 major_status;145146_mg_buffer_zero(status_string);147*message_content = 0;148149major_status = _gss_mg_get_error(mech_type, status_type,150status_value, status_string);151if (major_status == GSS_S_COMPLETE) {152153*message_content = 0;154*minor_status = 0;155return GSS_S_COMPLETE;156}157158*minor_status = 0;159switch (status_type) {160case GSS_C_GSS_CODE: {161char *buf = NULL;162int e;163164if (GSS_SUPPLEMENTARY_INFO(status_value))165e = asprintf(&buf, "%s", supplementary_error(166GSS_SUPPLEMENTARY_INFO(status_value)));167else168e = asprintf (&buf, "%s %s",169calling_error(GSS_CALLING_ERROR(status_value)),170routine_error(GSS_ROUTINE_ERROR(status_value)));171172if (e < 0 || buf == NULL)173break;174175status_string->length = strlen(buf);176status_string->value = buf;177178return GSS_S_COMPLETE;179}180case GSS_C_MECH_CODE: {181OM_uint32 maj_junk, min_junk;182gss_buffer_desc oid;183char *buf = NULL;184int e;185186maj_junk = gss_oid_to_str(&min_junk, mech_type, &oid);187if (maj_junk != GSS_S_COMPLETE) {188oid.value = rk_UNCONST("unknown");189oid.length = 7;190}191192e = asprintf (&buf, "unknown mech-code %lu for mech %.*s",193(unsigned long)status_value,194(int)oid.length, (char *)oid.value);195if (maj_junk == GSS_S_COMPLETE)196gss_release_buffer(&min_junk, &oid);197198if (e < 0 || buf == NULL)199break;200201status_string->length = strlen(buf);202status_string->value = buf;203204return GSS_S_COMPLETE;205}206}207_mg_buffer_zero(status_string);208return (GSS_S_BAD_STATUS);209}210211212