xref: /onnv-gate/usr/src/lib/libgss/g_userok.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #include <stdlib.h>
31*0Sstevel@tonic-gate #include <unistd.h>
32*0Sstevel@tonic-gate #include <deflt.h>
33*0Sstevel@tonic-gate #include <mechglueP.h>
34*0Sstevel@tonic-gate #include <gssapi/gssapi.h>
35*0Sstevel@tonic-gate #include <gssapi/gssapi_ext.h>
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate static OM_uint32
compare_names(OM_uint32 * minor,const gss_OID mech_type,const gss_name_t name,const char * user,int * user_ok)39*0Sstevel@tonic-gate compare_names(OM_uint32 *minor,
40*0Sstevel@tonic-gate 	    const gss_OID mech_type,
41*0Sstevel@tonic-gate 	    const gss_name_t name,
42*0Sstevel@tonic-gate 	    const char *user,
43*0Sstevel@tonic-gate 	    int *user_ok)
44*0Sstevel@tonic-gate {
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate 	OM_uint32 status, tmpMinor;
47*0Sstevel@tonic-gate 	gss_name_t imported_name;
48*0Sstevel@tonic-gate 	gss_name_t canon_name;
49*0Sstevel@tonic-gate 	gss_buffer_desc gss_user;
50*0Sstevel@tonic-gate 	int match = 0;
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate 	*user_ok = 0;
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate 	gss_user.value = (void *)user;
55*0Sstevel@tonic-gate 	if (!gss_user.value || !name || !mech_type)
56*0Sstevel@tonic-gate 		return (GSS_S_BAD_NAME);
57*0Sstevel@tonic-gate 	gss_user.length = strlen(gss_user.value);
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate 	status = gss_import_name(minor,
60*0Sstevel@tonic-gate 				&gss_user,
61*0Sstevel@tonic-gate 				GSS_C_NT_USER_NAME,
62*0Sstevel@tonic-gate 				&imported_name);
63*0Sstevel@tonic-gate 	if (status != GSS_S_COMPLETE) {
64*0Sstevel@tonic-gate 		goto out;
65*0Sstevel@tonic-gate 	}
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate 	status = gss_canonicalize_name(minor,
68*0Sstevel@tonic-gate 				    imported_name,
69*0Sstevel@tonic-gate 				    mech_type,
70*0Sstevel@tonic-gate 				    &canon_name);
71*0Sstevel@tonic-gate 	if (status != GSS_S_COMPLETE) {
72*0Sstevel@tonic-gate 		(void) gss_release_name(&tmpMinor, &imported_name);
73*0Sstevel@tonic-gate 		goto out;
74*0Sstevel@tonic-gate 	}
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate 	status = gss_compare_name(minor,
77*0Sstevel@tonic-gate 				canon_name,
78*0Sstevel@tonic-gate 				name,
79*0Sstevel@tonic-gate 				&match);
80*0Sstevel@tonic-gate 	(void) gss_release_name(&tmpMinor, &canon_name);
81*0Sstevel@tonic-gate 	(void) gss_release_name(&tmpMinor, &imported_name);
82*0Sstevel@tonic-gate 	if (status == GSS_S_COMPLETE) {
83*0Sstevel@tonic-gate 		if (match)
84*0Sstevel@tonic-gate 			*user_ok = 1; /* remote user is a-ok */
85*0Sstevel@tonic-gate 	}
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate out:
88*0Sstevel@tonic-gate 	return (status);
89*0Sstevel@tonic-gate }
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate OM_uint32
__gss_userok(OM_uint32 * minor,const gss_name_t name,const char * user,int * user_ok)93*0Sstevel@tonic-gate __gss_userok(OM_uint32 *minor,
94*0Sstevel@tonic-gate 	    const gss_name_t name,
95*0Sstevel@tonic-gate 	    const char *user,
96*0Sstevel@tonic-gate 	    int *user_ok)
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate {
99*0Sstevel@tonic-gate 	gss_mechanism mech;
100*0Sstevel@tonic-gate 	gss_union_name_t intName;
101*0Sstevel@tonic-gate 	gss_name_t mechName = NULL;
102*0Sstevel@tonic-gate 	OM_uint32 major;
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate 	if (minor == NULL || user_ok == NULL)
105*0Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate 	if (name == NULL || user == NULL)
108*0Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_READ);
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate 	*user_ok = 0;
111*0Sstevel@tonic-gate 	*minor = GSS_S_COMPLETE;
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate 	intName = (gss_union_name_t)name;
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate 	mech = __gss_get_mechanism(intName->mech_type);
116*0Sstevel@tonic-gate 	if (mech == NULL)
117*0Sstevel@tonic-gate 		return (GSS_S_UNAVAILABLE);
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate 	/* may need to import the name if this is not MN */
120*0Sstevel@tonic-gate 	if (intName->mech_type == NULL) {
121*0Sstevel@tonic-gate 		return (GSS_S_FAILURE);
122*0Sstevel@tonic-gate 	} else
123*0Sstevel@tonic-gate 		mechName = intName->mech_name;
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate 	if (mech->__gss_userok)
126*0Sstevel@tonic-gate 		major = mech->__gss_userok(mech->context,  minor, mechName,
127*0Sstevel@tonic-gate 				user, user_ok);
128*0Sstevel@tonic-gate 	else
129*0Sstevel@tonic-gate 		major = compare_names(minor, intName->mech_type,
130*0Sstevel@tonic-gate 				    name, user, user_ok);
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 	return (major);
133*0Sstevel@tonic-gate } /* gss_userok */
134