1226031Sstas/*- 2226031Sstas * Copyright (c) 2005 Doug Rabson 3226031Sstas * All rights reserved. 4226031Sstas * 5226031Sstas * Redistribution and use in source and binary forms, with or without 6226031Sstas * modification, are permitted provided that the following conditions 7226031Sstas * are met: 8226031Sstas * 1. Redistributions of source code must retain the above copyright 9226031Sstas * notice, this list of conditions and the following disclaimer. 10226031Sstas * 2. Redistributions in binary form must reproduce the above copyright 11226031Sstas * notice, this list of conditions and the following disclaimer in the 12226031Sstas * documentation and/or other materials provided with the distribution. 13226031Sstas * 14226031Sstas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17226031Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24226031Sstas * SUCH DAMAGE. 25226031Sstas * 26226031Sstas * $FreeBSD: src/lib/libgssapi/gss_utils.c,v 1.1 2005/12/29 14:40:20 dfr Exp $ 27226031Sstas */ 28226031Sstas 29226031Sstas#include "mech_locl.h" 30226031Sstas 31226031SstasOM_uint32 32226031Sstas_gss_copy_oid(OM_uint32 *minor_status, 33226031Sstas const gss_OID from_oid, gss_OID to_oid) 34226031Sstas{ 35226031Sstas size_t len = from_oid->length; 36226031Sstas 37226031Sstas *minor_status = 0; 38226031Sstas to_oid->elements = malloc(len); 39226031Sstas if (!to_oid->elements) { 40226031Sstas to_oid->length = 0; 41226031Sstas *minor_status = ENOMEM; 42226031Sstas return GSS_S_FAILURE; 43226031Sstas } 44226031Sstas to_oid->length = len; 45226031Sstas memcpy(to_oid->elements, from_oid->elements, len); 46226031Sstas return (GSS_S_COMPLETE); 47226031Sstas} 48226031Sstas 49226031SstasOM_uint32 50226031Sstas_gss_free_oid(OM_uint32 *minor_status, gss_OID oid) 51226031Sstas{ 52226031Sstas *minor_status = 0; 53226031Sstas if (oid->elements) { 54226031Sstas free(oid->elements); 55226031Sstas oid->elements = NULL; 56226031Sstas oid->length = 0; 57226031Sstas } 58226031Sstas return (GSS_S_COMPLETE); 59226031Sstas} 60226031Sstas 61226031SstasOM_uint32 62226031Sstas_gss_copy_buffer(OM_uint32 *minor_status, 63226031Sstas const gss_buffer_t from_buf, gss_buffer_t to_buf) 64226031Sstas{ 65226031Sstas size_t len = from_buf->length; 66226031Sstas 67226031Sstas *minor_status = 0; 68226031Sstas to_buf->value = malloc(len); 69226031Sstas if (!to_buf->value) { 70226031Sstas *minor_status = ENOMEM; 71226031Sstas to_buf->length = 0; 72226031Sstas return GSS_S_FAILURE; 73226031Sstas } 74226031Sstas to_buf->length = len; 75226031Sstas memcpy(to_buf->value, from_buf->value, len); 76226031Sstas return (GSS_S_COMPLETE); 77226031Sstas} 78226031Sstas 79