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