fixes from Stefan Metzmacher
[heimdal.git] / lib / gssapi / mech / gss_buffer_set.c
blob9f0bb4cce3ff71820c231aeb9b9199da427a7cee
1 /*
2 * Copyright (c) 2004, PADL Software Pty Ltd.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
30 * SUCH DAMAGE.
33 #include "mech_locl.h"
34 RCSID("$Id$");
36 OM_uint32 GSSAPI_LIB_FUNCTION
37 gss_create_empty_buffer_set
38 (OM_uint32 * minor_status,
39 gss_buffer_set_t *buffer_set)
41 gss_buffer_set_t set;
43 set = (gss_buffer_set_desc *) malloc(sizeof(*set));
44 if (set == GSS_C_NO_BUFFER_SET) {
45 *minor_status = ENOMEM;
46 return GSS_S_FAILURE;
49 set->count = 0;
50 set->elements = NULL;
52 *buffer_set = set;
54 *minor_status = 0;
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)
64 gss_buffer_set_t set;
65 gss_buffer_t p;
66 OM_uint32 ret;
68 if (*buffer_set == GSS_C_NO_BUFFER_SET) {
69 ret = gss_create_empty_buffer_set(minor_status,
70 buffer_set);
71 if (ret) {
72 return ret;
76 set = *buffer_set;
77 set->elements = realloc(set->elements,
78 (set->count + 1) * sizeof(set->elements[0]));
79 if (set->elements == NULL) {
80 *minor_status = ENOMEM;
81 return GSS_S_FAILURE;
84 p = &set->elements[set->count];
86 p->value = malloc(member_buffer->length);
87 if (p->value == NULL) {
88 *minor_status = ENOMEM;
89 return GSS_S_FAILURE;
91 memcpy(p->value, member_buffer->value, member_buffer->length);
92 p->length = member_buffer->length;
94 set->count++;
96 *minor_status = 0;
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)
104 int i;
105 OM_uint32 minor;
107 *minor_status = 0;
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;
120 free(*buffer_set);
121 *buffer_set = GSS_C_NO_BUFFER_SET;
123 return GSS_S_COMPLETE;