nfs_nfssvc.c revision 1.1.1.1.10.3 1 1.1.1.1.10.2 tls /* $NetBSD: nfs_nfssvc.c,v 1.1.1.1.10.3 2017/12/03 11:38:42 jdolecek Exp $ */
2 1.1.1.1.10.2 tls /*-
3 1.1.1.1.10.2 tls * Copyright (c) 1989, 1993
4 1.1.1.1.10.2 tls * The Regents of the University of California. All rights reserved.
5 1.1.1.1.10.2 tls *
6 1.1.1.1.10.2 tls * This code is derived from software contributed to Berkeley by
7 1.1.1.1.10.2 tls * Rick Macklem at The University of Guelph.
8 1.1.1.1.10.2 tls *
9 1.1.1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
10 1.1.1.1.10.2 tls * modification, are permitted provided that the following conditions
11 1.1.1.1.10.2 tls * are met:
12 1.1.1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
13 1.1.1.1.10.2 tls * notice, this list of conditions and the following disclaimer.
14 1.1.1.1.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.1.1.10.2 tls * notice, this list of conditions and the following disclaimer in the
16 1.1.1.1.10.2 tls * documentation and/or other materials provided with the distribution.
17 1.1.1.1.10.2 tls * 4. Neither the name of the University nor the names of its contributors
18 1.1.1.1.10.2 tls * may be used to endorse or promote products derived from this software
19 1.1.1.1.10.2 tls * without specific prior written permission.
20 1.1.1.1.10.2 tls *
21 1.1.1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1.1.1.10.2 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1.1.1.10.2 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1.1.1.10.2 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1.1.1.10.2 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1.1.1.10.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1.1.1.10.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1.1.1.10.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1.1.1.10.2 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1.1.1.10.2 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1.1.1.10.2 tls * SUCH DAMAGE.
32 1.1.1.1.10.2 tls *
33 1.1.1.1.10.2 tls */
34 1.1.1.1.10.2 tls
35 1.1.1.1.10.2 tls #include <sys/cdefs.h>
36 1.1.1.1.10.3 jdolecek /* __FBSDID("FreeBSD: head/sys/nfs/nfs_nfssvc.c 298788 2016-04-29 16:07:25Z pfg "); */
37 1.1.1.1.10.2 tls __RCSID("$NetBSD: nfs_nfssvc.c,v 1.1.1.1.10.3 2017/12/03 11:38:42 jdolecek Exp $");
38 1.1.1.1.10.2 tls
39 1.1.1.1.10.3 jdolecek #ifdef _KERNEL_OPT
40 1.1.1.1.10.3 jdolecek #include "opt_newnfs.h"
41 1.1.1.1.10.3 jdolecek #endif
42 1.1.1.1.10.2 tls
43 1.1.1.1.10.2 tls #include <sys/param.h>
44 1.1.1.1.10.2 tls #include <sys/systm.h>
45 1.1.1.1.10.2 tls #include <sys/sysproto.h>
46 1.1.1.1.10.2 tls #include <sys/kernel.h>
47 1.1.1.1.10.2 tls #include <sys/sysctl.h>
48 1.1.1.1.10.2 tls #include <sys/priv.h>
49 1.1.1.1.10.2 tls #include <sys/proc.h>
50 1.1.1.1.10.2 tls #include <sys/lock.h>
51 1.1.1.1.10.2 tls #include <sys/mutex.h>
52 1.1.1.1.10.2 tls #include <sys/module.h>
53 1.1.1.1.10.2 tls #include <sys/sysent.h>
54 1.1.1.1.10.2 tls #include <sys/syscall.h>
55 1.1.1.1.10.2 tls
56 1.1.1.1.10.2 tls #include <security/audit/audit.h>
57 1.1.1.1.10.2 tls
58 1.1.1.1.10.3 jdolecek #include <fs/nfs/common/nfssvc.h>
59 1.1.1.1.10.2 tls
60 1.1.1.1.10.2 tls static int nfssvc_offset = SYS_nfssvc;
61 1.1.1.1.10.2 tls static struct sysent nfssvc_prev_sysent;
62 1.1.1.1.10.2 tls MAKE_SYSENT(nfssvc);
63 1.1.1.1.10.2 tls
64 1.1.1.1.10.2 tls /*
65 1.1.1.1.10.2 tls * This tiny module simply handles the nfssvc() system call. The other
66 1.1.1.1.10.2 tls * nfs modules that use the system call register themselves by setting
67 1.1.1.1.10.2 tls * the nfsd_call_xxx function pointers non-NULL.
68 1.1.1.1.10.2 tls */
69 1.1.1.1.10.2 tls
70 1.1.1.1.10.2 tls int (*nfsd_call_nfsserver)(struct thread *, struct nfssvc_args *) = NULL;
71 1.1.1.1.10.2 tls int (*nfsd_call_nfscommon)(struct thread *, struct nfssvc_args *) = NULL;
72 1.1.1.1.10.2 tls int (*nfsd_call_nfscl)(struct thread *, struct nfssvc_args *) = NULL;
73 1.1.1.1.10.2 tls int (*nfsd_call_nfsd)(struct thread *, struct nfssvc_args *) = NULL;
74 1.1.1.1.10.2 tls
75 1.1.1.1.10.2 tls /*
76 1.1.1.1.10.3 jdolecek * Nfs server pseudo system call for the nfsd's
77 1.1.1.1.10.2 tls */
78 1.1.1.1.10.2 tls int
79 1.1.1.1.10.2 tls sys_nfssvc(struct thread *td, struct nfssvc_args *uap)
80 1.1.1.1.10.2 tls {
81 1.1.1.1.10.2 tls int error;
82 1.1.1.1.10.2 tls
83 1.1.1.1.10.2 tls KASSERT(!mtx_owned(&Giant), ("nfssvc(): called with Giant"));
84 1.1.1.1.10.2 tls
85 1.1.1.1.10.2 tls AUDIT_ARG_CMD(uap->flag);
86 1.1.1.1.10.2 tls
87 1.1.1.1.10.2 tls /* Allow anyone to get the stats. */
88 1.1.1.1.10.2 tls if ((uap->flag & ~NFSSVC_GETSTATS) != 0) {
89 1.1.1.1.10.2 tls error = priv_check(td, PRIV_NFS_DAEMON);
90 1.1.1.1.10.2 tls if (error != 0)
91 1.1.1.1.10.2 tls return (error);
92 1.1.1.1.10.2 tls }
93 1.1.1.1.10.2 tls error = EINVAL;
94 1.1.1.1.10.2 tls if ((uap->flag & (NFSSVC_ADDSOCK | NFSSVC_OLDNFSD | NFSSVC_NFSD)) &&
95 1.1.1.1.10.2 tls nfsd_call_nfsserver != NULL)
96 1.1.1.1.10.2 tls error = (*nfsd_call_nfsserver)(td, uap);
97 1.1.1.1.10.2 tls else if ((uap->flag & (NFSSVC_CBADDSOCK | NFSSVC_NFSCBD |
98 1.1.1.1.10.2 tls NFSSVC_DUMPMNTOPTS)) && nfsd_call_nfscl != NULL)
99 1.1.1.1.10.2 tls error = (*nfsd_call_nfscl)(td, uap);
100 1.1.1.1.10.2 tls else if ((uap->flag & (NFSSVC_IDNAME | NFSSVC_GETSTATS |
101 1.1.1.1.10.2 tls NFSSVC_GSSDADDPORT | NFSSVC_GSSDADDFIRST | NFSSVC_GSSDDELETEALL |
102 1.1.1.1.10.2 tls NFSSVC_NFSUSERDPORT | NFSSVC_NFSUSERDDELPORT)) &&
103 1.1.1.1.10.2 tls nfsd_call_nfscommon != NULL)
104 1.1.1.1.10.2 tls error = (*nfsd_call_nfscommon)(td, uap);
105 1.1.1.1.10.2 tls else if ((uap->flag & (NFSSVC_NFSDNFSD | NFSSVC_NFSDADDSOCK |
106 1.1.1.1.10.2 tls NFSSVC_PUBLICFH | NFSSVC_V4ROOTEXPORT | NFSSVC_NOPUBLICFH |
107 1.1.1.1.10.2 tls NFSSVC_STABLERESTART | NFSSVC_ADMINREVOKE |
108 1.1.1.1.10.2 tls NFSSVC_DUMPCLIENTS | NFSSVC_DUMPLOCKS | NFSSVC_BACKUPSTABLE |
109 1.1.1.1.10.2 tls NFSSVC_SUSPENDNFSD | NFSSVC_RESUMENFSD)) &&
110 1.1.1.1.10.2 tls nfsd_call_nfsd != NULL)
111 1.1.1.1.10.2 tls error = (*nfsd_call_nfsd)(td, uap);
112 1.1.1.1.10.2 tls if (error == EINTR || error == ERESTART)
113 1.1.1.1.10.2 tls error = 0;
114 1.1.1.1.10.2 tls return (error);
115 1.1.1.1.10.2 tls }
116 1.1.1.1.10.2 tls
117 1.1.1.1.10.2 tls /*
118 1.1.1.1.10.2 tls * Called once to initialize data structures...
119 1.1.1.1.10.2 tls */
120 1.1.1.1.10.2 tls static int
121 1.1.1.1.10.2 tls nfssvc_modevent(module_t mod, int type, void *data)
122 1.1.1.1.10.2 tls {
123 1.1.1.1.10.2 tls static int registered;
124 1.1.1.1.10.2 tls int error = 0;
125 1.1.1.1.10.2 tls
126 1.1.1.1.10.2 tls switch (type) {
127 1.1.1.1.10.2 tls case MOD_LOAD:
128 1.1.1.1.10.2 tls error = syscall_register(&nfssvc_offset, &nfssvc_sysent,
129 1.1.1.1.10.3 jdolecek &nfssvc_prev_sysent, SY_THR_STATIC_KLD);
130 1.1.1.1.10.2 tls if (error)
131 1.1.1.1.10.2 tls break;
132 1.1.1.1.10.2 tls registered = 1;
133 1.1.1.1.10.2 tls break;
134 1.1.1.1.10.2 tls
135 1.1.1.1.10.2 tls case MOD_UNLOAD:
136 1.1.1.1.10.2 tls if (nfsd_call_nfsserver != NULL || nfsd_call_nfscommon != NULL
137 1.1.1.1.10.2 tls || nfsd_call_nfscl != NULL || nfsd_call_nfsd != NULL) {
138 1.1.1.1.10.2 tls error = EBUSY;
139 1.1.1.1.10.2 tls break;
140 1.1.1.1.10.2 tls }
141 1.1.1.1.10.2 tls if (registered)
142 1.1.1.1.10.2 tls syscall_deregister(&nfssvc_offset, &nfssvc_prev_sysent);
143 1.1.1.1.10.2 tls registered = 0;
144 1.1.1.1.10.2 tls break;
145 1.1.1.1.10.2 tls default:
146 1.1.1.1.10.2 tls error = EOPNOTSUPP;
147 1.1.1.1.10.2 tls break;
148 1.1.1.1.10.2 tls }
149 1.1.1.1.10.2 tls return error;
150 1.1.1.1.10.2 tls }
151 1.1.1.1.10.2 tls static moduledata_t nfssvc_mod = {
152 1.1.1.1.10.2 tls "nfssvc",
153 1.1.1.1.10.2 tls nfssvc_modevent,
154 1.1.1.1.10.2 tls NULL,
155 1.1.1.1.10.2 tls };
156 1.1.1.1.10.2 tls DECLARE_MODULE(nfssvc, nfssvc_mod, SI_SUB_VFS, SI_ORDER_ANY);
157 1.1.1.1.10.2 tls
158 1.1.1.1.10.2 tls /* So that loader and kldload(2) can find us, wherever we are.. */
159 1.1.1.1.10.2 tls MODULE_VERSION(nfssvc, 1);
160 1.1.1.1.10.2 tls
161