Path: blob/main/crypto/krb5/src/lib/gssapi/generic/util_buffer_set.c
39563 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/*2* Copyright 2008 by the Massachusetts Institute of Technology.3* All Rights Reserved.4*5* Export of this software from the United States of America may6* require a specific license from the United States Government.7* It is the responsibility of any person or organization contemplating8* export to obtain such a license before exporting.9*10* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and11* distribute this software and its documentation for any purpose and12* without fee is hereby granted, provided that the above copyright13* notice appear in all copies and that both that copyright notice and14* this permission notice appear in supporting documentation, and that15* the name of M.I.T. not be used in advertising or publicity pertaining16* to distribution of the software without specific, written prior17* permission. Furthermore if you modify this software you must label18* your software as modified software and not distribute it in such a19* fashion that it might be confused with the original M.I.T. software.20* M.I.T. makes no representations about the suitability of21* this software for any purpose. It is provided "as is" without express22* or implied warranty.23*24*/2526#include "gssapiP_generic.h"27#include <stdio.h>28#ifdef HAVE_STDLIB_H29#include <stdlib.h>30#endif31#include <string.h>32#include <errno.h>3334OM_uint3235generic_gss_create_empty_buffer_set(OM_uint32 * minor_status,36gss_buffer_set_t *buffer_set)37{38gss_buffer_set_t set;3940set = (gss_buffer_set_desc *) gssalloc_malloc(sizeof(*set));41if (set == GSS_C_NO_BUFFER_SET) {42*minor_status = ENOMEM;43return GSS_S_FAILURE;44}4546set->count = 0;47set->elements = NULL;4849*buffer_set = set;5051*minor_status = 0;52return GSS_S_COMPLETE;53}5455OM_uint3256generic_gss_add_buffer_set_member(OM_uint32 * minor_status,57const gss_buffer_t member_buffer,58gss_buffer_set_t *buffer_set)59{60gss_buffer_set_t set;61gss_buffer_t p;62OM_uint32 ret;6364if (*buffer_set == GSS_C_NO_BUFFER_SET) {65ret = generic_gss_create_empty_buffer_set(minor_status,66buffer_set);67if (ret) {68return ret;69}70}7172set = *buffer_set;73set->elements = (gss_buffer_desc *)gssalloc_realloc(set->elements,74(set->count + 1) *75sizeof(gss_buffer_desc));76if (set->elements == NULL) {77*minor_status = ENOMEM;78return GSS_S_FAILURE;79}8081p = &set->elements[set->count];8283p->value = gssalloc_malloc(member_buffer->length);84if (p->value == NULL) {85*minor_status = ENOMEM;86return GSS_S_FAILURE;87}88memcpy(p->value, member_buffer->value, member_buffer->length);89p->length = member_buffer->length;9091set->count++;9293*minor_status = 0;94return GSS_S_COMPLETE;95}9697OM_uint3298generic_gss_release_buffer_set(OM_uint32 * minor_status,99gss_buffer_set_t *buffer_set)100{101size_t i;102OM_uint32 minor;103104*minor_status = 0;105106if (*buffer_set == GSS_C_NO_BUFFER_SET) {107return GSS_S_COMPLETE;108}109110for (i = 0; i < (*buffer_set)->count; i++) {111generic_gss_release_buffer(&minor, &((*buffer_set)->elements[i]));112}113114if ((*buffer_set)->elements != NULL) {115gssalloc_free((*buffer_set)->elements);116(*buffer_set)->elements = NULL;117}118119(*buffer_set)->count = 0;120121gssalloc_free(*buffer_set);122*buffer_set = GSS_C_NO_BUFFER_SET;123124return GSS_S_COMPLETE;125}126127128