xref: /titanic_50/usr/src/lib/libnsl/rpc/authsys_prot.c (revision 6fec3791b5a9a5621db93bfef3a6514bc0511b5d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29 /*
30  * Portions of this source code were derived from Berkeley
31  * 4.3 BSD under license from the Regents of the University of
32  * California.
33  */
34 
35 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
37 /*
38  * authsys_prot.c
39  * XDR for UNIX style authentication parameters for RPC
40  */
41 
42 #include <rpc/types.h>
43 #include <rpc/xdr.h>
44 #include <rpc/auth.h>
45 #include <rpc/auth_sys.h>
46 
47 extern bool_t xdr_uid_t(XDR *, uid_t *);
48 extern bool_t xdr_gid_t(XDR *, gid_t *);
49 
50 /*
51  * XDR for unix authentication parameters.
52  */
53 bool_t
54 xdr_authsys_parms(XDR *xdrs, struct authsys_parms *p)
55 {
56 	if (xdr_u_int(xdrs, &(p->aup_time)) &&
57 	    xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME) &&
58 	    xdr_uid_t(xdrs, (uid_t *)&(p->aup_uid)) &&
59 	    xdr_gid_t(xdrs, (gid_t *)&(p->aup_gid)) &&
60 	    xdr_array(xdrs, (caddr_t *)&(p->aup_gids),
61 	    &(p->aup_len), NGRPS, (uint_t)sizeof (gid_t),
62 	    (xdrproc_t)xdr_gid_t))
63 		return (TRUE);
64 	return (FALSE);
65 }
66 
67 /*
68  * XDR for loopback unix authentication parameters.
69  */
70 bool_t
71 xdr_authloopback_parms(XDR *xdrs, struct authsys_parms *p)
72 {
73 	if (xdr_u_int(xdrs, &(p->aup_time)) &&
74 	    xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME) &&
75 	    xdr_uid_t(xdrs, (uid_t *)&(p->aup_uid)) &&
76 	    xdr_gid_t(xdrs, (gid_t *)&(p->aup_gid)) &&
77 	    xdr_array(xdrs, (caddr_t *)&(p->aup_gids),
78 	    &(p->aup_len), NGRPS_LOOPBACK, (uint_t)sizeof (gid_t),
79 	    (xdrproc_t)xdr_gid_t))
80 		return (TRUE);
81 	return (FALSE);
82 }
83 
84 /*
85  * XDR user id types (uid_t)
86  */
87 bool_t
88 xdr_uid_t(XDR *xdrs, uid_t *ip)
89 {
90 	/* CONSTCOND */
91 	if (sizeof (uid_t) != sizeof (int))
92 		return (xdr_short(xdrs, (short *)ip));
93 	return (xdr_int(xdrs, (int *)ip));
94 }
95 
96 /*
97  * XDR group id types (gid_t)
98  */
99 bool_t
100 xdr_gid_t(XDR *xdrs, gid_t *ip)
101 {
102 	/* CONSTCOND */
103 	if (sizeof (gid_t) != sizeof (int))
104 		return (xdr_short(xdrs, (short *)ip));
105 	return (xdr_int(xdrs, (int *)ip));
106 }
107