xref: /titanic_50/usr/src/lib/smbsrv/libfksmbsrv/common/fksmb_init.c (revision a90cf9f29973990687fa61de9f1f6ea22e924e40)
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 2013 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  * smb_raw_mode: read_raw and write_raw supported (1) or NOT supported (0).
54  */
55 int	smb_maxbufsize = SMB_NT_MAXBUF;
56 int	smb_oplock_levelII = 1;
57 int	smb_oplock_timeout = OPLOCK_STD_TIMEOUT;
58 int	smb_oplock_min_timeout = OPLOCK_MIN_TIMEOUT;
59 int	smb_flush_required = 1;
60 int	smb_dirsymlink_enable = 1;
61 int	smb_sign_debug = 0;
62 int	smb_raw_mode = 0;
63 int	smb_shortnames = 1;
64 uint_t	smb_audit_flags =
65 #ifdef	DEBUG
66     SMB_AUDIT_NODE;
67 #else
68     0;
69 #endif
70 
71 /*
72  * Maximum number of simultaneous authentication, share mapping, pipe open
73  * requests to be processed.
74  */
75 int	smb_ssetup_threshold = 256;
76 int	smb_tcon_threshold = 1024;
77 int	smb_opipe_threshold = 1024;
78 
79 /*
80  * Number of milliseconds that a request will be stalled if it comes in after
81  * the maximum number of inflight operations are being proccessed.
82  */
83 int	smb_ssetup_timeout = (30 * 1000);
84 int	smb_tcon_timeout = (30 * 1000);
85 int	smb_opipe_timeout = (30 * 1000);
86 
87 int	smb_threshold_debug = 0;
88 
89 /*
90  * Thread priorities used in smbsrv.  Our threads spend most of their time
91  * blocked on various conditions.  However, if the system gets heavy load,
92  * the scheduler has to choose an order to run these.  We want the order:
93  * (a) timers, (b) notifications, (c) workers, (d) receivers (and etc.)
94  * where notifications are oplock and change notify work.  Aside from this
95  * relative ordering, smbsrv threads should run with a priority close to
96  * that of normal user-space threads (thus minclsyspri below), just like
97  * NFS and other "file service" kinds of processing.
98  */
99 int smbsrv_base_pri	= MINCLSYSPRI;
100 int smbsrv_listen_pri	= MINCLSYSPRI;
101 int smbsrv_receive_pri	= MINCLSYSPRI;
102 int smbsrv_worker_pri	= MINCLSYSPRI + 1;
103 int smbsrv_notify_pri	= MINCLSYSPRI + 2;
104 int smbsrv_timer_pri	= MINCLSYSPRI + 5;
105 
106 /*
107  * These are the (open,close,ioctl) entry points into this
108  * (fake) "driver".  They are declared in smb_ioctl.h
109  */
110 
111 static int g_init_done = 0;
112 
113 int fksmbsrv_vfs_init(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();
133 	return (rc);
134 }
135 
136 int
fksmbsrv_drv_close(void)137 fksmbsrv_drv_close(void)
138 {
139 	int rc;
140 
141 	rc = smb_server_delete();
142 
143 	if (g_init_done != 0) {
144 		smb_server_g_fini();
145 		g_init_done = 0;
146 	}
147 
148 	return (rc);
149 }
150 
151 /*
152  * This is the primary entry point into this library, called by
153  * fksmbd (user-level debug version of smbsrv).
154  */
155 int
fksmbsrv_drv_ioctl(int cmd,void * varg)156 fksmbsrv_drv_ioctl(int cmd, void *varg)
157 {
158 	smb_ioc_t	*ioc = varg;
159 	int		rc = 0;
160 
161 	switch (cmd) {
162 	case SMB_IOC_CONFIG:
163 		rc = smb_server_configure(&ioc->ioc_cfg);
164 		break;
165 	case SMB_IOC_START:
166 		rc = smb_server_start(&ioc->ioc_start);
167 		break;
168 	case SMB_IOC_STOP:
169 		rc = smb_server_stop();
170 		break;
171 	case SMB_IOC_EVENT:
172 		rc = smb_server_notify_event(&ioc->ioc_event);
173 		break;
174 	case SMB_IOC_GMTOFF:
175 		rc = smb_server_set_gmtoff(&ioc->ioc_gmt);
176 		break;
177 	case SMB_IOC_SHARE:
178 		rc = smb_kshare_export_list(&ioc->ioc_share);
179 		break;
180 	case SMB_IOC_UNSHARE:
181 		rc = smb_kshare_unexport_list(&ioc->ioc_share);
182 		break;
183 	case SMB_IOC_SHAREINFO:
184 		rc = smb_kshare_info(&ioc->ioc_shareinfo);
185 		break;
186 	case SMB_IOC_NUMOPEN:
187 		rc = smb_server_numopen(&ioc->ioc_opennum);
188 		break;
189 	case SMB_IOC_SVCENUM:
190 		rc = smb_server_enum(&ioc->ioc_svcenum);
191 		break;
192 	case SMB_IOC_SESSION_CLOSE:
193 		rc = smb_server_session_close(&ioc->ioc_session);
194 		break;
195 	case SMB_IOC_FILE_CLOSE:
196 		rc = smb_server_file_close(&ioc->ioc_fileid);
197 		break;
198 	case SMB_IOC_SPOOLDOC:
199 		rc = smb_server_spooldoc(&ioc->ioc_spooldoc);
200 		break;
201 	default:
202 		rc = ENOTTY;
203 		break;
204 	}
205 
206 	return (rc);
207 }
208 
209 /*
210  * This function intentionally does nothing.  It's used only to
211  * force libfksmbsrv to load when fksmbd starts so one can set
212  * breakpoints etc. without debugger "force load" tricks.
213  */
214 void
fksmbsrv_drv_load(void)215 fksmbsrv_drv_load(void)
216 {
217 }
218