Home | History | Annotate | Line # | Download | only in mech
      1  1.1  elric /*	$NetBSD: gss_utils.c,v 1.2 2017/01/28 21:31:46 christos Exp $	*/
      2  1.1  elric 
      3  1.1  elric /*-
      4  1.1  elric  * Copyright (c) 2005 Doug Rabson
      5  1.1  elric  * All rights reserved.
      6  1.1  elric  *
      7  1.1  elric  * Redistribution and use in source and binary forms, with or without
      8  1.1  elric  * modification, are permitted provided that the following conditions
      9  1.1  elric  * are met:
     10  1.1  elric  * 1. Redistributions of source code must retain the above copyright
     11  1.1  elric  *    notice, this list of conditions and the following disclaimer.
     12  1.1  elric  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  elric  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  elric  *    documentation and/or other materials provided with the distribution.
     15  1.1  elric  *
     16  1.1  elric  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  1.1  elric  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.1  elric  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.1  elric  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  1.1  elric  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.1  elric  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.1  elric  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1  elric  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.1  elric  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1  elric  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1  elric  * SUCH DAMAGE.
     27  1.1  elric  *
     28  1.1  elric  *	$FreeBSD: src/lib/libgssapi/gss_utils.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
     29  1.1  elric  */
     30  1.1  elric 
     31  1.1  elric #include "mech_locl.h"
     32  1.1  elric 
     33  1.1  elric OM_uint32
     34  1.1  elric _gss_copy_oid(OM_uint32 *minor_status,
     35  1.1  elric     const gss_OID from_oid, gss_OID to_oid)
     36  1.1  elric {
     37  1.1  elric 	size_t len = from_oid->length;
     38  1.1  elric 
     39  1.1  elric 	*minor_status = 0;
     40  1.1  elric 	to_oid->elements = malloc(len);
     41  1.1  elric 	if (!to_oid->elements) {
     42  1.1  elric 		to_oid->length = 0;
     43  1.1  elric 		*minor_status = ENOMEM;
     44  1.1  elric 		return GSS_S_FAILURE;
     45  1.1  elric 	}
     46  1.1  elric 	to_oid->length = len;
     47  1.1  elric 	memcpy(to_oid->elements, from_oid->elements, len);
     48  1.1  elric 	return (GSS_S_COMPLETE);
     49  1.1  elric }
     50  1.1  elric 
     51  1.1  elric OM_uint32
     52  1.1  elric _gss_free_oid(OM_uint32 *minor_status, gss_OID oid)
     53  1.1  elric {
     54  1.1  elric 	*minor_status = 0;
     55  1.1  elric 	if (oid->elements) {
     56  1.1  elric 	    free(oid->elements);
     57  1.1  elric 	    oid->elements = NULL;
     58  1.1  elric 	    oid->length = 0;
     59  1.1  elric 	}
     60  1.1  elric 	return (GSS_S_COMPLETE);
     61  1.1  elric }
     62  1.1  elric 
     63  1.1  elric OM_uint32
     64  1.1  elric _gss_copy_buffer(OM_uint32 *minor_status,
     65  1.1  elric     const gss_buffer_t from_buf, gss_buffer_t to_buf)
     66  1.1  elric {
     67  1.1  elric 	size_t len = from_buf->length;
     68  1.1  elric 
     69  1.1  elric 	*minor_status = 0;
     70  1.1  elric 	to_buf->value = malloc(len);
     71  1.1  elric 	if (!to_buf->value) {
     72  1.1  elric 		*minor_status = ENOMEM;
     73  1.1  elric 		to_buf->length = 0;
     74  1.1  elric 		return GSS_S_FAILURE;
     75  1.1  elric 	}
     76  1.1  elric 	to_buf->length = len;
     77  1.1  elric 	memcpy(to_buf->value, from_buf->value, len);
     78  1.1  elric 	return (GSS_S_COMPLETE);
     79  1.1  elric }
     80  1.1  elric 
     81