1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
24 * Copyright 2015-2024 RackTop Systems, Inc.
25 */
26
27 #include <sys/types.h>
28 #include <sys/ddi.h>
29 #include <sys/modctl.h>
30 #include <sys/cred.h>
31 #include <sys/disp.h>
32 #include <sys/ioccom.h>
33 #include <sys/policy.h>
34 #include <sys/cmn_err.h>
35 #include <smbsrv/smb_kproto.h>
36 #include <smbsrv/smb_ioctl.h>
37
38 /*
39 * *****************************************************************************
40 * ****************************** Global Variables *****************************
41 * *****************************************************************************
42 *
43 * These variables can only be changed through the /etc/system file.
44 */
45
46 /*
47 * Maximum buffer size for NT: configurable based on the client environment.
48 * IR104720 Experiments with Windows 2000 indicate that we achieve better
49 * SmbWriteX performance with a buffer size of 64KB instead of the 37KB used
50 * with Windows NT4.0. Previous experiments with NT4.0 resulted in directory
51 * listing problems so this buffer size is configurable based on the end-user
52 * environment. When in doubt use 37KB.
53 */
54 int smb_maxbufsize = SMB_NT_MAXBUF;
55 int smb_flush_required = 1;
56 int smb_dirsymlink_enable = 1;
57 int smb_sign_debug = 0;
58 uint_t smb_audit_flags =
59 #ifdef DEBUG
60 SMB_AUDIT_NODE;
61 #else
62 0;
63 #endif
64
65 /*
66 * We don't normally have nbmand support in the test share
67 * used by fksmbd, but we'd still like the locking code
68 * to be testable. Intereactions with NFS etc. are not a
69 * concern in fksmbd, so allow it to use advisory locks.
70 *
71 * Should fix the fksmbd test share so it supports nbmand,
72 * and then set this to zero like the real server.
73 */
74 int smb_allow_advisory_locks = 1; /* See smb_vops.c */
75
76 /*
77 * Maximum number of simultaneous authentication, share mapping, pipe open
78 * requests to be processed.
79 */
80 int smb_ssetup_threshold = SMB_AUTHSVC_MAXTHREAD;
81 int smb_tcon_threshold = 1024;
82 int smb_opipe_threshold = 1024;
83 int smb_logoff_threshold = 1024;
84
85 /*
86 * Number of milliseconds that a request will be stalled if it comes in after
87 * the maximum number of inflight operations are being proccessed.
88 */
89 int smb_ssetup_timeout = (30 * 1000);
90 int smb_tcon_timeout = (30 * 1000);
91 int smb_opipe_timeout = (30 * 1000);
92 int smb_logoff_timeout = (600 * 1000);
93
94 /*
95 * Thread priorities used in smbsrv -- actually unused here.
96 * See $UTS/common/fs/smbsrv/smb_init.c
97 */
98 int smbsrv_base_pri = MINCLSYSPRI;
99 int smbsrv_listen_pri = MINCLSYSPRI;
100 int smbsrv_receive_pri = MINCLSYSPRI;
101 int smbsrv_worker_pri = MINCLSYSPRI;
102 int smbsrv_notify_pri = MINCLSYSPRI;
103 int smbsrv_timer_pri = MINCLSYSPRI;
104
105 /*
106 * These are the (open,close,ioctl) entry points into this
107 * (fake) "driver". They are declared in smb_ioctl.h
108 */
109
110 static int g_init_done = 0;
111
112 int fksmbsrv_vfs_init(void);
113 void fksmbsrv_vfs_fini(void);
114
115 int
fksmbsrv_drv_open(void)116 fksmbsrv_drv_open(void)
117 {
118 int rc;
119
120 if (g_init_done == 0) {
121 if ((rc = fksmbsrv_vfs_init()) != 0) {
122 cmn_err(CE_WARN, "fksmbsrv_vfs_init, rc=%d", rc);
123 return (rc);
124 }
125 if ((rc = smb_server_g_init()) != 0) {
126 cmn_err(CE_WARN, "smb_server_g_init, rc=%d", rc);
127 return (rc);
128 }
129 g_init_done = 1;
130 }
131
132 rc = smb_server_create(0);
133 return (rc);
134 }
135
136 int
fksmbsrv_drv_close(void)137 fksmbsrv_drv_close(void)
138 {
139 smb_server_t *sv;
140 int rc;
141
142 rc = smb_server_lookup(&sv);
143 if (rc == 0)
144 rc = smb_server_delete(sv);
145
146 if (g_init_done != 0) {
147 smb_server_g_fini();
148 fksmbsrv_vfs_fini();
149 g_init_done = 0;
150 }
151
152 return (rc);
153 }
154
155 /*
156 * This is the primary entry point into this library, called by
157 * fksmbd (user-level debug version of smbsrv).
158 *
159 * The code here is a reduced version of: smb_drv_ioctl
160 * from $UTS/common/fs/smbsrv/smb_init.c
161 */
162 int
fksmbsrv_drv_ioctl(int cmd,void * varg)163 fksmbsrv_drv_ioctl(int cmd, void *varg)
164 {
165 smb_server_t *sv;
166 smb_ioc_t *ioc = varg;
167 int rc = 0;
168
169 /* Unlike smb_drv_ioctl(), no copyin/copyout here. */
170
171 rc = smb_server_lookup(&sv);
172 if (rc != 0)
173 return (rc);
174
175 /* No access control checks. */
176
177 switch (cmd) {
178 case SMB_IOC_CONFIG:
179 rc = smb_server_configure(sv, &ioc->ioc_cfg);
180 break;
181 case SMB_IOC_START:
182 rc = smb_server_start(sv, &ioc->ioc_start);
183 break;
184 case SMB_IOC_STOP:
185 rc = smb_server_stop(sv);
186 break;
187 case SMB_IOC_EVENT:
188 rc = smb_server_notify_event(sv, &ioc->ioc_event);
189 break;
190 case SMB_IOC_GMTOFF:
191 rc = smb_server_set_gmtoff(sv, &ioc->ioc_gmt);
192 break;
193 case SMB_IOC_SHARE:
194 rc = smb_kshare_export_list(sv, &ioc->ioc_share);
195 break;
196 case SMB_IOC_UNSHARE:
197 rc = smb_kshare_unexport_list(sv, &ioc->ioc_share);
198 break;
199 case SMB_IOC_SHAREINFO:
200 rc = smb_kshare_info(sv, &ioc->ioc_shareinfo);
201 break;
202 case SMB_IOC_SHAREACCESS:
203 rc = smb_kshare_access(sv, &ioc->ioc_shareaccess);
204 break;
205 case SMB_IOC_NUMOPEN:
206 rc = smb_server_numopen(sv, &ioc->ioc_opennum);
207 break;
208 case SMB_IOC_SVCENUM:
209 rc = smb_server_enum(sv, &ioc->ioc_svcenum);
210 break;
211 case SMB_IOC_SESSION_CLOSE:
212 rc = smb_server_session_close(sv, &ioc->ioc_session);
213 break;
214 case SMB_IOC_FILE_CLOSE:
215 rc = smb_server_file_close(sv, &ioc->ioc_fileid);
216 break;
217 case SMB_IOC_SPOOLDOC:
218 rc = smb_server_spooldoc(sv, &ioc->ioc_spooldoc);
219 break;
220 default:
221 rc = SET_ERROR(ENOTTY);
222 break;
223 }
224
225 smb_server_release(sv);
226
227 return (rc);
228 }
229
230 /*
231 * This function intentionally does nothing. It's used only to
232 * force libfksmbsrv to load when fksmbd starts so one can set
233 * breakpoints etc. without debugger "force load" tricks.
234 */
235 void
fksmbsrv_drv_load(void)236 fksmbsrv_drv_load(void)
237 {
238 }
239