1 /* $OpenBSD: mount_xdr.c,v 1.4 2003/06/02 23:36:52 millert 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 #if NFS_PROTOCOL_VERSION < 3 44 bool_t 45 xdr_fhandle(XDR *xdrs, fhandle objp) 46 { 47 if (!xdr_opaque(xdrs, objp, FHSIZE)) { 48 return (FALSE); 49 } 50 return (TRUE); 51 } 52 53 bool_t 54 xdr_fhstatus(XDR *xdrs, fhstatus *objp) 55 { 56 if (!xdr_u_int(xdrs, &objp->fhs_stat)) { 57 return (FALSE); 58 } 59 switch (objp->fhs_stat) { 60 case 0: 61 if (!xdr_fhandle(xdrs, objp->fhs_fhandle)) { 62 return (FALSE); 63 } 64 break; 65 } 66 return (TRUE); 67 } 68 69 #else 70 #include <nfs/rpcv2.h> 71 72 int 73 xdr_fhstatus(XDR *xdrsp, fhstatus *objp) 74 { 75 int i; 76 long auth, authcnt, authfnd = 0; 77 78 79 if (!xdr_u_long(xdrsp, &objp->fhs_stat)) 80 return (0); 81 if (objp->fhs_stat) 82 return (1); 83 switch (objp->fhs_vers) { 84 case 1: 85 objp->fhs_size = NFSX_V2FH; 86 return (xdr_opaque(xdrsp, (caddr_t)objp->fhs_fhandle, NFSX_V2FH)); 87 case 3: 88 if (!xdr_long(xdrsp, &objp->fhs_size)) 89 return (0); 90 if (objp->fhs_size <= 0 || objp->fhs_size > NFSX_V3FHMAX) 91 return (0); 92 if (!xdr_opaque(xdrsp, (caddr_t)objp->fhs_fhandle, objp->fhs_size)) 93 return (0); 94 if (!xdr_long(xdrsp, &authcnt)) 95 return (0); 96 for (i = 0; i < authcnt; i++) { 97 if (!xdr_long(xdrsp, &auth)) 98 return (0); 99 if (auth == objp->fhs_auth) 100 authfnd++; 101 } 102 /* 103 * Some servers, such as DEC's OSF/1 return a nil authenticator 104 * list to indicate RPCAUTH_UNIX. 105 */ 106 if (!authfnd && (authcnt > 0 || objp->fhs_auth != RPCAUTH_UNIX)) 107 objp->fhs_stat = EAUTH; 108 return (1); 109 default: 110 return (0); 111 }; 112 } 113 #endif 114 115 bool_t 116 xdr_dirpath(XDR *xdrs, dirpath *objp) 117 { 118 if (!xdr_string(xdrs, objp, MNTPATHLEN)) { 119 return (FALSE); 120 } 121 return (TRUE); 122 } 123 124 bool_t 125 xdr_name(XDR *xdrs, name *objp) 126 { 127 if (!xdr_string(xdrs, objp, MNTNAMLEN)) { 128 return (FALSE); 129 } 130 return (TRUE); 131 } 132 133 bool_t 134 xdr_mountlist(XDR *xdrs, mountlist *objp) 135 { 136 if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct mountbody), xdr_mountbody)) { 137 return (FALSE); 138 } 139 return (TRUE); 140 } 141 142 bool_t 143 xdr_mountbody(XDR *xdrs, mountbody *objp) 144 { 145 if (!xdr_name(xdrs, &objp->ml_hostname)) { 146 return (FALSE); 147 } 148 if (!xdr_dirpath(xdrs, &objp->ml_directory)) { 149 return (FALSE); 150 } 151 if (!xdr_mountlist(xdrs, &objp->ml_next)) { 152 return (FALSE); 153 } 154 return (TRUE); 155 } 156 157 bool_t 158 xdr_groups(XDR *xdrs, groups *objp) 159 { 160 if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct groupnode), xdr_groupnode)) { 161 return (FALSE); 162 } 163 return (TRUE); 164 } 165 166 bool_t 167 xdr_groupnode(XDR *xdrs, groupnode *objp) 168 { 169 if (!xdr_name(xdrs, &objp->gr_name)) { 170 return (FALSE); 171 } 172 if (!xdr_groups(xdrs, &objp->gr_next)) { 173 return (FALSE); 174 } 175 return (TRUE); 176 } 177 178 bool_t 179 xdr_exports(XDR *xdrs, exports *objp) 180 { 181 if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct exportnode), xdr_exportnode)) { 182 return (FALSE); 183 } 184 return (TRUE); 185 } 186 187 bool_t 188 xdr_exportnode(XDR *xdrs, exportnode *objp) 189 { 190 if (!xdr_dirpath(xdrs, &objp->ex_dir)) { 191 return (FALSE); 192 } 193 if (!xdr_groups(xdrs, &objp->ex_groups)) { 194 return (FALSE); 195 } 196 if (!xdr_exports(xdrs, &objp->ex_next)) { 197 return (FALSE); 198 } 199 return (TRUE); 200 } 201