nfs_prot_svc.c revision 131702
1/* 2 * Copyright (c) 1997-2004 Erez Zadok 3 * Copyright (c) 1989 Jan-Simon Pendry 4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1989 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgment: 21 * This product includes software developed by the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * %W% (Berkeley) %G% 40 * 41 * $Id: nfs_prot_svc.c,v 1.5.2.6 2004/01/21 04:04:58 ib42 Exp $ 42 * 43 */ 44 45#ifdef HAVE_CONFIG_H 46# include <config.h> 47#endif /* HAVE_CONFIG_H */ 48#include <am_defs.h> 49#include <amd.h> 50 51/* external definitions */ 52extern voidp nfsproc_null_2_svc(voidp, struct svc_req *); 53extern nfsattrstat *nfsproc_getattr_2_svc(am_nfs_fh *, struct svc_req *); 54extern nfsattrstat *nfsproc_setattr_2_svc(nfssattrargs *, struct svc_req *); 55extern voidp nfsproc_root_2_svc(voidp, struct svc_req *); 56extern nfsdiropres *nfsproc_lookup_2_svc(nfsdiropargs *, struct svc_req *); 57extern nfsreadlinkres *nfsproc_readlink_2_svc(am_nfs_fh *, struct svc_req *); 58extern nfsreadres *nfsproc_read_2_svc(nfsreadargs *, struct svc_req *); 59extern voidp nfsproc_writecache_2_svc(voidp, struct svc_req *); 60extern nfsattrstat *nfsproc_write_2_svc(nfswriteargs *, struct svc_req *); 61extern nfsdiropres *nfsproc_create_2_svc(nfscreateargs *, struct svc_req *); 62extern nfsstat *nfsproc_remove_2_svc(nfsdiropargs *, struct svc_req *); 63extern nfsstat *nfsproc_rename_2_svc(nfsrenameargs *, struct svc_req *); 64extern nfsstat *nfsproc_link_2_svc(nfslinkargs *, struct svc_req *); 65extern nfsstat *nfsproc_symlink_2_svc(nfssymlinkargs *, struct svc_req *); 66extern nfsdiropres *nfsproc_mkdir_2_svc(nfscreateargs *, struct svc_req *); 67extern nfsstat *nfsproc_rmdir_2_svc(nfsdiropargs *, struct svc_req *); 68extern nfsreaddirres *nfsproc_readdir_2_svc(nfsreaddirargs *, struct svc_req *); 69extern nfsstatfsres *nfsproc_statfs_2_svc(am_nfs_fh *, struct svc_req *); 70 71/* global variables */ 72SVCXPRT *nfs_program_2_transp; 73 74/* typedefs */ 75typedef char *(*nfssvcproc_t)(voidp, struct svc_req *); 76 77 78void 79nfs_program_2(struct svc_req *rqstp, SVCXPRT *transp) 80{ 81 union { 82 am_nfs_fh nfsproc_getattr_2_arg; 83 nfssattrargs nfsproc_setattr_2_arg; 84 nfsdiropargs nfsproc_lookup_2_arg; 85 am_nfs_fh nfsproc_readlink_2_arg; 86 nfsreadargs nfsproc_read_2_arg; 87 nfswriteargs nfsproc_write_2_arg; 88 nfscreateargs nfsproc_create_2_arg; 89 nfsdiropargs nfsproc_remove_2_arg; 90 nfsrenameargs nfsproc_rename_2_arg; 91 nfslinkargs nfsproc_link_2_arg; 92 nfssymlinkargs nfsproc_symlink_2_arg; 93 nfscreateargs nfsproc_mkdir_2_arg; 94 nfsdiropargs fsproc_rmdir_2_arg; 95 nfsreaddirargs nfsproc_readdir_2_arg; 96 am_nfs_fh nfsproc_statfs_2_arg; 97 } argument; 98 char *result; 99 xdrproc_t xdr_argument, xdr_result; 100 nfssvcproc_t local; 101 struct sockaddr_in *sinp; 102 char dq[20], dq2[28]; 103 104 sinp = amu_svc_getcaller(rqstp->rq_xprt); 105#ifdef MNT2_NFS_OPT_RESVPORT 106 /* Verify that the request comes from a reserved port */ 107 if (ntohs(sinp->sin_port) >= IPPORT_RESERVED) && 108 !(gopt.flags & CFM_NFS_INSECURE_PORT)) { 109 plog(XLOG_WARNING, "ignoring request from %s:%u, port not reserved", 110 inet_dquad(dq, sinp->sin_addr.s_addr), 111 ntohs(sinp->sin_port)); 112 return; 113 } 114#endif /* MNT2_NFS_OPT_RESVPORT */ 115 /* if the address does not match, ignore the request */ 116 if (sinp->sin_addr.s_addr && sinp->sin_addr.s_addr != myipaddr.s_addr) { 117 plog(XLOG_WARNING, "ignoring request from %s:%u, expected %s", 118 inet_dquad(dq, sinp->sin_addr.s_addr), 119 ntohs(sinp->sin_port), 120 inet_dquad(dq2, myipaddr.s_addr)); 121 return; 122 } 123 124 nfs_program_2_transp = NULL; 125 126 switch (rqstp->rq_proc) { 127 128 case NFSPROC_NULL: 129 xdr_argument = (xdrproc_t) xdr_void; 130 xdr_result = (xdrproc_t) xdr_void; 131 local = (nfssvcproc_t) nfsproc_null_2_svc; 132 break; 133 134 case NFSPROC_GETATTR: 135 xdr_argument = (xdrproc_t) xdr_nfs_fh; 136 xdr_result = (xdrproc_t) xdr_attrstat; 137 local = (nfssvcproc_t) nfsproc_getattr_2_svc; 138 break; 139 140 case NFSPROC_SETATTR: 141 xdr_argument = (xdrproc_t) xdr_sattrargs; 142 xdr_result = (xdrproc_t) xdr_attrstat; 143 local = (nfssvcproc_t) nfsproc_setattr_2_svc; 144 break; 145 146 case NFSPROC_ROOT: 147 xdr_argument = (xdrproc_t) xdr_void; 148 xdr_result = (xdrproc_t) xdr_void; 149 local = (nfssvcproc_t) nfsproc_root_2_svc; 150 break; 151 152 case NFSPROC_LOOKUP: 153 xdr_argument = (xdrproc_t) xdr_diropargs; 154 xdr_result = (xdrproc_t) xdr_diropres; 155 local = (nfssvcproc_t) nfsproc_lookup_2_svc; 156 /* 157 * Cheap way to pass transp down to amfs_auto_lookuppn so it can 158 * be stored in the am_node structure and later used for 159 * quick_reply(). 160 */ 161 nfs_program_2_transp = transp; 162 break; 163 164 case NFSPROC_READLINK: 165 xdr_argument = (xdrproc_t) xdr_nfs_fh; 166 xdr_result = (xdrproc_t) xdr_readlinkres; 167 local = (nfssvcproc_t) nfsproc_readlink_2_svc; 168 break; 169 170 case NFSPROC_READ: 171 xdr_argument = (xdrproc_t) xdr_readargs; 172 xdr_result = (xdrproc_t) xdr_readres; 173 local = (nfssvcproc_t) nfsproc_read_2_svc; 174 break; 175 176 case NFSPROC_WRITECACHE: 177 xdr_argument = (xdrproc_t) xdr_void; 178 xdr_result = (xdrproc_t) xdr_void; 179 local = (nfssvcproc_t) nfsproc_writecache_2_svc; 180 break; 181 182 case NFSPROC_WRITE: 183 xdr_argument = (xdrproc_t) xdr_writeargs; 184 xdr_result = (xdrproc_t) xdr_attrstat; 185 local = (nfssvcproc_t) nfsproc_write_2_svc; 186 break; 187 188 case NFSPROC_CREATE: 189 xdr_argument = (xdrproc_t) xdr_createargs; 190 xdr_result = (xdrproc_t) xdr_diropres; 191 local = (nfssvcproc_t) nfsproc_create_2_svc; 192 break; 193 194 case NFSPROC_REMOVE: 195 xdr_argument = (xdrproc_t) xdr_diropargs; 196 xdr_result = (xdrproc_t) xdr_nfsstat; 197 local = (nfssvcproc_t) nfsproc_remove_2_svc; 198 break; 199 200 case NFSPROC_RENAME: 201 xdr_argument = (xdrproc_t) xdr_renameargs; 202 xdr_result = (xdrproc_t) xdr_nfsstat; 203 local = (nfssvcproc_t) nfsproc_rename_2_svc; 204 break; 205 206 case NFSPROC_LINK: 207 xdr_argument = (xdrproc_t) xdr_linkargs; 208 xdr_result = (xdrproc_t) xdr_nfsstat; 209 local = (nfssvcproc_t) nfsproc_link_2_svc; 210 break; 211 212 case NFSPROC_SYMLINK: 213 xdr_argument = (xdrproc_t) xdr_symlinkargs; 214 xdr_result = (xdrproc_t) xdr_nfsstat; 215 local = (nfssvcproc_t) nfsproc_symlink_2_svc; 216 break; 217 218 case NFSPROC_MKDIR: 219 xdr_argument = (xdrproc_t) xdr_createargs; 220 xdr_result = (xdrproc_t) xdr_diropres; 221 local = (nfssvcproc_t) nfsproc_mkdir_2_svc; 222 break; 223 224 case NFSPROC_RMDIR: 225 xdr_argument = (xdrproc_t) xdr_diropargs; 226 xdr_result = (xdrproc_t) xdr_nfsstat; 227 local = (nfssvcproc_t) nfsproc_rmdir_2_svc; 228 break; 229 230 case NFSPROC_READDIR: 231 xdr_argument = (xdrproc_t) xdr_readdirargs; 232 xdr_result = (xdrproc_t) xdr_readdirres; 233 local = (nfssvcproc_t) nfsproc_readdir_2_svc; 234 break; 235 236 case NFSPROC_STATFS: 237 xdr_argument = (xdrproc_t) xdr_nfs_fh; 238 xdr_result = (xdrproc_t) xdr_statfsres; 239 local = (nfssvcproc_t) nfsproc_statfs_2_svc; 240 break; 241 242 default: 243 svcerr_noproc(transp); 244 return; 245 } 246 247 memset((char *) &argument, 0, sizeof(argument)); 248 if (!svc_getargs(transp, 249 (XDRPROC_T_TYPE) xdr_argument, 250 (SVC_IN_ARG_TYPE) &argument)) { 251 plog(XLOG_ERROR, 252 "NFS xdr decode failed for %d %d %d", 253 (int) rqstp->rq_prog, (int) rqstp->rq_vers, (int) rqstp->rq_proc); 254 svcerr_decode(transp); 255 return; 256 } 257 result = (*local) (&argument, rqstp); 258 259 nfs_program_2_transp = NULL; 260 261 if (result != NULL && !svc_sendreply(transp, 262 (XDRPROC_T_TYPE) xdr_result, 263 result)) { 264 svcerr_systemerr(transp); 265 } 266 if (!svc_freeargs(transp, 267 (XDRPROC_T_TYPE) xdr_argument, 268 (SVC_IN_ARG_TYPE) & argument)) { 269 plog(XLOG_FATAL, "unable to free rpc arguments in nfs_program_2"); 270 going_down(1); 271 } 272} 273