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 */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 1989 Sun Microsystems, Inc. All rights reserved. 244b3b7fc6SAlex Wilson * Copyright 2017 Joyent Inc 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 297c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD 337c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate /* 377c478bd9Sstevel@tonic-gate * svc_auth_unix.c 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_UNIX and AUTH_SHORT. 407c478bd9Sstevel@tonic-gate * _svcauth_unix does full blown unix style uid, gid+gids auth, 417c478bd9Sstevel@tonic-gate * _svcauth_short uses a shorthand auth to index into a cache of longhand auths. 427c478bd9Sstevel@tonic-gate * Note: the shorthand has been gutted for efficiency. 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #include <sys/param.h> 467c478bd9Sstevel@tonic-gate #include <sys/types.h> 477c478bd9Sstevel@tonic-gate #include <sys/time.h> 487c478bd9Sstevel@tonic-gate #include <sys/systm.h> 497c478bd9Sstevel@tonic-gate #include <sys/stream.h> 507c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 517c478bd9Sstevel@tonic-gate #include <sys/strsubr.h> 527c478bd9Sstevel@tonic-gate #include <sys/tiuser.h> 537c478bd9Sstevel@tonic-gate #include <sys/tihdr.h> 547c478bd9Sstevel@tonic-gate #include <sys/t_kuser.h> 557c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 564b3b7fc6SAlex Wilson #include <sys/debug.h> 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #include <rpc/types.h> 597c478bd9Sstevel@tonic-gate #include <rpc/xdr.h> 607c478bd9Sstevel@tonic-gate #include <rpc/auth.h> 617c478bd9Sstevel@tonic-gate #include <rpc/clnt.h> 627c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h> 637c478bd9Sstevel@tonic-gate #include <rpc/svc.h> 647c478bd9Sstevel@tonic-gate #include <rpc/auth_unix.h> 657c478bd9Sstevel@tonic-gate #include <rpc/svc_auth.h> 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * Unix longhand authenticator 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate enum auth_stat 727c478bd9Sstevel@tonic-gate _svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg) 737c478bd9Sstevel@tonic-gate { 747c478bd9Sstevel@tonic-gate struct authunix_parms *aup; 757c478bd9Sstevel@tonic-gate int32_t *buf; 767c478bd9Sstevel@tonic-gate struct area { 777c478bd9Sstevel@tonic-gate struct authunix_parms area_aup; 787c478bd9Sstevel@tonic-gate char area_machname[MAX_MACHINE_NAME+1]; 79*4beeddd9SMarcel Telka gid_t area_gids[NGRPS]; 807c478bd9Sstevel@tonic-gate } *area; 81*4beeddd9SMarcel Telka uint_t auth_len; 82*4beeddd9SMarcel Telka uint_t str_len, gid_len; 837c478bd9Sstevel@tonic-gate int i; 847c478bd9Sstevel@tonic-gate 854b3b7fc6SAlex Wilson CTASSERT(sizeof (struct area) <= RQCRED_SIZE); 867c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */ 877c478bd9Sstevel@tonic-gate area = (struct area *)rqst->rq_clntcred; 887c478bd9Sstevel@tonic-gate aup = &area->area_aup; 897c478bd9Sstevel@tonic-gate aup->aup_machname = area->area_machname; 90*4beeddd9SMarcel Telka aup->aup_gids = area->area_gids; 91*4beeddd9SMarcel Telka auth_len = msg->rm_call.cb_cred.oa_length; 92*4beeddd9SMarcel Telka if (auth_len == 0) 93*4beeddd9SMarcel Telka return (AUTH_BADCRED); 94*4beeddd9SMarcel Telka 95*4beeddd9SMarcel Telka /* LINTED pointer cast */ 96*4beeddd9SMarcel Telka buf = (int32_t *)msg->rm_call.cb_cred.oa_base; 97*4beeddd9SMarcel Telka 987c478bd9Sstevel@tonic-gate aup->aup_time = IXDR_GET_INT32(buf); 997c478bd9Sstevel@tonic-gate str_len = IXDR_GET_U_INT32(buf); 100*4beeddd9SMarcel Telka if (str_len > MAX_MACHINE_NAME) 101*4beeddd9SMarcel Telka return (AUTH_BADCRED); 102*4beeddd9SMarcel Telka bcopy((caddr_t)buf, aup->aup_machname, str_len); 1037c478bd9Sstevel@tonic-gate aup->aup_machname[str_len] = 0; 1047c478bd9Sstevel@tonic-gate str_len = RNDUP(str_len); 1057c478bd9Sstevel@tonic-gate buf += str_len / sizeof (int32_t); 1067c478bd9Sstevel@tonic-gate aup->aup_uid = IXDR_GET_INT32(buf); 1077c478bd9Sstevel@tonic-gate aup->aup_gid = IXDR_GET_INT32(buf); 1087c478bd9Sstevel@tonic-gate gid_len = IXDR_GET_U_INT32(buf); 109*4beeddd9SMarcel Telka if (gid_len > NGRPS) 110*4beeddd9SMarcel Telka return (AUTH_BADCRED); 1117c478bd9Sstevel@tonic-gate aup->aup_len = gid_len; 1127c478bd9Sstevel@tonic-gate for (i = 0; i < gid_len; i++) { 1137c478bd9Sstevel@tonic-gate aup->aup_gids[i] = IXDR_GET_INT32(buf); 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate /* 1167c478bd9Sstevel@tonic-gate * five is the smallest unix credentials structure - 1177c478bd9Sstevel@tonic-gate * timestamp, hostname len (0), uid, gid, and gids len (0). 1187c478bd9Sstevel@tonic-gate */ 119*4beeddd9SMarcel Telka if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) 120*4beeddd9SMarcel Telka return (AUTH_BADCRED); 121*4beeddd9SMarcel Telka 1227c478bd9Sstevel@tonic-gate rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL; 1237c478bd9Sstevel@tonic-gate rqst->rq_xprt->xp_verf.oa_length = 0; 124*4beeddd9SMarcel Telka 125*4beeddd9SMarcel Telka return (AUTH_OK); 1267c478bd9Sstevel@tonic-gate } 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* 1307c478bd9Sstevel@tonic-gate * Shorthand unix authenticator 1317c478bd9Sstevel@tonic-gate * Looks up longhand in a cache. 1327c478bd9Sstevel@tonic-gate */ 1337c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1347c478bd9Sstevel@tonic-gate enum auth_stat 1357c478bd9Sstevel@tonic-gate _svcauth_short(struct svc_req *rqst, struct rpc_msg *msg) 1367c478bd9Sstevel@tonic-gate { 1377c478bd9Sstevel@tonic-gate return (AUTH_REJECTEDCRED); 1387c478bd9Sstevel@tonic-gate } 139