authunix_prot.c revision 177685
1177633Sdfr/* $NetBSD: authunix_prot.c,v 1.12 2000/01/22 22:19:17 mycroft Exp $ */ 2177633Sdfr 3177633Sdfr/* 4177633Sdfr * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 5177633Sdfr * unrestricted use provided that this legend is included on all tape 6177633Sdfr * media and as a part of the software program in whole or part. Users 7177633Sdfr * may copy or modify Sun RPC without charge, but are not authorized 8177633Sdfr * to license or distribute it to anyone else except as part of a product or 9177633Sdfr * program developed by the user. 10177633Sdfr * 11177633Sdfr * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12177633Sdfr * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13177633Sdfr * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14177633Sdfr * 15177633Sdfr * Sun RPC is provided with no support and without any obligation on the 16177633Sdfr * part of Sun Microsystems, Inc. to assist in its use, correction, 17177633Sdfr * modification or enhancement. 18177633Sdfr * 19177633Sdfr * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20177633Sdfr * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21177633Sdfr * OR ANY PART THEREOF. 22177633Sdfr * 23177633Sdfr * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24177633Sdfr * or profits or other special, indirect and consequential damages, even if 25177633Sdfr * Sun has been advised of the possibility of such damages. 26177633Sdfr * 27177633Sdfr * Sun Microsystems, Inc. 28177633Sdfr * 2550 Garcia Avenue 29177633Sdfr * Mountain View, California 94043 30177633Sdfr */ 31177633Sdfr 32177633Sdfr#if defined(LIBC_SCCS) && !defined(lint) 33177633Sdfrstatic char *sccsid2 = "@(#)authunix_prot.c 1.15 87/08/11 Copyr 1984 Sun Micro"; 34177633Sdfrstatic char *sccsid = "@(#)authunix_prot.c 2.1 88/07/29 4.0 RPCSRC"; 35177633Sdfr#endif 36177633Sdfr#include <sys/cdefs.h> 37177633Sdfr__FBSDID("$FreeBSD: head/sys/rpc/authunix_prot.c 177685 2008-03-28 09:50:32Z dfr $"); 38177633Sdfr 39177633Sdfr/* 40177633Sdfr * authunix_prot.c 41177633Sdfr * XDR for UNIX style authentication parameters for RPC 42177633Sdfr * 43177633Sdfr * Copyright (C) 1984, Sun Microsystems, Inc. 44177633Sdfr */ 45177633Sdfr 46177633Sdfr#include <sys/param.h> 47177633Sdfr#include <sys/kernel.h> 48177633Sdfr#include <sys/systm.h> 49177633Sdfr#include <sys/ucred.h> 50177633Sdfr 51177633Sdfr#include <rpc/types.h> 52177633Sdfr#include <rpc/xdr.h> 53177633Sdfr#include <rpc/auth.h> 54177633Sdfr 55177685Sdfr#include <rpc/rpc_com.h> 56177633Sdfr 57177633Sdfr/* gids compose part of a credential; there may not be more than 16 of them */ 58177633Sdfr#define NGRPS 16 59177633Sdfr 60177633Sdfr/* 61177633Sdfr * XDR for unix authentication parameters. 62177633Sdfr */ 63177633Sdfrbool_t 64177633Sdfrxdr_authunix_parms(XDR *xdrs, uint32_t *time, struct xucred *cred) 65177633Sdfr{ 66177633Sdfr uint32_t namelen; 67177633Sdfr uint32_t ngroups, i; 68177633Sdfr uint32_t junk; 69177633Sdfr 70177633Sdfr if (xdrs->x_op == XDR_ENCODE) { 71177633Sdfr namelen = strlen(hostname); 72177633Sdfr } else { 73177633Sdfr namelen = 0; 74177633Sdfr } 75177633Sdfr junk = 0; 76177633Sdfr 77177633Sdfr if (!xdr_uint32_t(xdrs, time) 78177633Sdfr || !xdr_uint32_t(xdrs, &namelen)) 79177633Sdfr return (FALSE); 80177633Sdfr 81177633Sdfr /* 82177633Sdfr * Ignore the hostname on decode. 83177633Sdfr */ 84177633Sdfr if (xdrs->x_op == XDR_ENCODE) { 85177633Sdfr if (!xdr_opaque(xdrs, hostname, namelen)) 86177633Sdfr return (FALSE); 87177633Sdfr } else { 88177633Sdfr xdr_setpos(xdrs, xdr_getpos(xdrs) + RNDUP(namelen)); 89177633Sdfr } 90177633Sdfr 91177633Sdfr if (!xdr_uint32_t(xdrs, &cred->cr_uid)) 92177633Sdfr return (FALSE); 93177633Sdfr if (!xdr_uint32_t(xdrs, &cred->cr_groups[0])) 94177633Sdfr return (FALSE); 95177633Sdfr 96177633Sdfr if (xdrs->x_op == XDR_ENCODE) { 97177633Sdfr ngroups = cred->cr_ngroups - 1; 98177633Sdfr if (ngroups > NGRPS) 99177633Sdfr ngroups = NGRPS; 100177633Sdfr } 101177633Sdfr 102177633Sdfr if (!xdr_uint32_t(xdrs, &ngroups)) 103177633Sdfr return (FALSE); 104177633Sdfr for (i = 0; i < ngroups; i++) { 105177633Sdfr if (i + 1 < NGROUPS) { 106177633Sdfr if (!xdr_uint32_t(xdrs, &cred->cr_groups[i + 1])) 107177633Sdfr return (FALSE); 108177633Sdfr } else { 109177633Sdfr if (!xdr_uint32_t(xdrs, &junk)) 110177633Sdfr return (FALSE); 111177633Sdfr } 112177633Sdfr } 113177633Sdfr 114177633Sdfr if (xdrs->x_op == XDR_DECODE) { 115177633Sdfr if (ngroups + 1 > NGROUPS) 116177633Sdfr cred->cr_ngroups = NGROUPS; 117177633Sdfr else 118177633Sdfr cred->cr_ngroups = ngroups + 1; 119177633Sdfr } 120177633Sdfr 121177633Sdfr return (TRUE); 122177633Sdfr} 123