xref: /titanic_50/usr/src/uts/common/rpc/sec/svc_authu.c (revision 385cc6b4ad1792caef3f84eb61eed3f27085801f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1989 Sun Microsystems, Inc.  All rights reserved.
24  * Copyright 2017 Joyent Inc
25  * Use is subject to license terms.
26  */
27 
28 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
29 /*	  All Rights Reserved  	*/
30 
31 /*
32  * Portions of this source code were derived from Berkeley 4.3 BSD
33  * under license from the Regents of the University of California.
34  */
35 
36 /*
37  * svc_auth_unix.c
38  * Handles UNIX flavor authentication parameters on the service side of rpc.
39  * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
40  * _svcauth_unix does full blown unix style uid, gid+gids auth,
41  * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
42  * Note: the shorthand has been gutted for efficiency.
43  */
44 
45 #include <sys/param.h>
46 #include <sys/types.h>
47 #include <sys/time.h>
48 #include <sys/systm.h>
49 #include <sys/stream.h>
50 #include <sys/stropts.h>
51 #include <sys/strsubr.h>
52 #include <sys/tiuser.h>
53 #include <sys/tihdr.h>
54 #include <sys/t_kuser.h>
55 #include <sys/cmn_err.h>
56 #include <sys/debug.h>
57 
58 #include <rpc/types.h>
59 #include <rpc/xdr.h>
60 #include <rpc/auth.h>
61 #include <rpc/clnt.h>
62 #include <rpc/rpc_msg.h>
63 #include <rpc/svc.h>
64 #include <rpc/auth_unix.h>
65 #include <rpc/svc_auth.h>
66 
67 
68 /*
69  * Unix longhand authenticator
70  */
71 enum auth_stat
72 _svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg)
73 {
74 	struct authunix_parms *aup;
75 	int32_t *buf;
76 	struct area {
77 		struct authunix_parms area_aup;
78 		char area_machname[MAX_MACHINE_NAME+1];
79 		gid_t area_gids[NGRPS];
80 	} *area;
81 	uint_t auth_len;
82 	uint_t str_len, gid_len;
83 	int i;
84 
85 	CTASSERT(sizeof (struct area) <= RQCRED_SIZE);
86 	/* LINTED pointer alignment */
87 	area = (struct area *)rqst->rq_clntcred;
88 	aup = &area->area_aup;
89 	aup->aup_machname = area->area_machname;
90 	aup->aup_gids = area->area_gids;
91 	auth_len = msg->rm_call.cb_cred.oa_length;
92 	if (auth_len == 0)
93 		return (AUTH_BADCRED);
94 
95 	/* LINTED pointer cast */
96 	buf = (int32_t *)msg->rm_call.cb_cred.oa_base;
97 
98 	aup->aup_time = IXDR_GET_INT32(buf);
99 	str_len = IXDR_GET_U_INT32(buf);
100 	if (str_len > MAX_MACHINE_NAME)
101 		return (AUTH_BADCRED);
102 	bcopy((caddr_t)buf, aup->aup_machname, str_len);
103 	aup->aup_machname[str_len] = 0;
104 	str_len = RNDUP(str_len);
105 	buf += str_len / sizeof (int32_t);
106 	aup->aup_uid = IXDR_GET_INT32(buf);
107 	aup->aup_gid = IXDR_GET_INT32(buf);
108 	gid_len = IXDR_GET_U_INT32(buf);
109 	if (gid_len > NGRPS)
110 		return (AUTH_BADCRED);
111 	aup->aup_len = gid_len;
112 	for (i = 0; i < gid_len; i++) {
113 		aup->aup_gids[i] = IXDR_GET_INT32(buf);
114 	}
115 	/*
116 	 * five is the smallest unix credentials structure -
117 	 * timestamp, hostname len (0), uid, gid, and gids len (0).
118 	 */
119 	if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len)
120 		return (AUTH_BADCRED);
121 
122 	rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
123 	rqst->rq_xprt->xp_verf.oa_length = 0;
124 
125 	return (AUTH_OK);
126 }
127 
128 
129 /*
130  * Shorthand unix authenticator
131  * Looks up longhand in a cache.
132  */
133 /* ARGSUSED */
134 enum auth_stat
135 _svcauth_short(struct svc_req *rqst, struct rpc_msg *msg)
136 {
137 	return (AUTH_REJECTEDCRED);
138 }
139