Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/lib/gssapi/generic/util_buffer_set.c
39563 views
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
/*
3
* Copyright 2008 by the Massachusetts Institute of Technology.
4
* All Rights Reserved.
5
*
6
* Export of this software from the United States of America may
7
* require a specific license from the United States Government.
8
* It is the responsibility of any person or organization contemplating
9
* export to obtain such a license before exporting.
10
*
11
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12
* distribute this software and its documentation for any purpose and
13
* without fee is hereby granted, provided that the above copyright
14
* notice appear in all copies and that both that copyright notice and
15
* this permission notice appear in supporting documentation, and that
16
* the name of M.I.T. not be used in advertising or publicity pertaining
17
* to distribution of the software without specific, written prior
18
* permission. Furthermore if you modify this software you must label
19
* your software as modified software and not distribute it in such a
20
* fashion that it might be confused with the original M.I.T. software.
21
* M.I.T. makes no representations about the suitability of
22
* this software for any purpose. It is provided "as is" without express
23
* or implied warranty.
24
*
25
*/
26
27
#include "gssapiP_generic.h"
28
#include <stdio.h>
29
#ifdef HAVE_STDLIB_H
30
#include <stdlib.h>
31
#endif
32
#include <string.h>
33
#include <errno.h>
34
35
OM_uint32
36
generic_gss_create_empty_buffer_set(OM_uint32 * minor_status,
37
gss_buffer_set_t *buffer_set)
38
{
39
gss_buffer_set_t set;
40
41
set = (gss_buffer_set_desc *) gssalloc_malloc(sizeof(*set));
42
if (set == GSS_C_NO_BUFFER_SET) {
43
*minor_status = ENOMEM;
44
return GSS_S_FAILURE;
45
}
46
47
set->count = 0;
48
set->elements = NULL;
49
50
*buffer_set = set;
51
52
*minor_status = 0;
53
return GSS_S_COMPLETE;
54
}
55
56
OM_uint32
57
generic_gss_add_buffer_set_member(OM_uint32 * minor_status,
58
const gss_buffer_t member_buffer,
59
gss_buffer_set_t *buffer_set)
60
{
61
gss_buffer_set_t set;
62
gss_buffer_t p;
63
OM_uint32 ret;
64
65
if (*buffer_set == GSS_C_NO_BUFFER_SET) {
66
ret = generic_gss_create_empty_buffer_set(minor_status,
67
buffer_set);
68
if (ret) {
69
return ret;
70
}
71
}
72
73
set = *buffer_set;
74
set->elements = (gss_buffer_desc *)gssalloc_realloc(set->elements,
75
(set->count + 1) *
76
sizeof(gss_buffer_desc));
77
if (set->elements == NULL) {
78
*minor_status = ENOMEM;
79
return GSS_S_FAILURE;
80
}
81
82
p = &set->elements[set->count];
83
84
p->value = gssalloc_malloc(member_buffer->length);
85
if (p->value == NULL) {
86
*minor_status = ENOMEM;
87
return GSS_S_FAILURE;
88
}
89
memcpy(p->value, member_buffer->value, member_buffer->length);
90
p->length = member_buffer->length;
91
92
set->count++;
93
94
*minor_status = 0;
95
return GSS_S_COMPLETE;
96
}
97
98
OM_uint32
99
generic_gss_release_buffer_set(OM_uint32 * minor_status,
100
gss_buffer_set_t *buffer_set)
101
{
102
size_t i;
103
OM_uint32 minor;
104
105
*minor_status = 0;
106
107
if (*buffer_set == GSS_C_NO_BUFFER_SET) {
108
return GSS_S_COMPLETE;
109
}
110
111
for (i = 0; i < (*buffer_set)->count; i++) {
112
generic_gss_release_buffer(&minor, &((*buffer_set)->elements[i]));
113
}
114
115
if ((*buffer_set)->elements != NULL) {
116
gssalloc_free((*buffer_set)->elements);
117
(*buffer_set)->elements = NULL;
118
}
119
120
(*buffer_set)->count = 0;
121
122
gssalloc_free(*buffer_set);
123
*buffer_set = GSS_C_NO_BUFFER_SET;
124
125
return GSS_S_COMPLETE;
126
}
127
128