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.
254b3b7fc6SAlex 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>
394b3b7fc6SAlex Wilson #include <sys/debug.h>
404b3b7fc6SAlex Wilson
414b3b7fc6SAlex Wilson /*
424b3b7fc6SAlex Wilson * NOTE: this has to fit inside RQCRED_SIZE bytes. If you update this struct,
434b3b7fc6SAlex Wilson * double-check it still fits.
444b3b7fc6SAlex Wilson */
454b3b7fc6SAlex Wilson struct authlpbk_area {
464b3b7fc6SAlex Wilson struct authsys_parms area_aup;
474b3b7fc6SAlex Wilson char area_machname[MAX_MACHINE_NAME+1];
484b3b7fc6SAlex Wilson gid_t area_gids[NGRPS_LOOPBACK];
494b3b7fc6SAlex Wilson };
504b3b7fc6SAlex 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*4beeddd9SMarcel Telka int32_t *buf;
604b3b7fc6SAlex Wilson struct authlpbk_area *area;
61*4beeddd9SMarcel Telka uint_t auth_len;
62*4beeddd9SMarcel Telka uint_t str_len, gid_len;
637c478bd9Sstevel@tonic-gate int i;
647c478bd9Sstevel@tonic-gate
6561961e0fSrobinson /* LINTED pointer cast */
664b3b7fc6SAlex 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*4beeddd9SMarcel Telka auth_len = msg->rm_call.cb_cred.oa_length;
717c478bd9Sstevel@tonic-gate if (auth_len == 0)
727c478bd9Sstevel@tonic-gate return (AUTH_BADCRED);
73*4beeddd9SMarcel Telka
74*4beeddd9SMarcel Telka /* LINTED pointer cast */
75*4beeddd9SMarcel Telka buf = (int32_t *)msg->rm_call.cb_cred.oa_base;
76*4beeddd9SMarcel Telka
777c478bd9Sstevel@tonic-gate aup->aup_time = IXDR_GET_INT32(buf);
787c478bd9Sstevel@tonic-gate str_len = IXDR_GET_U_INT32(buf);
79*4beeddd9SMarcel Telka if (str_len > MAX_MACHINE_NAME)
80*4beeddd9SMarcel Telka return (AUTH_BADCRED);
81*4beeddd9SMarcel Telka if (str_len > auth_len)
82*4beeddd9SMarcel 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*4beeddd9SMarcel Telka if (gid_len > NGRPS_LOOPBACK)
91*4beeddd9SMarcel 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*4beeddd9SMarcel Telka if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len)
97*4beeddd9SMarcel Telka return (AUTH_BADCRED);
98*4beeddd9SMarcel Telka
994b3b7fc6SAlex Wilson aup->aup_len = gid_len;
1004b3b7fc6SAlex Wilson for (i = 0; i < gid_len; i++) {
1014b3b7fc6SAlex Wilson aup->aup_gids[i] = (gid_t)IXDR_GET_INT32(buf);
1024b3b7fc6SAlex Wilson }
103*4beeddd9SMarcel 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*4beeddd9SMarcel Telka
107*4beeddd9SMarcel Telka return (AUTH_OK);
1087c478bd9Sstevel@tonic-gate }
109