gssapi: remove non-mech status from _gss_mg_error() from Heimdal-520

_gss_mg_error() should only handle mechanism-specific status codes which are
returned in minor_status. major_status has a global namespace.
This commit is contained in:
Luke Howard
2019-01-03 18:15:34 +11:00
committed by Nico Williams
parent 83f15553e0
commit e9b3b2326d
27 changed files with 95 additions and 94 deletions

View File

@@ -1,11 +1,46 @@
/*
* Copyright (c) 2009 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Portions Copyright (c) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "mech_locl.h"
#include "heim_threads.h"
#include <krb5.h>
#include "krb5_locl.h"
struct mg_thread_ctx {
gss_OID mech;
OM_uint32 maj_stat;
OM_uint32 min_stat;
gss_buffer_desc maj_error;
gss_buffer_desc min_error;
};
@@ -23,8 +58,8 @@ destroy_context(void *ptr)
if (mg == NULL)
return;
gss_release_buffer(&junk, &mg->maj_error);
gss_release_buffer(&junk, &mg->min_error);
free(mg);
}
@@ -63,8 +98,9 @@ _gss_mechglue_thread(void)
}
OM_uint32
_gss_mg_get_error(const gss_OID mech, OM_uint32 type,
OM_uint32 value, gss_buffer_t string)
_gss_mg_get_error(const gss_OID mech,
OM_uint32 value,
gss_buffer_t string)
{
struct mg_thread_ctx *mg;
@@ -72,45 +108,25 @@ _gss_mg_get_error(const gss_OID mech, OM_uint32 type,
if (mg == NULL)
return GSS_S_BAD_STATUS;
#if 0
/*
* We cant check the mech here since a pseudo-mech might have
* called an lower layer and then the mech info is all broken
*/
if (mech != NULL && gss_oid_equal(mg->mech, mech) == 0)
if (value != mg->min_stat || mg->min_error.length == 0) {
_mg_buffer_zero(string);
return GSS_S_BAD_STATUS;
#endif
switch (type) {
case GSS_C_GSS_CODE: {
if (value != mg->maj_stat || mg->maj_error.length == 0)
break;
string->value = malloc(mg->maj_error.length + 1);
string->length = mg->maj_error.length;
memcpy(string->value, mg->maj_error.value, mg->maj_error.length);
((char *) string->value)[string->length] = '\0';
return GSS_S_COMPLETE;
}
case GSS_C_MECH_CODE: {
if (value != mg->min_stat || mg->min_error.length == 0)
break;
string->value = malloc(mg->min_error.length + 1);
string->length = mg->min_error.length;
memcpy(string->value, mg->min_error.value, mg->min_error.length);
((char *) string->value)[string->length] = '\0';
return GSS_S_COMPLETE;
string->value = malloc(mg->min_error.length);
if (string->value == NULL) {
_mg_buffer_zero(string);
return GSS_S_FAILURE;
}
}
string->value = NULL;
string->length = 0;
return GSS_S_BAD_STATUS;
string->length = mg->min_error.length;
memcpy(string->value, mg->min_error.value, mg->min_error.length);
return GSS_S_COMPLETE;
}
void
_gss_mg_error(gssapi_mech_interface m, OM_uint32 maj, OM_uint32 min)
_gss_mg_error(struct gssapi_mech_interface_desc *m, OM_uint32 min)
{
OM_uint32 major_status, minor_status;
OM_uint32 message_content;
OM_uint32 message_content = 0;
struct mg_thread_ctx *mg;
/*
@@ -124,33 +140,19 @@ _gss_mg_error(gssapi_mech_interface m, OM_uint32 maj, OM_uint32 min)
if (mg == NULL)
return;
gss_release_buffer(&minor_status, &mg->maj_error);
gss_release_buffer(&minor_status, &mg->min_error);
mg->mech = &m->gm_mech_oid;
mg->maj_stat = maj;
mg->min_stat = min;
major_status = m->gm_display_status(&minor_status,
maj,
GSS_C_GSS_CODE,
&m->gm_mech_oid,
&message_content,
&mg->maj_error);
if (GSS_ERROR(major_status)) {
mg->maj_error.value = NULL;
mg->maj_error.length = 0;
}
major_status = m->gm_display_status(&minor_status,
min,
GSS_C_MECH_CODE,
&m->gm_mech_oid,
&message_content,
&mg->min_error);
if (GSS_ERROR(major_status)) {
mg->min_error.value = NULL;
mg->min_error.length = 0;
}
if (major_status != GSS_S_COMPLETE)
_mg_buffer_zero(&mg->min_error);
}
void
@@ -159,5 +161,5 @@ gss_mg_collect_error(gss_OID mech, OM_uint32 maj, OM_uint32 min)
gssapi_mech_interface m = __gss_get_mechanism(mech);
if (m == NULL)
return;
_gss_mg_error(m, maj, min);
_gss_mg_error(m, min);
}