xref: /illumos-gate/usr/src/uts/common/smbsrv/smb2_aapl.h (revision d082c87763acd6b9390ffaefe9062d481a085d6c)
1 /*
2  * Copyright (c) 2011 - 2012 Apple Inc. All rights reserved.
3  *
4  * @APPLE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. Please obtain a copy of the License at
10  * http://www.opensource.apple.com/apsl/ and read it before using this
11  * file.
12  *
13  * The Original Code and all software distributed under the License are
14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18  * Please see the License for the specific language governing rights and
19  * limitations under the License.
20  *
21  * @APPLE_LICENSE_HEADER_END@
22  */
23 
24 /*
25  * This content was published as: smb-759.0/kernel/netsmb/smb_2.h
26  * in http://opensource.apple.com/source/smb/smb-759.0.tar.gz
27  */
28 
29 #ifndef	_SMB2AAPL_H
30 #define	_SMB2AAPL_H
31 
32 #include <sys/types.h>
33 
34 /*
35  * Apple SMB 2/3 "AAPL" Create Context extensions
36  */
37 
38 /* Define "AAPL" Context Command Codes */
39 enum {
40 	kAAPL_SERVER_QUERY = 1,
41 	kAAPL_RESOLVE_ID = 2
42 };
43 
44 /*
45  * Server Query Request
46  *
47  *	uint32_t command_code = kAAPL_SERVER_QUERY;
48  *	uint32_t reserved = 0;
49  *	uint64_t request_bitmap;
50  *	uint64_t client_capabilities;
51  *
52  * Server Query Response
53  *
54  *	uint32_t command_code = kAAPL_SERVER_QUERY;
55  *	uint32_t reserved = 0;
56  *	uint64_t reply_bitmap;
57  *	<reply specific data>
58  *
59  *	The reply data is packed in the response block in the order specified
60  *	by the reply_bitmap.
61  *
62  * Server Query request/reply bitmap
63  *  Bit 0 - kAAPL_SERVER_CAPS returns uint64_t bitmap of server capabilities
64  *  Bit 1 - kAAPL_VOLUME_CAPS returns uint64_t bitmap of volume capabilities
65  *  Bit 2 - kAAPL_MODEL_INFO returns uint32_t Pad2 followed by uint32_t length
66  *	followed by the Unicode model string. The Unicode string is padded with
67  *	zeros to end on an 8 byte boundary.
68  *
69  * Example Server Query Context Response Buffer:
70  *	uint32_t Next = 0;
71  *	uint16_t NameOffset = 16;
72  *	uint16_t NameLength = 4;
73  *	uint16_t Reserved = 0;
74  *	uint16_t DataOffset = 24;
75  *	uint32_t DataLength = variable based on ModelString length;
76  *	uint32_t ContextName = "AAPL";
77  *	uint32_t Pad = 0;
78  *	uint32_t CommandCode = kAAPL_SERVER_QUERY
79  *	uint32_t Reserved = 0;
80  *	uint64_t ReplyBitmap = kAAPL_SERVER_CAPS | kAAPL_VOLUME_CAPS |
81  *			       kAAPL_MODEL_INFO;
82  *	uint64_t ServerCaps = kAAPL_SUPPORTS_READ_DIR_ATTR |
83  *			      kAAPL_SUPPORTS_OSX_COPYFILE;
84  *	uint64_t VolumeCaps = kAAPL_SUPPORT_RESOLVE_ID | kAAPL_CASE_SENSITIVE;
85  *	uint32_t Pad2 = 0;
86  *	uint32_t ModelStringLen = variable;
87  *	char *   ModelString;
88  *	char     PadBytes = variable to end on 8 byte boundary;
89  *
90  * kAAPL_SUPPORTS_NFS_ACE - Uses to set Posix permission when ACLs are off
91  *	on the server. The server must allow the client to get the current
92  *	ACL and then the client will return it with the desired Posix
93  *	permissions in the NFS ACE in the ACL.
94  */
95 
96 /* Define Server Query request/response bitmap */
97 enum {
98 	kAAPL_SERVER_CAPS = 0x01,
99 	kAAPL_VOLUME_CAPS = 0x02,
100 	kAAPL_MODEL_INFO = 0x04
101 };
102 
103 /* Define Client/Server Capabilities bitmap */
104 enum {
105 	kAAPL_SUPPORTS_READ_DIR_ATTR = 0x01,
106 	kAAPL_SUPPORTS_OSX_COPYFILE = 0x02,
107 	kAAPL_UNIX_BASED = 0x04,
108 	kAAPL_SUPPORTS_NFS_ACE = 0x08
109 };
110 
111 /* Define Volume Capabilities bitmap */
112 enum {
113 	kAAPL_SUPPORT_RESOLVE_ID = 0x01,
114 	kAAPL_CASE_SENSITIVE = 0x02
115 };
116 
117 /*
118  * Resolve ID Request
119  *
120  *	uint32_t command_code = kAAPL_RESOLVE_ID;
121  *	uint32_t reserved = 0;
122  *	uint64_t file_id;
123  *
124  * Resolve ID Response
125  *
126  *	uint32_t command_code = kAAPL_RESOLVE_ID;
127  *	uint32_t reserved = 0;
128  *	uint32_t resolve_id_ntstatus;
129  *	uint32_t path_string_len = variable;
130  *	char *   path_string;
131  *
132  * Example Resolve ID Context Response Buffer:
133  *	uint32_t Next = 0;
134  *	uint16_t NameOffset = 16;
135  *	uint16_t NameLength = 4;
136  *	uint16_t Reserved = 0;
137  *	uint16_t DataOffset = 24;
138  *	uint32_t DataLength = variable based on PathString length;
139  *	uint32_t ContextName = "AAPL";
140  *	uint32_t Pad = 0;
141  *	uint32_t CommandCode = kAAPL_RESOLVE_ID;
142  *	uint32_t Reserved = 0;
143  *	uint32_t ResolveID_NTStatus = 0;
144  *	uint32_t ServerPathLen = variable;
145  *	char *   ServerPath;
146  *	char     PadBytes = variable to end on 8 byte boundary;
147  */
148 
149 /*
150  * ReadDirAttr Support
151  *
152  * Server has to support AAPL Create Context and support the
153  * command of kAAPL_SERVER_QUERY. In the ReplyBitMap, kAAPL_SERVER_CAPS
154  * has to be set and in the ServerCaps field, kAAPL_SUPPORTS_READ_DIR_ATTR
155  * must be set.
156  *
157  * Client uses FILE_ID_BOTH_DIR_INFORMATION for QueryDir
158  *
159  * In the Server reply for FILE_ID_BOTH_DIR_INFORMATION, fields are defined as:
160  *	uint32_t ea_size;
161  *	uint8_t short_name_len;
162  *	uint8_t reserved;
163  *	uint8_t short_name[24];
164  *	uint16_t reserved2;
165  *
166  * If kAAPL_SUPPORTS_READ_DIR_ATTR is set, the fields will be filled in as:
167  *	uint32_t max_access;
168  *	uint8_t short_name_len = 0;
169  *	uint8_t reserved = 0;
170  *	uint64_t rsrc_fork_len;
171  *	uint8_t compressed_finder_info[16];
172  *	uint16_t unix_mode;  (only if kAAPL_UNIX_BASED is set)
173  *
174  * Notes:
175  *	(1) ea_size is the max access if SMB_EFA_REPARSE_POINT is NOT set in
176  *	the file attributes. For a reparse point, the SMB Client will assume
177  *	full access.
178  *	(2) short_name is now the Resource Fork logical length and minimal
179  *	Finder Info.
180  *	(3) SMB Cient will calculate the resource fork allocation size based on
181  *	block size. This will be done in all places resource fork allocation
182  *	size is returned by the SMB Client so we return consistent answers.
183  *	(4) Compressed Finder Info will be only the fields actually still in
184  *	use in the regular Finder Info and in the Ext Finder Info. SMB client
185  *	will build a normal Finder Info and Ext Finder Info and fill in the
186  *	other fields in with zeros.
187  *	(5) If kAAPL_UNIX_BASED is set, then reserved2 is the entire Posix mode
188  *
189  *	struct smb_finder_file_info {
190  *		uint32_t finder_type;
191  *		uint32_t finder_creator;
192  *		uint16_t finder_flags;
193  *		uint16_t finder_ext_flags;
194  *		uint32_t finder_date_added;
195  *	}
196  *
197  *	struct smb_finder_folder_info {
198  *		uint64_t reserved1;
199  *		uint16_t finder_flags;
200  *		uint16_t finder_ext_flags;
201  *		uint32_t finder_date_added;
202  *	}
203  *
204  *
205  * Normal Finder Info and Extended Finder Info definitions
206  *	struct finder_file_info {
207  *		uint32_t finder_type;
208  *		uint32_t finder_creator;
209  *		uint16_t finder_flags;
210  *		uint32_t finder_old_location = 0;
211  *		uint16_t reserved = 0;
212  *
213  *		uint32_t reserved2 = 0;
214  *		uint32_t finder_date_added;
215  *		uint16_t finder_ext_flags;
216  *		uint16_t reserved3 = 0;
217  *		uint32_t reserved4 = 0;
218  *	}
219  *
220  *	struct finder_folder_info {
221  *		uint64_t reserved1;
222  *		uint16_t finder_flags;
223  *		uint32_t finder_old_location = 0;
224  *		uint16_t finder_old_view_flags = 0;
225  *
226  *		uint32_t finder_old_scroll_position = 0;
227  *		uint32_t finder_date_added;
228  *		uint16_t finder_ext_flags;
229  *		uint16_t reserved3 = 0;
230  *		uint32_t reserved4 = 0;
231  *	}
232  */
233 
234 /*
235  * Note: If you use the above smb_finder_* structs, they must be "packed".
236  * (no alignment padding).  On the server side, all of these can be
237  * opaque, so for simplicity we use smb_macinfo_t below.
238  */
239 
240 /*
241  * Implementation specific:
242  */
243 typedef struct smb_macinfo {
244 	uint64_t mi_rforksize;
245 	uint32_t mi_finderinfo[4];
246 	uint32_t mi_maxaccess;
247 	uint16_t mi_unixmode;
248 } smb_macinfo_t;
249 
250 int smb2_aapl_get_macinfo(smb_request_t *, smb_odir_t *,
251 	smb_fileinfo_t *, smb_macinfo_t *, char *, size_t);
252 
253 #endif	/* _SMB2AAPL_H */
254