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 /* 24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 25 * Copyright 2017 Joyent Inc 26 * Use is subject to license terms. 27 */ 28 29 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 30 /* All Rights Reserved */ 31 /* 32 * Portions of this source code were derived from Berkeley 33 * 4.3 BSD under license from the Regents of the University of 34 * California. 35 */ 36 37 /* 38 * Handles UNIX flavor authentication parameters on the service side of rpc. 39 * There are two svc auth implementations here: AUTH_SYS and AUTH_SHORT. 40 * __svcauth_sys does full blown unix style uid, gid+gids auth, 41 * __svcauth_short uses a shorthand auth to index into a cache of 42 * longhand auths. 43 * Note: the shorthand has been gutted for efficiency. 44 * 45 */ 46 47 #include "mt.h" 48 #include <stdio.h> 49 #include <rpc/rpc.h> 50 #include <syslog.h> 51 #include <sys/types.h> 52 #include <sys/debug.h> 53 #include <string.h> 54 55 /* 56 * NOTE: this has to fit inside RQCRED_SIZE bytes. If you update this struct, 57 * double-check it still fits. 58 */ 59 struct authsys_area { 60 struct authsys_parms area_aup; 61 char area_machname[MAX_MACHINE_NAME+1]; 62 gid_t area_gids[NGRPS]; 63 }; 64 CTASSERT(sizeof (struct authsys_area) <= RQCRED_SIZE); 65 66 /* 67 * System (Unix) longhand authenticator 68 */ 69 enum auth_stat 70 __svcauth_sys(struct svc_req *rqst, struct rpc_msg *msg) 71 { 72 enum auth_stat stat; 73 XDR xdrs; 74 struct authsys_parms *aup; 75 rpc_inline_t *buf; 76 struct authsys_area *area; 77 uint_t auth_len; 78 uint_t str_len, gid_len; 79 int i; 80 81 /* LINTED pointer cast */ 82 area = (struct authsys_area *)rqst->rq_clntcred; 83 aup = &area->area_aup; 84 aup->aup_machname = area->area_machname; 85 aup->aup_gids = area->area_gids; 86 auth_len = (uint_t)msg->rm_call.cb_cred.oa_length; 87 if (auth_len == 0) 88 return (AUTH_BADCRED); 89 xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len, 90 XDR_DECODE); 91 buf = XDR_INLINE(&xdrs, auth_len); 92 if (buf != NULL) { 93 aup->aup_time = IXDR_GET_INT32(buf); 94 str_len = IXDR_GET_U_INT32(buf); 95 if (str_len > MAX_MACHINE_NAME) { 96 stat = AUTH_BADCRED; 97 goto done; 98 } 99 (void) memcpy(aup->aup_machname, buf, str_len); 100 aup->aup_machname[str_len] = 0; 101 str_len = RNDUP(str_len); 102 buf += str_len / (int)sizeof (int32_t); 103 aup->aup_uid = IXDR_GET_INT32(buf); 104 aup->aup_gid = IXDR_GET_INT32(buf); 105 gid_len = IXDR_GET_U_INT32(buf); 106 if (gid_len > NGRPS) { 107 stat = AUTH_BADCRED; 108 goto done; 109 } 110 aup->aup_len = gid_len; 111 for (i = 0; i < gid_len; i++) { 112 aup->aup_gids[i] = (gid_t)IXDR_GET_INT32(buf); 113 } 114 /* 115 * five is the smallest unix credentials structure - 116 * timestamp, hostname len (0), uid, gid, and gids len (0). 117 */ 118 if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) { 119 (void) syslog(LOG_ERR, 120 "bad auth_len gid %d str %d auth %d", 121 gid_len, str_len, auth_len); 122 stat = AUTH_BADCRED; 123 goto done; 124 } 125 } else if (! xdr_authsys_parms(&xdrs, aup)) { 126 xdrs.x_op = XDR_FREE; 127 (void) xdr_authsys_parms(&xdrs, aup); 128 stat = AUTH_BADCRED; 129 goto done; 130 } 131 rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL; 132 rqst->rq_xprt->xp_verf.oa_length = 0; 133 stat = AUTH_OK; 134 done: 135 XDR_DESTROY(&xdrs); 136 return (stat); 137 } 138 139 /* 140 * Shorthand unix authenticator 141 * Looks up longhand in a cache. 142 */ 143 /*ARGSUSED*/ 144 enum auth_stat 145 __svcauth_short(struct svc_req *rqst, struct rpc_msg *msg) 146 { 147 return (AUTH_REJECTEDCRED); 148 } 149 150 /* 151 * Unix longhand authenticator. Will be obsoleted 152 */ 153 enum auth_stat 154 __svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg) 155 { 156 return (__svcauth_sys(rqst, msg)); 157 } 158