2 * Copyright (c) 2004, PADL Software Pty Ltd.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of PADL Software nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include "mech_locl.h"
34 RCSID("$Id: gss_buffer_set.c 23025 2008-04-17 10:01:57Z lha $");
36 OM_uint32 GSSAPI_LIB_FUNCTION
37 gss_create_empty_buffer_set
38 (OM_uint32 * minor_status,
39 gss_buffer_set_t *buffer_set)
43 set = (gss_buffer_set_desc *) malloc(sizeof(*set));
44 if (set == GSS_C_NO_BUFFER_SET) {
45 *minor_status = ENOMEM;
55 return GSS_S_COMPLETE;
58 OM_uint32 GSSAPI_LIB_FUNCTION
59 gss_add_buffer_set_member
60 (OM_uint32 * minor_status,
61 const gss_buffer_t member_buffer,
62 gss_buffer_set_t *buffer_set)
68 if (*buffer_set == GSS_C_NO_BUFFER_SET) {
69 ret = gss_create_empty_buffer_set(minor_status,
77 set->elements = realloc(set->elements,
78 (set->count + 1) * sizeof(set->elements[0]));
79 if (set->elements == NULL) {
80 *minor_status = ENOMEM;
84 p = &set->elements[set->count];
86 p->value = malloc(member_buffer->length);
87 if (p->value == NULL) {
88 *minor_status = ENOMEM;
91 memcpy(p->value, member_buffer->value, member_buffer->length);
92 p->length = member_buffer->length;
97 return GSS_S_COMPLETE;
100 OM_uint32 GSSAPI_LIB_FUNCTION
101 gss_release_buffer_set(OM_uint32 * minor_status,
102 gss_buffer_set_t *buffer_set)
109 if (*buffer_set == GSS_C_NO_BUFFER_SET)
110 return GSS_S_COMPLETE;
112 for (i = 0; i < (*buffer_set)->count; i++)
113 gss_release_buffer(&minor, &((*buffer_set)->elements[i]));
115 free((*buffer_set)->elements);
117 (*buffer_set)->elements = NULL;
118 (*buffer_set)->count = 0;
121 *buffer_set = GSS_C_NO_BUFFER_SET;
123 return GSS_S_COMPLETE;