xref: /onnv-gate/usr/src/lib/librpcsvc/common/mountlist_xdr.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1998 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #include <stdio.h>				/* for fprintf() */
32*0Sstevel@tonic-gate #include <stdlib.h>				/* for malloc() */
33*0Sstevel@tonic-gate #include <rpc/types.h>
34*0Sstevel@tonic-gate #include <rpc/xdr.h>
35*0Sstevel@tonic-gate #include <rpcsvc/mount.h>
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /*
39*0Sstevel@tonic-gate  * XDR routines to handle mountlist structure
40*0Sstevel@tonic-gate  *
41*0Sstevel@tonic-gate  * These are iterative versions to avoid the stack-blowing problems of
42*0Sstevel@tonic-gate  * the recursive routines generated by rpcgen.
43*0Sstevel@tonic-gate  *
44*0Sstevel@tonic-gate  * XXXX These should be removed when rpcgen is fixed to produce better
45*0Sstevel@tonic-gate  * code in these circumstances.
46*0Sstevel@tonic-gate  */
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate bool_t
xdr_mountlist(xdrs,objp)50*0Sstevel@tonic-gate xdr_mountlist(xdrs, objp)
51*0Sstevel@tonic-gate 	register XDR *xdrs;
52*0Sstevel@tonic-gate 	mountlist *objp;
53*0Sstevel@tonic-gate {
54*0Sstevel@tonic-gate 	bool_t more_data;
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate 	switch (xdrs->x_op) {
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate 	case XDR_FREE: {
59*0Sstevel@tonic-gate 		mountbody *mb, *tmp;
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate 		tmp = *objp;
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate 		while (tmp != NULL) {
64*0Sstevel@tonic-gate 			mb = tmp;
65*0Sstevel@tonic-gate 			tmp = mb->ml_next;
66*0Sstevel@tonic-gate 			if (!xdr_name(xdrs, &mb->ml_hostname))
67*0Sstevel@tonic-gate 				return (FALSE);
68*0Sstevel@tonic-gate 			if (!xdr_dirpath(xdrs, &mb->ml_directory))
69*0Sstevel@tonic-gate 				return (FALSE);
70*0Sstevel@tonic-gate 			free(mb);
71*0Sstevel@tonic-gate 		}
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate 		break;
74*0Sstevel@tonic-gate 	}
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate 	case XDR_DECODE: {
77*0Sstevel@tonic-gate 		mountbody *mb;
78*0Sstevel@tonic-gate 		mountbody *mb_prev = NULL;
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate 		for (;;) {
81*0Sstevel@tonic-gate 			if (!xdr_bool(xdrs, &more_data))
82*0Sstevel@tonic-gate 				return (FALSE);
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate 			if (!more_data)
85*0Sstevel@tonic-gate 				break;
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate 			mb = (mountbody *)malloc(sizeof (struct mountbody));
88*0Sstevel@tonic-gate 			if (mb == NULL) {
89*0Sstevel@tonic-gate 				fprintf(stderr,
90*0Sstevel@tonic-gate 				    "xdr_mountlist: out of memory\n");
91*0Sstevel@tonic-gate 				return (FALSE);
92*0Sstevel@tonic-gate 			}
93*0Sstevel@tonic-gate 			mb->ml_hostname = NULL;
94*0Sstevel@tonic-gate 			mb->ml_directory = NULL;
95*0Sstevel@tonic-gate 			mb->ml_next = NULL;
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate 			if (mb_prev == NULL) {
98*0Sstevel@tonic-gate 				mb_prev = mb;
99*0Sstevel@tonic-gate 				*objp = mb;
100*0Sstevel@tonic-gate 			}
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 			if (!xdr_name(xdrs, &mb->ml_hostname))
103*0Sstevel@tonic-gate 				return (FALSE);
104*0Sstevel@tonic-gate 			if (!xdr_dirpath(xdrs, &mb->ml_directory))
105*0Sstevel@tonic-gate 				return (FALSE);
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate 			if (mb_prev != mb) {
108*0Sstevel@tonic-gate 				mb_prev->ml_next = mb;
109*0Sstevel@tonic-gate 				mb_prev = mb;
110*0Sstevel@tonic-gate 			}
111*0Sstevel@tonic-gate 		}
112*0Sstevel@tonic-gate 		break;
113*0Sstevel@tonic-gate 	}
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate 	case XDR_ENCODE: {
116*0Sstevel@tonic-gate 		mountbody *mb;
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate 		mb = *objp;
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate 		for (;;) {
121*0Sstevel@tonic-gate 			more_data = mb != NULL;
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate 			if (!xdr_bool(xdrs, &more_data))
124*0Sstevel@tonic-gate 				return (FALSE);
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate 			if (!more_data)
127*0Sstevel@tonic-gate 				break;
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 			if (!xdr_name(xdrs, &mb->ml_hostname))
130*0Sstevel@tonic-gate 				return (FALSE);
131*0Sstevel@tonic-gate 			if (!xdr_dirpath(xdrs, &mb->ml_directory))
132*0Sstevel@tonic-gate 				return (FALSE);
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate 			mb = mb->ml_next;
135*0Sstevel@tonic-gate 		}
136*0Sstevel@tonic-gate 		break;
137*0Sstevel@tonic-gate 	}
138*0Sstevel@tonic-gate 
139*0Sstevel@tonic-gate 	default:
140*0Sstevel@tonic-gate 		break;
141*0Sstevel@tonic-gate 	}
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate 	return (TRUE);
144*0Sstevel@tonic-gate }
145*0Sstevel@tonic-gate 
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate /*
148*0Sstevel@tonic-gate  * xdr_mountbody() is included here simply for backward compatibility. It is
149*0Sstevel@tonic-gate  * no longer used by xdr_mountlist(), nor by any other SunOS routine as of
150*0Sstevel@tonic-gate  * now.
151*0Sstevel@tonic-gate  *
152*0Sstevel@tonic-gate  * This is simply a copy of the rpcgen generated routine.
153*0Sstevel@tonic-gate  */
154*0Sstevel@tonic-gate bool_t
xdr_mountbody(xdrs,objp)155*0Sstevel@tonic-gate xdr_mountbody(xdrs, objp)
156*0Sstevel@tonic-gate 	register XDR *xdrs;
157*0Sstevel@tonic-gate 	mountbody *objp;
158*0Sstevel@tonic-gate {
159*0Sstevel@tonic-gate 	if (!xdr_name(xdrs, &objp->ml_hostname))
160*0Sstevel@tonic-gate 		return (FALSE);
161*0Sstevel@tonic-gate 	if (!xdr_dirpath(xdrs, &objp->ml_directory))
162*0Sstevel@tonic-gate 		return (FALSE);
163*0Sstevel@tonic-gate 	if (!xdr_mountlist(xdrs, &objp->ml_next))
164*0Sstevel@tonic-gate 		return (FALSE);
165*0Sstevel@tonic-gate 	return (TRUE);
166*0Sstevel@tonic-gate }
167