xref: /openbsd-src/usr.sbin/amd/rpcx/mount_xdr.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*	$OpenBSD: mount_xdr.c,v 1.2 1996/03/25 15:54:57 niklas Exp $	*/
2 
3 /*
4  * Copyright (c) 1989 Jan-Simon Pendry
5  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
6  * Copyright (c) 1989, 1993
7  *	The Regents of the University of California.  All rights reserved.
8  *
9  * This code is derived from software contributed to Berkeley by
10  * Jan-Simon Pendry at Imperial College, London.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *	This product includes software developed by the University of
23  *	California, Berkeley and its contributors.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  *	from: @(#)mount_xdr.c	8.1 (Berkeley) 6/6/93
41  */
42 
43 #include "am.h"
44 #include "mount.h"
45 
46 
47 #if NFS_PROTOCOL_VERSION < 3
48 bool_t
49 xdr_fhandle(xdrs, objp)
50 	XDR *xdrs;
51 	fhandle objp;
52 {
53 	if (!xdr_opaque(xdrs, objp, FHSIZE)) {
54 		return (FALSE);
55 	}
56 	return (TRUE);
57 }
58 
59 bool_t
60 xdr_fhstatus(xdrs, objp)
61 	XDR *xdrs;
62 	fhstatus *objp;
63 {
64 	if (!xdr_u_int(xdrs, &objp->fhs_stat)) {
65 		return (FALSE);
66 	}
67 	switch (objp->fhs_stat) {
68 	case 0:
69 		if (!xdr_fhandle(xdrs, objp->fhs_fhandle)) {
70 			return (FALSE);
71 		}
72 		break;
73 	}
74 	return (TRUE);
75 }
76 
77 #else
78 #include <nfs/rpcv2.h>
79 
80 int
81 xdr_fhstatus(xdrsp, objp)
82 	XDR *xdrsp;
83 	fhstatus *objp;
84 {
85 	register int i;
86 	long auth, authcnt, authfnd = 0;
87 
88 
89 	if (!xdr_u_long(xdrsp, &objp->fhs_stat))
90 		return (0);
91 	if (objp->fhs_stat)
92 		return (1);
93 	switch (objp->fhs_vers) {
94 	case 1:
95 		objp->fhs_size = NFSX_V2FH;
96 		return (xdr_opaque(xdrsp, (caddr_t)objp->fhs_fhandle, NFSX_V2FH));
97 	case 3:
98 		if (!xdr_long(xdrsp, &objp->fhs_size))
99 			return (0);
100 		if (objp->fhs_size <= 0 || objp->fhs_size > NFSX_V3FHMAX)
101 			return (0);
102 		if (!xdr_opaque(xdrsp, (caddr_t)objp->fhs_fhandle, objp->fhs_size))
103 			return (0);
104 		if (!xdr_long(xdrsp, &authcnt))
105 			return (0);
106 		for (i = 0; i < authcnt; i++) {
107 			if (!xdr_long(xdrsp, &auth))
108 				return (0);
109 			if (auth == objp->fhs_auth)
110 				authfnd++;
111 		}
112 		/*
113 		 * Some servers, such as DEC's OSF/1 return a nil authenticator
114 		 * list to indicate RPCAUTH_UNIX.
115 		 */
116 		if (!authfnd && (authcnt > 0 || objp->fhs_auth != RPCAUTH_UNIX))
117 			objp->fhs_stat = EAUTH;
118 		return (1);
119 	default:
120 		return (0);
121 	};
122 }
123 #endif
124 
125 
126 
127 
128 
129 bool_t
130 xdr_dirpath(xdrs, objp)
131 	XDR *xdrs;
132 	dirpath *objp;
133 {
134 	if (!xdr_string(xdrs, objp, MNTPATHLEN)) {
135 		return (FALSE);
136 	}
137 	return (TRUE);
138 }
139 
140 
141 
142 
143 bool_t
144 xdr_name(xdrs, objp)
145 	XDR *xdrs;
146 	name *objp;
147 {
148 	if (!xdr_string(xdrs, objp, MNTNAMLEN)) {
149 		return (FALSE);
150 	}
151 	return (TRUE);
152 }
153 
154 
155 
156 
157 bool_t
158 xdr_mountlist(xdrs, objp)
159 	XDR *xdrs;
160 	mountlist *objp;
161 {
162 	if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct mountbody), xdr_mountbody)) {
163 		return (FALSE);
164 	}
165 	return (TRUE);
166 }
167 
168 
169 
170 bool_t
171 xdr_mountbody(xdrs, objp)
172 	XDR *xdrs;
173 	mountbody *objp;
174 {
175 	if (!xdr_name(xdrs, &objp->ml_hostname)) {
176 		return (FALSE);
177 	}
178 	if (!xdr_dirpath(xdrs, &objp->ml_directory)) {
179 		return (FALSE);
180 	}
181 	if (!xdr_mountlist(xdrs, &objp->ml_next)) {
182 		return (FALSE);
183 	}
184 	return (TRUE);
185 }
186 
187 
188 
189 
190 bool_t
191 xdr_groups(xdrs, objp)
192 	XDR *xdrs;
193 	groups *objp;
194 {
195 	if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct groupnode), xdr_groupnode)) {
196 		return (FALSE);
197 	}
198 	return (TRUE);
199 }
200 
201 
202 
203 
204 bool_t
205 xdr_groupnode(xdrs, objp)
206 	XDR *xdrs;
207 	groupnode *objp;
208 {
209 	if (!xdr_name(xdrs, &objp->gr_name)) {
210 		return (FALSE);
211 	}
212 	if (!xdr_groups(xdrs, &objp->gr_next)) {
213 		return (FALSE);
214 	}
215 	return (TRUE);
216 }
217 
218 
219 
220 
221 bool_t
222 xdr_exports(xdrs, objp)
223 	XDR *xdrs;
224 	exports *objp;
225 {
226 	if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct exportnode), xdr_exportnode)) {
227 		return (FALSE);
228 	}
229 	return (TRUE);
230 }
231 
232 
233 
234 
235 bool_t
236 xdr_exportnode(xdrs, objp)
237 	XDR *xdrs;
238 	exportnode *objp;
239 {
240 	if (!xdr_dirpath(xdrs, &objp->ex_dir)) {
241 		return (FALSE);
242 	}
243 	if (!xdr_groups(xdrs, &objp->ex_groups)) {
244 		return (FALSE);
245 	}
246 	if (!xdr_exports(xdrs, &objp->ex_next)) {
247 		return (FALSE);
248 	}
249 	return (TRUE);
250 }
251 
252 
253