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-2023 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
114 int
fksmbsrv_drv_open(void)115 fksmbsrv_drv_open(void)
116 {
117 int rc;
118
119 if (g_init_done == 0) {
120 if ((rc = fksmbsrv_vfs_init()) != 0) {
121 cmn_err(CE_WARN, "fksmbsrv_vfs_init, rc=%d", rc);
122 return (rc);
123 }
124 if ((rc = smb_server_g_init()) != 0) {
125 cmn_err(CE_WARN, "smb_server_g_init, rc=%d", rc);
126 return (rc);
127 }
128 g_init_done = 1;
129 }
130
131 rc = smb_server_create(0);
132 return (rc);
133 }
134
135 int
fksmbsrv_drv_close(void)136 fksmbsrv_drv_close(void)
137 {
138 smb_server_t *sv;
139 int rc;
140
141 rc = smb_server_lookup(&sv);
142 if (rc == 0)
143 rc = smb_server_delete(sv);
144
145 if (g_init_done != 0) {
146 smb_server_g_fini();
147 g_init_done = 0;
148 }
149
150 return (rc);
151 }
152
153 /*
154 * This is the primary entry point into this library, called by
155 * fksmbd (user-level debug version of smbsrv).
156 *
157 * The code here is a reduced version of: smb_drv_ioctl
158 * from $UTS/common/fs/smbsrv/smb_init.c
159 */
160 int
fksmbsrv_drv_ioctl(int cmd,void * varg)161 fksmbsrv_drv_ioctl(int cmd, void *varg)
162 {
163 smb_server_t *sv;
164 smb_ioc_t *ioc = varg;
165 int rc = 0;
166
167 /* Unlike smb_drv_ioctl(), no copyin/copyout here. */
168
169 rc = smb_server_lookup(&sv);
170 if (rc != 0)
171 return (rc);
172
173 /* No access control checks. */
174
175 switch (cmd) {
176 case SMB_IOC_CONFIG:
177 rc = smb_server_configure(sv, &ioc->ioc_cfg);
178 break;
179 case SMB_IOC_START:
180 rc = smb_server_start(sv, &ioc->ioc_start);
181 break;
182 case SMB_IOC_STOP:
183 rc = smb_server_stop(sv);
184 break;
185 case SMB_IOC_EVENT:
186 rc = smb_server_notify_event(sv, &ioc->ioc_event);
187 break;
188 case SMB_IOC_GMTOFF:
189 rc = smb_server_set_gmtoff(sv, &ioc->ioc_gmt);
190 break;
191 case SMB_IOC_SHARE:
192 rc = smb_kshare_export_list(sv, &ioc->ioc_share);
193 break;
194 case SMB_IOC_UNSHARE:
195 rc = smb_kshare_unexport_list(sv, &ioc->ioc_share);
196 break;
197 case SMB_IOC_SHAREINFO:
198 rc = smb_kshare_info(sv, &ioc->ioc_shareinfo);
199 break;
200 case SMB_IOC_SHAREACCESS:
201 rc = smb_kshare_access(sv, &ioc->ioc_shareaccess);
202 break;
203 case SMB_IOC_NUMOPEN:
204 rc = smb_server_numopen(sv, &ioc->ioc_opennum);
205 break;
206 case SMB_IOC_SVCENUM:
207 rc = smb_server_enum(sv, &ioc->ioc_svcenum);
208 break;
209 case SMB_IOC_SESSION_CLOSE:
210 rc = smb_server_session_close(sv, &ioc->ioc_session);
211 break;
212 case SMB_IOC_FILE_CLOSE:
213 rc = smb_server_file_close(sv, &ioc->ioc_fileid);
214 break;
215 case SMB_IOC_SPOOLDOC:
216 rc = smb_server_spooldoc(sv, &ioc->ioc_spooldoc);
217 break;
218 default:
219 rc = SET_ERROR(ENOTTY);
220 break;
221 }
222
223 smb_server_release(sv);
224
225 return (rc);
226 }
227
228 /*
229 * This function intentionally does nothing. It's used only to
230 * force libfksmbsrv to load when fksmbd starts so one can set
231 * breakpoints etc. without debugger "force load" tricks.
232 */
233 void
fksmbsrv_drv_load(void)234 fksmbsrv_drv_load(void)
235 {
236 }
237