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