xref: /titanic_52/usr/src/uts/common/smbsrv/smb_share.h (revision 2b0dc8b01dca343292bb578d34c94862246934b8)
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_NTNAME_MAX		81
100 #define	SMB_SHARE_CMNT_MAX		(64 * MTS_MB_CHAR_MAX)
101 
102 /*
103  *	struct SHARE_INFO_1 {
104  *		char		shi1_netname[13]
105  *		char		shi1_pad;
106  *		unsigned short	shi1_type
107  *		char		*shi1_remark;
108  *	}
109  */
110 #define	SHARE_INFO_1_SIZE	(SMB_SHARE_OEMNAME_MAX + 1 + 2 + 4)
111 
112 /*
113  * Share flags:
114  *
115  * SMB_SHRF_TRANS	Transient share
116  * SMB_SHRF_PERM	Permanent share
117  * SMB_SHRF_AUTOHOME	Autohome share.
118  * SMB_SHRF_LONGNAME	Share name in OEM is longer than 13 chars
119  * SMB_SHRF_CSC_DISABLED	Client-side caching is disabled for this share
120  * SMB_SHRF_CSC_MANUAL	Manual client-side caching is allowed
121  * SMB_SHRF_CSC_AUTO	Automatic client-side caching (CSC) is allowed
122  * SMB_SHRF_CSC_VDO	Automatic CSC and local cache lookup is allowed
123  * SMB_SHRF_ACC_OPEN	No restrictions set
124  * SMB_SHRF_ACC_NONE	"none" property set
125  * SMB_SHRF_ACC_RO	"ro" (readonly) property set
126  * SMB_SHRF_ACC_RW	"rw" (read/write) property set
127  * SMB_SHRF_ACC_ALL	All of the access bits
128  * SMB_SHRF_ADMIN	Admin share
129  * SMB_SHRF_CATIA	CATIA character translation on/off
130  * SMB_SHRF_GUEST_OK	Guest access on/off
131  * SMB_SHRF_ABE		Access Based Enumeration on/off
132  * SMB_SHRF_MAP		Map command is specified
133  * SMB_SHRF_UNMAP	Unmap command is specified
134  * SMB_SHRF_DISP_TERM	Disposition is set to terminate
135  * SMB_SHRF_EXEC_MASK	All of the exec bits
136  *
137  * All autohome shares are transient but not all transient shares are autohome.
138  * IPC$ and drive letter shares (e.g. d$, e$, etc) are transient but
139  * not autohome.
140  */
141 #define	SMB_SHRF_TRANS		0x0001
142 #define	SMB_SHRF_PERM		0x0002
143 #define	SMB_SHRF_AUTOHOME	0x0004
144 #define	SMB_SHRF_LONGNAME	0x0008
145 
146 #define	SMB_SHRF_CSC_MASK	0x00F0
147 #define	SMB_SHRF_CSC_DISABLED	0x0010
148 #define	SMB_SHRF_CSC_MANUAL	0x0020
149 #define	SMB_SHRF_CSC_AUTO	0x0040
150 #define	SMB_SHRF_CSC_VDO	0x0080
151 
152 /* Access Flags */
153 #define	SMB_SHRF_ACC_OPEN	0x0000
154 #define	SMB_SHRF_ACC_NONE	0x0100
155 #define	SMB_SHRF_ACC_RO		0x0200
156 #define	SMB_SHRF_ACC_RW		0x0400
157 #define	SMB_SHRF_ACC_ALL	0x0F00
158 
159 #define	SMB_SHRF_ADMIN		0x1000
160 #define	SMB_SHRF_CATIA		0x2000
161 #define	SMB_SHRF_GUEST_OK	0x4000
162 #define	SMB_SHRF_ABE		0x8000
163 
164 /* Exec Flags */
165 #define	SMB_SHRF_MAP		0x10000
166 #define	SMB_SHRF_UNMAP		0x20000
167 #define	SMB_SHRF_DISP_TERM	0x40000
168 #define	SMB_SHRF_EXEC_MASK	0x70000
169 
170 /*
171  * refcnt is currently only used for autohome.  autohome needs a refcnt
172  * because a user can map his autohome share from more than one client
173  * at the same time and the share should only be removed when the last
174  * one is disconnected
175  */
176 typedef struct smb_share {
177 	char		shr_name[MAXNAMELEN];
178 	char		shr_path[MAXPATHLEN];
179 	char		shr_cmnt[SMB_SHARE_CMNT_MAX];
180 	char		shr_container[MAXPATHLEN];
181 	char		shr_oemname[SMB_SHARE_OEMNAME_MAX];
182 	uint32_t	shr_flags;
183 	uint32_t	shr_type;
184 	uint32_t	shr_refcnt;
185 	uint32_t	shr_access_value;	/* host return access value */
186 	uid_t		shr_uid;		/* autohome only */
187 	gid_t		shr_gid;		/* autohome only */
188 	char		shr_access_none[MAXPATHLEN];
189 	char		shr_access_ro[MAXPATHLEN];
190 	char		shr_access_rw[MAXPATHLEN];
191 } smb_share_t;
192 
193 typedef struct smb_shriter {
194 	smb_share_t	si_share;
195 	HT_ITERATOR	si_hashiter;
196 	boolean_t	si_first;
197 } smb_shriter_t;
198 
199 #define	LMSHARES_PER_REQUEST  10
200 typedef struct smb_shrlist {
201 	int		sl_cnt;
202 	smb_share_t	sl_shares[LMSHARES_PER_REQUEST];
203 } smb_shrlist_t;
204 
205 /*
206  * This structure is a helper for building NetShareEnum response
207  * in user space and send it back down to kernel.
208  *
209  * es_username	name of the user requesting the shares list which
210  * 		is used to detect if the user has any autohome
211  * es_bufsize	size of the response buffer
212  * es_buf	pointer to the response buffer
213  * es_ntotal	total number of shares exported by server which
214  * 		their OEM names is less then 13 chars
215  * es_nsent	number of shares that can fit in the specified buffer
216  * es_datasize	actual data size (share's data) which was encoded
217  * 		in the response buffer
218  */
219 typedef struct smb_enumshare_info {
220 	char		*es_username;
221 	uint16_t	es_bufsize;
222 	char		*es_buf;
223 	uint16_t	es_ntotal;
224 	uint16_t	es_nsent;
225 	uint16_t	es_datasize;
226 } smb_enumshare_info_t;
227 
228 typedef struct smb_execsub_info {
229 	char		*e_winname;
230 	char		*e_userdom;
231 	smb_inaddr_t	e_srv_ipaddr;
232 	smb_inaddr_t	e_cli_ipaddr;
233 	char		*e_cli_netbiosname;
234 	uid_t		e_uid;
235 } smb_execsub_info_t;
236 
237 /*
238  * LanMan share API (for both SMB kernel module and GUI/CLI sub-system)
239  *
240  * NOTE: If any error is encounted by either the door server or client,
241  * NERR_InternalError will be returned by most functions, smb_share_count
242  * will return -1.
243  */
244 
245 #ifndef _KERNEL
246 
247 /*
248  * CIFS share management functions exported by libmlsvc
249  */
250 int smb_shr_start(void);
251 void smb_shr_stop(void);
252 int smb_shr_load(void);
253 void smb_shr_iterinit(smb_shriter_t *);
254 smb_share_t *smb_shr_iterate(smb_shriter_t *);
255 void smb_shr_list(int, smb_shrlist_t *);
256 int smb_shr_count(void);
257 uint32_t smb_shr_add(smb_share_t *);
258 uint32_t smb_shr_remove(char *);
259 uint32_t smb_shr_rename(char *, char *);
260 uint32_t smb_shr_get(char *, smb_share_t *);
261 uint32_t smb_shr_modify(smb_share_t *);
262 uint32_t smb_shr_get_realpath(const char *, char *, int);
263 void smb_shr_hostaccess(smb_share_t *, smb_inaddr_t *);
264 int smb_shr_exec(char *, smb_execsub_info_t *, int);
265 
266 boolean_t smb_shr_exists(char *);
267 int smb_shr_is_special(char *);
268 boolean_t smb_shr_is_restricted(char *);
269 boolean_t smb_shr_is_admin(char *);
270 
271 sa_handle_t smb_shr_sa_enter(void);
272 void smb_shr_sa_exit(void);
273 void smb_shr_sa_csc_option(const char *, smb_share_t *);
274 char *smb_shr_sa_csc_name(const smb_share_t *);
275 void smb_shr_sa_catia_option(const char *, smb_share_t *);
276 void smb_shr_sa_abe_option(const char *, smb_share_t *);
277 
278 /*
279  * CIFS share management API exported for other processes
280  */
281 uint32_t smb_share_list(int, smb_shrlist_t *);
282 int smb_share_count(void);
283 uint32_t smb_share_delete(char *);
284 uint32_t smb_share_rename(char *, char *);
285 uint32_t smb_share_create(smb_share_t *);
286 uint32_t smb_share_modify(smb_share_t *);
287 
288 #else
289 
290 door_handle_t smb_kshare_init(int);
291 void smb_kshare_fini(door_handle_t);
292 uint32_t smb_kshare_getinfo(door_handle_t, char *, smb_share_t *,
293     smb_inaddr_t *);
294 int smb_kshare_upcall(door_handle_t, void *, boolean_t);
295 uint32_t smb_kshare_enum(door_handle_t, smb_enumshare_info_t *);
296 uint32_t smb_kshare_exec(door_handle_t, char *, smb_execsub_info_t *, int);
297 
298 #endif
299 
300 #define	SMB_SHARE_DNAME		"/var/run/smb_share_door"
301 #define	SMB_SHARE_DSIZE		(65 * 1024)
302 
303 /*
304  * Door interface
305  *
306  * Define door operations
307  */
308 #define	SMB_SHROP_NUM_SHARES		1
309 #define	SMB_SHROP_DELETE		2
310 #define	SMB_SHROP_RENAME		3
311 #define	SMB_SHROP_GETINFO		4
312 #define	SMB_SHROP_ADD			5
313 #define	SMB_SHROP_MODIFY		6
314 #define	SMB_SHROP_LIST			7
315 #define	SMB_SHROP_ENUM			8
316 #define	SMB_SHROP_EXEC			9
317 
318 /*
319  * Door server status
320  *
321  * SMB_SHARE_DERROR is returned by the door server if there is problem
322  * with marshalling/unmarshalling. Otherwise, SMB_SHARE_DSUCCESS is
323  * returned.
324  *
325  */
326 #define	SMB_SHARE_DSUCCESS		0
327 #define	SMB_SHARE_DERROR		-1
328 
329 void smb_dr_get_share(smb_dr_ctx_t *, smb_share_t *);
330 void smb_dr_put_share(smb_dr_ctx_t *, smb_share_t *);
331 
332 void smb_share_door_clnt_init(void);
333 void smb_share_door_clnt_fini(void);
334 
335 #ifdef __cplusplus
336 }
337 #endif
338 
339 #endif /* _SMB_SHARE_H */
340