Path: blob/main/crypto/krb5/src/lib/gssapi/mechglue/g_encapsulate_token.c
39586 views
/*1* Copyright (c) 2011, PADL Software Pty Ltd.2* 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*8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10*11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* 3. Neither the name of PADL Software nor the names of its contributors16* may be used to endorse or promote products derived from this software17* without specific prior written permission.18*19* THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE23* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*/3132#include "mglueP.h"3334OM_uint32 KRB5_CALLCONV35gss_encapsulate_token(gss_const_buffer_t input_token,36gss_const_OID token_oid,37gss_buffer_t output_token)38{39unsigned int tokenSize;40struct k5buf buf;4142if (input_token == GSS_C_NO_BUFFER || token_oid == GSS_C_NO_OID)43return GSS_S_CALL_INACCESSIBLE_READ;4445if (output_token == GSS_C_NO_BUFFER)46return GSS_S_CALL_INACCESSIBLE_WRITE;4748tokenSize = g_token_size(token_oid, input_token->length);4950assert(tokenSize > 2);51tokenSize -= 2; /* TOK_ID */5253output_token->value = gssalloc_malloc(tokenSize);54if (output_token->value == NULL)55return GSS_S_FAILURE;5657k5_buf_init_fixed(&buf, output_token->value, tokenSize);58g_make_token_header(&buf, token_oid, input_token->length, -1);59k5_buf_add_len(&buf, input_token->value, input_token->length);60assert(buf.len == tokenSize);61output_token->length = tokenSize;6263return GSS_S_COMPLETE;64}656667