/*
* 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
*/
/*
*/
/*
* // Copyright (C) 2002 Microsoft Corporation
* // All rights reserved.
* //
* // THIS CODE AND INFORMATION IS PROVIDED "AS IS"
* // WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
* // OR IMPLIED, INCLUDING BUT NOT LIMITED
* // TO THE IMPLIED WARRANTIES OF MERCHANTIBILITY
* //
* // Date - 10/08/2002
* // Author - Sanj Surati
*/
/*
* SPNEGO Token Handler Source File
*
* Contains implementation of SPNEGO Token Handling API.
*/
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include "smbfs_derparse.h"
#include "smbfs_spnegoparse.h"
/* Defined in DERPARSE.C */
extern MECH_OID g_stcMechOIDList [];
/* SPNEGO Token Handler API implementation */
/*
*
* Function:
* smbfs_spnegoInitFromBinary
*
* Parameters:
* [in] pbTokenData - Binary Token Data
* [in] ulLength - Length of binary Token Data
* [out] phSpnegoToken - SPNEGO_TOKEN_HANDLE pointer
*
* Returns:
* int Success - SPNEGO_E_SUCCESS
* Failure - SPNEGO API Error code
*
* Comments :
* Initializes a SPNEGO_TOKEN_HANDLE from the supplied
* binary data. Data is copied locally. Returned data structure
* must be freed by calling smbfs_spnegoFreeData().
*
*/
int
{
/*
* Pass off to a handler function that allows tighter control over how
* the token structure is handled. In this case, we want the token data
* copied and we want the associated buffer freed.
*/
return (nReturn);
}
/*
*
* Function:
* smbfs_spnegoCreateNegTokenInit
*
* Parameters:
* [in] MechType - MechType to specify in MechTypeList element
* [in] ucContextFlags - Context Flags element value
* [in] pbMechToken - Pointer to binary MechToken Data
* [in] ulMechTokenLen - Length of MechToken Data
* [in] pbMechListMIC - Pointer to binary MechListMIC Data
* [in] ulMechListMICLen - Length of MechListMIC Data
* [out] phSpnegoToken - SPNEGO_TOKEN_HANDLE pointer
*
* Returns:
* int Success - SPNEGO_E_SUCCESS
* Failure - SPNEGO API Error code
*
* Comments :
* Initializes a SPNEGO_TOKEN_HANDLE for a NegTokenInit type
* from the supplied parameters. ucContextFlags may be 0 or must be
* a valid flag combination. MechToken data can be NULL - if not, it
* must correspond to the MechType. MechListMIC can also be NULL.
* Returned data structure must be freed by calling smbfs_spnegoFreeData().
*
*/
int
unsigned char ucContextFlags, unsigned char *pbMechToken,
unsigned long ulMechTokenLen, unsigned char *pbMechListMIC,
{
long nTokenLength = 0L;
long nInternalTokenLength = 0L;
/* Get the actual token size */
if (nReturn == SPNEGO_E_SUCCESS) {
/* Allocate a buffer to hold the data. */
if (NULL != pbTokenData) {
/* Now write the token */
if (nReturn == SPNEGO_E_SUCCESS) {
/*
* This will copy our allocated pointer,
* and ensure that the sructure cleans
* up the data later
*/
}
/* Cleanup on failure */
if (SPNEGO_E_SUCCESS != nReturn)
} else {
}
} /* If calculated token size */
} /* IF Valid Parameters */
return (nReturn);
}
/*
*
* Function:
* smbfs_spnegoCreateNegTokenTarg
*
* Parameters:
* [in] MechType - MechType to specify in supported MechType elem
* [in] spnegoNegResult - NegResult value
* [in] pbMechToken - Pointer to response MechToken Data
* [in] ulMechTokenLen - Length of MechToken Data
* [in] pbMechListMIC - Pointer to binary MechListMIC Data
* [in] ulMechListMICLen - Length of MechListMIC Data
* [out] phSpnegoToken - SPNEGO_TOKEN_HANDLE pointer
*
* Returns:
* int Success - SPNEGO_E_SUCCESS
* Failure - SPNEGO API Error code
*
* Comments :
* Initializes a SPNEGO_TOKEN_HANDLE for a NegTokenTarg type
* from the supplied parameters. MechToken data can be NULL - if not,
* it must correspond to the MechType. MechListMIC can also be NULL.
* Returned data structure must be freed by calling smbfs_spnegoFreeData().
*
*/
int
unsigned long ulMechTokenLen, unsigned char *pbMechListMIC,
{
long nTokenLength = 0L;
long nInternalTokenLength = 0L;
/*
* spnego_mech_oid_NotUsed and spnego_negresult_NotUsed
* are okay here.
*/
if (NULL != ppSpnegoToken && \
(smbfs_IsValidMechOid(MechType) || \
spnego_mech_oid_NotUsed == MechType) && \
/* Get the actual token size */
if (nReturn == SPNEGO_E_SUCCESS) {
/* Allocate a buffer to hold the data. */
if (NULL != pbTokenData) {
/* Now write the token */
if (nReturn == SPNEGO_E_SUCCESS) {
/*
* This will copy our allocated pointer,
* and ensure that the sructure cleans
* up the data later.
*/
}
/* Cleanup on failure */
if (SPNEGO_E_SUCCESS != nReturn)
} else {
}
} /* If calculated token size */
} /* IF Valid Parameters */
return (nReturn);
}
/*
*
* Function:
* smbfs_spnegoTokenGetBinary
*
* Parameters:
* [in] hSpnegoToken - Initialized SPNEGO_TOKEN_HANDLE
* [out] pbTokenData - Buffer to copy token into
* with actual size used upon function return.
*
* Returns:
* int Success - SPNEGO_E_SUCCESS
* Failure - SPNEGO API Error code
*
* Comments :
* Copies binary SPNEGO token data from hSpnegoToken into the user
* supplied buffer. If pbTokenData is NULL, or the value in pulDataLen
* is too small, the function will return SPNEGO_E_BUFFER_TOO_SMALL and
* fill out pulDataLen with the minimum required buffer size.
*
*/
int
unsigned char *pbTokenData, unsigned long *pulDataLen)
{
/* Check parameters - pbTokenData is optional */
/* Check for Buffer too small conditions */
if (NULL == pbTokenData ||
} else {
}
} /* IF parameters OK */
return (nReturn);
}
/*
*
* Function:
* smbfs_spnegoFreeData
*
* Parameters:
* [in] hSpnegoToken - Initialized SPNEGO_TOKEN_HANDLE
*
* Returns:
* void
*
* Comments :
* Frees up resources consumed by hSpnegoToken. The supplied data
* pointer is invalidated by this function.
*
*/
void
{
}
/*
*
* Function:
* smbfs_spnegoIsMechTypeAvailable
*
* Parameters:
* [in] hSpnegoToken - Initialized SPNEGO_TOKEN_HANDLE
* [in] MechOID - MechOID to search MechTypeList for
* [out] piMechTypeIndex - Filled out with index in MechTypeList
* element if MechOID is found.
*
* Returns:
* int Success - SPNEGO_E_SUCCESS
* Failure - SPNEGO API Error code
*
* Comments :
* hSpnegoToken must reference a token of type NegTokenInit. The
* function will search the MechTypeList element for an OID corresponding
* to the specified MechOID. If one is found, the index (0 based) will
* be passed into the piMechTypeIndex parameter.
*
*
* Returns the Initial Mech Type in the MechList element in the NegInitToken.
*/
int
{
/* Check parameters */
/* Check if MechList is available */
/* Locate the MechOID in the list element */
} else {
}
} /* IF parameters OK */
return (nReturn);
}
/*
*
* Function:
* smbfs_spnegoGetNegotiationResult
*
* Parameters:
* [in] hSpnegoToken - Initialized SPNEGO_TOKEN_HANDLE
* [out] pnegResult - Filled out with NegResult value.
*
* Returns:
* int Success - SPNEGO_E_SUCCESS
* Failure - SPNEGO API Error code
*
* Comments :
* hSpnegoToken must reference a token of type NegTokenTarg. The
* function will copy data from the NegResult element into the
* location pointed to by pnegResult. Note that the function will
* fail if the actual NegResult data appears invalid.
*
*/
int
{
/* Check parameters */
/* Check if NegResult is available */
/* Must be 1 byte long and a valid value */
if (pSpnegoToken->aElementArray\
*pnegResult = \
} else {
}
} else {
}
} /* IF parameters OK */
return (nReturn);
}
/*
*
* Function:
* smbfs_spnegoGetMechToken
*
* Parameters:
* [in] hSpnegoToken - Initialized SPNEGO_TOKEN_HANDLE
* [out] pbTokenData - Buffer to copy MechToken into
* with actual size used upon function return.
*
* Returns:
* int Success - SPNEGO_E_SUCCESS
* Failure - SPNEGO API Error code
*
* Comments :
* hSpnegoToken can point to either NegTokenInit or a NegTokenTarg token.
* The function will copy the MechToken (the initial MechToken if
* NegTokenInit, the response MechToken if NegTokenTarg) from the
* underlying token into the buffer pointed to by pbTokenData. If
* pbTokenData is NULL, or the value in pulDataLen is too small, the
* function will return SPNEGO_E_BUFFER_TOO_SMALL and fill out pulDataLen
* with the minimum required buffer size. The token can then be passed
* to a GSS-API function for processing.
*
*/
int
unsigned char *pbTokenData, unsigned long *pulDataLen)
{
/* Check parameters */
/* Point at the proper Element */
} else {
}
/* Check if MechType is available */
if (SPNEGO_TOKEN_ELEMENT_AVAILABLE == \
/* Check for Buffer too small conditions */
if (NULL == pbTokenData || \
} else {
/* Copy Memory */
(void) memcpy(pbTokenData,
}
} else {
}
} /* IF parameters OK */
return (nReturn);
}