1/* 2 * Copyright (c) 1997-2014 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. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * 36 * File: am-utils/hlfsd/nfs_prot_svc.c 37 * 38 */ 39 40#ifdef HAVE_CONFIG_H 41# include <config.h> 42#endif /* HAVE_CONFIG_H */ 43#include <am_defs.h> 44#include <hlfsd.h> 45 46/* EXTERNAL FUNCTIONS */ 47extern voidp nfsproc_null_2_svc(voidp, struct svc_req *); 48extern nfsattrstat *nfsproc_getattr_2_svc(am_nfs_fh *, struct svc_req *); 49extern nfsattrstat *nfsproc_setattr_2_svc(nfssattrargs *, struct svc_req *); 50extern voidp nfsproc_root_2_svc(voidp, struct svc_req *); 51extern nfsdiropres *nfsproc_lookup_2_svc(nfsdiropargs *, struct svc_req *); 52extern nfsreadlinkres *nfsproc_readlink_2_svc(am_nfs_fh *, struct svc_req *); 53extern nfsreadres *nfsproc_read_2_svc(nfsreadargs *, struct svc_req *); 54extern voidp nfsproc_writecache_2_svc(voidp, struct svc_req *); 55extern nfsattrstat *nfsproc_write_2_svc(nfswriteargs *, struct svc_req *); 56extern nfsdiropres *nfsproc_create_2_svc(nfscreateargs *, struct svc_req *); 57extern nfsstat *nfsproc_remove_2_svc(nfsdiropargs *, struct svc_req *); 58extern nfsstat *nfsproc_rename_2_svc(nfsrenameargs *, struct svc_req *); 59extern nfsstat *nfsproc_link_2_svc(nfslinkargs *, struct svc_req *); 60extern nfsstat *nfsproc_symlink_2_svc(nfssymlinkargs *, struct svc_req *); 61extern nfsdiropres *nfsproc_mkdir_2_svc(nfscreateargs *, struct svc_req *); 62extern nfsstat *nfsproc_rmdir_2_svc(nfsdiropargs *, struct svc_req *); 63extern nfsreaddirres *nfsproc_readdir_2_svc(nfsreaddirargs *, struct svc_req *); 64extern nfsstatfsres *nfsproc_statfs_2_svc(am_nfs_fh *, struct svc_req *); 65 66/* GLOBALS */ 67SVCXPRT *nfs_program_2_transp; 68 69/* TYPEDEFS */ 70typedef char *(*nfssvcproc_t)(voidp, struct svc_req *); 71 72 73void 74nfs_program_2(struct svc_req *rqstp, SVCXPRT *transp) 75{ 76 union { 77 am_nfs_fh nfsproc_getattr_2_arg; 78 nfssattrargs nfsproc_setattr_2_arg; 79 nfsdiropargs nfsproc_lookup_2_arg; 80 am_nfs_fh nfsproc_readlink_2_arg; 81 nfsreadargs nfsproc_read_2_arg; 82 nfswriteargs nfsproc_write_2_arg; 83 nfscreateargs nfsproc_create_2_arg; 84 nfsdiropargs nfsproc_remove_2_arg; 85 nfsrenameargs nfsproc_rename_2_arg; 86 nfslinkargs nfsproc_link_2_arg; 87 nfssymlinkargs nfsproc_symlink_2_arg; 88 nfscreateargs nfsproc_mkdir_2_arg; 89 nfsdiropargs nfsproc_rmdir_2_arg; 90 nfsreaddirargs nfsproc_readdir_2_arg; 91 am_nfs_fh nfsproc_statfs_2_arg; 92 } argument; 93 char *result; 94 xdrproc_t xdr_argument, xdr_result; 95 nfssvcproc_t local; 96 97 nfs_program_2_transp = NULL; 98 99 switch (rqstp->rq_proc) { 100 101 case NFSPROC_NULL: 102 xdr_argument = (xdrproc_t) xdr_void; 103 xdr_result = (xdrproc_t) xdr_void; 104 local = (nfssvcproc_t) nfsproc_null_2_svc; 105 break; 106 107 case NFSPROC_GETATTR: 108 xdr_argument = (xdrproc_t) xdr_nfs_fh; 109 xdr_result = (xdrproc_t) xdr_attrstat; 110 local = (nfssvcproc_t) nfsproc_getattr_2_svc; 111 break; 112 113 case NFSPROC_SETATTR: 114 xdr_argument = (xdrproc_t) xdr_sattrargs; 115 xdr_result = (xdrproc_t) xdr_attrstat; 116 local = (nfssvcproc_t) nfsproc_setattr_2_svc; 117 break; 118 119 case NFSPROC_ROOT: 120 xdr_argument = (xdrproc_t) xdr_void; 121 xdr_result = (xdrproc_t) xdr_void; 122 local = (nfssvcproc_t) nfsproc_root_2_svc; 123 break; 124 125 case NFSPROC_LOOKUP: 126 xdr_argument = (xdrproc_t) xdr_diropargs; 127 xdr_result = (xdrproc_t) xdr_diropres; 128 local = (nfssvcproc_t) nfsproc_lookup_2_svc; 129 /* 130 * Cheap way to pass transp down to afs_lookuppn so it can 131 * be stored in the am_node structure and later used for 132 * quick_reply(). 133 */ 134 nfs_program_2_transp = transp; 135 break; 136 137 case NFSPROC_READLINK: 138 xdr_argument = (xdrproc_t) xdr_nfs_fh; 139 xdr_result = (xdrproc_t) xdr_readlinkres; 140 local = (nfssvcproc_t) nfsproc_readlink_2_svc; 141 break; 142 143 case NFSPROC_READ: 144 xdr_argument = (xdrproc_t) xdr_readargs; 145 xdr_result = (xdrproc_t) xdr_readres; 146 local = (nfssvcproc_t) nfsproc_read_2_svc; 147 break; 148 149 case NFSPROC_WRITECACHE: 150 xdr_argument = (xdrproc_t) xdr_void; 151 xdr_result = (xdrproc_t) xdr_void; 152 local = (nfssvcproc_t) nfsproc_writecache_2_svc; 153 break; 154 155 case NFSPROC_WRITE: 156 xdr_argument = (xdrproc_t) xdr_writeargs; 157 xdr_result = (xdrproc_t) xdr_attrstat; 158 local = (nfssvcproc_t) nfsproc_write_2_svc; 159 break; 160 161 case NFSPROC_CREATE: 162 xdr_argument = (xdrproc_t) xdr_createargs; 163 xdr_result = (xdrproc_t) xdr_diropres; 164 local = (nfssvcproc_t) nfsproc_create_2_svc; 165 break; 166 167 case NFSPROC_REMOVE: 168 xdr_argument = (xdrproc_t) xdr_diropargs; 169 xdr_result = (xdrproc_t) xdr_nfsstat; 170 local = (nfssvcproc_t) nfsproc_remove_2_svc; 171 break; 172 173 case NFSPROC_RENAME: 174 xdr_argument = (xdrproc_t) xdr_renameargs; 175 xdr_result = (xdrproc_t) xdr_nfsstat; 176 local = (nfssvcproc_t) nfsproc_rename_2_svc; 177 break; 178 179 case NFSPROC_LINK: 180 xdr_argument = (xdrproc_t) xdr_linkargs; 181 xdr_result = (xdrproc_t) xdr_nfsstat; 182 local = (nfssvcproc_t) nfsproc_link_2_svc; 183 break; 184 185 case NFSPROC_SYMLINK: 186 xdr_argument = (xdrproc_t) xdr_symlinkargs; 187 xdr_result = (xdrproc_t) xdr_nfsstat; 188 local = (nfssvcproc_t) nfsproc_symlink_2_svc; 189 break; 190 191 case NFSPROC_MKDIR: 192 xdr_argument = (xdrproc_t) xdr_createargs; 193 xdr_result = (xdrproc_t) xdr_diropres; 194 local = (nfssvcproc_t) nfsproc_mkdir_2_svc; 195 break; 196 197 case NFSPROC_RMDIR: 198 xdr_argument = (xdrproc_t) xdr_diropargs; 199 xdr_result = (xdrproc_t) xdr_nfsstat; 200 local = (nfssvcproc_t) nfsproc_rmdir_2_svc; 201 break; 202 203 case NFSPROC_READDIR: 204 xdr_argument = (xdrproc_t) xdr_readdirargs; 205 xdr_result = (xdrproc_t) xdr_readdirres; 206 local = (nfssvcproc_t) nfsproc_readdir_2_svc; 207 break; 208 209 case NFSPROC_STATFS: 210 xdr_argument = (xdrproc_t) xdr_nfs_fh; 211 xdr_result = (xdrproc_t) xdr_statfsres; 212 local = (nfssvcproc_t) nfsproc_statfs_2_svc; 213 break; 214 215 default: 216 svcerr_noproc(transp); 217 return; 218 } 219 220 memset((char *) &argument, 0, sizeof(argument)); 221 if (!svc_getargs(transp, 222 (XDRPROC_T_TYPE) xdr_argument, 223 (SVC_IN_ARG_TYPE) &argument)) { 224 plog(XLOG_ERROR, 225 "NFS xdr decode failed for %d %d %d", 226 (int) rqstp->rq_prog, (int) rqstp->rq_vers, (int) rqstp->rq_proc); 227 svcerr_decode(transp); 228 return; 229 } 230 result = (*local) (&argument, rqstp); 231 232 nfs_program_2_transp = NULL; 233 234 if (result != NULL && !svc_sendreply(transp, 235 (XDRPROC_T_TYPE) xdr_result, 236 result)) { 237 svcerr_systemerr(transp); 238 } 239 if (!svc_freeargs(transp, 240 (XDRPROC_T_TYPE) xdr_argument, 241 (SVC_IN_ARG_TYPE) & argument)) { 242 plog(XLOG_FATAL, "unable to free rpc arguments in nfs_program_2"); 243 going_down(1); 244 } 245} 246