xref: /titanic_44/usr/src/lib/libnsl/rpc/svc_auth_loopb.c (revision 06cbfb198aac64fa21de116badc21f311728d0fc)
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
217c478bd9Sstevel@tonic-gate  */
2261961e0fSrobinson 
237c478bd9Sstevel@tonic-gate /*
24e8031f0aSraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
2577b65ce6SAlex Wilson  * Copyright 2017 Joyent Inc
2661961e0fSrobinson  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Handles the loopback UNIX flavor authentication parameters on the
317c478bd9Sstevel@tonic-gate  * service side of rpc.
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
34e8031f0aSraf #include "mt.h"
357c478bd9Sstevel@tonic-gate #include <stdio.h>
367c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
377c478bd9Sstevel@tonic-gate #include <syslog.h>
387c478bd9Sstevel@tonic-gate #include <sys/types.h>
3977b65ce6SAlex Wilson #include <sys/debug.h>
4077b65ce6SAlex Wilson 
4177b65ce6SAlex Wilson /*
4277b65ce6SAlex Wilson  * NOTE: this has to fit inside RQCRED_SIZE bytes. If you update this struct,
4377b65ce6SAlex Wilson  * double-check it still fits.
4477b65ce6SAlex Wilson  */
4577b65ce6SAlex Wilson struct authlpbk_area {
4677b65ce6SAlex Wilson 	struct authsys_parms area_aup;
4777b65ce6SAlex Wilson 	char area_machname[MAX_MACHINE_NAME+1];
4877b65ce6SAlex Wilson 	gid_t area_gids[NGRPS_LOOPBACK];
4977b65ce6SAlex Wilson };
5077b65ce6SAlex Wilson CTASSERT(sizeof (struct authlpbk_area) <= RQCRED_SIZE);
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * Loopback system (Unix) longhand authenticator
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate enum auth_stat
__svcauth_loopback(struct svc_req * rqst,struct rpc_msg * msg)567c478bd9Sstevel@tonic-gate __svcauth_loopback(struct svc_req *rqst, struct rpc_msg *msg)
577c478bd9Sstevel@tonic-gate {
587c478bd9Sstevel@tonic-gate 	struct authsys_parms *aup;
59*06cbfb19SMarcel Telka 	int32_t *buf;
6077b65ce6SAlex Wilson 	struct authlpbk_area *area;
61*06cbfb19SMarcel Telka 	uint_t auth_len;
62*06cbfb19SMarcel Telka 	uint_t str_len, gid_len;
637c478bd9Sstevel@tonic-gate 	int i;
647c478bd9Sstevel@tonic-gate 
6561961e0fSrobinson 	/* LINTED pointer cast */
6677b65ce6SAlex Wilson 	area = (struct authlpbk_area *)rqst->rq_clntcred;
677c478bd9Sstevel@tonic-gate 	aup = &area->area_aup;
687c478bd9Sstevel@tonic-gate 	aup->aup_machname = area->area_machname;
697c478bd9Sstevel@tonic-gate 	aup->aup_gids = area->area_gids;
70*06cbfb19SMarcel Telka 	auth_len = msg->rm_call.cb_cred.oa_length;
717c478bd9Sstevel@tonic-gate 	if (auth_len == 0)
727c478bd9Sstevel@tonic-gate 		return (AUTH_BADCRED);
73*06cbfb19SMarcel Telka 
74*06cbfb19SMarcel Telka 	/* LINTED pointer cast */
75*06cbfb19SMarcel Telka 	buf = (int32_t *)msg->rm_call.cb_cred.oa_base;
76*06cbfb19SMarcel Telka 
777c478bd9Sstevel@tonic-gate 	aup->aup_time = IXDR_GET_INT32(buf);
787c478bd9Sstevel@tonic-gate 	str_len = IXDR_GET_U_INT32(buf);
79*06cbfb19SMarcel Telka 	if (str_len > MAX_MACHINE_NAME)
80*06cbfb19SMarcel Telka 		return (AUTH_BADCRED);
81*06cbfb19SMarcel Telka 	if (str_len > auth_len)
82*06cbfb19SMarcel Telka 		return (AUTH_BADCRED);
837c478bd9Sstevel@tonic-gate 	(void) memcpy(aup->aup_machname, buf, str_len);
847c478bd9Sstevel@tonic-gate 	aup->aup_machname[str_len] = 0;
857c478bd9Sstevel@tonic-gate 	str_len = RNDUP(str_len);
867c478bd9Sstevel@tonic-gate 	buf += str_len / sizeof (int);
877c478bd9Sstevel@tonic-gate 	aup->aup_uid = IXDR_GET_INT32(buf);
887c478bd9Sstevel@tonic-gate 	aup->aup_gid = IXDR_GET_INT32(buf);
897c478bd9Sstevel@tonic-gate 	gid_len = IXDR_GET_U_INT32(buf);
90*06cbfb19SMarcel Telka 	if (gid_len > NGRPS_LOOPBACK)
91*06cbfb19SMarcel Telka 		return (AUTH_BADCRED);
927c478bd9Sstevel@tonic-gate 	/*
937c478bd9Sstevel@tonic-gate 	 * five is the smallest unix credentials structure -
947c478bd9Sstevel@tonic-gate 	 * timestamp, hostname len (0), uid, gid, and gids len (0).
957c478bd9Sstevel@tonic-gate 	 */
96*06cbfb19SMarcel Telka 	if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len)
97*06cbfb19SMarcel Telka 		return (AUTH_BADCRED);
98*06cbfb19SMarcel Telka 
9977b65ce6SAlex Wilson 	aup->aup_len = gid_len;
10077b65ce6SAlex Wilson 	for (i = 0; i < gid_len; i++) {
10177b65ce6SAlex Wilson 		aup->aup_gids[i] = (gid_t)IXDR_GET_INT32(buf);
10277b65ce6SAlex Wilson 	}
103*06cbfb19SMarcel Telka 
1047c478bd9Sstevel@tonic-gate 	rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
1057c478bd9Sstevel@tonic-gate 	rqst->rq_xprt->xp_verf.oa_length = 0;
106*06cbfb19SMarcel Telka 
107*06cbfb19SMarcel Telka 	return (AUTH_OK);
1087c478bd9Sstevel@tonic-gate }
109