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