xref: /illumos-gate/usr/src/lib/gss_mechs/mech_dh/dh_common/dh_common.c (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
28*7c478bd9Sstevel@tonic-gate #include <stdio.h>
29*7c478bd9Sstevel@tonic-gate #include <dlfcn.h>
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #include "dh_gssapi.h"
32*7c478bd9Sstevel@tonic-gate #include "dh_common.h"
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #define	MECH_LIB_PREFIX1	"/usr/lib/"
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate /*
37*7c478bd9Sstevel@tonic-gate  * This #ifdef mess figures out if we are to be compiled into an
38*7c478bd9Sstevel@tonic-gate  * lp64 binary for the purposes of figuring the absolute location
39*7c478bd9Sstevel@tonic-gate  * of gss-api mechanism modules.
40*7c478bd9Sstevel@tonic-gate  */
41*7c478bd9Sstevel@tonic-gate #ifdef  _LP64
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #ifdef __sparc
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #define	MECH_LIB_PREFIX2	"sparcv9/"
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate #elif defined(__amd64)
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate #define	MECH_LIB_PREFIX2	"amd64/"
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate #else   /* __sparc */
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate you need to define where under /usr the LP64 libraries live for this platform
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate #endif  /* __sparc */
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate #else   /* _LP64 */
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate #define	MECH_LIB_PREFIX2	""
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate #endif  /* _LP64 */
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate #define	MECH_LIB_DIR		"gss/"
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate #define	MECH_LIB_PREFIX MECH_LIB_PREFIX1 MECH_LIB_PREFIX2 MECH_LIB_DIR
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate #define	DH_MECH_BACKEND		"mech_dh.so.1"
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate #define	DH_MECH_BACKEND_PATH MECH_LIB_PREFIX DH_MECH_BACKEND
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate static char *DHLIB = DH_MECH_BACKEND_PATH;
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate #ifndef DH_MECH_SYM
74*7c478bd9Sstevel@tonic-gate #define	DH_MECH_SYM		"__dh_gss_initialize"
75*7c478bd9Sstevel@tonic-gate #endif
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate /*
78*7c478bd9Sstevel@tonic-gate  * __dh_generic_initialize: This routine is called from the mechanism
79*7c478bd9Sstevel@tonic-gate  * specific gss_mech_initialize routine, which in turn is called from
80*7c478bd9Sstevel@tonic-gate  * libgss to initialize a mechanism. This routine takes a pointer to
81*7c478bd9Sstevel@tonic-gate  * a struct gss_config, the OID for the calling mechanism and that mechanisms
82*7c478bd9Sstevel@tonic-gate  * keyopts. It returns the same gss_mechanism back, but with all fields
83*7c478bd9Sstevel@tonic-gate  * correctly initialized. This routine in turn opens the common wire
84*7c478bd9Sstevel@tonic-gate  * protocol moduel mech_dh.so.1 to fill in the common parts of the
85*7c478bd9Sstevel@tonic-gate  * gss_mechanism. It then associatates the OID and the keyopts with this
86*7c478bd9Sstevel@tonic-gate  * gss_mechanism. If there is any failure NULL is return instead.
87*7c478bd9Sstevel@tonic-gate  */
88*7c478bd9Sstevel@tonic-gate gss_mechanism
__dh_generic_initialize(gss_mechanism dhmech,gss_OID_desc mech_type,dh_keyopts_t keyopts)89*7c478bd9Sstevel@tonic-gate __dh_generic_initialize(gss_mechanism dhmech, /* The mechanism to initialize */
90*7c478bd9Sstevel@tonic-gate 			gss_OID_desc mech_type, /* OID of mechanism */
91*7c478bd9Sstevel@tonic-gate 			dh_keyopts_t keyopts /* Key mechanism entry points  */)
92*7c478bd9Sstevel@tonic-gate {
93*7c478bd9Sstevel@tonic-gate 	gss_mechanism (*mech_init)(gss_mechanism mech);
94*7c478bd9Sstevel@tonic-gate 	gss_mechanism mech;
95*7c478bd9Sstevel@tonic-gate 	void *dlhandle;
96*7c478bd9Sstevel@tonic-gate 	dh_context_t context;
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate 	/* Open the common backend */
99*7c478bd9Sstevel@tonic-gate 	if ((dlhandle = dlopen(DHLIB, RTLD_NOW)) == NULL) {
100*7c478bd9Sstevel@tonic-gate 		return (NULL);
101*7c478bd9Sstevel@tonic-gate 	}
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate 	/* Fetch the common backend initialization routine */
104*7c478bd9Sstevel@tonic-gate 	mech_init = (gss_mechanism (*)(gss_mechanism))
105*7c478bd9Sstevel@tonic-gate 		dlsym(dlhandle, DH_MECH_SYM);
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 	/* Oops this should not happen */
108*7c478bd9Sstevel@tonic-gate 	if (mech_init == NULL) {
109*7c478bd9Sstevel@tonic-gate 		return (NULL);
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	}
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	/* Initialize the common parts of the gss_mechanism */
114*7c478bd9Sstevel@tonic-gate 	if ((mech = mech_init(dhmech)) == NULL) {
115*7c478bd9Sstevel@tonic-gate 		return (NULL);
116*7c478bd9Sstevel@tonic-gate 	}
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	/* Set the mechanism OID */
119*7c478bd9Sstevel@tonic-gate 	mech->mech_type = mech_type;
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	/* Grab the mechanism context */
122*7c478bd9Sstevel@tonic-gate 	context = (dh_context_t)mech->context;
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate 	/* Set the keyopts */
125*7c478bd9Sstevel@tonic-gate 	context->keyopts = keyopts;
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate 	/* Set a handle to the mechanism OID in the per mechanism context */
128*7c478bd9Sstevel@tonic-gate 	context->mech = &mech->mech_type;
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 	return (mech);
131*7c478bd9Sstevel@tonic-gate }
132