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