4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
25 * Copyright (c) 1997, by Sun Microsystems, Inc.
26 * All rights reserved.
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include "dh_gssapi.h"
36 * These are private mech_dh oid support routines.
39 /* See if two oids have the same value */
41 __OID_equal(const gss_OID_desc
* const oid1
, const gss_OID_desc
* const oid2
)
43 if (oid1
->length
!= oid2
->length
)
45 return (memcmp(oid1
->elements
, oid2
->elements
, oid1
->length
) == 0);
49 /* Count the number of elements in an oid. Return -1 on badly formed OID */
51 __OID_nel(const gss_OID_desc
* const oid
)
54 unsigned char *p
= (unsigned char *)oid
->elements
;
55 unsigned char *e
= p
+ oid
->length
;
58 for (i
= 0; p
< e
; i
++) {
59 /* If the upper bit is set it is part of this element */
71 /* Copy an oid to an allocated gss_OID_desc */
73 __OID_copy_desc(gss_OID dest
, const gss_OID_desc
* const source
)
76 /* Allocate the elements of the new OID */
77 dest
->elements
= (void *)New(char, source
->length
);
78 if (dest
->elements
== NULL
)
79 return (DH_NOMEM_FAILURE
);
82 dest
->length
= source
->length
;
84 /* And copy the elements */
85 memcpy(dest
->elements
, source
->elements
, dest
->length
);
90 /* Copy an oid, allocating storage */
92 __OID_copy(gss_OID
*dest
, const gss_OID_desc
* const source
)
94 /* Allocate a new OID */
95 gss_OID oid
= New(gss_OID_desc
, 1);
97 /* Clear the destination */
100 /* return failure if no memory for oid */
102 return (DH_NOMEM_FAILURE
);
104 /* Copy the soure oid in to the new OID */
105 if (__OID_copy_desc(oid
, source
) != DH_SUCCESS
) {
107 return (DH_NOMEM_FAILURE
);
110 /* Set the destination oid */
115 /* Check if an oid is a member of an oid set */
117 __OID_is_member(gss_OID_set set
, const gss_OID_desc
* const element
)
121 /* For each member in the set ... */
122 for (i
= 0; i
< set
->count
; i
++)
123 if (__OID_equal(element
, &set
->elements
[i
]))
129 /* Copy oid set to a newly allocated set */
131 __OID_copy_set(gss_OID_set
*dest
, gss_OID_set source
)
136 /* Clear the destination */
137 *dest
= GSS_C_NO_OID_SET
;
139 /* Allocate a new container for the set */
140 set
= New(gss_OID_set_desc
, 1);
142 return (DH_NOMEM_FAILURE
);
144 /* Allocate storage for the elements of the set */
145 set
->elements
= New(gss_OID_desc
, source
->count
);
146 if (set
->elements
== NULL
) {
148 return (DH_NOMEM_FAILURE
);
150 /* set the number of elements in the set */
151 set
->count
= source
->count
;
153 /* Add each member of the source set to the new set */
154 for (i
= 0; i
< source
->count
; i
++)
155 if (__OID_copy_desc(&set
->elements
[i
], &source
->elements
[i
])
159 /* Free partially allocated set on error */
160 if (i
!= source
->count
) {
162 Free(set
->elements
[i
].elements
);
165 return (DH_NOMEM_FAILURE
);
168 /* Set the destination to the set */
175 * Form a gss_OID_set from an array of gss_OID_desc.
178 __OID_copy_set_from_array(gss_OID_set
*dest
,
179 const gss_OID_desc
*array
[], size_t nel
)
184 /* Clear the output set */
185 *dest
= GSS_C_NO_OID_SET
;
187 /* Allocate the set */
188 set
= New(gss_OID_set_desc
, 1);
190 return (DH_NOMEM_FAILURE
);
192 /* And space for the members */
193 set
->elements
= New(gss_OID_desc
, nel
);
194 if (set
->elements
== NULL
) {
196 return (DH_NOMEM_FAILURE
);
198 /* Set the set count */
201 /* For each element in the array, addit to the set */
202 for (i
= 0; i
< set
->count
; i
++)
203 if (__OID_copy_desc(&set
->elements
[i
], array
[i
])
207 /* if we failed recover memory */
208 if (i
!= set
->count
) {
210 Free(set
->elements
[i
].elements
);
213 return (DH_NOMEM_FAILURE
);
216 /* Set the destination */
223 * Given an oid create a GSS_OID_set with a copy of that oid as its
227 __OID_to_OID_set(gss_OID_set
*set
, const gss_OID_desc
* const oid
)
236 /* Allocate a set description */
237 if ((s
= New(gss_OID_set_desc
, 1)) == NULL
)
238 return (DH_NOMEM_FAILURE
);
240 /* Add the OID to the set */
242 if (rc
= __OID_copy(&s
->elements
, oid
)) {