xref: /titanic_50/usr/src/uts/common/smbsrv/smb_share.h (revision a74f7440e9d4ba2cf59e6cbfc445479a28170f2a)
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 2008 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * This file defines the LanMan (CIFS/SMB) resource share interface.
33  */
34 
35 #include <sys/param.h>
36 #include <smbsrv/string.h>
37 #include <smbsrv/hash_table.h>
38 #include <smbsrv/smb_fsd.h>
39 #include <smbsrv/wintypes.h>
40 #include <smbsrv/lmerr.h>
41 #include <smbsrv/smb_common_door.h>
42 
43 #ifndef _KERNEL
44 #include <libshare.h>
45 #else
46 #include <sys/door.h>
47 #endif
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 /*
54  * The following 4 macros are mainly for sharemgr use
55  */
56 #define	SMB_SHROPT_AD_CONTAINER	"ad-container"
57 #define	SMB_SHROPT_NAME		"name"	/* name is a pseudo property */
58 
59 #define	SMB_DEFAULT_SHARE_GROUP	"smb"
60 #define	SMB_PROTOCOL_NAME	"smb"
61 
62 /*
63  * RAP protocol share related commands only understand
64  * share names in OEM format and there is a 13 char size
65  * limitation
66  */
67 #define	SMB_SHARE_OEMNAME_MAX		13
68 #define	SMB_SHARE_CMNT_MAX		(64 * MTS_MB_CHAR_MAX)
69 
70 /*
71  *	struct SHARE_INFO_1 {
72  *		char		shi1_netname[13]
73  *		char		shi1_pad;
74  *		unsigned short	shi1_type
75  *		char		*shi1_remark;
76  *	}
77  */
78 #define	SHARE_INFO_1_SIZE	(SMB_SHARE_OEMNAME_MAX + 1 + 2 + 4)
79 
80 /*
81  * Share flags:
82  *
83  * SMB_SHRF_TRANS	Transient share
84  * SMB_SHRF_PERM	Permanent share
85  * SMB_SHRF_AUTOHOME	Autohome share.
86  * SMB_SHRF_LONGNAME	Share name in OEM is longer than 13 chars
87  * SMB_SHRF_ADMIN	Admin share
88  *
89  * All autohome shares are transient but not all transient shares are autohome.
90  * IPC$ and drive letter shares (e.g. d$, e$, etc) are transient but
91  * not autohome.
92  */
93 #define	SMB_SHRF_TRANS		0x0001
94 #define	SMB_SHRF_PERM		0x0002
95 #define	SMB_SHRF_AUTOHOME	0x0004
96 #define	SMB_SHRF_LONGNAME	0x0008
97 #define	SMB_SHRF_ADMIN		0x0010
98 #define	SMB_SHRF_ALL		(SMB_SHRF_TRANS | SMB_SHRF_PERM)
99 
100 /*
101  * refcnt is currently only used for autohome.  autohome needs a refcnt
102  * because a user can map his autohome share from more than one client
103  * at the same time and the share should only be removed when the last
104  * one is disconnected
105  */
106 typedef struct smb_share {
107 	char		shr_name[MAXNAMELEN];
108 	char		shr_path[MAXPATHLEN];
109 	char		shr_cmnt[SMB_SHARE_CMNT_MAX];
110 	char		shr_container[MAXPATHLEN];
111 	char		shr_oemname[SMB_SHARE_OEMNAME_MAX];
112 	uint32_t	shr_flags;
113 	uint32_t	shr_type;
114 	uint32_t	shr_refcnt;
115 } smb_share_t;
116 
117 typedef struct smb_shriter {
118 	smb_share_t	si_share;
119 	HT_ITERATOR	si_hashiter;
120 	uint32_t	si_counter;
121 	uint32_t	si_mode;
122 } smb_shriter_t;
123 
124 #define	LMSHARES_PER_REQUEST  10
125 typedef struct smb_shrlist {
126 	int		no;
127 	smb_share_t	smbshr[LMSHARES_PER_REQUEST];
128 } smb_shrlist_t;
129 
130 /*
131  * This structure is a helper for building NetShareEnum response
132  * in user space and send it back down to kernel.
133  *
134  * es_username	name of the user requesting the shares list which
135  * 		is used to detect if the user has any autohome
136  * es_bufsize	size of the response buffer
137  * es_buf	pointer to the response buffer
138  * es_ntotal	total number of shares exported by server which
139  * 		their OEM names is less then 13 chars
140  * es_nsent	number of shares that can fit in the specified buffer
141  * es_datasize	actual data size (share's data) which was encoded
142  * 		in the response buffer
143  */
144 typedef struct smb_enumshare_info {
145 	char		*es_username;
146 	uint16_t	es_bufsize;
147 	char		*es_buf;
148 	uint16_t	es_ntotal;
149 	uint16_t	es_nsent;
150 	uint16_t	es_datasize;
151 } smb_enumshare_info_t;
152 
153 /*
154  * LanMan share API (for both SMB kernel module and GUI/CLI sub-system)
155  *
156  * NOTE: If any error is encounted by either the door server or client,
157  * NERR_InternalError will be returned by most functions, smb_share_count
158  * will return -1.
159  */
160 
161 #ifndef _KERNEL
162 
163 /*
164  * CIFS share management functions in libmlsvc
165  */
166 int smb_shr_start(void);
167 void smb_shr_stop(void);
168 void smb_shr_iterinit(smb_shriter_t *, uint32_t);
169 smb_share_t *smb_shr_iterate(smb_shriter_t *iterator);
170 void smb_shr_list(int offset, smb_shrlist_t *list);
171 int smb_shr_count(void);
172 uint32_t smb_shr_add(smb_share_t *si, int);
173 uint32_t smb_shr_del(char *share_name, int);
174 uint32_t smb_shr_ren(char *from, char *to, int);
175 uint32_t smb_shr_get(char *share_name, smb_share_t *si);
176 uint32_t smb_shr_set(smb_share_t *si, int);
177 uint32_t smb_shr_get_realpath(const char *srcbuf, char *dstbuf, int maxlen);
178 
179 int smb_shr_exists(char *share_name);
180 int smb_shr_is_special(char *share_name);
181 int smb_shr_is_restricted(char *share_name);
182 int smb_shr_is_admin(char *share_name);
183 int smb_shr_is_valid(char *share_name);
184 int smb_shr_is_dir(char *path);
185 uint32_t smb_shr_add_adminshare(char *volname, unsigned char drive);
186 
187 sa_group_t smb_get_smb_share_group(sa_handle_t);
188 void smb_build_lmshare_info(char *, char *, sa_resource_t, smb_share_t *);
189 
190 /*
191  * CIFS share management API exported for other processes
192  */
193 uint32_t smb_share_list(int offset, smb_shrlist_t *list);
194 int smb_share_count(void);
195 uint32_t smb_share_get(char *, smb_share_t *);
196 uint32_t smb_share_del(char *);
197 uint32_t smb_share_ren(char *, char *);
198 uint32_t smb_share_add(smb_share_t *);
199 uint32_t smb_share_set(smb_share_t *);
200 
201 #else
202 
203 door_handle_t smb_kshare_init(int);
204 void smb_kshare_fini(door_handle_t);
205 uint32_t smb_kshare_getinfo(door_handle_t, char *, smb_share_t *);
206 int smb_kshare_upcall(door_handle_t, void *, boolean_t);
207 uint32_t smb_kshare_enum(door_handle_t, smb_enumshare_info_t *);
208 
209 #endif
210 
211 #define	SMB_SHARE_DNAME		"/var/run/smb_lmshare_door"
212 #define	SMB_SHARE_DSIZE		(65 * 1024)
213 
214 /*
215  * Door interface
216  *
217  * Define door operations
218  */
219 #define	SMB_SHROP_NUM_SHARES		1
220 #define	SMB_SHROP_DELETE		2
221 #define	SMB_SHROP_RENAME		3
222 #define	SMB_SHROP_GETINFO		4
223 #define	SMB_SHROP_ADD			5
224 #define	SMB_SHROP_SETINFO		6
225 #define	SMB_SHROP_LIST			7
226 #define	SMB_SHROP_ENUM			8
227 
228 /*
229  * Door server status
230  *
231  * SMB_SHARE_DERROR is returned by the door server if there is problem
232  * with marshalling/unmarshalling. Otherwise, SMB_SHARE_DSUCCESS is
233  * returned.
234  *
235  */
236 #define	SMB_SHARE_DSUCCESS		0
237 #define	SMB_SHARE_DERROR		-1
238 
239 void smb_dr_get_share(smb_dr_ctx_t *, smb_share_t *);
240 void smb_dr_put_share(smb_dr_ctx_t *, smb_share_t *);
241 
242 void smb_dr_get_shrlist(smb_dr_ctx_t *, smb_shrlist_t *);
243 void smb_dr_put_shrlist(smb_dr_ctx_t *, smb_shrlist_t *);
244 
245 void smb_share_dclose(void);
246 
247 #ifdef __cplusplus
248 }
249 #endif
250 
251 #endif /* _SMB_SHARE_H */
252