Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_nfssvc.c revision 1.3.2.2
      1 /*	$NetBSD: netbsd32_nfssvc.c,v 1.3.2.2 2015/09/22 12:05:55 skrll Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2015 Matthew R. Green
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  */
     30 
     31 #include <sys/cdefs.h>
     32 __KERNEL_RCSID(0, "$NetBSD: netbsd32_nfssvc.c,v 1.3.2.2 2015/09/22 12:05:55 skrll Exp $");
     33 
     34 #if defined(_KERNEL_OPT)
     35 #include "opt_nfs.h"
     36 #include "opt_nfsserver.h"
     37 #include "opt_compat_netbsd.h"
     38 #endif
     39 
     40 #include <sys/param.h>
     41 #include <sys/vnode.h>
     42 #include <sys/filedesc.h>
     43 
     44 #include <compat/netbsd32/netbsd32.h>
     45 #include <compat/netbsd32/netbsd32_syscall.h>
     46 #include <compat/netbsd32/netbsd32_syscallargs.h>
     47 #include <compat/netbsd32/netbsd32_conv.h>
     48 
     49 #include <nfs/rpcv2.h>
     50 #include <nfs/nfsproto.h>
     51 #include <nfs/nfs.h>
     52 #include <nfs/nfs_var.h>
     53 
     54 static int nfssvc32_addsock_in(struct nfsd_args *, const void *);
     55 static int nfssvc32_setexports_in(struct mountd_exports_list *, const void *);
     56 static int nfssvc32_nsd_in(struct nfsd_srvargs *, const void *);
     57 static int nfssvc32_nsd_out(void *, const struct nfsd_srvargs *);
     58 static int nfssvc32_exp_in(struct export_args *, const void *, size_t);
     59 
     60 static int
     61 nfssvc32_addsock_in(struct nfsd_args *nfsdarg, const void *argp)
     62 {
     63 	struct netbsd32_nfsd_args args32;
     64 	int error;
     65 
     66 	error = copyin(argp, &args32, sizeof args32);
     67 	if (!error) {
     68 		nfsdarg->sock = args32.sock;
     69 		nfsdarg->name = NETBSD32PTR64(args32.name);
     70 		nfsdarg->namelen = args32.namelen;
     71 	}
     72 
     73 	return error;
     74 }
     75 
     76 static int
     77 nfssvc32_setexports_in(struct mountd_exports_list *mel, const void *argp)
     78 {
     79 	struct netbsd32_mountd_exports_list args32;
     80 	int error;
     81 
     82 	error = copyin(argp, &args32, sizeof args32);
     83 	if (!error) {
     84 		mel->mel_path = NETBSD32PTR64(args32.mel_path);
     85 		mel->mel_nexports = args32.mel_nexports;
     86 		mel->mel_exports = NETBSD32PTR64(args32.mel_exports);
     87 	}
     88 
     89 	return error;
     90 }
     91 
     92 static int
     93 nfssvc32_nsd_in(struct nfsd_srvargs *nsd, const void *argp)
     94 {
     95 	struct netbsd32_nfsd_srvargs args32;
     96 	int error;
     97 
     98 	error = copyin(argp, &args32, sizeof args32);
     99 	if (!error) {
    100 		nsd->nsd_nfsd = NETBSD32PTR64(args32.nsd_nfsd);
    101 		nsd->nsd_uid = args32.nsd_uid;
    102 		nsd->nsd_haddr = args32.nsd_haddr;
    103 		nsd->nsd_cr = args32.nsd_cr;
    104 		nsd->nsd_authlen = args32.nsd_authlen;
    105 		nsd->nsd_authstr = NETBSD32PTR64(args32.nsd_authstr);
    106 		nsd->nsd_verflen = args32.nsd_verflen;
    107 		nsd->nsd_uid = args32.nsd_uid;
    108 		netbsd32_to_timeval(&args32.nsd_timestamp, &nsd->nsd_timestamp);
    109 		nsd->nsd_ttl = args32.nsd_ttl;
    110 		nsd->nsd_key[0] = args32.nsd_key[0];
    111 		nsd->nsd_key[1] = args32.nsd_key[1];
    112 	}
    113 
    114 	return error;
    115 }
    116 
    117 static int
    118 nfssvc32_nsd_out(void *argp, const struct nfsd_srvargs *nsd)
    119 {
    120 	struct netbsd32_nfsd_srvargs args32;
    121 
    122 	NETBSD32PTR32(args32.nsd_nfsd, nsd->nsd_nfsd);
    123 	args32.nsd_uid = nsd->nsd_uid;
    124 	args32.nsd_haddr = nsd->nsd_haddr;
    125 	args32.nsd_cr = nsd->nsd_cr;
    126 	args32.nsd_authlen = nsd->nsd_authlen;
    127 	NETBSD32PTR32(args32.nsd_authstr, nsd->nsd_authstr);
    128 	args32.nsd_verflen = nsd->nsd_verflen;
    129 	args32.nsd_uid = nsd->nsd_uid;
    130 	netbsd32_from_timeval(&nsd->nsd_timestamp, &args32.nsd_timestamp);
    131 	args32.nsd_ttl = nsd->nsd_ttl;
    132 	args32.nsd_key[0] = nsd->nsd_key[0];
    133 	args32.nsd_key[1] = nsd->nsd_key[1];
    134 
    135 	return copyout(nsd, argp, sizeof *nsd);
    136 }
    137 
    138 static int
    139 nfssvc32_exp_in(struct export_args *exp, const void *argp, size_t nexports)
    140 {
    141 	struct netbsd32_export_args exp32;
    142 	struct netbsd32_export_args const *argp32 = argp;
    143 	int error = 0;
    144 
    145 	for (size_t i = 0; i < nexports; i++) {
    146 		error = copyin(argp32, &exp32, sizeof exp32);
    147 		if (error)
    148 			break;
    149 		exp->ex_flags = exp32.ex_flags;
    150 		exp->ex_root = exp32.ex_root;
    151 		exp->ex_anon = exp32.ex_anon;
    152 		exp->ex_addr = NETBSD32PTR64(exp32.ex_addr);
    153 		exp->ex_addrlen = exp32.ex_addrlen;
    154 		exp->ex_mask = NETBSD32PTR64(exp32.ex_mask);
    155 		exp->ex_masklen = exp32.ex_masklen;
    156 		exp->ex_indexfile = NETBSD32PTR64(exp32.ex_indexfile);
    157 		exp++;
    158 		argp32++;
    159 	}
    160 
    161 	return error;
    162 }
    163 
    164 /*
    165  * NFS server system calls
    166  */
    167 
    168 static struct nfssvc_copy_ops netbsd32_ops = {
    169 	.addsock_in = nfssvc32_addsock_in,
    170 	.setexports_in = nfssvc32_setexports_in,
    171 	.nsd_in = nfssvc32_nsd_in,
    172 	.nsd_out = nfssvc32_nsd_out,
    173 	.exp_in = nfssvc32_exp_in,
    174 };
    175 
    176 int
    177 netbsd32_nfssvc(struct lwp *l, const struct netbsd32_nfssvc_args *uap,
    178     register_t *retval)
    179 {
    180 	/* {
    181 		syscallarg(int) flag;
    182 		syscallarg(netbsd32_voidp *) argp;
    183 	} */
    184 	int	flag = SCARG(uap, flag);
    185 	void	*argp = SCARG_P32(uap, argp);
    186 
    187 	return do_nfssvc(&netbsd32_ops, l, flag, argp, retval);
    188 }
    189