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