svc_auth_unix.c revision 177685
11556Srgrimes/* 21556Srgrimes * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 31556Srgrimes * unrestricted use provided that this legend is included on all tape 41556Srgrimes * media and as a part of the software program in whole or part. Users 51556Srgrimes * may copy or modify Sun RPC without charge, but are not authorized 61556Srgrimes * to license or distribute it to anyone else except as part of a product or 71556Srgrimes * program developed by the user. 81556Srgrimes * 91556Srgrimes * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 101556Srgrimes * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 111556Srgrimes * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 121556Srgrimes * 131556Srgrimes * Sun RPC is provided with no support and without any obligation on the 141556Srgrimes * part of Sun Microsystems, Inc. to assist in its use, correction, 151556Srgrimes * modification or enhancement. 161556Srgrimes * 171556Srgrimes * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 181556Srgrimes * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 191556Srgrimes * OR ANY PART THEREOF. 201556Srgrimes * 211556Srgrimes * In no event will Sun Microsystems, Inc. be liable for any lost revenue 221556Srgrimes * or profits or other special, indirect and consequential damages, even if 231556Srgrimes * Sun has been advised of the possibility of such damages. 241556Srgrimes * 251556Srgrimes * Sun Microsystems, Inc. 261556Srgrimes * 2550 Garcia Avenue 271556Srgrimes * Mountain View, California 94043 281556Srgrimes */ 291556Srgrimes 301556Srgrimes#if defined(LIBC_SCCS) && !defined(lint) 311556Srgrimesstatic char *sccsid2 = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro"; 321556Srgrimesstatic char *sccsid = "@(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC"; 3317987Speter#endif 3417987Speter#include <sys/cdefs.h> 351556Srgrimes__FBSDID("$FreeBSD: head/sys/rpc/svc_auth_unix.c 177685 2008-03-28 09:50:32Z dfr $"); 361556Srgrimes 371556Srgrimes/* 381556Srgrimes * svc_auth_unix.c 391556Srgrimes * Handles UNIX flavor authentication parameters on the service side of rpc. 401556Srgrimes * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT. 411556Srgrimes * _svcauth_unix does full blown unix style uid,gid+gids auth, 4217987Speter * _svcauth_short uses a shorthand auth to index into a cache of longhand auths. 4317987Speter * Note: the shorthand has been gutted for efficiency. 4417987Speter * 4517987Speter * Copyright (C) 1984, Sun Microsystems, Inc. 4617987Speter */ 4717987Speter 4817987Speter#include <sys/param.h> 49#include <sys/lock.h> 50#include <sys/mutex.h> 51#include <sys/systm.h> 52#include <sys/ucred.h> 53 54#include <rpc/rpc.h> 55 56#include <rpc/rpc_com.h> 57 58#define MAX_MACHINE_NAME 255 59#define NGRPS 16 60 61/* 62 * Unix longhand authenticator 63 */ 64enum auth_stat 65_svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg) 66{ 67 enum auth_stat stat; 68 XDR xdrs; 69 int32_t *buf; 70 uint32_t time; 71 struct xucred *xcr; 72 u_int auth_len; 73 size_t str_len, gid_len; 74 u_int i; 75 76 xcr = rqst->rq_clntcred; 77 auth_len = (u_int)msg->rm_call.cb_cred.oa_length; 78 xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len, 79 XDR_DECODE); 80 buf = XDR_INLINE(&xdrs, auth_len); 81 if (buf != NULL) { 82 time = IXDR_GET_UINT32(buf); 83 str_len = (size_t)IXDR_GET_UINT32(buf); 84 if (str_len > MAX_MACHINE_NAME) { 85 stat = AUTH_BADCRED; 86 goto done; 87 } 88 str_len = RNDUP(str_len); 89 buf += str_len / sizeof (int32_t); 90 xcr->cr_uid = IXDR_GET_UINT32(buf); 91 xcr->cr_groups[0] = IXDR_GET_UINT32(buf); 92 gid_len = (size_t)IXDR_GET_UINT32(buf); 93 if (gid_len > NGRPS) { 94 stat = AUTH_BADCRED; 95 goto done; 96 } 97 for (i = 0; i < gid_len; i++) { 98 if (i + 1 < NGROUPS) 99 xcr->cr_groups[i + 1] = IXDR_GET_INT32(buf); 100 else 101 buf++; 102 } 103 if (gid_len + 1 > NGROUPS) 104 xcr->cr_ngroups = NGROUPS; 105 else 106 xcr->cr_ngroups = gid_len + 1; 107 108 /* 109 * five is the smallest unix credentials structure - 110 * timestamp, hostname len (0), uid, gid, and gids len (0). 111 */ 112 if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) { 113 (void) printf("bad auth_len gid %ld str %ld auth %u\n", 114 (long)gid_len, (long)str_len, auth_len); 115 stat = AUTH_BADCRED; 116 goto done; 117 } 118 } else if (! xdr_authunix_parms(&xdrs, &time, xcr)) { 119 stat = AUTH_BADCRED; 120 goto done; 121 } 122 123 rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL; 124 rqst->rq_xprt->xp_verf.oa_length = 0; 125 stat = AUTH_OK; 126done: 127 XDR_DESTROY(&xdrs); 128 129 return (stat); 130} 131 132 133/* 134 * Shorthand unix authenticator 135 * Looks up longhand in a cache. 136 */ 137/*ARGSUSED*/ 138enum auth_stat 139_svcauth_short(rqst, msg) 140 struct svc_req *rqst; 141 struct rpc_msg *msg; 142{ 143 return (AUTH_REJECTEDCRED); 144} 145