xref: /illumos-gate/usr/src/lib/librpcsvc/common/rusersxdr.c (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
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 2004 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 /*
34  * rusersxdr.c
35  * These are the non-rpcgen-able XDR routines for version 2 of the rusers
36  * protocol.
37  *
38  */
39 
40 #include <sys/types.h>
41 #include <rpc/rpc.h>
42 #include <rpcsvc/rusers.h>
43 
44 int
45 xdr_ru_utmp(xdrsp, up)
46 	XDR *xdrsp;
47 	struct ru_utmp *up;
48 {
49 	u_int len;
50 	char *p;
51 
52 	/*
53 	 * This code implements demented byte vectors:  we send out the length
54 	 * of fixed-length vectors, followed by the opaque bytes.  This is to
55 	 * be compatible with the over-the-wire protocol, as well as the
56 	 * rusers.h definition for struct ru_utmp.
57 	 */
58 	len = (int)sizeof (up->ut_line);
59 	if (xdr_u_int(xdrsp, &len) == FALSE)
60 		return (0);
61 	if (len != sizeof (up->ut_line)) {
62 		return (0);
63 	}
64 	if (!xdr_opaque(xdrsp, (char *)up->ut_line, len)) {
65 		return (0);
66 	}
67 	len = (int)sizeof (up->ut_name);
68 	if (xdr_u_int(xdrsp, &len) == FALSE)
69 		return (0);
70 	if (len != sizeof (up->ut_name)) {
71 		return (0);
72 	}
73 	if (!xdr_opaque(xdrsp, (char *)up->ut_name, len)) {
74 		return (0);
75 	}
76 	len = (int)sizeof (up->ut_host);
77 	if (xdr_u_int(xdrsp, &len) == FALSE)
78 		return (0);
79 	if (len != sizeof (up->ut_host)) {
80 		return (0);
81 	}
82 	if (!xdr_opaque(xdrsp, (char *)up->ut_host, len)) {
83 		return (0);
84 	}
85 	if (xdr_int(xdrsp, (int32_t *) &up->ut_time) == FALSE)
86 		return (0);
87 	return (1);
88 }
89 
90 int
91 xdr_utmpidle(xdrsp, ui)
92 	XDR *xdrsp;
93 	struct utmpidle *ui;
94 {
95 	if (xdr_ru_utmp(xdrsp, &ui->ui_utmp) == FALSE)
96 		return (0);
97 	if (xdr_u_int(xdrsp, &ui->ui_idle) == FALSE)
98 		return (0);
99 	return (1);
100 }
101 
102 int
103 xdr_utmpidleptr(xdrsp, up)
104 	XDR *xdrsp;
105 	struct utmpidle **up;
106 {
107 	if (xdr_reference(xdrsp, (char **) up, sizeof (struct utmpidle),
108 			xdr_utmpidle) == FALSE)
109 		return (0);
110 	return (1);
111 }
112 
113 int
114 xdr_utmpidlearr(xdrsp, up)
115 	XDR *xdrsp;
116 	struct utmpidlearr *up;
117 {
118 	return (xdr_array(xdrsp, (char **) &up->uia_arr,
119 		(u_int *)&(up->uia_cnt), MAXUSERS, sizeof (struct utmpidle *),
120 		xdr_utmpidleptr));
121 }
122