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