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