xref: /onnv-gate/usr/src/uts/common/rpc/sec/auth_none.c (revision 8637:ea911f428078)
1*8637SVallish.Vaidyeshwara@Sun.COM /*
2*8637SVallish.Vaidyeshwara@Sun.COM  * CDDL HEADER START
3*8637SVallish.Vaidyeshwara@Sun.COM  *
4*8637SVallish.Vaidyeshwara@Sun.COM  * The contents of this file are subject to the terms of the
5*8637SVallish.Vaidyeshwara@Sun.COM  * Common Development and Distribution License (the "License").
6*8637SVallish.Vaidyeshwara@Sun.COM  * You may not use this file except in compliance with the License.
7*8637SVallish.Vaidyeshwara@Sun.COM  *
8*8637SVallish.Vaidyeshwara@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*8637SVallish.Vaidyeshwara@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*8637SVallish.Vaidyeshwara@Sun.COM  * See the License for the specific language governing permissions
11*8637SVallish.Vaidyeshwara@Sun.COM  * and limitations under the License.
12*8637SVallish.Vaidyeshwara@Sun.COM  *
13*8637SVallish.Vaidyeshwara@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*8637SVallish.Vaidyeshwara@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*8637SVallish.Vaidyeshwara@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*8637SVallish.Vaidyeshwara@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*8637SVallish.Vaidyeshwara@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*8637SVallish.Vaidyeshwara@Sun.COM  *
19*8637SVallish.Vaidyeshwara@Sun.COM  * CDDL HEADER END
20*8637SVallish.Vaidyeshwara@Sun.COM  */
21*8637SVallish.Vaidyeshwara@Sun.COM 
22*8637SVallish.Vaidyeshwara@Sun.COM /*
23*8637SVallish.Vaidyeshwara@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*8637SVallish.Vaidyeshwara@Sun.COM  * Use is subject to license terms.
25*8637SVallish.Vaidyeshwara@Sun.COM  */
26*8637SVallish.Vaidyeshwara@Sun.COM 
27*8637SVallish.Vaidyeshwara@Sun.COM /*
28*8637SVallish.Vaidyeshwara@Sun.COM  * auth_none.c implements routines used to pass "null" credentials
29*8637SVallish.Vaidyeshwara@Sun.COM  * and "null" verifiers in kernel RPC.
30*8637SVallish.Vaidyeshwara@Sun.COM  */
31*8637SVallish.Vaidyeshwara@Sun.COM 
32*8637SVallish.Vaidyeshwara@Sun.COM #include <rpc/auth.h>
33*8637SVallish.Vaidyeshwara@Sun.COM 
34*8637SVallish.Vaidyeshwara@Sun.COM /*
35*8637SVallish.Vaidyeshwara@Sun.COM  * Null authenticator operations vector
36*8637SVallish.Vaidyeshwara@Sun.COM  */
37*8637SVallish.Vaidyeshwara@Sun.COM static void	authnone_nextverf(AUTH *);
38*8637SVallish.Vaidyeshwara@Sun.COM static bool_t	authnone_marshal(AUTH *, XDR *, struct cred *);
39*8637SVallish.Vaidyeshwara@Sun.COM static bool_t	authnone_validate(AUTH *, struct opaque_auth *);
40*8637SVallish.Vaidyeshwara@Sun.COM static bool_t	authnone_refresh(AUTH *, struct rpc_msg *, cred_t *);
41*8637SVallish.Vaidyeshwara@Sun.COM static void	authnone_destroy(AUTH *);
42*8637SVallish.Vaidyeshwara@Sun.COM 
43*8637SVallish.Vaidyeshwara@Sun.COM static struct auth_ops auth_none_ops = {
44*8637SVallish.Vaidyeshwara@Sun.COM 	authnone_nextverf,
45*8637SVallish.Vaidyeshwara@Sun.COM 	authnone_marshal,
46*8637SVallish.Vaidyeshwara@Sun.COM 	authnone_validate,
47*8637SVallish.Vaidyeshwara@Sun.COM 	authnone_refresh,
48*8637SVallish.Vaidyeshwara@Sun.COM 	authnone_destroy,
49*8637SVallish.Vaidyeshwara@Sun.COM 	authany_wrap,
50*8637SVallish.Vaidyeshwara@Sun.COM 	authany_unwrap
51*8637SVallish.Vaidyeshwara@Sun.COM };
52*8637SVallish.Vaidyeshwara@Sun.COM 
53*8637SVallish.Vaidyeshwara@Sun.COM /*
54*8637SVallish.Vaidyeshwara@Sun.COM  * Create a kernel null style authenticator.
55*8637SVallish.Vaidyeshwara@Sun.COM  * Returns an auth handle.
56*8637SVallish.Vaidyeshwara@Sun.COM  */
57*8637SVallish.Vaidyeshwara@Sun.COM AUTH *
authnone_create(void)58*8637SVallish.Vaidyeshwara@Sun.COM authnone_create(void)
59*8637SVallish.Vaidyeshwara@Sun.COM {
60*8637SVallish.Vaidyeshwara@Sun.COM 	/*
61*8637SVallish.Vaidyeshwara@Sun.COM 	 * Allocate and set up auth handle
62*8637SVallish.Vaidyeshwara@Sun.COM 	 */
63*8637SVallish.Vaidyeshwara@Sun.COM 	return (kmem_cache_alloc(authnone_cache, KM_SLEEP));
64*8637SVallish.Vaidyeshwara@Sun.COM }
65*8637SVallish.Vaidyeshwara@Sun.COM 
66*8637SVallish.Vaidyeshwara@Sun.COM /*
67*8637SVallish.Vaidyeshwara@Sun.COM  *  The constructor of the authnone_cache.
68*8637SVallish.Vaidyeshwara@Sun.COM  */
69*8637SVallish.Vaidyeshwara@Sun.COM /* ARGSUSED */
70*8637SVallish.Vaidyeshwara@Sun.COM int
authnone_init(void * buf,void * cdrarg,int kmflags)71*8637SVallish.Vaidyeshwara@Sun.COM authnone_init(void *buf, void *cdrarg, int kmflags)
72*8637SVallish.Vaidyeshwara@Sun.COM {
73*8637SVallish.Vaidyeshwara@Sun.COM 	AUTH *auth = (AUTH *)buf;
74*8637SVallish.Vaidyeshwara@Sun.COM 
75*8637SVallish.Vaidyeshwara@Sun.COM 	auth->ah_ops = &auth_none_ops;
76*8637SVallish.Vaidyeshwara@Sun.COM 
77*8637SVallish.Vaidyeshwara@Sun.COM 	/*
78*8637SVallish.Vaidyeshwara@Sun.COM 	 * Flavor of RPC message's credential and verifier should be set to
79*8637SVallish.Vaidyeshwara@Sun.COM 	 * AUTH_NONE. Opaque data associated with AUTH_NONE is undefined.
80*8637SVallish.Vaidyeshwara@Sun.COM 	 * The length of the opaque data should be zero.
81*8637SVallish.Vaidyeshwara@Sun.COM 	 *	oa_flavor = AUTH_NONE
82*8637SVallish.Vaidyeshwara@Sun.COM 	 *	oa_base = NULL
83*8637SVallish.Vaidyeshwara@Sun.COM 	 *	oa_length = 0
84*8637SVallish.Vaidyeshwara@Sun.COM 	 */
85*8637SVallish.Vaidyeshwara@Sun.COM 	auth->ah_cred = auth->ah_verf = _null_auth;
86*8637SVallish.Vaidyeshwara@Sun.COM 
87*8637SVallish.Vaidyeshwara@Sun.COM 	return (0);
88*8637SVallish.Vaidyeshwara@Sun.COM }
89*8637SVallish.Vaidyeshwara@Sun.COM 
90*8637SVallish.Vaidyeshwara@Sun.COM /*
91*8637SVallish.Vaidyeshwara@Sun.COM  * authnone operations
92*8637SVallish.Vaidyeshwara@Sun.COM  */
93*8637SVallish.Vaidyeshwara@Sun.COM /* ARGSUSED */
94*8637SVallish.Vaidyeshwara@Sun.COM static void
authnone_nextverf(AUTH * auth)95*8637SVallish.Vaidyeshwara@Sun.COM authnone_nextverf(AUTH *auth)
96*8637SVallish.Vaidyeshwara@Sun.COM {
97*8637SVallish.Vaidyeshwara@Sun.COM 	/* no action necessary */
98*8637SVallish.Vaidyeshwara@Sun.COM }
99*8637SVallish.Vaidyeshwara@Sun.COM 
100*8637SVallish.Vaidyeshwara@Sun.COM /* ARGSUSED */
101*8637SVallish.Vaidyeshwara@Sun.COM static bool_t
authnone_marshal(AUTH * auth,XDR * xdrs,struct cred * cr)102*8637SVallish.Vaidyeshwara@Sun.COM authnone_marshal(AUTH *auth, XDR *xdrs, struct cred *cr)
103*8637SVallish.Vaidyeshwara@Sun.COM {
104*8637SVallish.Vaidyeshwara@Sun.COM 	int32_t	*ptr;
105*8637SVallish.Vaidyeshwara@Sun.COM 
106*8637SVallish.Vaidyeshwara@Sun.COM 	/*
107*8637SVallish.Vaidyeshwara@Sun.COM 	 * auth_none has no opaque data. Encode auth_none
108*8637SVallish.Vaidyeshwara@Sun.COM 	 * value with 0 len data for both cred and verf.
109*8637SVallish.Vaidyeshwara@Sun.COM 	 * We first try a fast path to complete this operation.
110*8637SVallish.Vaidyeshwara@Sun.COM 	 */
111*8637SVallish.Vaidyeshwara@Sun.COM 	ptr = XDR_INLINE(xdrs, 4 + 4 + 4 + 4);
112*8637SVallish.Vaidyeshwara@Sun.COM 	if (ptr) {
113*8637SVallish.Vaidyeshwara@Sun.COM 		IXDR_PUT_INT32(ptr, AUTH_NONE);
114*8637SVallish.Vaidyeshwara@Sun.COM 		IXDR_PUT_INT32(ptr, 0);
115*8637SVallish.Vaidyeshwara@Sun.COM 		IXDR_PUT_INT32(ptr, AUTH_NONE);
116*8637SVallish.Vaidyeshwara@Sun.COM 		IXDR_PUT_INT32(ptr, 0);
117*8637SVallish.Vaidyeshwara@Sun.COM 		return (TRUE);
118*8637SVallish.Vaidyeshwara@Sun.COM 	}
119*8637SVallish.Vaidyeshwara@Sun.COM 
120*8637SVallish.Vaidyeshwara@Sun.COM 	/*
121*8637SVallish.Vaidyeshwara@Sun.COM 	 * serialize AUTH_NONE credential and AUTH_NONE verifier
122*8637SVallish.Vaidyeshwara@Sun.COM 	 */
123*8637SVallish.Vaidyeshwara@Sun.COM 	if ((xdr_opaque_auth(xdrs, &(auth->ah_cred))) &&
124*8637SVallish.Vaidyeshwara@Sun.COM 	    (xdr_opaque_auth(xdrs, &(auth->ah_verf))))
125*8637SVallish.Vaidyeshwara@Sun.COM 		return (TRUE);
126*8637SVallish.Vaidyeshwara@Sun.COM 	else
127*8637SVallish.Vaidyeshwara@Sun.COM 		return (FALSE);
128*8637SVallish.Vaidyeshwara@Sun.COM }
129*8637SVallish.Vaidyeshwara@Sun.COM 
130*8637SVallish.Vaidyeshwara@Sun.COM /* ARGSUSED */
131*8637SVallish.Vaidyeshwara@Sun.COM static bool_t
authnone_validate(AUTH * auth,struct opaque_auth * verf)132*8637SVallish.Vaidyeshwara@Sun.COM authnone_validate(AUTH *auth, struct opaque_auth *verf)
133*8637SVallish.Vaidyeshwara@Sun.COM {
134*8637SVallish.Vaidyeshwara@Sun.COM 	return (TRUE);
135*8637SVallish.Vaidyeshwara@Sun.COM }
136*8637SVallish.Vaidyeshwara@Sun.COM 
137*8637SVallish.Vaidyeshwara@Sun.COM /* ARGSUSED */
138*8637SVallish.Vaidyeshwara@Sun.COM static bool_t
authnone_refresh(AUTH * auth,struct rpc_msg * msg,cred_t * cr)139*8637SVallish.Vaidyeshwara@Sun.COM authnone_refresh(AUTH *auth, struct rpc_msg *msg, cred_t *cr)
140*8637SVallish.Vaidyeshwara@Sun.COM {
141*8637SVallish.Vaidyeshwara@Sun.COM 	return (FALSE);
142*8637SVallish.Vaidyeshwara@Sun.COM }
143*8637SVallish.Vaidyeshwara@Sun.COM 
144*8637SVallish.Vaidyeshwara@Sun.COM static void
authnone_destroy(AUTH * auth)145*8637SVallish.Vaidyeshwara@Sun.COM authnone_destroy(AUTH *auth)
146*8637SVallish.Vaidyeshwara@Sun.COM {
147*8637SVallish.Vaidyeshwara@Sun.COM 	kmem_cache_free(authnone_cache, auth);
148*8637SVallish.Vaidyeshwara@Sun.COM }
149