xref: /titanic_41/usr/src/lib/libnsl/rpc/authsys_prot.c (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
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 2006 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30 /*
31  * Portions of this source code were derived from Berkeley
32  * 4.3 BSD under license from the Regents of the University of
33  * California.
34  */
35 
36 #pragma ident	"%Z%%M%	%I%	%E% SMI"
37 
38 /*
39  * XDR for UNIX style authentication parameters for RPC
40  */
41 
42 #include "mt.h"
43 #include <rpc/types.h>
44 #include <rpc/xdr.h>
45 #include <rpc/auth.h>
46 #include <rpc/auth_sys.h>
47 
48 extern bool_t xdr_uid_t(XDR *, uid_t *);
49 extern bool_t xdr_gid_t(XDR *, gid_t *);
50 
51 /*
52  * XDR for unix authentication parameters.
53  */
54 bool_t
55 xdr_authsys_parms(XDR *xdrs, struct authsys_parms *p)
56 {
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, (uint_t)sizeof (gid_t),
63 	    (xdrproc_t)xdr_gid_t))
64 		return (TRUE);
65 	return (FALSE);
66 }
67 
68 /*
69  * XDR for loopback unix authentication parameters.
70  */
71 bool_t
72 xdr_authloopback_parms(XDR *xdrs, struct authsys_parms *p)
73 {
74 	if (xdr_u_int(xdrs, &(p->aup_time)) &&
75 	    xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME) &&
76 	    xdr_uid_t(xdrs, (uid_t *)&(p->aup_uid)) &&
77 	    xdr_gid_t(xdrs, (gid_t *)&(p->aup_gid)) &&
78 	    xdr_array(xdrs, (caddr_t *)&(p->aup_gids),
79 	    &(p->aup_len), NGRPS_LOOPBACK, (uint_t)sizeof (gid_t),
80 	    (xdrproc_t)xdr_gid_t))
81 		return (TRUE);
82 	return (FALSE);
83 }
84 
85 /*
86  * XDR user id types (uid_t)
87  */
88 bool_t
89 xdr_uid_t(XDR *xdrs, uid_t *ip)
90 {
91 	/* CONSTCOND */
92 	if (sizeof (uid_t) != sizeof (int))
93 		return (xdr_short(xdrs, (short *)ip));
94 	return (xdr_int(xdrs, (int *)ip));
95 }
96 
97 /*
98  * XDR group id types (gid_t)
99  */
100 bool_t
101 xdr_gid_t(XDR *xdrs, gid_t *ip)
102 {
103 	/* CONSTCOND */
104 	if (sizeof (gid_t) != sizeof (int))
105 		return (xdr_short(xdrs, (short *)ip));
106 	return (xdr_int(xdrs, (int *)ip));
107 }
108