xref: /illumos-gate/usr/src/lib/smbsrv/libfksmbsrv/common/fksmb_init.c (revision de27825976aef9b5a7b956ede505fc9bab8acfd2)
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  */
25 
26 #include <sys/types.h>
27 #include <sys/ddi.h>
28 #include <sys/modctl.h>
29 #include <sys/cred.h>
30 #include <sys/disp.h>
31 #include <sys/ioccom.h>
32 #include <sys/policy.h>
33 #include <sys/cmn_err.h>
34 #include <smbsrv/smb_kproto.h>
35 #include <smbsrv/smb_ioctl.h>
36 
37 /*
38  * *****************************************************************************
39  * ****************************** Global Variables *****************************
40  * *****************************************************************************
41  *
42  * These variables can only be changed through the /etc/system file.
43  */
44 
45 /*
46  * Maximum buffer size for NT: configurable based on the client environment.
47  * IR104720 Experiments with Windows 2000 indicate that we achieve better
48  * SmbWriteX performance with a buffer size of 64KB instead of the 37KB used
49  * with Windows NT4.0. Previous experiments with NT4.0 resulted in directory
50  * listing problems so this buffer size is configurable based on the end-user
51  * environment. When in doubt use 37KB.
52  */
53 int	smb_maxbufsize = SMB_NT_MAXBUF;
54 int	smb_flush_required = 1;
55 int	smb_dirsymlink_enable = 1;
56 int	smb_sign_debug = 0;
57 int	smb_shortnames = 1;
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 = 256;
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 int	smb_threshold_debug = 0;
95 
96 /*
97  * Thread priorities used in smbsrv.  Our threads spend most of their time
98  * blocked on various conditions.  However, if the system gets heavy load,
99  * the scheduler has to choose an order to run these.  We want the order:
100  * (a) timers, (b) notifications, (c) workers, (d) receivers (and etc.)
101  * where notifications are oplock and change notify work.  Aside from this
102  * relative ordering, smbsrv threads should run with a priority close to
103  * that of normal user-space threads (thus minclsyspri below), just like
104  * NFS and other "file service" kinds of processing.
105  */
106 int smbsrv_base_pri	= MINCLSYSPRI;
107 int smbsrv_listen_pri	= MINCLSYSPRI;
108 int smbsrv_receive_pri	= MINCLSYSPRI;
109 int smbsrv_worker_pri	= MINCLSYSPRI + 1;
110 int smbsrv_notify_pri	= MINCLSYSPRI + 2;
111 int smbsrv_timer_pri	= MINCLSYSPRI + 5;
112 
113 /*
114  * These are the (open,close,ioctl) entry points into this
115  * (fake) "driver".  They are declared in smb_ioctl.h
116  */
117 
118 static int g_init_done = 0;
119 
120 int fksmbsrv_vfs_init(void);
121 
122 int
123 fksmbsrv_drv_open(void)
124 {
125 	int rc;
126 
127 	if (g_init_done == 0) {
128 		if ((rc = fksmbsrv_vfs_init()) != 0) {
129 			cmn_err(CE_WARN, "fksmbsrv_vfs_init, rc=%d", rc);
130 			return (rc);
131 		}
132 		if ((rc = smb_server_g_init()) != 0) {
133 			cmn_err(CE_WARN, "smb_server_g_init, rc=%d", rc);
134 			return (rc);
135 		}
136 		g_init_done = 1;
137 	}
138 
139 	rc = smb_server_create();
140 	return (rc);
141 }
142 
143 int
144 fksmbsrv_drv_close(void)
145 {
146 	smb_server_t *sv;
147 	int rc;
148 
149 	rc = smb_server_lookup(&sv);
150 	if (rc == 0)
151 		rc = smb_server_delete(sv);
152 
153 	if (g_init_done != 0) {
154 		smb_server_g_fini();
155 		g_init_done = 0;
156 	}
157 
158 	return (rc);
159 }
160 
161 /*
162  * This is the primary entry point into this library, called by
163  * fksmbd (user-level debug version of smbsrv).
164  */
165 int
166 fksmbsrv_drv_ioctl(int cmd, void *varg)
167 {
168 	smb_ioc_t	*ioc = varg;
169 	int		rc = 0;
170 
171 	switch (cmd) {
172 	case SMB_IOC_CONFIG:
173 		rc = smb_server_configure(&ioc->ioc_cfg);
174 		break;
175 	case SMB_IOC_START:
176 		rc = smb_server_start(&ioc->ioc_start);
177 		break;
178 	case SMB_IOC_STOP:
179 		rc = smb_server_stop();
180 		break;
181 	case SMB_IOC_EVENT:
182 		rc = smb_server_notify_event(&ioc->ioc_event);
183 		break;
184 	case SMB_IOC_GMTOFF:
185 		rc = smb_server_set_gmtoff(&ioc->ioc_gmt);
186 		break;
187 	case SMB_IOC_SHARE:
188 		rc = smb_kshare_export_list(&ioc->ioc_share);
189 		break;
190 	case SMB_IOC_UNSHARE:
191 		rc = smb_kshare_unexport_list(&ioc->ioc_share);
192 		break;
193 	case SMB_IOC_SHAREINFO:
194 		rc = smb_kshare_info(&ioc->ioc_shareinfo);
195 		break;
196 	case SMB_IOC_NUMOPEN:
197 		rc = smb_server_numopen(&ioc->ioc_opennum);
198 		break;
199 	case SMB_IOC_SVCENUM:
200 		rc = smb_server_enum(&ioc->ioc_svcenum);
201 		break;
202 	case SMB_IOC_SESSION_CLOSE:
203 		rc = smb_server_session_close(&ioc->ioc_session);
204 		break;
205 	case SMB_IOC_FILE_CLOSE:
206 		rc = smb_server_file_close(&ioc->ioc_fileid);
207 		break;
208 	case SMB_IOC_SPOOLDOC:
209 		rc = smb_server_spooldoc(&ioc->ioc_spooldoc);
210 		break;
211 	default:
212 		rc = ENOTTY;
213 		break;
214 	}
215 
216 	return (rc);
217 }
218 
219 /*
220  * This function intentionally does nothing.  It's used only to
221  * force libfksmbsrv to load when fksmbd starts so one can set
222  * breakpoints etc. without debugger "force load" tricks.
223  */
224 void
225 fksmbsrv_drv_load(void)
226 {
227 }
228