/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* glue routine gss_import_name
*
*/
#include <mglueP.h>
#include "gssapiP_generic.h"
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <string.h>
#include <errno.h>
extern int
get_der_length(unsigned char **, unsigned int, unsigned int *);
/* local function to import GSS_C_EXPORT_NAME names */
static OM_uint32
{
/* Initialize outputs. */
if (minor_status != NULL)
*minor_status = 0;
if (output_name != NULL)
/* Validate arguments. */
if (minor_status == NULL)
return (GSS_S_CALL_INACCESSIBLE_WRITE);
if (output_name == NULL)
return (GSS_S_CALL_INACCESSIBLE_WRITE);
if (input_name_buffer == GSS_C_NO_BUFFER)
return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
return (GSS_S_COMPLETE);
}
const gss_buffer_t input_name_buffer;
const gss_OID input_name_type;
{
if (major_status != GSS_S_COMPLETE)
return (major_status);
/*
* First create the union name struct that will hold the external
* name and the name type.
*/
if (!union_name)
return (GSS_S_FAILURE);
union_name->loopback = 0;
union_name->mech_type = 0;
union_name->mech_name = 0;
union_name->name_type = 0;
union_name->external_name = 0;
/*
* All we do here is record the external name and name_type.
* When the name is actually used, the underlying gss_import_name()
* is called for the appropriate mechanism. The exception to this
* rule is when the name of GSS_C_NT_EXPORT_NAME type. If that is
* the case, then we make it MN in this call.
*/
&union_name->external_name, 0);
if (major_status != GSS_S_COMPLETE) {
return (major_status);
}
if (input_name_type != GSS_C_NULL_OID) {
&union_name->name_type);
if (major_status != GSS_S_COMPLETE) {
goto allocation_failure;
}
}
/*
* In MIT Distribution the mechanism is determined from the nametype;
* This is not a good idea - first mechanism that supports a given
* name type is picked up; later on the caller can request a
* different mechanism. So we don't determine the mechanism here. Now
* the user level and kernel level import_name routine looks similar
* except the kernel routine makes a copy of the nametype structure. We
* do however make this an MN for names of GSS_C_NT_EXPORT_NAME type.
*/
if (input_name_type != GSS_C_NULL_OID &&
if (major_status != GSS_S_COMPLETE)
goto allocation_failure;
}
return (GSS_S_COMPLETE);
if (union_name) {
if (union_name->external_name) {
}
if (union_name->name_type)
(void) generic_gss_release_oid(&tmp,
&union_name->name_type);
if (union_name->mech_name)
&union_name->mech_name);
if (union_name->mech_type)
(void) generic_gss_release_oid(&tmp,
&union_name->mech_type);
}
return (major_status);
}
/*
* GSS export name constants
*/
static OM_uint32
{
unsigned char *buf;
unsigned int bytes;
return (GSS_S_DEFECTIVE_TOKEN);
return (GSS_S_DEFECTIVE_TOKEN);
buf += expNameTokIdLen;
/* extract the mechanism oid length */
mechOidLen |= (*buf++);
curLength += mechOidLen;
return (GSS_S_DEFECTIVE_TOKEN);
/*
* The mechOid itself is encoded in DER format, OID Tag (0x06)
* length and the value of mech_OID
*/
if (*buf++ != 0x06)
return (GSS_S_DEFECTIVE_TOKEN);
/*
* mechoid Length is encoded twice; once in 2 bytes as
* explained in RFC2743 (under mechanism independent exported
* name object format) and once using DER encoding
*
* We verify both lengths.
*/
/*
* 'bytes' is the length of the DER length, '1' is for the DER
* tag for OID
*/
return (GSS_S_DEFECTIVE_TOKEN);
return (GSS_S_BAD_MECH);
return (GSS_S_UNAVAILABLE);
/*
* we must now determine if we should unwrap the name ourselves
* or make the mechanism do it - we should only unwrap it
* if we create it; so if mech->gss_export_name == NULL, we must
* have created it.
*/
if (mech->gss_export_name) {
&expName,
if (major != GSS_S_COMPLETE)
else {
if (major != GSS_S_COMPLETE)
}
return (major);
}
/*
* we must have exported the name - so we now need to reconstruct it
* and call the mechanism to create it
*
* WARNING: Older versions of __gss_export_internal_name() did
* not export names correctly, but now it does. In
* order to stay compatible with existing exported
* names we must support names exported the broken
* way.
*
* Specifically, __gss_export_internal_name() used to include
* the name type OID in the encoding of the exported MN.
* Additionally, the Kerberos V mech used to make display names
* that included a null terminator which was counted in the
* display name gss_buffer_desc.
*/
return (GSS_S_DEFECTIVE_TOKEN);
/* next 4 bytes in the name are the name length */
/*
* we use < here because bad code in rpcsec_gss rounds up exported
* name token lengths and pads with nulls, otherwise != would be
* appropriate
*/
return (GSS_S_DEFECTIVE_TOKEN);
/*
* We detect broken exported names here: they always start with
* a two-octet network-byte order OID length, which is always
* less than 256 bytes, so the first octet of the length is
* always '\0', which is not allowed in GSS-API display names
* (or never occurs in them anyways). Of course, the OID
* shouldn't be there, but it is. After the OID (sans DER tag
* and length) there's the name itself, though null-terminated;
* this null terminator should also not be there, but it is.
*/
/* next two bytes are the name oid */
if (nameLen < nameTypeLenLen)
return (GSS_S_DEFECTIVE_TOKEN);
nameTypeLen |= (*buf++);
if (nameLen < nameTypeLen)
return (GSS_S_DEFECTIVE_TOKEN);
buf += nameTypeLen;
nameLen -= nameTypeLen;
/*
* adjust for expected null terminator that should
* really not be there
*/
nameLen--;
}
/*
* Can a name be null? Let the mech decide.
*
* NOTE: We use GSS_C_NULL_OID as the name type when importing
* the unwrapped name. Presumably the exported name had,
* prior to being exported been obtained in such a way
* that it has been properly perpared ("canonicalized," in
* GSS-API terms) accroding to some name type; we cannot
* tell what that name type was now, but the name should
* need no further preparation other than the lowest
* common denominator afforded by the mech to names
* imported with GSS_C_NULL_OID. For the Kerberos V mech
* this means doing less busywork too (particularly once
* IDN is thrown in with Kerberos V extensions).
*/
if (major != GSS_S_COMPLETE) {
return (major);
}
if (major != GSS_S_COMPLETE) {
}
return (major);
} /* importExportName */