xref: /titanic_41/usr/src/lib/libnsl/rpc/svc_auth_sys.c (revision f793df011b713adf3a98ad884e5807162ee1e878)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
2161961e0fSrobinson  */
2261961e0fSrobinson 
2361961e0fSrobinson /*
24e8031f0aSraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25e962c73bSAlex Wilson  * Copyright 2017 Joyent Inc
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
28e8031f0aSraf 
297c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
307c478bd9Sstevel@tonic-gate /* All Rights Reserved */
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley
337c478bd9Sstevel@tonic-gate  * 4.3 BSD under license from the Regents of the University of
347c478bd9Sstevel@tonic-gate  * California.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * Handles UNIX flavor authentication parameters on the service side of rpc.
397c478bd9Sstevel@tonic-gate  * There are two svc auth implementations here: AUTH_SYS and AUTH_SHORT.
407c478bd9Sstevel@tonic-gate  * __svcauth_sys does full blown unix style uid, gid+gids auth,
417c478bd9Sstevel@tonic-gate  * __svcauth_short uses a shorthand auth to index into a cache of
427c478bd9Sstevel@tonic-gate  *	longhand auths.
437c478bd9Sstevel@tonic-gate  * Note: the shorthand has been gutted for efficiency.
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate 
47e8031f0aSraf #include "mt.h"
487c478bd9Sstevel@tonic-gate #include <stdio.h>
497c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
507c478bd9Sstevel@tonic-gate #include <syslog.h>
517c478bd9Sstevel@tonic-gate #include <sys/types.h>
52e962c73bSAlex Wilson #include <sys/debug.h>
5361961e0fSrobinson #include <string.h>
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
56e962c73bSAlex Wilson  * NOTE: this has to fit inside RQCRED_SIZE bytes. If you update this struct,
57e962c73bSAlex Wilson  * double-check it still fits.
58e962c73bSAlex Wilson  */
59e962c73bSAlex Wilson struct authsys_area {
60e962c73bSAlex Wilson 	struct authsys_parms area_aup;
61e962c73bSAlex Wilson 	char area_machname[MAX_MACHINE_NAME+1];
62e962c73bSAlex Wilson 	gid_t area_gids[NGRPS];
63e962c73bSAlex Wilson };
64e962c73bSAlex Wilson CTASSERT(sizeof (struct authsys_area) <= RQCRED_SIZE);
65e962c73bSAlex Wilson 
66e962c73bSAlex Wilson /*
677c478bd9Sstevel@tonic-gate  * System (Unix) longhand authenticator
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate enum auth_stat
__svcauth_sys(struct svc_req * rqst,struct rpc_msg * msg)7061961e0fSrobinson __svcauth_sys(struct svc_req *rqst, struct rpc_msg *msg)
717c478bd9Sstevel@tonic-gate {
7261961e0fSrobinson 	struct authsys_parms *aup;
73*f793df01SMarcel Telka 	int32_t *buf;
74e962c73bSAlex Wilson 	struct authsys_area *area;
7561961e0fSrobinson 	uint_t auth_len;
7661961e0fSrobinson 	uint_t str_len, gid_len;
7761961e0fSrobinson 	int i;
787c478bd9Sstevel@tonic-gate 
7961961e0fSrobinson 	/* LINTED pointer cast */
80e962c73bSAlex Wilson 	area = (struct authsys_area *)rqst->rq_clntcred;
817c478bd9Sstevel@tonic-gate 	aup = &area->area_aup;
827c478bd9Sstevel@tonic-gate 	aup->aup_machname = area->area_machname;
837c478bd9Sstevel@tonic-gate 	aup->aup_gids = area->area_gids;
84*f793df01SMarcel Telka 	auth_len = msg->rm_call.cb_cred.oa_length;
8561961e0fSrobinson 	if (auth_len == 0)
867c478bd9Sstevel@tonic-gate 		return (AUTH_BADCRED);
87*f793df01SMarcel Telka 
88*f793df01SMarcel Telka 	/* LINTED pointer cast */
89*f793df01SMarcel Telka 	buf = (int32_t *)msg->rm_call.cb_cred.oa_base;
90*f793df01SMarcel Telka 
917c478bd9Sstevel@tonic-gate 	aup->aup_time = IXDR_GET_INT32(buf);
927c478bd9Sstevel@tonic-gate 	str_len = IXDR_GET_U_INT32(buf);
93*f793df01SMarcel Telka 	if (str_len > MAX_MACHINE_NAME)
94*f793df01SMarcel Telka 		return (AUTH_BADCRED);
9561961e0fSrobinson 	(void) memcpy(aup->aup_machname, buf, str_len);
967c478bd9Sstevel@tonic-gate 	aup->aup_machname[str_len] = 0;
977c478bd9Sstevel@tonic-gate 	str_len = RNDUP(str_len);
987c478bd9Sstevel@tonic-gate 	buf += str_len / (int)sizeof (int32_t);
997c478bd9Sstevel@tonic-gate 	aup->aup_uid = IXDR_GET_INT32(buf);
1007c478bd9Sstevel@tonic-gate 	aup->aup_gid = IXDR_GET_INT32(buf);
1017c478bd9Sstevel@tonic-gate 	gid_len = IXDR_GET_U_INT32(buf);
102*f793df01SMarcel Telka 	if (gid_len > NGRPS)
103*f793df01SMarcel Telka 		return (AUTH_BADCRED);
1047c478bd9Sstevel@tonic-gate 	aup->aup_len = gid_len;
1057c478bd9Sstevel@tonic-gate 	for (i = 0; i < gid_len; i++) {
1067c478bd9Sstevel@tonic-gate 		aup->aup_gids[i] = (gid_t)IXDR_GET_INT32(buf);
1077c478bd9Sstevel@tonic-gate 	}
1087c478bd9Sstevel@tonic-gate 	/*
1097c478bd9Sstevel@tonic-gate 	 * five is the smallest unix credentials structure -
1107c478bd9Sstevel@tonic-gate 	 * timestamp, hostname len (0), uid, gid, and gids len (0).
1117c478bd9Sstevel@tonic-gate 	 */
112*f793df01SMarcel Telka 	if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len)
113*f793df01SMarcel Telka 		return (AUTH_BADCRED);
114*f793df01SMarcel Telka 
1157c478bd9Sstevel@tonic-gate 	rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
1167c478bd9Sstevel@tonic-gate 	rqst->rq_xprt->xp_verf.oa_length = 0;
117*f793df01SMarcel Telka 
118*f793df01SMarcel Telka 	return (AUTH_OK);
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate  * Shorthand unix authenticator
1237c478bd9Sstevel@tonic-gate  * Looks up longhand in a cache.
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1267c478bd9Sstevel@tonic-gate enum auth_stat
__svcauth_short(struct svc_req * rqst,struct rpc_msg * msg)12761961e0fSrobinson __svcauth_short(struct svc_req *rqst, struct rpc_msg *msg)
1287c478bd9Sstevel@tonic-gate {
1297c478bd9Sstevel@tonic-gate 	return (AUTH_REJECTEDCRED);
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * Unix longhand authenticator. Will be obsoleted
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate enum auth_stat
__svcauth_unix(struct svc_req * rqst,struct rpc_msg * msg)13661961e0fSrobinson __svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg)
1377c478bd9Sstevel@tonic-gate {
13861961e0fSrobinson 	return (__svcauth_sys(rqst, msg));
1397c478bd9Sstevel@tonic-gate }
140