1 /* $NetBSD: gss_add_oid_set_member.c,v 1.2 2017/01/28 21:31:46 christos Exp $ */
2
3 /*
4 * Copyright (c) 1997 - 2001, 2003 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include "mech_locl.h"
37
38 /**
39 * Add a oid to the oid set, function does not make a copy of the oid,
40 * so the pointer to member_oid needs to be stable for the whole time
41 * oid_set is used.
42 *
43 * If there is a duplicate member of the oid, the new member is not
44 * added to to the set.
45 *
46 * @param minor_status minor status code.
47 * @param member_oid member to add to the oid set
48 * @param oid_set oid set to add the member too
49 *
50 * @returns a gss_error code, see gss_display_status() about printing
51 * the error code.
52 *
53 * @ingroup gssapi
54 */
55
56 GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
gss_add_oid_set_member(OM_uint32 * minor_status,const gss_OID member_oid,gss_OID_set * oid_set)57 gss_add_oid_set_member (OM_uint32 * minor_status,
58 const gss_OID member_oid,
59 gss_OID_set * oid_set)
60 {
61 gss_OID tmp;
62 size_t n;
63 OM_uint32 res;
64 int present;
65
66 res = gss_test_oid_set_member(minor_status, member_oid, *oid_set, &present);
67 if (res != GSS_S_COMPLETE)
68 return res;
69
70 if (present) {
71 *minor_status = 0;
72 return GSS_S_COMPLETE;
73 }
74
75 n = (*oid_set)->count + 1;
76 tmp = realloc ((*oid_set)->elements, n * sizeof(gss_OID_desc));
77 if (tmp == NULL) {
78 *minor_status = ENOMEM;
79 return GSS_S_FAILURE;
80 }
81 (*oid_set)->elements = tmp;
82 (*oid_set)->count = n;
83 (*oid_set)->elements[n-1] = *member_oid;
84 *minor_status = 0;
85 return GSS_S_COMPLETE;
86 }
87