Udiff oid_ops.c
--- /net/etna.eng/build7/semery/mit2/webrev/usr/src/lib/libgss/oid_ops.c- Wed Sep 8 17:01:17 2004
+++ oid_ops.c Wed Sep 8 13:42:06 2004
@@ -1,11 +1,11 @@
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "@(#)oid_ops.c 1.20 04/09/08 SMI"
+#pragma ident "@(#)oid_ops.c 1.19 04/02/23 SMI"
/*
* lib/gssapi/generic/oid_ops.c
*
* Copyright 1995 by the Massachusetts Institute of Technology.
@@ -53,10 +53,11 @@
OM_uint32
generic_gss_release_oid(minor_status, oid)
OM_uint32 *minor_status;
gss_OID *oid;
{
+ if (minor_status)
*minor_status = 0;
if (*oid == GSS_C_NO_OID)
return (GSS_S_COMPLETE);
@@ -68,16 +69,24 @@
* for other OIDs it will call the C free() routine for both the OID
* data and the descriptor. This allows applications to freely mix
* their own heap allocated OID values with OIDs returned by GSS-API.
*/
- if ((*oid != gss_nt_user_name) &&
- (*oid != gss_nt_machine_uid_name) &&
- (*oid != gss_nt_string_uid_name) &&
- (*oid != gss_nt_service_name) &&
- (*oid != gss_nt_exported_name) &&
- (*oid != gss_nt_service_name_v2)) {
+ /*
+ * We use the official OID definitions instead of the unofficial OID
+ * defintions. But we continue to support the unofficial OID
+ * gss_nt_service_name just in case if some gss applications use
+ * the old OID.
+ */
+
+ if ((*oid != GSS_C_NT_USER_NAME) &&
+ (*oid != GSS_C_NT_MACHINE_UID_NAME) &&
+ (*oid != GSS_C_NT_STRING_UID_NAME) &&
+ (*oid != GSS_C_NT_HOSTBASED_SERVICE) &&
+ (*oid != GSS_C_NT_ANONYMOUS) &&
+ (*oid != GSS_C_NT_EXPORT_NAME) &&
+ (*oid != gss_nt_service_name)) {
free((*oid)->elements);
free(*oid);
}
*oid = GSS_C_NO_OID;
return (GSS_S_COMPLETE);
@@ -89,20 +98,21 @@
const gss_OID oid;
gss_OID *new_oid;
{
gss_OID p;
+ if (minor_status)
+ *minor_status = 0;
+
p = (gss_OID) malloc(sizeof (gss_OID_desc));
if (!p) {
- *minor_status = ENOMEM;
return (GSS_S_FAILURE);
}
p->length = oid->length;
p->elements = malloc(p->length);
if (!p->elements) {
free(p);
- *minor_status = ENOMEM;
return (GSS_S_FAILURE);
}
(void) memcpy(p->elements, oid->elements, p->length);
*new_oid = p;
return (GSS_S_COMPLETE);
@@ -112,16 +122,17 @@
OM_uint32
generic_gss_create_empty_oid_set(minor_status, oid_set)
OM_uint32 *minor_status;
gss_OID_set *oid_set;
{
+ if (minor_status)
+ *minor_status = 0;
+
if ((*oid_set = (gss_OID_set) malloc(sizeof (gss_OID_set_desc)))) {
(void) memset(*oid_set, 0, sizeof (gss_OID_set_desc));
- *minor_status = 0;
return (GSS_S_COMPLETE);
} else {
- *minor_status = ENOMEM;
return (GSS_S_FAILURE);
}
}
OM_uint32
@@ -131,10 +142,17 @@
gss_OID_set *oid_set;
{
gss_OID elist;
gss_OID lastel;
+ if (minor_status)
+ *minor_status = 0;
+
+ if (member_oid == NULL || member_oid->length == 0 ||
+ member_oid->elements == NULL)
+ return (GSS_S_CALL_INACCESSIBLE_READ);
+
elist = (*oid_set)->elements;
/* Get an enlarged copy of the array */
if (((*oid_set)->elements = (gss_OID) malloc(((*oid_set)->count+1) *
sizeof (gss_OID_desc)))) {
/* Copy in the old junk */
@@ -160,11 +178,10 @@
} else
free((*oid_set)->elements);
}
/* Failure - restore old contents of list */
(*oid_set)->elements = elist;
- *minor_status = ENOMEM;
return (GSS_S_FAILURE);
}
OM_uint32
generic_gss_test_oid_set_member(minor_status, member, set, present)
@@ -171,13 +188,22 @@
OM_uint32 *minor_status;
const gss_OID member;
const gss_OID_set set;
int *present;
{
- size_t i;
+ OM_uint32 i;
int result;
+ if (minor_status)
+ *minor_status = 0;
+
+ if (member == NULL || set == NULL)
+ return (GSS_S_CALL_INACCESSIBLE_READ);
+
+ if (present == NULL)
+ return (GSS_S_CALL_INACCESSIBLE_WRITE);
+
result = 0;
for (i = 0; i < set->count; i++) {
if ((set->elements[i].length == member->length) &&
!memcmp(set->elements[i].elements,
member->elements, member->length)) {
@@ -184,11 +210,10 @@
result = 1;
break;
}
}
*present = result;
- *minor_status = 0;
return (GSS_S_COMPLETE);
}
/*
* OID<->string routines. These are uuuuugly.
@@ -198,17 +223,26 @@
OM_uint32 *minor_status;
const gss_OID oid;
gss_buffer_t oid_str;
{
char numstr[128];
- unsigned long number;
+ OM_uint32 number;
int numshift;
- size_t string_length;
- size_t i;
+ OM_uint32 string_length;
+ OM_uint32 i;
unsigned char *cp;
char *bp;
+ if (minor_status)
+ *minor_status = 0;
+
+ if (oid == NULL || oid->length == 0 || oid->elements == NULL)
+ return (GSS_S_CALL_INACCESSIBLE_READ);
+
+ if (oid_str == NULL)
+ return (GSS_S_CALL_INACCESSIBLE_WRITE);
+
/* Decoded according to krb5/gssapi_krb5.c */
/* First determine the size of the string */
string_length = 0;
number = 0;
@@ -218,15 +252,14 @@
(void) sprintf(numstr, "%d ", number/40);
string_length += strlen(numstr);
(void) sprintf(numstr, "%d ", number%40);
string_length += strlen(numstr);
for (i = 1; i < oid->length; i++) {
- if ((size_t) (numshift+7) < (sizeof (unsigned long)*8)) {
+ if ((OM_uint32) (numshift+7) < (sizeof (OM_uint32)*8)) {
number = (number << 7) | (cp[i] & 0x7f);
numshift += 7;
} else {
- *minor_status = EINVAL;
return (GSS_S_FAILURE);
}
if ((cp[i] & 0x80) == 0) {
(void) sprintf(numstr, "%d ", number);
@@ -240,11 +273,11 @@
* here for "{ " and "}\0".
*/
string_length += 4;
if ((bp = (char *)malloc(string_length))) {
(void) strcpy(bp, "{ ");
- number = (unsigned long) cp[0];
+ number = (OM_uint32) cp[0];
(void) sprintf(numstr, "%d ", number/40);
(void) strcat(bp, numstr);
(void) sprintf(numstr, "%d ", number%40);
(void) strcat(bp, numstr);
number = 0;
@@ -258,14 +291,12 @@
}
}
(void) strcat(bp, "}");
oid_str->length = strlen(bp)+1;
oid_str->value = (void *) bp;
- *minor_status = 0;
return (GSS_S_COMPLETE);
}
- *minor_status = ENOMEM;
return (GSS_S_FAILURE);
}
/*
* This routine will handle 2 types of oid string formats:
@@ -284,13 +315,22 @@
char *cp, *bp, *startp;
int brace;
int numbuf;
int onumbuf;
OM_uint32 nbytes;
- int idx;
+ int index;
unsigned char *op;
+ if (minor_status)
+ *minor_status = 0;
+
+ if (GSS_EMPTY_BUFFER(oid_str))
+ return (GSS_S_CALL_INACCESSIBLE_READ);
+
+ if (oid == NULL)
+ return (GSS_S_CALL_INACCESSIBLE_WRITE);
+
brace = 0;
bp = (char *)oid_str->value;
cp = bp;
/* Skip over leading space */
while ((bp < &cp[oid_str->length]) && isspace(*bp))
@@ -306,70 +346,68 @@
/*
* The first two numbers are chewed up by the first octet.
*/
if (sscanf(bp, "%d", &numbuf) != 1) {
- *minor_status = EINVAL;
return (GSS_S_FAILURE);
}
while ((bp < &cp[oid_str->length]) && isdigit(*bp))
bp++;
while ((bp < &cp[oid_str->length]) &&
(isspace(*bp) || *bp == '.'))
bp++;
if (sscanf(bp, "%d", &numbuf) != 1) {
- *minor_status = EINVAL;
return (GSS_S_FAILURE);
}
- while ((bp < &cp[oid_str->length]) && isdigit((int) *bp))
+ while ((bp < &cp[oid_str->length]) && isdigit(*bp))
bp++;
- while ((bp < &cp[oid_str->length]) && isspace((int) *bp)
+ while ((bp < &cp[oid_str->length]) &&
+ (isspace(*bp) || *bp == '.'))
bp++;
nbytes++;
- while (isdigit((int) *bp)) {
- if (sscanf(bp, "%ld", &numbuf) != 1) {
- *minor_status = EINVAL;
+ while (isdigit(*bp)) {
+ if (sscanf(bp, "%d", &numbuf) != 1) {
return (GSS_S_FAILURE);
}
while (numbuf) {
nbytes++;
numbuf >>= 7;
}
- while ((bp < &cp[oid_str->length]) && isdigit((int) *bp))
+ while ((bp < &cp[oid_str->length]) && isdigit(*bp))
bp++;
- while ((bp < &cp[oid_str->length]) && isspace((int) *bp))
+ while ((bp < &cp[oid_str->length]) &&
+ (isspace(*bp) || *bp == '.'))
bp++;
}
if (brace && (*bp != '}')) {
- *minor_status = EINVAL;
return (GSS_S_FAILURE);
}
/*
* Phew! We've come this far, so the syntax is good.
*/
if ((*oid = (gss_OID) malloc(sizeof (gss_OID_desc)))) {
- if (((*oid)->elements = (void *) malloc((size_t) nbytes))) {
+ if (((*oid)->elements = (void *) malloc(nbytes))) {
(*oid)->length = nbytes;
op = (unsigned char *) (*oid)->elements;
bp = startp;
- (void) sscanf(bp, "%ld", &numbuf);
- while (isdigit((int) *bp))
+ (void) sscanf(bp, "%d", &numbuf);
+ while (isdigit(*bp))
bp++;
- while (isspace((int) *bp) || *bp == '.')
+ while (isspace(*bp) || *bp == '.')
bp++;
onumbuf = 40*numbuf;
- (void) sscanf(bp, "%ld", &numbuf);
+ (void) sscanf(bp, "%d", &numbuf);
onumbuf += numbuf;
*op = (unsigned char) onumbuf;
op++;
- while (isdigit((int) *bp))
+ while (isdigit(*bp))
bp++;
- while (isspace((int) *bp))
+ while (isspace(*bp) || *bp == '.')
bp++;
- while (isdigit((int) *bp)) {
- (void) sscanf(bp, "%ld", &numbuf);
+ while (isdigit(*bp)) {
+ (void) sscanf(bp, "%d", &numbuf);
nbytes = 0;
/* Have to fill in the bytes msb-first */
onumbuf = numbuf;
while (numbuf) {
nbytes++;
@@ -384,21 +422,95 @@
if (index != -1)
op[index] |= 0x80;
index--;
numbuf >>= 7;
}
- while (isdigit((int) *bp))
+ while (isdigit(*bp))
bp++;
- while (isspace((int) *bp))
+ while (isspace(*bp) || *bp == '.')
bp++;
}
- *minor_status = 0;
return (GSS_S_COMPLETE);
} else {
free(*oid);
*oid = GSS_C_NO_OID;
}
}
- *minor_status = ENOMEM;
return (GSS_S_FAILURE);
}
+/*
+ * Copyright 1993 by OpenVision Technologies, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appears in all copies and
+ * that both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of OpenVision not be used
+ * in advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. OpenVision makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+OM_uint32
+gss_copy_oid_set(
+ OM_uint32 *minor_status,
+ const gss_OID_set_desc * const oidset,
+ gss_OID_set *new_oidset
+)
+{
+ gss_OID_set_desc *copy;
+ OM_uint32 minor = 0;
+ OM_uint32 major = GSS_S_COMPLETE;
+ OM_uint32 index;
+
+ if (minor_status)
+ *minor_status = 0;
+
+ if (oidset == NULL)
+ return (GSS_S_CALL_INACCESSIBLE_READ);
+
+ if (new_oidset == NULL)
+ return (GSS_S_CALL_INACCESSIBLE_WRITE);
+
+ *new_oidset = NULL;
+
+ if ((copy = (gss_OID_set_desc *) calloc(1, sizeof (*copy))) == NULL) {
+ major = GSS_S_FAILURE;
+ goto done;
+ }
+
+ if ((copy->elements = (gss_OID_desc *)
+ calloc(oidset->count, sizeof (*copy->elements))) == NULL) {
+ major = GSS_S_FAILURE;
+ goto done;
+ }
+ copy->count = oidset->count;
+
+ for (index = 0; index < copy->count; index++) {
+ gss_OID_desc *out = ©->elements[index];
+ gss_OID_desc *in = &oidset->elements[index];
+
+ if ((out->elements = (void *) malloc(in->length)) == NULL) {
+ major = GSS_S_FAILURE;
+ goto done;
+ }
+ (void) memcpy(out->elements, in->elements, in->length);
+ out->length = in->length;
+ }
+
+ *new_oidset = copy;
+done:
+ if (major != GSS_S_COMPLETE) {
+ (void) gss_release_oid_set(&minor, ©);
+ }
+
+ return (major);
+}