]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/rpc/authunix_prot.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / rpc / authunix_prot.c
1 /*      $NetBSD: authunix_prot.c,v 1.12 2000/01/22 22:19:17 mycroft 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 #if defined(LIBC_SCCS) && !defined(lint)
33 static char *sccsid2 = "@(#)authunix_prot.c 1.15 87/08/11 Copyr 1984 Sun Micro";
34 static char *sccsid = "@(#)authunix_prot.c      2.1 88/07/29 4.0 RPCSRC";
35 #endif
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
38
39 /*
40  * authunix_prot.c
41  * XDR for UNIX style authentication parameters for RPC
42  *
43  * Copyright (C) 1984, Sun Microsystems, Inc.
44  */
45
46 #include <sys/param.h>
47 #include <sys/jail.h>
48 #include <sys/kernel.h>
49 #include <sys/systm.h>
50 #include <sys/ucred.h>
51
52 #include <rpc/types.h>
53 #include <rpc/xdr.h>
54 #include <rpc/auth.h>
55
56 #include <rpc/rpc_com.h>
57
58 /* gids compose part of a credential; there may not be more than 16 of them */
59 #define NGRPS 16
60
61 /*
62  * XDR for unix authentication parameters.
63  */
64 bool_t
65 xdr_authunix_parms(XDR *xdrs, uint32_t *time, struct xucred *cred)
66 {
67         uint32_t namelen;
68         uint32_t ngroups, i;
69         uint32_t junk;
70         char hostbuf[MAXHOSTNAMELEN];
71
72         if (xdrs->x_op == XDR_ENCODE) {
73                 /*
74                  * Restrict name length to 255 according to RFC 1057.
75                  */
76                 getcredhostname(NULL, hostbuf, sizeof(hostbuf));
77                 namelen = strlen(hostbuf);
78                 if (namelen > 255)
79                         namelen = 255;
80         } else {
81                 namelen = 0;
82         }
83         junk = 0;
84
85         if (!xdr_uint32_t(xdrs, time)
86             || !xdr_uint32_t(xdrs, &namelen))
87                 return (FALSE);
88
89         /*
90          * Ignore the hostname on decode.
91          */
92         if (xdrs->x_op == XDR_ENCODE) {
93                 if (!xdr_opaque(xdrs, hostbuf, namelen))
94                         return (FALSE);
95         } else {
96                 xdr_setpos(xdrs, xdr_getpos(xdrs) + RNDUP(namelen));
97         }
98
99         if (!xdr_uint32_t(xdrs, &cred->cr_uid))
100                 return (FALSE);
101         if (!xdr_uint32_t(xdrs, &cred->cr_groups[0]))
102                 return (FALSE);
103
104         if (xdrs->x_op == XDR_ENCODE) {
105                 ngroups = cred->cr_ngroups - 1;
106                 if (ngroups > NGRPS)
107                         ngroups = NGRPS;
108         }
109
110         if (!xdr_uint32_t(xdrs, &ngroups))
111                 return (FALSE);
112         for (i = 0; i < ngroups; i++) {
113                 if (i + 1 < ngroups_max + 1) {
114                         if (!xdr_uint32_t(xdrs, &cred->cr_groups[i + 1]))
115                                 return (FALSE);
116                 } else {
117                         if (!xdr_uint32_t(xdrs, &junk))
118                                 return (FALSE);
119                 }
120         }
121
122         if (xdrs->x_op == XDR_DECODE) {
123                 if (ngroups + 1 > ngroups_max + 1)
124                         cred->cr_ngroups = ngroups_max + 1;
125                 else
126                         cred->cr_ngroups = ngroups + 1;
127         }
128
129         return (TRUE);
130 }