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