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