1226031Sstas/*
2226031Sstas * Copyright (c) 1997 - 2001, 2003 Kungliga Tekniska H��gskolan
3226031Sstas * (Royal Institute of Technology, Stockholm, Sweden).
4226031Sstas * All rights reserved.
5226031Sstas *
6226031Sstas * Redistribution and use in source and binary forms, with or without
7226031Sstas * modification, are permitted provided that the following conditions
8226031Sstas * are met:
9226031Sstas *
10226031Sstas * 1. Redistributions of source code must retain the above copyright
11226031Sstas *    notice, this list of conditions and the following disclaimer.
12226031Sstas *
13226031Sstas * 2. Redistributions in binary form must reproduce the above copyright
14226031Sstas *    notice, this list of conditions and the following disclaimer in the
15226031Sstas *    documentation and/or other materials provided with the distribution.
16226031Sstas *
17226031Sstas * 3. Neither the name of the Institute nor the names of its contributors
18226031Sstas *    may be used to endorse or promote products derived from this software
19226031Sstas *    without specific prior written permission.
20226031Sstas *
21226031Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24226031Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31226031Sstas * SUCH DAMAGE.
32226031Sstas */
33226031Sstas
34226031Sstas#include "mech_locl.h"
35226031Sstas
36226031Sstas/**
37226031Sstas * Add a oid to the oid set, function does not make a copy of the oid,
38226031Sstas * so the pointer to member_oid needs to be stable for the whole time
39226031Sstas * oid_set is used.
40226031Sstas *
41226031Sstas * If there is a duplicate member of the oid, the new member is not
42226031Sstas * added to to the set.
43226031Sstas *
44226031Sstas * @param minor_status minor status code.
45226031Sstas * @param member_oid member to add to the oid set
46226031Sstas * @param oid_set oid set to add the member too
47226031Sstas *
48226031Sstas * @returns a gss_error code, see gss_display_status() about printing
49226031Sstas *          the error code.
50226031Sstas *
51226031Sstas * @ingroup gssapi
52226031Sstas */
53226031Sstas
54226031SstasGSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
55226031Sstasgss_add_oid_set_member (OM_uint32 * minor_status,
56226031Sstas			const gss_OID member_oid,
57226031Sstas			gss_OID_set * oid_set)
58226031Sstas{
59226031Sstas    gss_OID tmp;
60226031Sstas    size_t n;
61226031Sstas    OM_uint32 res;
62226031Sstas    int present;
63226031Sstas
64226031Sstas    res = gss_test_oid_set_member(minor_status, member_oid, *oid_set, &present);
65226031Sstas    if (res != GSS_S_COMPLETE)
66226031Sstas	return res;
67226031Sstas
68226031Sstas    if (present) {
69226031Sstas	*minor_status = 0;
70226031Sstas	return GSS_S_COMPLETE;
71226031Sstas    }
72226031Sstas
73226031Sstas    n = (*oid_set)->count + 1;
74226031Sstas    tmp = realloc ((*oid_set)->elements, n * sizeof(gss_OID_desc));
75226031Sstas    if (tmp == NULL) {
76226031Sstas	*minor_status = ENOMEM;
77226031Sstas	return GSS_S_FAILURE;
78226031Sstas    }
79226031Sstas    (*oid_set)->elements = tmp;
80226031Sstas    (*oid_set)->count = n;
81226031Sstas    (*oid_set)->elements[n-1] = *member_oid;
82226031Sstas    *minor_status = 0;
83226031Sstas    return GSS_S_COMPLETE;
84226031Sstas}
85