xref: /openbsd/usr.sbin/amd/rpcx/mount_xdr.c (revision 4bdff4be)
1 /*	$OpenBSD: mount_xdr.c,v 1.5 2014/10/20 02:33:42 guenther 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. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *	from: @(#)mount_xdr.c	8.1 (Berkeley) 6/6/93
37  */
38 
39 #include "am.h"
40 #include "mount.h"
41 
42 
43 #include <nfs/rpcv2.h>
44 
45 int
46 xdr_fhstatus(XDR *xdrsp, fhstatus *objp)
47 {
48 	int i;
49 	long auth, authcnt, authfnd = 0;
50 
51 
52 	if (!xdr_u_long(xdrsp, &objp->fhs_stat))
53 		return (0);
54 	if (objp->fhs_stat)
55 		return (1);
56 	switch (objp->fhs_vers) {
57 	case 1:
58 		objp->fhs_size = NFSX_V2FH;
59 		return (xdr_opaque(xdrsp, (caddr_t)objp->fhs_fhandle, NFSX_V2FH));
60 	case 3:
61 		if (!xdr_long(xdrsp, &objp->fhs_size))
62 			return (0);
63 		if (objp->fhs_size <= 0 || objp->fhs_size > NFSX_V3FHMAX)
64 			return (0);
65 		if (!xdr_opaque(xdrsp, (caddr_t)objp->fhs_fhandle, objp->fhs_size))
66 			return (0);
67 		if (!xdr_long(xdrsp, &authcnt))
68 			return (0);
69 		for (i = 0; i < authcnt; i++) {
70 			if (!xdr_long(xdrsp, &auth))
71 				return (0);
72 			if (auth == objp->fhs_auth)
73 				authfnd++;
74 		}
75 		/*
76 		 * Some servers, such as DEC's OSF/1 return a nil authenticator
77 		 * list to indicate RPCAUTH_UNIX.
78 		 */
79 		if (!authfnd && (authcnt > 0 || objp->fhs_auth != RPCAUTH_UNIX))
80 			objp->fhs_stat = EAUTH;
81 		return (1);
82 	default:
83 		return (0);
84 	};
85 }
86 
87 bool_t
88 xdr_dirpath(XDR *xdrs, dirpath *objp)
89 {
90 	if (!xdr_string(xdrs, objp, MNTPATHLEN)) {
91 		return (FALSE);
92 	}
93 	return (TRUE);
94 }
95 
96 bool_t
97 xdr_name(XDR *xdrs, name *objp)
98 {
99 	if (!xdr_string(xdrs, objp, MNTNAMLEN)) {
100 		return (FALSE);
101 	}
102 	return (TRUE);
103 }
104 
105 bool_t
106 xdr_mountlist(XDR *xdrs, mountlist *objp)
107 {
108 	if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct mountbody), xdr_mountbody)) {
109 		return (FALSE);
110 	}
111 	return (TRUE);
112 }
113 
114 bool_t
115 xdr_mountbody(XDR *xdrs, mountbody *objp)
116 {
117 	if (!xdr_name(xdrs, &objp->ml_hostname)) {
118 		return (FALSE);
119 	}
120 	if (!xdr_dirpath(xdrs, &objp->ml_directory)) {
121 		return (FALSE);
122 	}
123 	if (!xdr_mountlist(xdrs, &objp->ml_next)) {
124 		return (FALSE);
125 	}
126 	return (TRUE);
127 }
128 
129 bool_t
130 xdr_groups(XDR *xdrs, groups *objp)
131 {
132 	if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct groupnode), xdr_groupnode)) {
133 		return (FALSE);
134 	}
135 	return (TRUE);
136 }
137 
138 bool_t
139 xdr_groupnode(XDR *xdrs, groupnode *objp)
140 {
141 	if (!xdr_name(xdrs, &objp->gr_name)) {
142 		return (FALSE);
143 	}
144 	if (!xdr_groups(xdrs, &objp->gr_next)) {
145 		return (FALSE);
146 	}
147 	return (TRUE);
148 }
149 
150 bool_t
151 xdr_exports(XDR *xdrs, exports *objp)
152 {
153 	if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct exportnode), xdr_exportnode)) {
154 		return (FALSE);
155 	}
156 	return (TRUE);
157 }
158 
159 bool_t
160 xdr_exportnode(XDR *xdrs, exportnode *objp)
161 {
162 	if (!xdr_dirpath(xdrs, &objp->ex_dir)) {
163 		return (FALSE);
164 	}
165 	if (!xdr_groups(xdrs, &objp->ex_groups)) {
166 		return (FALSE);
167 	}
168 	if (!xdr_exports(xdrs, &objp->ex_next)) {
169 		return (FALSE);
170 	}
171 	return (TRUE);
172 }
173