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