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