17c478bd9Sstevel@tonic-gate /* 2*503a2b89SPeter Shoults * CDDL HEADER START 3*503a2b89SPeter Shoults * 4*503a2b89SPeter Shoults * The contents of this file are subject to the terms of the 5*503a2b89SPeter Shoults * Common Development and Distribution License (the "License"). 6*503a2b89SPeter Shoults * You may not use this file except in compliance with the License. 7*503a2b89SPeter Shoults * 8*503a2b89SPeter Shoults * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*503a2b89SPeter Shoults * or http://www.opensolaris.org/os/licensing. 10*503a2b89SPeter Shoults * See the License for the specific language governing permissions 11*503a2b89SPeter Shoults * and limitations under the License. 12*503a2b89SPeter Shoults * 13*503a2b89SPeter Shoults * When distributing Covered Code, include this CDDL HEADER in each 14*503a2b89SPeter Shoults * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*503a2b89SPeter Shoults * If applicable, add the following below this CDDL HEADER, with the 16*503a2b89SPeter Shoults * fields enclosed by brackets "[]" replaced with your own identifying 17*503a2b89SPeter Shoults * information: Portions Copyright [yyyy] [name of copyright owner] 18*503a2b89SPeter Shoults * 19*503a2b89SPeter Shoults * CDDL HEADER END 20*503a2b89SPeter Shoults */ 21*503a2b89SPeter Shoults /* 22*503a2b89SPeter Shoults * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * lib/gssapi/generic/oid_ops.c 287c478bd9Sstevel@tonic-gate * 297c478bd9Sstevel@tonic-gate * Copyright 1995 by the Massachusetts Institute of Technology. 307c478bd9Sstevel@tonic-gate * All Rights Reserved. 317c478bd9Sstevel@tonic-gate * 327c478bd9Sstevel@tonic-gate * Export of this software from the United States of America may 337c478bd9Sstevel@tonic-gate * require a specific license from the United States Government. 347c478bd9Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating 357c478bd9Sstevel@tonic-gate * export to obtain such a license before exporting. 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 387c478bd9Sstevel@tonic-gate * distribute this software and its documentation for any purpose and 397c478bd9Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright 407c478bd9Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and 417c478bd9Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that 427c478bd9Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining 437c478bd9Sstevel@tonic-gate * to distribution of the software without specific, written prior 447c478bd9Sstevel@tonic-gate * permission. M.I.T. makes no representations about the suitability of 457c478bd9Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express 467c478bd9Sstevel@tonic-gate * or implied warranty. 477c478bd9Sstevel@tonic-gate * 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * oid_ops.c - GSS-API V2 interfaces to manipulate OIDs 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #include <mechglueP.h> 557c478bd9Sstevel@tonic-gate #ifdef HAVE_UNISTD_H 567c478bd9Sstevel@tonic-gate #include <unistd.h> 577c478bd9Sstevel@tonic-gate #endif 587c478bd9Sstevel@tonic-gate #include <stdlib.h> 597c478bd9Sstevel@tonic-gate #include <string.h> 607c478bd9Sstevel@tonic-gate #include <stdio.h> 617c478bd9Sstevel@tonic-gate #include <errno.h> 627c478bd9Sstevel@tonic-gate #include <ctype.h> 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* 657c478bd9Sstevel@tonic-gate * this oid is defined in the oid structure but not exported to 667c478bd9Sstevel@tonic-gate * external callers; we must still ensure that we do not delete it. 677c478bd9Sstevel@tonic-gate */ 687c478bd9Sstevel@tonic-gate extern const gss_OID_desc * const gss_nt_service_name; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate OM_uint32 727c478bd9Sstevel@tonic-gate generic_gss_release_oid(minor_status, oid) 737c478bd9Sstevel@tonic-gate OM_uint32 *minor_status; 747c478bd9Sstevel@tonic-gate gss_OID *oid; 757c478bd9Sstevel@tonic-gate { 767c478bd9Sstevel@tonic-gate if (minor_status) 777c478bd9Sstevel@tonic-gate *minor_status = 0; 787c478bd9Sstevel@tonic-gate 79*503a2b89SPeter Shoults if (oid == NULL || *oid == GSS_C_NO_OID) 807c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE); 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* 837c478bd9Sstevel@tonic-gate * The V2 API says the following! 847c478bd9Sstevel@tonic-gate * 857c478bd9Sstevel@tonic-gate * gss_release_oid[()] will recognize any of the GSSAPI's own OID 867c478bd9Sstevel@tonic-gate * values, and will silently ignore attempts to free these OIDs; 877c478bd9Sstevel@tonic-gate * for other OIDs it will call the C free() routine for both the OID 887c478bd9Sstevel@tonic-gate * data and the descriptor. This allows applications to freely mix 897c478bd9Sstevel@tonic-gate * their own heap allocated OID values with OIDs returned by GSS-API. 907c478bd9Sstevel@tonic-gate */ 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate /* 937c478bd9Sstevel@tonic-gate * We use the official OID definitions instead of the unofficial OID 947c478bd9Sstevel@tonic-gate * defintions. But we continue to support the unofficial OID 957c478bd9Sstevel@tonic-gate * gss_nt_service_name just in case if some gss applications use 967c478bd9Sstevel@tonic-gate * the old OID. 977c478bd9Sstevel@tonic-gate */ 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate if ((*oid != GSS_C_NT_USER_NAME) && 1007c478bd9Sstevel@tonic-gate (*oid != GSS_C_NT_MACHINE_UID_NAME) && 1017c478bd9Sstevel@tonic-gate (*oid != GSS_C_NT_STRING_UID_NAME) && 1027c478bd9Sstevel@tonic-gate (*oid != GSS_C_NT_HOSTBASED_SERVICE) && 1037c478bd9Sstevel@tonic-gate (*oid != GSS_C_NT_ANONYMOUS) && 1047c478bd9Sstevel@tonic-gate (*oid != GSS_C_NT_EXPORT_NAME) && 1057c478bd9Sstevel@tonic-gate (*oid != gss_nt_service_name)) { 1067c478bd9Sstevel@tonic-gate free((*oid)->elements); 1077c478bd9Sstevel@tonic-gate free(*oid); 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate *oid = GSS_C_NO_OID; 1107c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE); 1117c478bd9Sstevel@tonic-gate } 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate OM_uint32 1147c478bd9Sstevel@tonic-gate generic_gss_copy_oid(minor_status, oid, new_oid) 1157c478bd9Sstevel@tonic-gate OM_uint32 *minor_status; 1167c478bd9Sstevel@tonic-gate const gss_OID oid; 1177c478bd9Sstevel@tonic-gate gss_OID *new_oid; 1187c478bd9Sstevel@tonic-gate { 1197c478bd9Sstevel@tonic-gate gss_OID p; 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate if (minor_status) 1227c478bd9Sstevel@tonic-gate *minor_status = 0; 1237c478bd9Sstevel@tonic-gate 124354d1447Swyllys if (new_oid == NULL) 125354d1447Swyllys return (GSS_S_CALL_INACCESSIBLE_WRITE); 126354d1447Swyllys 127354d1447Swyllys if (oid == GSS_C_NO_OID) 128354d1447Swyllys return (GSS_S_CALL_INACCESSIBLE_READ); 129354d1447Swyllys 1307c478bd9Sstevel@tonic-gate p = (gss_OID) malloc(sizeof (gss_OID_desc)); 1317c478bd9Sstevel@tonic-gate if (!p) { 1327c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE); 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate p->length = oid->length; 1357c478bd9Sstevel@tonic-gate p->elements = malloc(p->length); 1367c478bd9Sstevel@tonic-gate if (!p->elements) { 1377c478bd9Sstevel@tonic-gate free(p); 1387c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE); 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate (void) memcpy(p->elements, oid->elements, p->length); 1417c478bd9Sstevel@tonic-gate *new_oid = p; 1427c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE); 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate OM_uint32 1477c478bd9Sstevel@tonic-gate generic_gss_create_empty_oid_set(minor_status, oid_set) 1487c478bd9Sstevel@tonic-gate OM_uint32 *minor_status; 1497c478bd9Sstevel@tonic-gate gss_OID_set *oid_set; 1507c478bd9Sstevel@tonic-gate { 1517c478bd9Sstevel@tonic-gate if (minor_status) 1527c478bd9Sstevel@tonic-gate *minor_status = 0; 1537c478bd9Sstevel@tonic-gate 154354d1447Swyllys if (oid_set == NULL) 155354d1447Swyllys return (GSS_S_CALL_INACCESSIBLE_WRITE); 156354d1447Swyllys 1577c478bd9Sstevel@tonic-gate if ((*oid_set = (gss_OID_set) malloc(sizeof (gss_OID_set_desc)))) { 1587c478bd9Sstevel@tonic-gate (void) memset(*oid_set, 0, sizeof (gss_OID_set_desc)); 1597c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE); 1607c478bd9Sstevel@tonic-gate } else { 1617c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE); 1627c478bd9Sstevel@tonic-gate } 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate OM_uint32 1667c478bd9Sstevel@tonic-gate generic_gss_add_oid_set_member(minor_status, member_oid, oid_set) 1677c478bd9Sstevel@tonic-gate OM_uint32 *minor_status; 1687c478bd9Sstevel@tonic-gate const gss_OID member_oid; 1697c478bd9Sstevel@tonic-gate gss_OID_set *oid_set; 1707c478bd9Sstevel@tonic-gate { 1717c478bd9Sstevel@tonic-gate gss_OID elist; 1727c478bd9Sstevel@tonic-gate gss_OID lastel; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate if (minor_status) 1757c478bd9Sstevel@tonic-gate *minor_status = 0; 1767c478bd9Sstevel@tonic-gate 177354d1447Swyllys if (member_oid == GSS_C_NO_OID || member_oid->length == 0 || 1787c478bd9Sstevel@tonic-gate member_oid->elements == NULL) 1797c478bd9Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_READ); 1807c478bd9Sstevel@tonic-gate 181354d1447Swyllys if (oid_set == NULL) 182354d1447Swyllys return (GSS_S_CALL_INACCESSIBLE_WRITE); 183354d1447Swyllys 1847c478bd9Sstevel@tonic-gate elist = (*oid_set)->elements; 1857c478bd9Sstevel@tonic-gate /* Get an enlarged copy of the array */ 1867c478bd9Sstevel@tonic-gate if (((*oid_set)->elements = (gss_OID) malloc(((*oid_set)->count+1) * 1877c478bd9Sstevel@tonic-gate sizeof (gss_OID_desc)))) { 188354d1447Swyllys /* Copy in the old junk */ 1897c478bd9Sstevel@tonic-gate if (elist) 1907c478bd9Sstevel@tonic-gate (void) memcpy((*oid_set)->elements, elist, 1917c478bd9Sstevel@tonic-gate ((*oid_set)->count * sizeof (gss_OID_desc))); 1927c478bd9Sstevel@tonic-gate 193354d1447Swyllys /* Duplicate the input element */ 1947c478bd9Sstevel@tonic-gate lastel = &(*oid_set)->elements[(*oid_set)->count]; 1957c478bd9Sstevel@tonic-gate if ((lastel->elements = 1967c478bd9Sstevel@tonic-gate (void *) malloc(member_oid->length))) { 197354d1447Swyllys 198354d1447Swyllys /* Success - copy elements */ 1997c478bd9Sstevel@tonic-gate (void) memcpy(lastel->elements, member_oid->elements, 2007c478bd9Sstevel@tonic-gate member_oid->length); 201354d1447Swyllys /* Set length */ 2027c478bd9Sstevel@tonic-gate lastel->length = member_oid->length; 2037c478bd9Sstevel@tonic-gate 204354d1447Swyllys /* Update count */ 2057c478bd9Sstevel@tonic-gate (*oid_set)->count++; 2067c478bd9Sstevel@tonic-gate if (elist) 2077c478bd9Sstevel@tonic-gate free(elist); 2087c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE); 2097c478bd9Sstevel@tonic-gate } else 2107c478bd9Sstevel@tonic-gate free((*oid_set)->elements); 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate /* Failure - restore old contents of list */ 2137c478bd9Sstevel@tonic-gate (*oid_set)->elements = elist; 2147c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE); 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate OM_uint32 2187c478bd9Sstevel@tonic-gate generic_gss_test_oid_set_member(minor_status, member, set, present) 2197c478bd9Sstevel@tonic-gate OM_uint32 *minor_status; 2207c478bd9Sstevel@tonic-gate const gss_OID member; 2217c478bd9Sstevel@tonic-gate const gss_OID_set set; 2227c478bd9Sstevel@tonic-gate int *present; 2237c478bd9Sstevel@tonic-gate { 2247c478bd9Sstevel@tonic-gate OM_uint32 i; 2257c478bd9Sstevel@tonic-gate int result; 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate if (minor_status) 2287c478bd9Sstevel@tonic-gate *minor_status = 0; 2297c478bd9Sstevel@tonic-gate 230354d1447Swyllys if (member == GSS_C_NO_OID || set == NULL) 2317c478bd9Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_READ); 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate if (present == NULL) 2347c478bd9Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_WRITE); 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate result = 0; 2377c478bd9Sstevel@tonic-gate for (i = 0; i < set->count; i++) { 2387c478bd9Sstevel@tonic-gate if ((set->elements[i].length == member->length) && 2397c478bd9Sstevel@tonic-gate !memcmp(set->elements[i].elements, 2407c478bd9Sstevel@tonic-gate member->elements, member->length)) { 2417c478bd9Sstevel@tonic-gate result = 1; 2427c478bd9Sstevel@tonic-gate break; 2437c478bd9Sstevel@tonic-gate } 2447c478bd9Sstevel@tonic-gate } 2457c478bd9Sstevel@tonic-gate *present = result; 2467c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE); 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate /* 2507c478bd9Sstevel@tonic-gate * OID<->string routines. These are uuuuugly. 2517c478bd9Sstevel@tonic-gate */ 2527c478bd9Sstevel@tonic-gate OM_uint32 2537c478bd9Sstevel@tonic-gate generic_gss_oid_to_str(minor_status, oid, oid_str) 2547c478bd9Sstevel@tonic-gate OM_uint32 *minor_status; 2557c478bd9Sstevel@tonic-gate const gss_OID oid; 2567c478bd9Sstevel@tonic-gate gss_buffer_t oid_str; 2577c478bd9Sstevel@tonic-gate { 2587c478bd9Sstevel@tonic-gate char numstr[128]; 2597c478bd9Sstevel@tonic-gate OM_uint32 number; 2607c478bd9Sstevel@tonic-gate int numshift; 2617c478bd9Sstevel@tonic-gate OM_uint32 string_length; 2627c478bd9Sstevel@tonic-gate OM_uint32 i; 2637c478bd9Sstevel@tonic-gate unsigned char *cp; 2647c478bd9Sstevel@tonic-gate char *bp; 2657c478bd9Sstevel@tonic-gate 266*503a2b89SPeter Shoults if (minor_status != NULL) 2677c478bd9Sstevel@tonic-gate *minor_status = 0; 2687c478bd9Sstevel@tonic-gate 269*503a2b89SPeter Shoults if (oid_str != GSS_C_NO_BUFFER) { 270*503a2b89SPeter Shoults oid_str->length = 0; 271*503a2b89SPeter Shoults oid_str->value = NULL; 272*503a2b89SPeter Shoults } 273*503a2b89SPeter Shoults 274354d1447Swyllys if (oid == GSS_C_NO_OID || oid->length == 0 || oid->elements == NULL) 2757c478bd9Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_READ); 2767c478bd9Sstevel@tonic-gate 277*503a2b89SPeter Shoults if (oid_str == GSS_C_NO_BUFFER) 2787c478bd9Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_WRITE); 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate /* First determine the size of the string */ 2817c478bd9Sstevel@tonic-gate string_length = 0; 2827c478bd9Sstevel@tonic-gate number = 0; 2837c478bd9Sstevel@tonic-gate numshift = 0; 2847c478bd9Sstevel@tonic-gate cp = (unsigned char *) oid->elements; 2857c478bd9Sstevel@tonic-gate number = (OM_uint32) cp[0]; 2867c478bd9Sstevel@tonic-gate (void) sprintf(numstr, "%d ", number/40); 2877c478bd9Sstevel@tonic-gate string_length += strlen(numstr); 2887c478bd9Sstevel@tonic-gate (void) sprintf(numstr, "%d ", number%40); 2897c478bd9Sstevel@tonic-gate string_length += strlen(numstr); 2907c478bd9Sstevel@tonic-gate for (i = 1; i < oid->length; i++) { 2917c478bd9Sstevel@tonic-gate if ((OM_uint32) (numshift+7) < (sizeof (OM_uint32)*8)) { 2927c478bd9Sstevel@tonic-gate number = (number << 7) | (cp[i] & 0x7f); 2937c478bd9Sstevel@tonic-gate numshift += 7; 2947c478bd9Sstevel@tonic-gate } else { 2957c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE); 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate if ((cp[i] & 0x80) == 0) { 2997c478bd9Sstevel@tonic-gate (void) sprintf(numstr, "%d ", number); 3007c478bd9Sstevel@tonic-gate string_length += strlen(numstr); 3017c478bd9Sstevel@tonic-gate number = 0; 3027c478bd9Sstevel@tonic-gate numshift = 0; 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate /* 3067c478bd9Sstevel@tonic-gate * If we get here, we've calculated the length of "n n n ... n ". Add 4 3077c478bd9Sstevel@tonic-gate * here for "{ " and "}\0". 3087c478bd9Sstevel@tonic-gate */ 3097c478bd9Sstevel@tonic-gate string_length += 4; 3107c478bd9Sstevel@tonic-gate if ((bp = (char *)malloc(string_length))) { 3117c478bd9Sstevel@tonic-gate (void) strcpy(bp, "{ "); 3127c478bd9Sstevel@tonic-gate number = (OM_uint32) cp[0]; 3137c478bd9Sstevel@tonic-gate (void) sprintf(numstr, "%d ", number/40); 3147c478bd9Sstevel@tonic-gate (void) strcat(bp, numstr); 3157c478bd9Sstevel@tonic-gate (void) sprintf(numstr, "%d ", number%40); 3167c478bd9Sstevel@tonic-gate (void) strcat(bp, numstr); 3177c478bd9Sstevel@tonic-gate number = 0; 3187c478bd9Sstevel@tonic-gate cp = (unsigned char *) oid->elements; 3197c478bd9Sstevel@tonic-gate for (i = 1; i < oid->length; i++) { 3207c478bd9Sstevel@tonic-gate number = (number << 7) | (cp[i] & 0x7f); 3217c478bd9Sstevel@tonic-gate if ((cp[i] & 0x80) == 0) { 3227c478bd9Sstevel@tonic-gate (void) sprintf(numstr, "%d ", number); 3237c478bd9Sstevel@tonic-gate (void) strcat(bp, numstr); 3247c478bd9Sstevel@tonic-gate number = 0; 3257c478bd9Sstevel@tonic-gate } 3267c478bd9Sstevel@tonic-gate } 3277c478bd9Sstevel@tonic-gate (void) strcat(bp, "}"); 3287c478bd9Sstevel@tonic-gate oid_str->length = strlen(bp)+1; 3297c478bd9Sstevel@tonic-gate oid_str->value = (void *) bp; 3307c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE); 3317c478bd9Sstevel@tonic-gate } 3327c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE); 3337c478bd9Sstevel@tonic-gate } 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate /* 3367c478bd9Sstevel@tonic-gate * This routine will handle 2 types of oid string formats: 3377c478bd9Sstevel@tonic-gate * 1 - { 1 2 3 4 } where the braces are optional 3387c478bd9Sstevel@tonic-gate * 2 - 1.2.3.4 this is an alernative format 3397c478bd9Sstevel@tonic-gate * The first format is mandated by the gss spec. The 3407c478bd9Sstevel@tonic-gate * second format is popular outside of the gss community so 3417c478bd9Sstevel@tonic-gate * has been added. 3427c478bd9Sstevel@tonic-gate */ 3437c478bd9Sstevel@tonic-gate OM_uint32 3447c478bd9Sstevel@tonic-gate generic_gss_str_to_oid(minor_status, oid_str, oid) 3457c478bd9Sstevel@tonic-gate OM_uint32 *minor_status; 3467c478bd9Sstevel@tonic-gate const gss_buffer_t oid_str; 3477c478bd9Sstevel@tonic-gate gss_OID *oid; 3487c478bd9Sstevel@tonic-gate { 3497c478bd9Sstevel@tonic-gate char *cp, *bp, *startp; 3507c478bd9Sstevel@tonic-gate int brace; 3517c478bd9Sstevel@tonic-gate int numbuf; 3527c478bd9Sstevel@tonic-gate int onumbuf; 3537c478bd9Sstevel@tonic-gate OM_uint32 nbytes; 3547c478bd9Sstevel@tonic-gate int index; 3557c478bd9Sstevel@tonic-gate unsigned char *op; 3567c478bd9Sstevel@tonic-gate 357*503a2b89SPeter Shoults if (minor_status != NULL) 3587c478bd9Sstevel@tonic-gate *minor_status = 0; 3597c478bd9Sstevel@tonic-gate 360*503a2b89SPeter Shoults if (oid != NULL) 361*503a2b89SPeter Shoults *oid = GSS_C_NO_OID; 362*503a2b89SPeter Shoults 3637c478bd9Sstevel@tonic-gate if (GSS_EMPTY_BUFFER(oid_str)) 3647c478bd9Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_READ); 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate if (oid == NULL) 3677c478bd9Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_WRITE); 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate brace = 0; 3707c478bd9Sstevel@tonic-gate bp = (char *)oid_str->value; 3717c478bd9Sstevel@tonic-gate cp = bp; 3727c478bd9Sstevel@tonic-gate /* Skip over leading space */ 3737c478bd9Sstevel@tonic-gate while ((bp < &cp[oid_str->length]) && isspace(*bp)) 3747c478bd9Sstevel@tonic-gate bp++; 3757c478bd9Sstevel@tonic-gate if (*bp == '{') { 3767c478bd9Sstevel@tonic-gate brace = 1; 3777c478bd9Sstevel@tonic-gate bp++; 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate while ((bp < &cp[oid_str->length]) && isspace(*bp)) 3807c478bd9Sstevel@tonic-gate bp++; 3817c478bd9Sstevel@tonic-gate startp = bp; 3827c478bd9Sstevel@tonic-gate nbytes = 0; 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate /* 3857c478bd9Sstevel@tonic-gate * The first two numbers are chewed up by the first octet. 3867c478bd9Sstevel@tonic-gate */ 3877c478bd9Sstevel@tonic-gate if (sscanf(bp, "%d", &numbuf) != 1) { 3887c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE); 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate while ((bp < &cp[oid_str->length]) && isdigit(*bp)) 3917c478bd9Sstevel@tonic-gate bp++; 3927c478bd9Sstevel@tonic-gate while ((bp < &cp[oid_str->length]) && 3937c478bd9Sstevel@tonic-gate (isspace(*bp) || *bp == '.')) 3947c478bd9Sstevel@tonic-gate bp++; 3957c478bd9Sstevel@tonic-gate if (sscanf(bp, "%d", &numbuf) != 1) { 3967c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE); 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate while ((bp < &cp[oid_str->length]) && isdigit(*bp)) 3997c478bd9Sstevel@tonic-gate bp++; 4007c478bd9Sstevel@tonic-gate while ((bp < &cp[oid_str->length]) && 4017c478bd9Sstevel@tonic-gate (isspace(*bp) || *bp == '.')) 4027c478bd9Sstevel@tonic-gate bp++; 4037c478bd9Sstevel@tonic-gate nbytes++; 4047c478bd9Sstevel@tonic-gate while (isdigit(*bp)) { 4057c478bd9Sstevel@tonic-gate if (sscanf(bp, "%d", &numbuf) != 1) { 4067c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE); 4077c478bd9Sstevel@tonic-gate } 4087c478bd9Sstevel@tonic-gate while (numbuf) { 4097c478bd9Sstevel@tonic-gate nbytes++; 4107c478bd9Sstevel@tonic-gate numbuf >>= 7; 4117c478bd9Sstevel@tonic-gate } 4127c478bd9Sstevel@tonic-gate while ((bp < &cp[oid_str->length]) && isdigit(*bp)) 4137c478bd9Sstevel@tonic-gate bp++; 4147c478bd9Sstevel@tonic-gate while ((bp < &cp[oid_str->length]) && 4157c478bd9Sstevel@tonic-gate (isspace(*bp) || *bp == '.')) 4167c478bd9Sstevel@tonic-gate bp++; 4177c478bd9Sstevel@tonic-gate } 4187c478bd9Sstevel@tonic-gate if (brace && (*bp != '}')) { 4197c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE); 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate /* 4237c478bd9Sstevel@tonic-gate * Phew! We've come this far, so the syntax is good. 4247c478bd9Sstevel@tonic-gate */ 4257c478bd9Sstevel@tonic-gate if ((*oid = (gss_OID) malloc(sizeof (gss_OID_desc)))) { 4267c478bd9Sstevel@tonic-gate if (((*oid)->elements = (void *) malloc(nbytes))) { 4277c478bd9Sstevel@tonic-gate (*oid)->length = nbytes; 4287c478bd9Sstevel@tonic-gate op = (unsigned char *) (*oid)->elements; 4297c478bd9Sstevel@tonic-gate bp = startp; 4307c478bd9Sstevel@tonic-gate (void) sscanf(bp, "%d", &numbuf); 4317c478bd9Sstevel@tonic-gate while (isdigit(*bp)) 4327c478bd9Sstevel@tonic-gate bp++; 4337c478bd9Sstevel@tonic-gate while (isspace(*bp) || *bp == '.') 4347c478bd9Sstevel@tonic-gate bp++; 4357c478bd9Sstevel@tonic-gate onumbuf = 40*numbuf; 4367c478bd9Sstevel@tonic-gate (void) sscanf(bp, "%d", &numbuf); 4377c478bd9Sstevel@tonic-gate onumbuf += numbuf; 4387c478bd9Sstevel@tonic-gate *op = (unsigned char) onumbuf; 4397c478bd9Sstevel@tonic-gate op++; 4407c478bd9Sstevel@tonic-gate while (isdigit(*bp)) 4417c478bd9Sstevel@tonic-gate bp++; 4427c478bd9Sstevel@tonic-gate while (isspace(*bp) || *bp == '.') 4437c478bd9Sstevel@tonic-gate bp++; 4447c478bd9Sstevel@tonic-gate while (isdigit(*bp)) { 4457c478bd9Sstevel@tonic-gate (void) sscanf(bp, "%d", &numbuf); 4467c478bd9Sstevel@tonic-gate nbytes = 0; 4477c478bd9Sstevel@tonic-gate /* Have to fill in the bytes msb-first */ 4487c478bd9Sstevel@tonic-gate onumbuf = numbuf; 4497c478bd9Sstevel@tonic-gate while (numbuf) { 4507c478bd9Sstevel@tonic-gate nbytes++; 4517c478bd9Sstevel@tonic-gate numbuf >>= 7; 4527c478bd9Sstevel@tonic-gate } 4537c478bd9Sstevel@tonic-gate numbuf = onumbuf; 4547c478bd9Sstevel@tonic-gate op += nbytes; 4557c478bd9Sstevel@tonic-gate index = -1; 4567c478bd9Sstevel@tonic-gate while (numbuf) { 4577c478bd9Sstevel@tonic-gate op[index] = (unsigned char) 4587c478bd9Sstevel@tonic-gate numbuf & 0x7f; 4597c478bd9Sstevel@tonic-gate if (index != -1) 4607c478bd9Sstevel@tonic-gate op[index] |= 0x80; 4617c478bd9Sstevel@tonic-gate index--; 4627c478bd9Sstevel@tonic-gate numbuf >>= 7; 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate while (isdigit(*bp)) 4657c478bd9Sstevel@tonic-gate bp++; 4667c478bd9Sstevel@tonic-gate while (isspace(*bp) || *bp == '.') 4677c478bd9Sstevel@tonic-gate bp++; 4687c478bd9Sstevel@tonic-gate } 4697c478bd9Sstevel@tonic-gate return (GSS_S_COMPLETE); 4707c478bd9Sstevel@tonic-gate } else { 4717c478bd9Sstevel@tonic-gate free(*oid); 4727c478bd9Sstevel@tonic-gate *oid = GSS_C_NO_OID; 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate } 4757c478bd9Sstevel@tonic-gate return (GSS_S_FAILURE); 4767c478bd9Sstevel@tonic-gate } 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate /* 4797c478bd9Sstevel@tonic-gate * Copyright 1993 by OpenVision Technologies, Inc. 4807c478bd9Sstevel@tonic-gate * 4817c478bd9Sstevel@tonic-gate * Permission to use, copy, modify, distribute, and sell this software 4827c478bd9Sstevel@tonic-gate * and its documentation for any purpose is hereby granted without fee, 4837c478bd9Sstevel@tonic-gate * provided that the above copyright notice appears in all copies and 4847c478bd9Sstevel@tonic-gate * that both that copyright notice and this permission notice appear in 4857c478bd9Sstevel@tonic-gate * supporting documentation, and that the name of OpenVision not be used 4867c478bd9Sstevel@tonic-gate * in advertising or publicity pertaining to distribution of the software 4877c478bd9Sstevel@tonic-gate * without specific, written prior permission. OpenVision makes no 4887c478bd9Sstevel@tonic-gate * representations about the suitability of this software for any 4897c478bd9Sstevel@tonic-gate * purpose. It is provided "as is" without express or implied warranty. 4907c478bd9Sstevel@tonic-gate * 4917c478bd9Sstevel@tonic-gate * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 4927c478bd9Sstevel@tonic-gate * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 4937c478bd9Sstevel@tonic-gate * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR 4947c478bd9Sstevel@tonic-gate * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 4957c478bd9Sstevel@tonic-gate * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 4967c478bd9Sstevel@tonic-gate * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 4977c478bd9Sstevel@tonic-gate * PERFORMANCE OF THIS SOFTWARE. 4987c478bd9Sstevel@tonic-gate */ 4997c478bd9Sstevel@tonic-gate OM_uint32 5007c478bd9Sstevel@tonic-gate gss_copy_oid_set( 5017c478bd9Sstevel@tonic-gate OM_uint32 *minor_status, 5027c478bd9Sstevel@tonic-gate const gss_OID_set_desc * const oidset, 5037c478bd9Sstevel@tonic-gate gss_OID_set *new_oidset 5047c478bd9Sstevel@tonic-gate ) 5057c478bd9Sstevel@tonic-gate { 5067c478bd9Sstevel@tonic-gate gss_OID_set_desc *copy; 5077c478bd9Sstevel@tonic-gate OM_uint32 minor = 0; 5087c478bd9Sstevel@tonic-gate OM_uint32 major = GSS_S_COMPLETE; 5097c478bd9Sstevel@tonic-gate OM_uint32 index; 5107c478bd9Sstevel@tonic-gate 511*503a2b89SPeter Shoults if (minor_status != NULL) 5127c478bd9Sstevel@tonic-gate *minor_status = 0; 5137c478bd9Sstevel@tonic-gate 514*503a2b89SPeter Shoults if (new_oidset != NULL) 515*503a2b89SPeter Shoults *new_oidset = GSS_C_NO_OID_SET; 516*503a2b89SPeter Shoults 517*503a2b89SPeter Shoults if (oidset == GSS_C_NO_OID_SET) 5187c478bd9Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_READ); 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate if (new_oidset == NULL) 5217c478bd9Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_WRITE); 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate if ((copy = (gss_OID_set_desc *) calloc(1, sizeof (*copy))) == NULL) { 5247c478bd9Sstevel@tonic-gate major = GSS_S_FAILURE; 5257c478bd9Sstevel@tonic-gate goto done; 5267c478bd9Sstevel@tonic-gate } 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate if ((copy->elements = (gss_OID_desc *) 5297c478bd9Sstevel@tonic-gate calloc(oidset->count, sizeof (*copy->elements))) == NULL) { 5307c478bd9Sstevel@tonic-gate major = GSS_S_FAILURE; 5317c478bd9Sstevel@tonic-gate goto done; 5327c478bd9Sstevel@tonic-gate } 5337c478bd9Sstevel@tonic-gate copy->count = oidset->count; 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate for (index = 0; index < copy->count; index++) { 5367c478bd9Sstevel@tonic-gate gss_OID_desc *out = ©->elements[index]; 5377c478bd9Sstevel@tonic-gate gss_OID_desc *in = &oidset->elements[index]; 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate if ((out->elements = (void *) malloc(in->length)) == NULL) { 5407c478bd9Sstevel@tonic-gate major = GSS_S_FAILURE; 5417c478bd9Sstevel@tonic-gate goto done; 5427c478bd9Sstevel@tonic-gate } 5437c478bd9Sstevel@tonic-gate (void) memcpy(out->elements, in->elements, in->length); 5447c478bd9Sstevel@tonic-gate out->length = in->length; 5457c478bd9Sstevel@tonic-gate } 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate *new_oidset = copy; 5487c478bd9Sstevel@tonic-gate done: 5497c478bd9Sstevel@tonic-gate if (major != GSS_S_COMPLETE) { 5507c478bd9Sstevel@tonic-gate (void) gss_release_oid_set(&minor, ©); 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate return (major); 5547c478bd9Sstevel@tonic-gate } 555