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  * Copyright 1991 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
27 /*
28  * Portions of this source code were derived from Berkeley
29  * 4.3 BSD under license from the Regents of the University of
30  * California.
31  */
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 /*
36  * authsys_prot.c
37  * XDR for UNIX style authentication parameters for RPC
38  *
39  */
40 
41 #include <rpc/types.h>
42 #include <rpc/trace.h>
43 #include <rpc/xdr.h>
44 #include <rpc/auth.h>
45 #include <rpc/auth_sys.h>
46 
47 bool_t xdr_uid_t();
48 bool_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 	trace1(TR_xdr_authsys_parms, 0);
57 	if (xdr_u_int(xdrs, &(p->aup_time)) &&
58 	    xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME) &&
59 	    xdr_uid_t(xdrs, (uid_t *)&(p->aup_uid)) &&
60 	    xdr_gid_t(xdrs, (gid_t *)&(p->aup_gid)) &&
61 	    xdr_array(xdrs, (caddr_t *)&(p->aup_gids),
62 	    &(p->aup_len), NGRPS, (u_int)sizeof (gid_t),
63 	    (xdrproc_t) xdr_gid_t)) {
64 		trace1(TR_xdr_authsys_parms, 1);
65 		return (TRUE);
66 	}
67 	trace1(TR_xdr_authsys_parms, 1);
68 	return (FALSE);
69 }
70 
71 /*
72  * XDR for loopback unix authentication parameters.
73  */
74 bool_t
75 xdr_authloopback_parms(XDR *xdrs, struct authsys_parms *p)
76 {
77 	/* trace1(TR_xdr_authsys_parms, 0); */
78 	if (xdr_u_int(xdrs, &(p->aup_time)) &&
79 	    xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME) &&
80 	    xdr_uid_t(xdrs, (uid_t *)&(p->aup_uid)) &&
81 	    xdr_gid_t(xdrs, (gid_t *)&(p->aup_gid)) &&
82 	    xdr_array(xdrs, (caddr_t *)&(p->aup_gids),
83 	    &(p->aup_len), NGRPS_LOOPBACK, sizeof (gid_t),
84 	    (xdrproc_t) xdr_gid_t)) {
85 		/* trace1(TR_xdr_authsys_parms, 1); */
86 		return (TRUE);
87 	}
88 	/* trace1(TR_xdr_authsys_parms, 1); */
89 	return (FALSE);
90 }
91 
92 /*
93  * XDR user id types (uid_t)
94  */
95 bool_t
96 xdr_uid_t(XDR *xdrs, uid_t *ip)
97 {
98 	bool_t dummy;
99 
100 	trace1(TR_xdr_uid_t, 0);
101 #ifdef lint
102 	(void) (xdr_short(xdrs, (short *)ip));
103 	dummy = xdr_int(xdrs, (int *)ip);
104 	trace1(TR_xdr_uid_t, 1);
105 	return (dummy);
106 #else
107 	if (sizeof (uid_t) == sizeof (int)) {
108 		dummy = xdr_int(xdrs, (int *)ip);
109 		trace1(TR_xdr_uid_t, 1);
110 		return (dummy);
111 	} else {
112 		dummy = xdr_short(xdrs, (short *)ip);
113 		trace1(TR_xdr_uid_t, 1);
114 		return (dummy);
115 	}
116 #endif
117 }
118 
119 /*
120  * XDR group id types (gid_t)
121  */
122 bool_t
123 xdr_gid_t(XDR *xdrs, gid_t *ip)
124 {
125 	bool_t dummy;
126 
127 	trace1(TR_xdr_gid_t, 0);
128 #ifdef lint
129 	(void) (xdr_short(xdrs, (short *)ip));
130 	dummy = xdr_int(xdrs, (int *)ip);
131 	trace1(TR_xdr_gid_t, 1);
132 	return (dummy);
133 #else
134 	if (sizeof (gid_t) == sizeof (int)) {
135 		dummy = xdr_int(xdrs, (int *)ip);
136 		trace1(TR_xdr_gid_t, 1);
137 		return (dummy);
138 	} else {
139 		dummy = xdr_short(xdrs, (short *)ip);
140 		trace1(TR_xdr_gid_t, 1);
141 		return (dummy);
142 	}
143 #endif
144 }
145