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