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