netbsd32_nfssvc.c revision 1.6.4.1 1 /* $NetBSD: netbsd32_nfssvc.c,v 1.6.4.1 2022/08/03 10:58:58 martin 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.6.4.1 2022/08/03 10:58:58 martin 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 #include <sys/module.h>
44 #include <sys/syscallvar.h>
45
46 #include <compat/netbsd32/netbsd32.h>
47 #include <compat/netbsd32/netbsd32_syscall.h>
48 #include <compat/netbsd32/netbsd32_syscallargs.h>
49 #include <compat/netbsd32/netbsd32_conv.h>
50
51 #include <nfs/rpcv2.h>
52 #include <nfs/nfsproto.h>
53 #include <nfs/nfs.h>
54 #include <nfs/nfs_var.h>
55
56 static int nfssvc32_addsock_in(struct nfsd_args *, const void *);
57 static int nfssvc32_setexports_in(struct mountd_exports_list *, const void *);
58 static int nfssvc32_nsd_in(struct nfsd_srvargs *, const void *);
59 static int nfssvc32_nsd_out(void *, const struct nfsd_srvargs *);
60 static int nfssvc32_exp_in(struct export_args *, const void *, size_t);
61
62 static int
63 nfssvc32_addsock_in(struct nfsd_args *nfsdarg, const void *argp)
64 {
65 struct netbsd32_nfsd_args args32;
66 int error;
67
68 error = copyin(argp, &args32, sizeof args32);
69 if (!error) {
70 nfsdarg->sock = args32.sock;
71 nfsdarg->name = NETBSD32PTR64(args32.name);
72 nfsdarg->namelen = args32.namelen;
73 }
74
75 return error;
76 }
77
78 static int
79 nfssvc32_setexports_in(struct mountd_exports_list *mel, const void *argp)
80 {
81 struct netbsd32_mountd_exports_list args32;
82 int error;
83
84 error = copyin(argp, &args32, sizeof args32);
85 if (!error) {
86 mel->mel_path = NETBSD32PTR64(args32.mel_path);
87 mel->mel_nexports = args32.mel_nexports;
88 mel->mel_exports = NETBSD32PTR64(args32.mel_exports);
89 }
90
91 return error;
92 }
93
94 static int
95 nfssvc32_nsd_in(struct nfsd_srvargs *nsd, const void *argp)
96 {
97 struct netbsd32_nfsd_srvargs args32;
98 int error;
99
100 error = copyin(argp, &args32, sizeof args32);
101 if (!error) {
102 nsd->nsd_nfsd = NETBSD32PTR64(args32.nsd_nfsd);
103 nsd->nsd_uid = args32.nsd_uid;
104 nsd->nsd_haddr = args32.nsd_haddr;
105 nsd->nsd_cr = args32.nsd_cr;
106 nsd->nsd_authlen = args32.nsd_authlen;
107 nsd->nsd_authstr = NETBSD32PTR64(args32.nsd_authstr);
108 nsd->nsd_verflen = args32.nsd_verflen;
109 nsd->nsd_uid = args32.nsd_uid;
110 netbsd32_to_timeval(&args32.nsd_timestamp, &nsd->nsd_timestamp);
111 nsd->nsd_ttl = args32.nsd_ttl;
112 nsd->nsd_key[0] = args32.nsd_key[0];
113 nsd->nsd_key[1] = args32.nsd_key[1];
114 }
115
116 return error;
117 }
118
119 static int
120 nfssvc32_nsd_out(void *argp, const struct nfsd_srvargs *nsd)
121 {
122 struct netbsd32_nfsd_srvargs args32;
123
124 NETBSD32PTR32(args32.nsd_nfsd, nsd->nsd_nfsd);
125 args32.nsd_uid = nsd->nsd_uid;
126 args32.nsd_haddr = nsd->nsd_haddr;
127 args32.nsd_cr = nsd->nsd_cr;
128 args32.nsd_authlen = nsd->nsd_authlen;
129 NETBSD32PTR32(args32.nsd_authstr, nsd->nsd_authstr);
130 args32.nsd_verflen = nsd->nsd_verflen;
131 args32.nsd_uid = nsd->nsd_uid;
132 netbsd32_from_timeval(&nsd->nsd_timestamp, &args32.nsd_timestamp);
133 args32.nsd_ttl = nsd->nsd_ttl;
134 args32.nsd_key[0] = nsd->nsd_key[0];
135 args32.nsd_key[1] = nsd->nsd_key[1];
136
137 return copyout(&args32, argp, sizeof args32);
138 }
139
140 static int
141 nfssvc32_exp_in(struct export_args *exp, const void *argp, size_t nexports)
142 {
143 struct netbsd32_export_args exp32;
144 struct netbsd32_export_args const *argp32 = argp;
145 int error = 0;
146
147 for (size_t i = 0; i < nexports; i++) {
148 error = copyin(argp32, &exp32, sizeof exp32);
149 if (error)
150 break;
151 exp->ex_flags = exp32.ex_flags;
152 exp->ex_root = exp32.ex_root;
153 exp->ex_anon = exp32.ex_anon;
154 exp->ex_addr = NETBSD32PTR64(exp32.ex_addr);
155 exp->ex_addrlen = exp32.ex_addrlen;
156 exp->ex_mask = NETBSD32PTR64(exp32.ex_mask);
157 exp->ex_masklen = exp32.ex_masklen;
158 exp->ex_indexfile = NETBSD32PTR64(exp32.ex_indexfile);
159 exp++;
160 argp32++;
161 }
162
163 return error;
164 }
165
166 /*
167 * NFS server system calls
168 */
169
170 static struct nfssvc_copy_ops netbsd32_ops = {
171 .addsock_in = nfssvc32_addsock_in,
172 .setexports_in = nfssvc32_setexports_in,
173 .nsd_in = nfssvc32_nsd_in,
174 .nsd_out = nfssvc32_nsd_out,
175 .exp_in = nfssvc32_exp_in,
176 };
177
178 int
179 netbsd32_nfssvc(struct lwp *l, const struct netbsd32_nfssvc_args *uap,
180 register_t *retval)
181 {
182 /* {
183 syscallarg(int) flag;
184 syscallarg(netbsd32_voidp *) argp;
185 } */
186 int flag = SCARG(uap, flag);
187 void *argp = SCARG_P32(uap, argp);
188
189 return do_nfssvc(&netbsd32_ops, l, flag, argp, retval);
190 }
191
192 static const struct syscall_package compat_nfssvc_syscalls[] = {
193 { NETBSD32_SYS_netbsd32_nfssvc, 0, (sy_call_t *)netbsd32_nfssvc },
194 { 0, 0, NULL },
195 };
196
197 MODULE(MODULE_CLASS_EXEC, compat_netbsd32_nfssrv, "nfsserver,compat_netbsd32");
198
199 static int
200 compat_netbsd32_nfssrv_modcmd(modcmd_t cmd, void *arg)
201 {
202 int error;
203
204 switch (cmd) {
205 case MODULE_CMD_INIT:
206 error = syscall_establish(&emul_netbsd32,
207 compat_nfssvc_syscalls);
208 break;
209 case MODULE_CMD_FINI:
210 error = syscall_disestablish(&emul_netbsd32,
211 compat_nfssvc_syscalls);
212 break;
213 default:
214 error = ENOTTY;
215 break;
216 }
217 return error;
218 }
219