authunix_prot.c revision 180025
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 180025 2008-06-26 10:21:54Z 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) { 71180025Sdfr /* 72180025Sdfr * Restrict name length to 255 according to RFC 1057. 73180025Sdfr */ 74177633Sdfr namelen = strlen(hostname); 75180025Sdfr if (namelen > 255) 76180025Sdfr namelen = 255; 77177633Sdfr } else { 78177633Sdfr namelen = 0; 79177633Sdfr } 80177633Sdfr junk = 0; 81177633Sdfr 82177633Sdfr if (!xdr_uint32_t(xdrs, time) 83177633Sdfr || !xdr_uint32_t(xdrs, &namelen)) 84177633Sdfr return (FALSE); 85177633Sdfr 86177633Sdfr /* 87177633Sdfr * Ignore the hostname on decode. 88177633Sdfr */ 89177633Sdfr if (xdrs->x_op == XDR_ENCODE) { 90177633Sdfr if (!xdr_opaque(xdrs, hostname, namelen)) 91177633Sdfr return (FALSE); 92177633Sdfr } else { 93177633Sdfr xdr_setpos(xdrs, xdr_getpos(xdrs) + RNDUP(namelen)); 94177633Sdfr } 95177633Sdfr 96177633Sdfr if (!xdr_uint32_t(xdrs, &cred->cr_uid)) 97177633Sdfr return (FALSE); 98177633Sdfr if (!xdr_uint32_t(xdrs, &cred->cr_groups[0])) 99177633Sdfr return (FALSE); 100177633Sdfr 101177633Sdfr if (xdrs->x_op == XDR_ENCODE) { 102177633Sdfr ngroups = cred->cr_ngroups - 1; 103177633Sdfr if (ngroups > NGRPS) 104177633Sdfr ngroups = NGRPS; 105177633Sdfr } 106177633Sdfr 107177633Sdfr if (!xdr_uint32_t(xdrs, &ngroups)) 108177633Sdfr return (FALSE); 109177633Sdfr for (i = 0; i < ngroups; i++) { 110177633Sdfr if (i + 1 < NGROUPS) { 111177633Sdfr if (!xdr_uint32_t(xdrs, &cred->cr_groups[i + 1])) 112177633Sdfr return (FALSE); 113177633Sdfr } else { 114177633Sdfr if (!xdr_uint32_t(xdrs, &junk)) 115177633Sdfr return (FALSE); 116177633Sdfr } 117177633Sdfr } 118177633Sdfr 119177633Sdfr if (xdrs->x_op == XDR_DECODE) { 120177633Sdfr if (ngroups + 1 > NGROUPS) 121177633Sdfr cred->cr_ngroups = NGROUPS; 122177633Sdfr else 123177633Sdfr cred->cr_ngroups = ngroups + 1; 124177633Sdfr } 125177633Sdfr 126177633Sdfr return (TRUE); 127177633Sdfr} 128