1 /* 2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 * unrestricted use provided that this legend is included on all tape 4 * media and as a part of the software program in whole or part. Users 5 * may copy or modify Sun RPC without charge, but are not authorized 6 * to license or distribute it to anyone else except as part of a product or 7 * program developed by the user. 8 * 9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12 * 13 * Sun RPC is provided with no support and without any obligation on the 14 * part of Sun Microsystems, Inc. to assist in its use, correction, 15 * modification or enhancement. 16 * 17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19 * OR ANY PART THEREOF. 20 * 21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22 * or profits or other special, indirect and consequential damages, even if 23 * Sun has been advised of the possibility of such damages. 24 * 25 * Sun Microsystems, Inc. 26 * 2550 Garcia Avenue 27 * Mountain View, California 94043 28 */ 29 30 #if defined(LIBC_SCCS) && !defined(lint) 31 static char *sccsid2 = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro"; 32 static char *sccsid = "@(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC"; 33 #endif 34 #include <sys/cdefs.h> 35 __FBSDID("$FreeBSD$"); 36 37 /* 38 * svc_auth_unix.c 39 * Handles UNIX flavor authentication parameters on the service side of rpc. 40 * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT. 41 * _svcauth_unix does full blown unix style uid,gid+gids auth, 42 * _svcauth_short uses a shorthand auth to index into a cache of longhand auths. 43 * Note: the shorthand has been gutted for efficiency. 44 * 45 * Copyright (C) 1984, Sun Microsystems, Inc. 46 */ 47 48 #include "namespace.h" 49 #include <assert.h> 50 #include <stdio.h> 51 #include <string.h> 52 53 #include <rpc/rpc.h> 54 #include "un-namespace.h" 55 56 /* 57 * Unix longhand authenticator 58 */ 59 enum auth_stat 60 _svcauth_unix(rqst, msg) 61 struct svc_req *rqst; 62 struct rpc_msg *msg; 63 { 64 enum auth_stat stat; 65 XDR xdrs; 66 struct authunix_parms *aup; 67 int32_t *buf; 68 struct area { 69 struct authunix_parms area_aup; 70 char area_machname[MAX_MACHINE_NAME+1]; 71 int area_gids[NGRPS]; 72 } *area; 73 u_int auth_len; 74 size_t str_len, gid_len; 75 u_int i; 76 77 assert(rqst != NULL); 78 assert(msg != NULL); 79 80 area = (struct area *) rqst->rq_clntcred; 81 aup = &area->area_aup; 82 aup->aup_machname = area->area_machname; 83 aup->aup_gids = area->area_gids; 84 auth_len = (u_int)msg->rm_call.cb_cred.oa_length; 85 xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE); 86 buf = XDR_INLINE(&xdrs, auth_len); 87 if (buf != NULL) { 88 aup->aup_time = IXDR_GET_INT32(buf); 89 str_len = (size_t)IXDR_GET_U_INT32(buf); 90 if (str_len > MAX_MACHINE_NAME) { 91 stat = AUTH_BADCRED; 92 goto done; 93 } 94 memmove(aup->aup_machname, buf, str_len); 95 aup->aup_machname[str_len] = 0; 96 str_len = RNDUP(str_len); 97 buf += str_len / sizeof (int32_t); 98 aup->aup_uid = (int)IXDR_GET_INT32(buf); 99 aup->aup_gid = (int)IXDR_GET_INT32(buf); 100 gid_len = (size_t)IXDR_GET_U_INT32(buf); 101 if (gid_len > NGRPS) { 102 stat = AUTH_BADCRED; 103 goto done; 104 } 105 aup->aup_len = gid_len; 106 for (i = 0; i < gid_len; i++) { 107 aup->aup_gids[i] = (int)IXDR_GET_INT32(buf); 108 } 109 /* 110 * five is the smallest unix credentials structure - 111 * timestamp, hostname len (0), uid, gid, and gids len (0). 112 */ 113 if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) { 114 (void) printf("bad auth_len gid %ld str %ld auth %u\n", 115 (long)gid_len, (long)str_len, auth_len); 116 stat = AUTH_BADCRED; 117 goto done; 118 } 119 } else if (! xdr_authunix_parms(&xdrs, aup)) { 120 xdrs.x_op = XDR_FREE; 121 (void)xdr_authunix_parms(&xdrs, aup); 122 stat = AUTH_BADCRED; 123 goto done; 124 } 125 126 /* get the verifier */ 127 if ((u_int)msg->rm_call.cb_verf.oa_length) { 128 rqst->rq_xprt->xp_verf.oa_flavor = 129 msg->rm_call.cb_verf.oa_flavor; 130 rqst->rq_xprt->xp_verf.oa_base = 131 msg->rm_call.cb_verf.oa_base; 132 rqst->rq_xprt->xp_verf.oa_length = 133 msg->rm_call.cb_verf.oa_length; 134 } else { 135 rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL; 136 rqst->rq_xprt->xp_verf.oa_length = 0; 137 } 138 stat = AUTH_OK; 139 done: 140 XDR_DESTROY(&xdrs); 141 return (stat); 142 } 143 144 145 /* 146 * Shorthand unix authenticator 147 * Looks up longhand in a cache. 148 */ 149 /*ARGSUSED*/ 150 enum auth_stat 151 _svcauth_short(rqst, msg) 152 struct svc_req *rqst; 153 struct rpc_msg *msg; 154 { 155 return (AUTH_REJECTEDCRED); 156 } 157