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 * @(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro 30 * @(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC 31 * $FreeBSD: src/lib/libc/rpc/svc_auth_unix.c,v 1.11 2004/10/16 06:11:35 obrien Exp $ 32 */ 33 34 /* 35 * svc_auth_unix.c 36 * Handles UNIX flavor authentication parameters on the service side of rpc. 37 * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT. 38 * _svcauth_unix does full blown unix style uid,gid+gids auth, 39 * _svcauth_short uses a shorthand auth to index into a cache of longhand auths. 40 * Note: the shorthand has been gutted for efficiency. 41 * 42 * Copyright (C) 1984, Sun Microsystems, Inc. 43 */ 44 45 #include "namespace.h" 46 #include <assert.h> 47 #include <stdio.h> 48 #include <string.h> 49 50 #include <rpc/rpc.h> 51 #include "un-namespace.h" 52 53 /* 54 * Unix longhand authenticator 55 */ 56 enum auth_stat 57 _svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg) 58 { 59 enum auth_stat stat; 60 XDR xdrs; 61 struct authunix_parms *aup; 62 int32_t *buf; 63 struct area { 64 struct authunix_parms area_aup; 65 char area_machname[MAX_MACHINE_NAME+1]; 66 int area_gids[NGRPS]; 67 } *area; 68 u_int auth_len; 69 size_t str_len, gid_len; 70 u_int i; 71 72 assert(rqst != NULL); 73 assert(msg != NULL); 74 75 area = (struct area *) rqst->rq_clntcred; 76 aup = &area->area_aup; 77 aup->aup_machname = area->area_machname; 78 aup->aup_gids = area->area_gids; 79 auth_len = (u_int)msg->rm_call.cb_cred.oa_length; 80 xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE); 81 buf = XDR_INLINE(&xdrs, auth_len); 82 if (buf != NULL) { 83 aup->aup_time = IXDR_GET_INT32(buf); 84 str_len = (size_t)IXDR_GET_U_INT32(buf); 85 if (str_len > MAX_MACHINE_NAME) { 86 stat = AUTH_BADCRED; 87 goto done; 88 } 89 memmove(aup->aup_machname, buf, str_len); 90 aup->aup_machname[str_len] = 0; 91 str_len = RNDUP(str_len); 92 buf += str_len / sizeof (int32_t); 93 aup->aup_uid = (int)IXDR_GET_INT32(buf); 94 aup->aup_gid = (int)IXDR_GET_INT32(buf); 95 gid_len = (size_t)IXDR_GET_U_INT32(buf); 96 if (gid_len > NGRPS) { 97 stat = AUTH_BADCRED; 98 goto done; 99 } 100 aup->aup_len = gid_len; 101 for (i = 0; i < gid_len; i++) { 102 aup->aup_gids[i] = (int)IXDR_GET_INT32(buf); 103 } 104 /* 105 * five is the smallest unix credentials structure - 106 * timestamp, hostname len (0), uid, gid, and gids len (0). 107 */ 108 if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) { 109 printf("bad auth_len gid %ld str %ld auth %u\n", 110 (long)gid_len, (long)str_len, auth_len); 111 stat = AUTH_BADCRED; 112 goto done; 113 } 114 } else if (! xdr_authunix_parms(&xdrs, aup)) { 115 xdrs.x_op = XDR_FREE; 116 xdr_authunix_parms(&xdrs, aup); 117 stat = AUTH_BADCRED; 118 goto done; 119 } 120 121 /* get the verifier */ 122 if ((u_int)msg->rm_call.cb_verf.oa_length) { 123 rqst->rq_xprt->xp_verf.oa_flavor = 124 msg->rm_call.cb_verf.oa_flavor; 125 rqst->rq_xprt->xp_verf.oa_base = 126 msg->rm_call.cb_verf.oa_base; 127 rqst->rq_xprt->xp_verf.oa_length = 128 msg->rm_call.cb_verf.oa_length; 129 } else { 130 rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL; 131 rqst->rq_xprt->xp_verf.oa_length = 0; 132 } 133 stat = AUTH_OK; 134 done: 135 XDR_DESTROY(&xdrs); 136 return (stat); 137 } 138 139 140 /* 141 * Shorthand unix authenticator 142 * Looks up longhand in a cache. 143 */ 144 /*ARGSUSED*/ 145 enum auth_stat 146 _svcauth_short(struct svc_req *rqst __unused, struct rpc_msg *msg __unused) 147 { 148 return (AUTH_REJECTEDCRED); 149 } 150