xref: /illumos-gate/usr/src/uts/common/smbsrv/smb_share.h (revision 1160dcf7283d2485f2b9c32da573db0275558d9b)
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 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
25  * Copyright (c) 2016 by Delphix. All rights reserved.
26  */
27 
28 #ifndef _SMB_SHARE_H
29 #define	_SMB_SHARE_H
30 
31 #include <sys/param.h>
32 #include <smb/lmerr.h>
33 #include <smb/wintypes.h>
34 #include <smbsrv/string.h>
35 #include <smbsrv/smb_inet.h>
36 #include <smbsrv/hash_table.h>
37 #include <smbsrv/smbinfo.h>
38 
39 #if !defined(_KERNEL) && !defined(_FAKE_KERNEL)
40 #include <libshare.h>
41 #endif
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #define	SMB_CVOL		"/var/smb/cvol"
48 #define	SMB_SYSROOT		SMB_CVOL "/windows"
49 #define	SMB_SYSTEM32		SMB_SYSROOT "/system32"
50 #define	SMB_VSS			SMB_SYSTEM32 "/vss"
51 
52 /* Exported named pipes are in... */
53 #define	SMB_PIPE_DIR		"/var/smb/pipe"
54 
55 /*
56  * Share Properties:
57  *
58  * name			Advertised name of the share
59  *
60  * ad-container		Active directory container in which the share
61  *			will be published
62  *
63  * abe			Determines whether Access Based Enumeration is applied
64  *			to a share
65  *
66  * csc			Client-side caching (CSC) options applied to this share
67  *	disabled	The client MUST NOT cache any files
68  *	manual		The client should not automatically cache every file
69  *			that it	opens
70  *	auto		The client may cache every file that it opens
71  *	vdo		The client may cache every file that it opens
72  *			and satisfy file requests from its local cache.
73  *
74  * catia		CATIA character substitution
75  *
76  * guestok		Determines whether guest access is allowed
77  *
78  * quotas		SMB quotas presented & supported (T/F)
79  *
80  * encrypt		Controls SMB3 encryption per-share.
81  *	disabled	Server does not tell the client to encrypt requests.
82  *	enabled		Server asks, but does not require, that the client
83  *			encrypt its requests.
84  *	required	Server denies unencrypted share access.
85  *
86  * next three properties use access-list a la NFS
87  *
88  * ro			list of hosts that will have read-only access
89  * rw			list of hosts that will have read/write access
90  * none			list of hosts that won't be allowed access
91  */
92 #define	SHOPT_AD_CONTAINER	"ad-container"
93 #define	SHOPT_ABE		"abe"
94 #define	SHOPT_NAME		"name"
95 #define	SHOPT_CSC		"csc"
96 #define	SHOPT_CATIA		"catia"
97 #define	SHOPT_GUEST		"guestok"
98 #define	SHOPT_RO		"ro"
99 #define	SHOPT_RW		"rw"
100 #define	SHOPT_NONE		"none"
101 #define	SHOPT_DFSROOT		"dfsroot"
102 #define	SHOPT_DESCRIPTION	"description"
103 #define	SHOPT_QUOTAS		"quotas"
104 #define	SHOPT_FSO		"fso"	/* Force Shared Oplocks */
105 #define	SHOPT_ENCRYPT		"encrypt"
106 #define	SHOPT_AUTOHOME		"Autohome"
107 
108 #define	SMB_DEFAULT_SHARE_GROUP	"smb"
109 #define	SMB_PROTOCOL_NAME	"smb"
110 
111 /*
112  * RAP protocol share related commands only understand
113  * share names in OEM format and there is a 13 char size
114  * limitation
115  */
116 #define	SMB_SHARE_OEMNAME_MAX		13
117 #define	SMB_SHARE_NTNAME_MAX		81
118 #define	SMB_SHARE_CMNT_MAX		(64 * MTS_MB_CHAR_MAX)
119 
120 /*
121  *	struct SHARE_INFO_1 {
122  *		char		shi1_netname[13]
123  *		char		shi1_pad;
124  *		unsigned short	shi1_type
125  *		char		*shi1_remark;
126  *	}
127  */
128 #define	SHARE_INFO_1_SIZE	(SMB_SHARE_OEMNAME_MAX + 1 + 2 + 4)
129 
130 /*
131  * Share flags:
132  *
133  * There are two types of flags:
134  *
135  *   - flags that represent a share property
136  *   - other flags set at runtime
137  *
138  * Property flags:
139  *
140  * SMB_SHRF_CSC_DISABLED	Client-side caching is disabled for this share
141  * SMB_SHRF_CSC_MANUAL	Manual client-side caching is allowed
142  * SMB_SHRF_CSC_AUTO	Automatic client-side caching (CSC) is allowed
143  * SMB_SHRF_CSC_VDO	Automatic CSC and local cache lookup is allowed
144  * SMB_SHRF_ACC_OPEN	No restrictions set
145  * SMB_SHRF_ACC_NONE	"none" property set
146  * SMB_SHRF_ACC_RO	"ro" (readonly) property set
147  * SMB_SHRF_ACC_RW	"rw" (read/write) property set
148  * SMB_SHRF_ACC_ALL	All of the access bits
149  * SMB_SHRF_CATIA	CATIA character translation on/off
150  * SMB_SHRF_GUEST_OK	Guest access on/off
151  * SMB_SHRF_ABE		Access Based Enumeration on/off
152  * SMB_SHRF_DFSROOT	Share is a standalone DFS root
153  *
154  * Runtime flags:
155  *
156  * SMB_SHRF_TRANS	Transient share
157  * SMB_SHRF_PERM	Permanent share
158  * SMB_SHRF_AUTOHOME	Autohome share.
159  * SMB_SHRF_ADMIN	Admin share
160  *
161  * All autohome shares are transient but not all transient shares are autohome.
162  * IPC$ and drive letter shares (e.g. d$, e$, etc) are transient but
163  * not autohome.
164  */
165 
166 /*
167  * Property flags
168  */
169 #define	SMB_SHRF_DFSROOT	0x0001
170 #define	SMB_SHRF_CATIA		0x0002
171 #define	SMB_SHRF_GUEST_OK	0x0004
172 #define	SMB_SHRF_ABE		0x0008
173 
174 #define	SMB_SHRF_CSC_DISABLED	0x0010
175 #define	SMB_SHRF_CSC_MANUAL	0x0020
176 #define	SMB_SHRF_CSC_AUTO	0x0040
177 #define	SMB_SHRF_CSC_VDO	0x0080
178 #define	SMB_SHRF_CSC_MASK	0x00F0
179 
180 #define	SMB_SHRF_ACC_OPEN	0x0000
181 #define	SMB_SHRF_ACC_NONE	0x0100
182 #define	SMB_SHRF_ACC_RO		0x0200
183 #define	SMB_SHRF_ACC_RW		0x0400
184 #define	SMB_SHRF_ACC_ALL	0x0F00
185 
186 #define	SMB_SHRF_QUOTAS		0x1000	/* Enable SMB Quotas */
187 #define	SMB_SHRF_FSO		0x2000	/* Force Shared Oplocks */
188 
189 /*
190  * Runtime flags
191  */
192 #define	SMB_SHRF_ADMIN		0x01000000
193 #define	SMB_SHRF_TRANS		0x10000000
194 #define	SMB_SHRF_PERM		0x20000000
195 #define	SMB_SHRF_AUTOHOME	0x40000000
196 
197 #define	SMB_SHARE_PRINT		"print$"
198 #define	SMB_SHARE_PRINT_LEN	6
199 /*
200  * refcnt is currently only used for autohome.  autohome needs a refcnt
201  * because a user can map their autohome share from more than one client
202  * at the same time and the share should only be removed when the last
203  * one is disconnected
204  */
205 typedef struct smb_share {
206 	char		shr_name[MAXNAMELEN];
207 	char		shr_path[MAXPATHLEN];
208 	char		shr_cmnt[SMB_SHARE_CMNT_MAX];
209 	char		shr_container[MAXPATHLEN];
210 	uint32_t	shr_flags;
211 	uint32_t	shr_type;
212 	uint32_t	shr_refcnt;
213 	uint32_t	shr_access_value;	/* host return access value */
214 	uid_t		shr_uid;		/* autohome only */
215 	gid_t		shr_gid;		/* autohome only */
216 	char		shr_access_none[MAXPATHLEN];
217 	char		shr_access_ro[MAXPATHLEN];
218 	char		shr_access_rw[MAXPATHLEN];
219 	smb_cfg_val_t	shr_encrypt;
220 } smb_share_t;
221 
222 typedef struct smb_shriter {
223 	smb_share_t	si_share;
224 	HT_ITERATOR	si_hashiter;
225 	boolean_t	si_first;
226 } smb_shriter_t;
227 
228 #define	LMSHARES_PER_REQUEST  10
229 typedef struct smb_shrlist {
230 	int		sl_cnt;
231 	smb_share_t	sl_shares[LMSHARES_PER_REQUEST];
232 } smb_shrlist_t;
233 
234 typedef struct smb_shr_execinfo {
235 	char		*e_sharename;
236 	char		*e_winname;
237 	char		*e_userdom;
238 	smb_inaddr_t	e_srv_ipaddr;
239 	smb_inaddr_t	e_cli_ipaddr;
240 	char		*e_cli_netbiosname;
241 	uid_t		e_uid;
242 	int		e_type;
243 } smb_shr_execinfo_t;
244 
245 /*
246  * LanMan share API (for both SMB kernel module and GUI/CLI sub-system)
247  *
248  * NOTE: If any error is encounted by either the door server or client,
249  * NERR_InternalError will be returned by most functions, smb_share_count
250  * will return -1.
251  */
252 
253 #if !defined(_KERNEL) && !defined(_FAKE_KERNEL)
254 
255 /*
256  * CIFS share management functions exported by libmlsvc
257  */
258 int smb_shr_start(void);
259 void smb_shr_stop(void);
260 void *smb_shr_load(void *);
261 void smb_shr_load_execinfo(void);
262 void smb_shr_unload(void);
263 void smb_shr_iterinit(smb_shriter_t *);
264 smb_share_t *smb_shr_iterate(smb_shriter_t *);
265 void smb_shr_list(int, smb_shrlist_t *);
266 int smb_shr_count(void);
267 uint32_t smb_shr_add(smb_share_t *);
268 uint32_t smb_shr_remove(char *);
269 uint32_t smb_shr_rename(char *, char *);
270 uint32_t smb_shr_get(char *, smb_share_t *);
271 uint32_t smb_shr_modify(smb_share_t *);
272 uint32_t smb_shr_get_realpath(const char *, char *, int);
273 uint32_t smb_shr_hostaccess(smb_inaddr_t *, char *, char *, char *, uint32_t);
274 int smb_shr_exec(smb_shr_execinfo_t *);
275 
276 boolean_t smb_shr_exists(char *);
277 int smb_shr_is_special(char *);
278 boolean_t smb_shr_is_restricted(char *);
279 boolean_t smb_shr_is_admin(char *);
280 char smb_shr_drive_letter(const char *);
281 
282 sa_handle_t smb_shr_sa_enter(void);
283 void smb_shr_sa_exit(void);
284 void smb_shr_sa_csc_option(const char *, smb_share_t *);
285 char *smb_shr_sa_csc_name(const smb_share_t *);
286 void smb_shr_sa_setflag(const char *, smb_share_t *, uint32_t);
287 
288 /*
289  * CIFS share management API exported for other processes
290  */
291 uint32_t smb_share_list(int, smb_shrlist_t *);
292 int smb_share_count(void);
293 uint32_t smb_share_delete(char *);
294 uint32_t smb_share_rename(char *, char *);
295 uint32_t smb_share_create(smb_share_t *);
296 uint32_t smb_share_modify(smb_share_t *);
297 
298 #endif	/* _KERNEL */
299 
300 #ifdef __cplusplus
301 }
302 #endif
303 
304 #endif /* _SMB_SHARE_H */
305