xref: /freebsd/crypto/krb5/src/lib/gssapi/mechglue/g_export_name.c (revision f1c4c3daccbaf3820f0e2224de53df12fc952fcc)
1 /*
2  * Copyright (c) 1996,1997, by Sun Microsystems, Inc.
3  * All rights reserved.
4  */
5 
6 /* #pragma ident	"@(#)g_export_name.c	1.11	00/07/17 SMI" */
7 
8 /*
9  * glue routine gss_export_name
10  *
11  * Will either call the mechanism defined gss_export_name, or if one is
12  * not defined will call a generic_gss_export_name routine.
13  */
14 
15 #include <mglueP.h>
16 #ifdef HAVE_STDLIB_H
17 #include <stdlib.h>
18 #endif
19 #include <string.h>
20 #include <errno.h>
21 
22 OM_uint32 KRB5_CALLCONV
gss_export_name(OM_uint32 * minor_status,const gss_name_t input_name,gss_buffer_t exported_name)23 gss_export_name(OM_uint32 *minor_status, const gss_name_t input_name,
24 		gss_buffer_t exported_name)
25 {
26 	gss_union_name_t		union_name;
27 
28 	/* Initialize outputs. */
29 
30 	if (minor_status != NULL)
31 		*minor_status = 0;
32 
33 	if (exported_name != GSS_C_NO_BUFFER) {
34 		exported_name->value = NULL;
35 		exported_name->length = 0;
36 	}
37 
38 	/* Validate arguments. */
39 
40 	if (minor_status == NULL || exported_name == GSS_C_NO_BUFFER)
41 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
42 
43 	if (input_name == GSS_C_NO_NAME)
44 		return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME);
45 
46 	union_name = (gss_union_name_t)input_name;
47 
48 	/* the name must be in mechanism specific format */
49 	if (!union_name->mech_type)
50 		return (GSS_S_NAME_NOT_MN);
51 
52 	return gssint_export_internal_name(minor_status, union_name->mech_type,
53 					union_name->mech_name, exported_name);
54 }
55