xref: /titanic_44/usr/src/uts/common/smbsrv/smb_share.h (revision 5bbb4db2c3f208d12bf0fd11769728f9e5ba66a2)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SMB_SHARE_H
27 #define	_SMB_SHARE_H
28 
29 #include <sys/param.h>
30 #include <smbsrv/string.h>
31 #include <smbsrv/hash_table.h>
32 #include <smbsrv/wintypes.h>
33 #include <smbsrv/lmerr.h>
34 #include <smbsrv/smb_common_door.h>
35 
36 #ifndef _KERNEL
37 #include <libshare.h>
38 #else
39 #include <sys/door.h>
40 #endif
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * Share Properties:
48  *
49  * name			Advertised name of the share
50  *
51  * ad-container		Active directory container in which the share
52  * 			will be published
53  *
54  * abe			Determines whether Access Based Enumeration is applied
55  *			to a share
56  *
57  * csc			Client-side caching (CSC) options applied to this share
58  * 	disabled	The client MUST NOT cache any files
59  * 	manual		The client should not automatically cache every file
60  * 			that it	opens
61  * 	auto		The client may cache every file that it opens
62  * 	vdo		The client may cache every file that it opens
63  *			and satisfy file requests from its local cache.
64  *
65  * catia		CATIA character substitution
66  *
67  * guestok		Determines whether guest access is allowed
68  *
69  * next three properties use access-list a al NFS
70  *
71  * ro			list of hosts that will have read-only access
72  * rw			list of hosts that will have read/write access
73  * none			list of hosts that won't be allowed access
74  */
75 #define	SHOPT_AD_CONTAINER	"ad-container"
76 #define	SHOPT_ABE		"abe"
77 #define	SHOPT_NAME		"name"
78 #define	SHOPT_CSC		"csc"
79 #define	SHOPT_CATIA		"catia"
80 #define	SHOPT_GUEST		"guestok"
81 #define	SHOPT_RO		"ro"
82 #define	SHOPT_RW		"rw"
83 #define	SHOPT_NONE		"none"
84 
85 #define	SMB_DEFAULT_SHARE_GROUP	"smb"
86 #define	SMB_PROTOCOL_NAME	"smb"
87 
88 #define	SMB_SHR_MAP		0
89 #define	SMB_SHR_UNMAP		1
90 #define	SMB_SHR_DISP_CONT_STR	"continue"
91 #define	SMB_SHR_DISP_TERM_STR	"terminate"
92 
93 /*
94  * RAP protocol share related commands only understand
95  * share names in OEM format and there is a 13 char size
96  * limitation
97  */
98 #define	SMB_SHARE_OEMNAME_MAX		13
99 #define	SMB_SHARE_CMNT_MAX		(64 * MTS_MB_CHAR_MAX)
100 
101 /*
102  *	struct SHARE_INFO_1 {
103  *		char		shi1_netname[13]
104  *		char		shi1_pad;
105  *		unsigned short	shi1_type
106  *		char		*shi1_remark;
107  *	}
108  */
109 #define	SHARE_INFO_1_SIZE	(SMB_SHARE_OEMNAME_MAX + 1 + 2 + 4)
110 
111 /*
112  * Share flags:
113  *
114  * SMB_SHRF_TRANS	Transient share
115  * SMB_SHRF_PERM	Permanent share
116  * SMB_SHRF_AUTOHOME	Autohome share.
117  * SMB_SHRF_LONGNAME	Share name in OEM is longer than 13 chars
118  * SMB_SHRF_CSC_DISABLED	Client-side caching is disabled for this share
119  * SMB_SHRF_CSC_MANUAL	Manual client-side caching is allowed
120  * SMB_SHRF_CSC_AUTO	Automatic client-side caching (CSC) is allowed
121  * SMB_SHRF_CSC_VDO	Automatic CSC and local cache lookup is allowed
122  * SMB_SHRF_ACC_OPEN	No restrictions set
123  * SMB_SHRF_ACC_NONE	"none" property set
124  * SMB_SHRF_ACC_RO	"ro" (readonly) property set
125  * SMB_SHRF_ACC_RW	"rw" (read/write) property set
126  * SMB_SHRF_ACC_ALL	All of the access bits
127  * SMB_SHRF_ADMIN	Admin share
128  * SMB_SHRF_CATIA	CATIA character translation on/off
129  * SMB_SHRF_GUEST_OK	Guest access on/off
130  * SMB_SHRF_ABE		Access Based Enumeration on/off
131  * SMB_SHRF_MAP		Map command is specified
132  * SMB_SHRF_UNMAP	Unmap command is specified
133  * SMB_SHRF_DISP_TERM	Disposition is set to terminate
134  * SMB_SHRF_EXEC_MASK	All of the exec bits
135  *
136  * All autohome shares are transient but not all transient shares are autohome.
137  * IPC$ and drive letter shares (e.g. d$, e$, etc) are transient but
138  * not autohome.
139  */
140 #define	SMB_SHRF_TRANS		0x0001
141 #define	SMB_SHRF_PERM		0x0002
142 #define	SMB_SHRF_AUTOHOME	0x0004
143 #define	SMB_SHRF_LONGNAME	0x0008
144 
145 #define	SMB_SHRF_CSC_MASK	0x00F0
146 #define	SMB_SHRF_CSC_DISABLED	0x0010
147 #define	SMB_SHRF_CSC_MANUAL	0x0020
148 #define	SMB_SHRF_CSC_AUTO	0x0040
149 #define	SMB_SHRF_CSC_VDO	0x0080
150 
151 /* Access Flags */
152 #define	SMB_SHRF_ACC_OPEN	0x0000
153 #define	SMB_SHRF_ACC_NONE	0x0100
154 #define	SMB_SHRF_ACC_RO		0x0200
155 #define	SMB_SHRF_ACC_RW		0x0400
156 #define	SMB_SHRF_ACC_ALL	0x0F00
157 
158 #define	SMB_SHRF_ADMIN		0x1000
159 #define	SMB_SHRF_CATIA		0x2000
160 #define	SMB_SHRF_GUEST_OK	0x4000
161 #define	SMB_SHRF_ABE		0x8000
162 
163 /* Exec Flags */
164 #define	SMB_SHRF_MAP		0x10000
165 #define	SMB_SHRF_UNMAP		0x20000
166 #define	SMB_SHRF_DISP_TERM	0x40000
167 #define	SMB_SHRF_EXEC_MASK	0x70000
168 
169 /*
170  * refcnt is currently only used for autohome.  autohome needs a refcnt
171  * because a user can map his autohome share from more than one client
172  * at the same time and the share should only be removed when the last
173  * one is disconnected
174  */
175 typedef struct smb_share {
176 	char		shr_name[MAXNAMELEN];
177 	char		shr_path[MAXPATHLEN];
178 	char		shr_cmnt[SMB_SHARE_CMNT_MAX];
179 	char		shr_container[MAXPATHLEN];
180 	char		shr_oemname[SMB_SHARE_OEMNAME_MAX];
181 	uint32_t	shr_flags;
182 	uint32_t	shr_type;
183 	uint32_t	shr_refcnt;
184 	uint32_t	shr_access_value;	/* host return access value */
185 	char		shr_access_none[MAXPATHLEN];
186 	char		shr_access_ro[MAXPATHLEN];
187 	char		shr_access_rw[MAXPATHLEN];
188 } smb_share_t;
189 
190 typedef struct smb_shriter {
191 	smb_share_t	si_share;
192 	HT_ITERATOR	si_hashiter;
193 	boolean_t	si_first;
194 } smb_shriter_t;
195 
196 #define	LMSHARES_PER_REQUEST  10
197 typedef struct smb_shrlist {
198 	int		sl_cnt;
199 	smb_share_t	sl_shares[LMSHARES_PER_REQUEST];
200 } smb_shrlist_t;
201 
202 /*
203  * This structure is a helper for building NetShareEnum response
204  * in user space and send it back down to kernel.
205  *
206  * es_username	name of the user requesting the shares list which
207  * 		is used to detect if the user has any autohome
208  * es_bufsize	size of the response buffer
209  * es_buf	pointer to the response buffer
210  * es_ntotal	total number of shares exported by server which
211  * 		their OEM names is less then 13 chars
212  * es_nsent	number of shares that can fit in the specified buffer
213  * es_datasize	actual data size (share's data) which was encoded
214  * 		in the response buffer
215  */
216 typedef struct smb_enumshare_info {
217 	char		*es_username;
218 	uint16_t	es_bufsize;
219 	char		*es_buf;
220 	uint16_t	es_ntotal;
221 	uint16_t	es_nsent;
222 	uint16_t	es_datasize;
223 } smb_enumshare_info_t;
224 
225 typedef struct smb_execsub_info {
226 	char		*e_winname;
227 	char		*e_userdom;
228 	smb_inaddr_t	e_srv_ipaddr;
229 	smb_inaddr_t	e_cli_ipaddr;
230 	char		*e_cli_netbiosname;
231 	uid_t		e_uid;
232 } smb_execsub_info_t;
233 
234 /*
235  * LanMan share API (for both SMB kernel module and GUI/CLI sub-system)
236  *
237  * NOTE: If any error is encounted by either the door server or client,
238  * NERR_InternalError will be returned by most functions, smb_share_count
239  * will return -1.
240  */
241 
242 #ifndef _KERNEL
243 
244 /*
245  * CIFS share management functions exported by libmlsvc
246  */
247 int smb_shr_start(void);
248 void smb_shr_stop(void);
249 int smb_shr_load(void);
250 void smb_shr_iterinit(smb_shriter_t *);
251 smb_share_t *smb_shr_iterate(smb_shriter_t *);
252 void smb_shr_list(int, smb_shrlist_t *);
253 int smb_shr_count(void);
254 uint32_t smb_shr_add(smb_share_t *);
255 uint32_t smb_shr_remove(char *);
256 uint32_t smb_shr_rename(char *, char *);
257 uint32_t smb_shr_get(char *, smb_share_t *);
258 uint32_t smb_shr_modify(smb_share_t *);
259 uint32_t smb_shr_get_realpath(const char *, char *, int);
260 void smb_shr_hostaccess(smb_share_t *, smb_inaddr_t *);
261 int smb_shr_exec(char *, smb_execsub_info_t *, int);
262 
263 boolean_t smb_shr_exists(char *);
264 int smb_shr_is_special(char *);
265 boolean_t smb_shr_is_restricted(char *);
266 boolean_t smb_shr_is_admin(char *);
267 boolean_t smb_shr_chkname(char *);
268 
269 sa_handle_t smb_shr_sa_enter(void);
270 void smb_shr_sa_exit(void);
271 void smb_shr_sa_csc_option(const char *, smb_share_t *);
272 char *smb_shr_sa_csc_name(const smb_share_t *);
273 void smb_shr_sa_catia_option(const char *, smb_share_t *);
274 void smb_shr_sa_abe_option(const char *, smb_share_t *);
275 
276 /*
277  * CIFS share management API exported for other processes
278  */
279 uint32_t smb_share_list(int, smb_shrlist_t *);
280 int smb_share_count(void);
281 uint32_t smb_share_delete(char *);
282 uint32_t smb_share_rename(char *, char *);
283 uint32_t smb_share_create(smb_share_t *);
284 uint32_t smb_share_modify(smb_share_t *);
285 
286 #else
287 
288 door_handle_t smb_kshare_init(int);
289 void smb_kshare_fini(door_handle_t);
290 uint32_t smb_kshare_getinfo(door_handle_t, char *, smb_share_t *,
291     smb_inaddr_t *);
292 int smb_kshare_upcall(door_handle_t, void *, boolean_t);
293 uint32_t smb_kshare_enum(door_handle_t, smb_enumshare_info_t *);
294 uint32_t smb_kshare_exec(door_handle_t, char *, smb_execsub_info_t *, int);
295 
296 #endif
297 
298 #define	SMB_SHARE_DNAME		"/var/run/smb_share_door"
299 #define	SMB_SHARE_DSIZE		(65 * 1024)
300 
301 /*
302  * Door interface
303  *
304  * Define door operations
305  */
306 #define	SMB_SHROP_NUM_SHARES		1
307 #define	SMB_SHROP_DELETE		2
308 #define	SMB_SHROP_RENAME		3
309 #define	SMB_SHROP_GETINFO		4
310 #define	SMB_SHROP_ADD			5
311 #define	SMB_SHROP_MODIFY		6
312 #define	SMB_SHROP_LIST			7
313 #define	SMB_SHROP_ENUM			8
314 #define	SMB_SHROP_EXEC			9
315 
316 /*
317  * Door server status
318  *
319  * SMB_SHARE_DERROR is returned by the door server if there is problem
320  * with marshalling/unmarshalling. Otherwise, SMB_SHARE_DSUCCESS is
321  * returned.
322  *
323  */
324 #define	SMB_SHARE_DSUCCESS		0
325 #define	SMB_SHARE_DERROR		-1
326 
327 void smb_dr_get_share(smb_dr_ctx_t *, smb_share_t *);
328 void smb_dr_put_share(smb_dr_ctx_t *, smb_share_t *);
329 
330 void smb_share_door_clnt_init(void);
331 void smb_share_door_clnt_fini(void);
332 
333 #ifdef __cplusplus
334 }
335 #endif
336 
337 #endif /* _SMB_SHARE_H */
338