xref: /titanic_44/usr/src/lib/libgss/g_userok.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
31*7c478bd9Sstevel@tonic-gate #include <unistd.h>
32*7c478bd9Sstevel@tonic-gate #include <deflt.h>
33*7c478bd9Sstevel@tonic-gate #include <mechglueP.h>
34*7c478bd9Sstevel@tonic-gate #include <gssapi/gssapi.h>
35*7c478bd9Sstevel@tonic-gate #include <gssapi/gssapi_ext.h>
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@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*7c478bd9Sstevel@tonic-gate compare_names(OM_uint32 *minor,
40*7c478bd9Sstevel@tonic-gate 	    const gss_OID mech_type,
41*7c478bd9Sstevel@tonic-gate 	    const gss_name_t name,
42*7c478bd9Sstevel@tonic-gate 	    const char *user,
43*7c478bd9Sstevel@tonic-gate 	    int *user_ok)
44*7c478bd9Sstevel@tonic-gate {
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate 	OM_uint32 status, tmpMinor;
47*7c478bd9Sstevel@tonic-gate 	gss_name_t imported_name;
48*7c478bd9Sstevel@tonic-gate 	gss_name_t canon_name;
49*7c478bd9Sstevel@tonic-gate 	gss_buffer_desc gss_user;
50*7c478bd9Sstevel@tonic-gate 	int match = 0;
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate 	*user_ok = 0;
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate 	gss_user.value = (void *)user;
55*7c478bd9Sstevel@tonic-gate 	if (!gss_user.value || !name || !mech_type)
56*7c478bd9Sstevel@tonic-gate 		return (GSS_S_BAD_NAME);
57*7c478bd9Sstevel@tonic-gate 	gss_user.length = strlen(gss_user.value);
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate 	status = gss_import_name(minor,
60*7c478bd9Sstevel@tonic-gate 				&gss_user,
61*7c478bd9Sstevel@tonic-gate 				GSS_C_NT_USER_NAME,
62*7c478bd9Sstevel@tonic-gate 				&imported_name);
63*7c478bd9Sstevel@tonic-gate 	if (status != GSS_S_COMPLETE) {
64*7c478bd9Sstevel@tonic-gate 		goto out;
65*7c478bd9Sstevel@tonic-gate 	}
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate 	status = gss_canonicalize_name(minor,
68*7c478bd9Sstevel@tonic-gate 				    imported_name,
69*7c478bd9Sstevel@tonic-gate 				    mech_type,
70*7c478bd9Sstevel@tonic-gate 				    &canon_name);
71*7c478bd9Sstevel@tonic-gate 	if (status != GSS_S_COMPLETE) {
72*7c478bd9Sstevel@tonic-gate 		(void) gss_release_name(&tmpMinor, &imported_name);
73*7c478bd9Sstevel@tonic-gate 		goto out;
74*7c478bd9Sstevel@tonic-gate 	}
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	status = gss_compare_name(minor,
77*7c478bd9Sstevel@tonic-gate 				canon_name,
78*7c478bd9Sstevel@tonic-gate 				name,
79*7c478bd9Sstevel@tonic-gate 				&match);
80*7c478bd9Sstevel@tonic-gate 	(void) gss_release_name(&tmpMinor, &canon_name);
81*7c478bd9Sstevel@tonic-gate 	(void) gss_release_name(&tmpMinor, &imported_name);
82*7c478bd9Sstevel@tonic-gate 	if (status == GSS_S_COMPLETE) {
83*7c478bd9Sstevel@tonic-gate 		if (match)
84*7c478bd9Sstevel@tonic-gate 			*user_ok = 1; /* remote user is a-ok */
85*7c478bd9Sstevel@tonic-gate 	}
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate out:
88*7c478bd9Sstevel@tonic-gate 	return (status);
89*7c478bd9Sstevel@tonic-gate }
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate OM_uint32
__gss_userok(OM_uint32 * minor,const gss_name_t name,const char * user,int * user_ok)93*7c478bd9Sstevel@tonic-gate __gss_userok(OM_uint32 *minor,
94*7c478bd9Sstevel@tonic-gate 	    const gss_name_t name,
95*7c478bd9Sstevel@tonic-gate 	    const char *user,
96*7c478bd9Sstevel@tonic-gate 	    int *user_ok)
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate {
99*7c478bd9Sstevel@tonic-gate 	gss_mechanism mech;
100*7c478bd9Sstevel@tonic-gate 	gss_union_name_t intName;
101*7c478bd9Sstevel@tonic-gate 	gss_name_t mechName = NULL;
102*7c478bd9Sstevel@tonic-gate 	OM_uint32 major;
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	if (minor == NULL || user_ok == NULL)
105*7c478bd9Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_WRITE);
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 	if (name == NULL || user == NULL)
108*7c478bd9Sstevel@tonic-gate 		return (GSS_S_CALL_INACCESSIBLE_READ);
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	*user_ok = 0;
111*7c478bd9Sstevel@tonic-gate 	*minor = GSS_S_COMPLETE;
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	intName = (gss_union_name_t)name;
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 	mech = __gss_get_mechanism(intName->mech_type);
116*7c478bd9Sstevel@tonic-gate 	if (mech == NULL)
117*7c478bd9Sstevel@tonic-gate 		return (GSS_S_UNAVAILABLE);
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate 	/* may need to import the name if this is not MN */
120*7c478bd9Sstevel@tonic-gate 	if (intName->mech_type == NULL) {
121*7c478bd9Sstevel@tonic-gate 		return (GSS_S_FAILURE);
122*7c478bd9Sstevel@tonic-gate 	} else
123*7c478bd9Sstevel@tonic-gate 		mechName = intName->mech_name;
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	if (mech->__gss_userok)
126*7c478bd9Sstevel@tonic-gate 		major = mech->__gss_userok(mech->context,  minor, mechName,
127*7c478bd9Sstevel@tonic-gate 				user, user_ok);
128*7c478bd9Sstevel@tonic-gate 	else
129*7c478bd9Sstevel@tonic-gate 		major = compare_names(minor, intName->mech_type,
130*7c478bd9Sstevel@tonic-gate 				    name, user, user_ok);
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 	return (major);
133*7c478bd9Sstevel@tonic-gate } /* gss_userok */
134