Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_nfssvc.c revision 1.1
      1 /*	$NetBSD: netbsd32_nfssvc.c,v 1.1 2015/06/22 10:35:00 mrg 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.1 2015/06/22 10:35:00 mrg Exp $");
     33 
     34 #if defined(_KERNEL_OPT)
     35 #include "opt_nfs.h"
     36 #include "opt_compat_netbsd.h"
     37 #endif
     38 
     39 #include <sys/param.h>
     40 #include <sys/vnode.h>
     41 #include <sys/filedesc.h>
     42 
     43 #include <compat/netbsd32/netbsd32.h>
     44 #include <compat/netbsd32/netbsd32_syscall.h>
     45 #include <compat/netbsd32/netbsd32_syscallargs.h>
     46 #include <compat/netbsd32/netbsd32_conv.h>
     47 
     48 #include <nfs/rpcv2.h>
     49 #include <nfs/nfsproto.h>
     50 #include <nfs/nfs.h>
     51 #include <nfs/nfs_var.h>
     52 
     53 static int nfssvc32_addsock_in(struct nfsd_args *, const void *);
     54 static int nfssvc32_setexports_in(struct mountd_exports_list *, const void *);
     55 static int nfssvc32_nsd_in(struct nfsd_srvargs *, const void *);
     56 static int nfssvc32_nsd_out(void *, const struct nfsd_srvargs *);
     57 static int nfssvc32_exp_in(struct export_args *, const void *, size_t);
     58 
     59 static int
     60 nfssvc32_addsock_in(struct nfsd_args *nfsdarg, const void *argp)
     61 {
     62 	struct netbsd32_nfsd_args args32;
     63 	int error;
     64 
     65 	error = copyin(argp, &args32, sizeof args32);
     66 	if (!error) {
     67 		nfsdarg->sock = args32.sock;
     68 		nfsdarg->name = NETBSD32PTR64(args32.name);
     69 		nfsdarg->namelen = args32.namelen;
     70 	}
     71 
     72 	return error;
     73 }
     74 
     75 static int
     76 nfssvc32_setexports_in(struct mountd_exports_list *mel, const void *argp)
     77 {
     78 	struct netbsd32_mountd_exports_list args32;
     79 	int error;
     80 
     81 	error = copyin(argp, &args32, sizeof args32);
     82 	if (!error) {
     83 		mel->mel_path = NETBSD32PTR64(args32.mel_path);
     84 		mel->mel_nexports = args32.mel_nexports;
     85 		mel->mel_exports = NETBSD32PTR64(args32.mel_exports);
     86 	}
     87 
     88 	return error;
     89 }
     90 
     91 static int
     92 nfssvc32_nsd_in(struct nfsd_srvargs *nsd, const void *argp)
     93 {
     94 	struct netbsd32_nfsd_srvargs args32;
     95 	int error;
     96 
     97 	error = copyin(argp, &args32, sizeof args32);
     98 	if (!error) {
     99 		nsd->nsd_nfsd = NETBSD32PTR64(args32.nsd_nfsd);
    100 		nsd->nsd_uid = args32.nsd_uid;
    101 		nsd->nsd_haddr = args32.nsd_haddr;
    102 		nsd->nsd_cr = args32.nsd_cr;
    103 		nsd->nsd_authlen = args32.nsd_authlen;
    104 		nsd->nsd_authstr = NETBSD32PTR64(args32.nsd_authstr);
    105 		nsd->nsd_verflen = args32.nsd_verflen;
    106 		nsd->nsd_uid = args32.nsd_uid;
    107 		netbsd32_to_timeval(&args32.nsd_timestamp, &nsd->nsd_timestamp);
    108 		nsd->nsd_ttl = args32.nsd_ttl;
    109 		nsd->nsd_key[0] = args32.nsd_key[0];
    110 		nsd->nsd_key[1] = args32.nsd_key[1];
    111 	}
    112 
    113 	return error;
    114 }
    115 
    116 static int
    117 nfssvc32_nsd_out(void *argp, const struct nfsd_srvargs *nsd)
    118 {
    119 	struct netbsd32_nfsd_srvargs args32;
    120 
    121 	NETBSD32PTR32(args32.nsd_nfsd, nsd->nsd_nfsd);
    122 	args32.nsd_uid = nsd->nsd_uid;
    123 	args32.nsd_haddr = nsd->nsd_haddr;
    124 	args32.nsd_cr = nsd->nsd_cr;
    125 	args32.nsd_authlen = nsd->nsd_authlen;
    126 	NETBSD32PTR32(args32.nsd_authstr, nsd->nsd_authstr);
    127 	args32.nsd_verflen = nsd->nsd_verflen;
    128 	args32.nsd_uid = nsd->nsd_uid;
    129 	netbsd32_from_timeval(&nsd->nsd_timestamp, &args32.nsd_timestamp);
    130 	args32.nsd_ttl = nsd->nsd_ttl;
    131 	args32.nsd_key[0] = nsd->nsd_key[0];
    132 	args32.nsd_key[1] = nsd->nsd_key[1];
    133 
    134 	return copyout(nsd, argp, sizeof *nsd);
    135 }
    136 
    137 static int
    138 nfssvc32_exp_in(struct export_args *exp, const void *argp, size_t nexports)
    139 {
    140 	struct netbsd32_export_args args32;
    141 	int error = 0;
    142 
    143 	for (size_t i = 0; i < nexports; i++) {
    144 		error = copyin(argp, &args32, sizeof args32);
    145 		if (error)
    146 			break;
    147 		exp->ex_flags = args32.ex_flags;
    148 		exp->ex_root = args32.ex_root;
    149 		exp->ex_anon = args32.ex_anon;
    150 		exp->ex_addr = NETBSD32PTR64(args32.ex_addr);
    151 		exp->ex_addrlen = args32.ex_addrlen;
    152 		exp->ex_mask = NETBSD32PTR64(args32.ex_mask);
    153 		exp->ex_masklen = args32.ex_masklen;
    154 		exp->ex_indexfile = NETBSD32PTR64(args32.ex_indexfile);
    155 		exp++;
    156 	}
    157 
    158 	return error;
    159 }
    160 
    161 /*
    162  * NFS server system calls
    163  */
    164 
    165 static struct nfssvc_copy_ops netbsd32_ops = {
    166 	.addsock_in = nfssvc32_addsock_in,
    167 	.setexports_in = nfssvc32_setexports_in,
    168 	.nsd_in = nfssvc32_nsd_in,
    169 	.nsd_out = nfssvc32_nsd_out,
    170 	.exp_in = nfssvc32_exp_in,
    171 };
    172 
    173 int
    174 netbsd32_nfssvc(struct lwp *l, const struct netbsd32_nfssvc_args *uap,
    175     register_t *retval)
    176 {
    177 	/* {
    178 		syscallarg(int) flag;
    179 		syscallarg(netbsd32_voidp *) argp;
    180 	} */
    181 	int	flag = SCARG(uap, flag);
    182 	void	*argp = SCARG_P32(uap, argp);
    183 
    184 	return do_nfssvc(&netbsd32_ops, l, flag, argp, retval);
    185 }
    186