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