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