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 enum auth_stat stat; 75 XDR xdrs; 76 struct authunix_parms *aup; 77 int32_t *buf; 78 struct area { 79 struct authunix_parms area_aup; 80 char area_machname[MAX_MACHINE_NAME+1]; 81 u_int area_gids[NGRPS]; 82 } *area; 83 u_int auth_len; 84 u_int str_len, gid_len; 85 int i; 86 87 CTASSERT(sizeof (struct area) <= RQCRED_SIZE); 88 /* LINTED pointer alignment */ 89 area = (struct area *) rqst->rq_clntcred; 90 aup = &area->area_aup; 91 aup->aup_machname = area->area_machname; 92 aup->aup_gids = (gid_t *)area->area_gids; 93 auth_len = (u_int)msg->rm_call.cb_cred.oa_length; 94 xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len, 95 XDR_DECODE); 96 buf = XDR_INLINE(&xdrs, auth_len); 97 if (buf != NULL) { 98 aup->aup_time = IXDR_GET_INT32(buf); 99 str_len = IXDR_GET_U_INT32(buf); 100 if (str_len > MAX_MACHINE_NAME) { 101 stat = AUTH_BADCRED; 102 goto done; 103 } 104 bcopy((caddr_t)buf, aup->aup_machname, (u_int)str_len); 105 aup->aup_machname[str_len] = 0; 106 str_len = RNDUP(str_len); 107 buf += str_len / sizeof (int32_t); 108 aup->aup_uid = IXDR_GET_INT32(buf); 109 aup->aup_gid = IXDR_GET_INT32(buf); 110 gid_len = IXDR_GET_U_INT32(buf); 111 if (gid_len > NGRPS) { 112 stat = AUTH_BADCRED; 113 goto done; 114 } 115 aup->aup_len = gid_len; 116 for (i = 0; i < gid_len; i++) { 117 aup->aup_gids[i] = IXDR_GET_INT32(buf); 118 } 119 /* 120 * five is the smallest unix credentials structure - 121 * timestamp, hostname len (0), uid, gid, and gids len (0). 122 */ 123 if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) { 124 printf("bad auth_len gid %d str %d auth %d", 125 gid_len, str_len, auth_len); 126 stat = AUTH_BADCRED; 127 goto done; 128 } 129 } else if (! xdr_authunix_parms(&xdrs, aup)) { 130 xdrs.x_op = XDR_FREE; 131 (void) xdr_authunix_parms(&xdrs, aup); 132 stat = AUTH_BADCRED; 133 goto done; 134 } 135 rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL; 136 rqst->rq_xprt->xp_verf.oa_length = 0; 137 stat = AUTH_OK; 138 done: 139 XDR_DESTROY(&xdrs); 140 return (stat); 141 } 142 143 144 /* 145 * Shorthand unix authenticator 146 * Looks up longhand in a cache. 147 */ 148 /* ARGSUSED */ 149 enum auth_stat 150 _svcauth_short(struct svc_req *rqst, struct rpc_msg *msg) 151 { 152 return (AUTH_REJECTEDCRED); 153 } 154