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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
25 */
26
27 #ifndef _SMBSRV_SMB_H
28 #define _SMBSRV_SMB_H
29
30
31 /*
32 * SMB definitions and interfaces, mostly defined in the SMB and CIFS specs.
33 */
34 #include <sys/types.h>
35 #include <smbsrv/string.h>
36 #include <smbsrv/msgbuf.h>
37
38 #include <smb/ntstatus.h>
39 #include <smb/nterror.h>
40 #include <smb/lmerr.h>
41 #include <smb/doserror.h>
42 #include <smbsrv/ntaccess.h>
43
44 /*
45 * Macintosh Extensions for CIFS
46 */
47 #include <smbsrv/mac_cifs.h>
48
49 /*
50 * NT Installable File System (IFS) interface.
51 */
52 #include <smbsrv/ntifs.h>
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 /*
59 * The msgbuf format and length of an SMB header.
60 */
61 #define SMB_HEADER_DOS_FMT "Mbbbwbww10.wwww"
62 #define SMB_HEADER_NT_FMT "Mblbww#c2.wwww"
185 #endif /* _SHARE_TYPES_DEFINED_ */
186
187 #define STYPE_ISDSK(S) (((S) & STYPE_MASK) == STYPE_DISKTREE)
188 #define STYPE_ISPRN(S) (((S) & STYPE_MASK) == STYPE_PRINTQ)
189 #define STYPE_ISDEV(S) (((S) & STYPE_MASK) == STYPE_DEVICE)
190 #define STYPE_ISIPC(S) (((S) & STYPE_MASK) == STYPE_IPC)
191
192 /*
193 * NtCreateAndX and NtTransactCreate creation flags: defined in CIFS
194 * section 4.2.2
195 *
196 * Creation Flag Name Value Description
197 * ========================== ====== ==================================
198 * NT_CREATE_REQUEST_OPLOCK 0x02 Level I oplock requested
199 * NT_CREATE_REQUEST_OPBATCH 0x04 Batch oplock requested
200 * NT_CREATE_OPEN_TARGET_DIR 0x08 Target for open is a directory
201 */
202 #define NT_CREATE_FLAG_REQUEST_OPLOCK 0x02
203 #define NT_CREATE_FLAG_REQUEST_OPBATCH 0x04
204 #define NT_CREATE_FLAG_OPEN_TARGET_DIR 0x08
205
206
207 /*
208 * Define the filter flags for NtNotifyChangeDirectoryFile
209 */
210 #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
211 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
212 #define FILE_NOTIFY_CHANGE_NAME 0x00000003
213 #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
214 #define FILE_NOTIFY_CHANGE_SIZE 0x00000008
215 #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
216 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
217 #define FILE_NOTIFY_CHANGE_CREATION 0x00000040
218 #define FILE_NOTIFY_CHANGE_EA 0x00000080
219 #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
220 #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
221 #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
222 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
223 #define FILE_NOTIFY_VALID_MASK 0x00000fff
224
225
226 /*
227 * Define the file action type codes for NtNotifyChangeDirectoryFile
228 */
229 #define FILE_ACTION_ADDED 0x00000001
230 #define FILE_ACTION_REMOVED 0x00000002
231 #define FILE_ACTION_MODIFIED 0x00000003
232 #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
233 #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
234 #define FILE_ACTION_ADDED_STREAM 0x00000006
235 #define FILE_ACTION_REMOVED_STREAM 0x00000007
236 #define FILE_ACTION_MODIFIED_STREAM 0x00000008
237 /*
238 * Note: These action values are not from MS-FSCC.
239 * FILE_ACTION_SUBDIR_CHANGED is used internally for
240 * "watch tree" support, posted to all parents of a
241 * directory that had one of the changes above.
242 * FILE_ACTION_DELETE_PENDING is used internally to tell
243 * notify change requests when the "delete-on-close" flag
244 * has been set on the directory being watched.
245 */
246 #define FILE_ACTION_SUBDIR_CHANGED 0x00000009
247 #define FILE_ACTION_DELETE_PENDING 0x0000000a
248
249
250 /* Lock type flags */
251 #define LOCKING_ANDX_NORMAL_LOCK 0x00
252 #define LOCKING_ANDX_SHARED_LOCK 0x01
253 #define LOCKING_ANDX_OPLOCK_RELEASE 0x02
254 #define LOCKING_ANDX_CHANGE_LOCK_TYPE 0x04
255 #define LOCKING_ANDX_CANCEL_LOCK 0x08
256 #define LOCKING_ANDX_LARGE_FILES 0x10
257
258 #define SMB_COM_CREATE_DIRECTORY 0x00
259 #define SMB_COM_DELETE_DIRECTORY 0x01
260 #define SMB_COM_OPEN 0x02
261 #define SMB_COM_CREATE 0x03
262 #define SMB_COM_CLOSE 0x04
263 #define SMB_COM_FLUSH 0x05
264 #define SMB_COM_DELETE 0x06
265 #define SMB_COM_RENAME 0x07
266 #define SMB_COM_QUERY_INFORMATION 0x08
267 #define SMB_COM_SET_INFORMATION 0x09
268 #define SMB_COM_READ 0x0A
269 #define SMB_COM_WRITE 0x0B
400 #define SMB_FLAGS2_READ_IF_EXECUTE 0x2000
401 #define SMB_FLAGS2_NT_STATUS 0x4000
402 #define SMB_FLAGS2_UNICODE 0x8000
403
404 #define DIALECT_UNKNOWN 0
405 #define PC_NETWORK_PROGRAM_1_0 1 /* The original MSNET SMB protocol */
406 #define PCLAN1_0 2 /* Some versions of the original MSNET */
407 #define MICROSOFT_NETWORKS_1_03 3 /* This is used for the MS-NET 1.03 */
408 #define MICROSOFT_NETWORKS_3_0 4 /* This is the DOS LANMAN 1.0 specific */
409 #define LANMAN1_0 5 /* This is the first version of the full */
410 #define LM1_2X002 6 /* This is the first version of the full */
411 #define DOS_LM1_2X002 7 /* This is the dos equivalent of the */
412 #define DOS_LANMAN2_1 8 /* DOS LANMAN2.1 */
413 #define LANMAN2_1 9 /* OS/2 LANMAN2.1 */
414 #define Windows_for_Workgroups_3_1a 10 /* Windows for Workgroups Version 1.0 */
415 #define NT_LM_0_12 11 /* The SMB protocol designed for NT */
416 #define DIALECT_SMB2002 12 /* SMB 2.002 (switch to SMB2) */
417 #define DIALECT_SMB2XXX 13 /* SMB 2.??? (switch to SMB2) */
418
419 /*
420 * SMB_TREE_CONNECT_ANDX OptionalSupport flags
421 *
422 * SMB_SUPPORT_SEARCH_BITS The server supports SearchAttributes.
423 * SMB_SHARE_IS_IN_DFS The share is managed by DFS.
424 * SMB_CSC_MASK Offline-caching mask - see CSC values.
425 * SMB_UNIQUE_FILE_NAME The server uses long names and does not support
426 * short names. This indicates to clients that
427 * they may perform directory name-space caching.
428 * SMB_EXTENDED_SIGNATURES The server will use signing key protection.
429 *
430 * SMB_CSC_CACHE_MANUAL_REINT Clients are allowed to cache files for offline
431 * use as requested by users but automatic
432 * file-by-file reintegration is not allowed.
433 * SMB_CSC_CACHE_AUTO_REINT Clients are allowed to automatically cache
434 * files for offline use and file-by-file
435 * reintegration is allowed.
436 * SMB_CSC_CACHE_VDO Clients are allowed to automatically cache files
437 * for offline use, file-by-file reintegration is
438 * allowed and clients are permitted to work from
439 * their local cache even while offline.
620 #define SMB_OFUN_CREATE_FAIL 0x00
621 #define SMB_OFUN_CREATE_CREATE 0x10
622
623 /*
624 * The Action field of OpenAndX has the following format:
625 *
626 * 1111 11
627 * 5432 1098 7654 3210
628 * Lrrr rrrr rrrr rrOO
629 *
630 * where:
631 *
632 * L - Opportunistic lock. 1 if lock granted, else 0.
633 *
634 * O - Open action:
635 * 1 - The file existed and was opened
636 * 2 - The file did not exist but was created
637 * 3 - The file existed and was truncated
638 */
639
640 #define SMB_OACT_LOCK 0x8000
641 #define SMB_OACT_OPENED 0x01
642 #define SMB_OACT_CREATED 0x02
643 #define SMB_OACT_TRUNCATED 0x03
644
645 #define SMB_OACT_OPLOCK 0x8000
646
647 #define SMB_FTYPE_DISK 0
648 #define SMB_FTYPE_BYTE_PIPE 1
649 #define SMB_FTYPE_MESG_PIPE 2
650 #define SMB_FTYPE_PRINTER 3
651 #define SMB_FTYPE_UNKNOWN 0xFFFF
652
653 #define SMB_DEVST_BLOCKING 0x8000
654 #define SMB_DEVST_ENDPOINT 0x4000
655 #define SMB_DEVST_TYPE_MASK 0x0C00
656 #define SMB_DEVST_TYPE_BYTE_PIPE 0x0000
657 #define SMB_DEVST_TYPE_MESG_PIPE 0x0400
658 #define SMB_DEVST_RMODE_MASK 0x0300
659 #define SMB_DEVST_RMODE_BYTES 0x0000
660 #define SMB_DEVST_RMODE_MESGS 0x0100
661 #define SMB_DEVST_ICOUNT_MASK 0x00FF /* not used */
662
663 #define SMB_FTYPE_IS_DISK(F) ((F) == SMB_FTYPE_DISK)
664 #define SMB_FTYPE_IS_PIPE(F) \
|
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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
25 */
26
27 #ifndef _SMBSRV_SMB_H
28 #define _SMBSRV_SMB_H
29
30
31 /*
32 * SMB definitions and interfaces, mostly defined in the SMB and CIFS specs.
33 */
34 #include <sys/types.h>
35 #include <smbsrv/string.h>
36 #include <smbsrv/msgbuf.h>
37
38 #include <smb/ntstatus.h>
39 #include <smb/nterror.h>
40 #include <smb/lmerr.h>
41 #include <smb/doserror.h>
42 #include <smb/ntaccess.h>
43
44 /*
45 * Macintosh Extensions for CIFS
46 */
47 #include <smbsrv/mac_cifs.h>
48
49 /*
50 * NT Installable File System (IFS) interface.
51 */
52 #include <smbsrv/ntifs.h>
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 /*
59 * The msgbuf format and length of an SMB header.
60 */
61 #define SMB_HEADER_DOS_FMT "Mbbbwbww10.wwww"
62 #define SMB_HEADER_NT_FMT "Mblbww#c2.wwww"
185 #endif /* _SHARE_TYPES_DEFINED_ */
186
187 #define STYPE_ISDSK(S) (((S) & STYPE_MASK) == STYPE_DISKTREE)
188 #define STYPE_ISPRN(S) (((S) & STYPE_MASK) == STYPE_PRINTQ)
189 #define STYPE_ISDEV(S) (((S) & STYPE_MASK) == STYPE_DEVICE)
190 #define STYPE_ISIPC(S) (((S) & STYPE_MASK) == STYPE_IPC)
191
192 /*
193 * NtCreateAndX and NtTransactCreate creation flags: defined in CIFS
194 * section 4.2.2
195 *
196 * Creation Flag Name Value Description
197 * ========================== ====== ==================================
198 * NT_CREATE_REQUEST_OPLOCK 0x02 Level I oplock requested
199 * NT_CREATE_REQUEST_OPBATCH 0x04 Batch oplock requested
200 * NT_CREATE_OPEN_TARGET_DIR 0x08 Target for open is a directory
201 */
202 #define NT_CREATE_FLAG_REQUEST_OPLOCK 0x02
203 #define NT_CREATE_FLAG_REQUEST_OPBATCH 0x04
204 #define NT_CREATE_FLAG_OPEN_TARGET_DIR 0x08
205 #define NT_CREATE_FLAG_EXTENDED_RESPONSE 0x10
206
207 /*
208 * The option flags valid in the SMB nt_create_andx call are a subset of
209 * those defined in ntifs.h (ditto SMB nt_transact_create)
210 */
211 #define SMB_NTCREATE_VALID_OPTIONS (FILE_VALID_OPTION_FLAGS & ~( \
212 FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT |\
213 FILE_RESERVE_OPFILTER))
214
215 /*
216 * Oplocks levels as expressed in the SMB procotol, i.e.
217 * in nt_create_andx and nt_transact_create responses.
218 * The FS-level oplock interface flags are in ntifs.h
219 * (See OPLOCK_LEVEL_...)
220 */
221 #define SMB_OPLOCK_NONE 0
222 #define SMB_OPLOCK_EXCLUSIVE 1
223 #define SMB_OPLOCK_BATCH 2
224 #define SMB_OPLOCK_LEVEL_II 3
225
226 /*
227 * Define the filter flags for NtNotifyChangeDirectoryFile
228 */
229 #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
230 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
231 #define FILE_NOTIFY_CHANGE_NAME 0x00000003
232 #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
233 #define FILE_NOTIFY_CHANGE_SIZE 0x00000008
234 #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
235 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
236 #define FILE_NOTIFY_CHANGE_CREATION 0x00000040
237 #define FILE_NOTIFY_CHANGE_EA 0x00000080
238 #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
239 #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
240 #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
241 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
242 #define FILE_NOTIFY_VALID_MASK 0x00000fff
243
244
245 /*
246 * Define the file action type codes for NtNotifyChangeDirectoryFile
247 */
248 #define FILE_ACTION_ADDED 0x00000001
249 #define FILE_ACTION_REMOVED 0x00000002
250 #define FILE_ACTION_MODIFIED 0x00000003
251 #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
252 #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
253 #define FILE_ACTION_ADDED_STREAM 0x00000006
254 #define FILE_ACTION_REMOVED_STREAM 0x00000007
255 #define FILE_ACTION_MODIFIED_STREAM 0x00000008
256 /* See also: FILE_ACTION_SUBDIR_CHANGED etc. */
257
258 /* Lock type flags */
259 #define LOCKING_ANDX_NORMAL_LOCK 0x00
260 #define LOCKING_ANDX_SHARED_LOCK 0x01
261 #define LOCKING_ANDX_OPLOCK_RELEASE 0x02
262 #define LOCKING_ANDX_CHANGE_LOCK_TYPE 0x04
263 #define LOCKING_ANDX_CANCEL_LOCK 0x08
264 #define LOCKING_ANDX_LARGE_FILES 0x10
265
266 #define SMB_COM_CREATE_DIRECTORY 0x00
267 #define SMB_COM_DELETE_DIRECTORY 0x01
268 #define SMB_COM_OPEN 0x02
269 #define SMB_COM_CREATE 0x03
270 #define SMB_COM_CLOSE 0x04
271 #define SMB_COM_FLUSH 0x05
272 #define SMB_COM_DELETE 0x06
273 #define SMB_COM_RENAME 0x07
274 #define SMB_COM_QUERY_INFORMATION 0x08
275 #define SMB_COM_SET_INFORMATION 0x09
276 #define SMB_COM_READ 0x0A
277 #define SMB_COM_WRITE 0x0B
408 #define SMB_FLAGS2_READ_IF_EXECUTE 0x2000
409 #define SMB_FLAGS2_NT_STATUS 0x4000
410 #define SMB_FLAGS2_UNICODE 0x8000
411
412 #define DIALECT_UNKNOWN 0
413 #define PC_NETWORK_PROGRAM_1_0 1 /* The original MSNET SMB protocol */
414 #define PCLAN1_0 2 /* Some versions of the original MSNET */
415 #define MICROSOFT_NETWORKS_1_03 3 /* This is used for the MS-NET 1.03 */
416 #define MICROSOFT_NETWORKS_3_0 4 /* This is the DOS LANMAN 1.0 specific */
417 #define LANMAN1_0 5 /* This is the first version of the full */
418 #define LM1_2X002 6 /* This is the first version of the full */
419 #define DOS_LM1_2X002 7 /* This is the dos equivalent of the */
420 #define DOS_LANMAN2_1 8 /* DOS LANMAN2.1 */
421 #define LANMAN2_1 9 /* OS/2 LANMAN2.1 */
422 #define Windows_for_Workgroups_3_1a 10 /* Windows for Workgroups Version 1.0 */
423 #define NT_LM_0_12 11 /* The SMB protocol designed for NT */
424 #define DIALECT_SMB2002 12 /* SMB 2.002 (switch to SMB2) */
425 #define DIALECT_SMB2XXX 13 /* SMB 2.??? (switch to SMB2) */
426
427 /*
428 * SMB_TREE_CONNECT_ANDX request flags
429 *
430 * The tree specified by TID in the SMB header
431 * should be disconnected - disconnect errors
432 * should be ignored.
433 */
434 #define SMB_TCONX_DISCONECT_TID 0x0001
435 /*
436 * Client request for signing key protection.
437 */
438 #define SMB_TCONX_EXTENDED_SIGNATURES 0x0004
439 /*
440 * Client request for extended information.
441 */
442 #define SMB_TCONX_EXTENDED_RESPONSE 0x0008
443
444 /*
445 * SMB_TREE_CONNECT_ANDX OptionalSupport flags
446 *
447 * SMB_SUPPORT_SEARCH_BITS The server supports SearchAttributes.
448 * SMB_SHARE_IS_IN_DFS The share is managed by DFS.
449 * SMB_CSC_MASK Offline-caching mask - see CSC values.
450 * SMB_UNIQUE_FILE_NAME The server uses long names and does not support
451 * short names. This indicates to clients that
452 * they may perform directory name-space caching.
453 * SMB_EXTENDED_SIGNATURES The server will use signing key protection.
454 *
455 * SMB_CSC_CACHE_MANUAL_REINT Clients are allowed to cache files for offline
456 * use as requested by users but automatic
457 * file-by-file reintegration is not allowed.
458 * SMB_CSC_CACHE_AUTO_REINT Clients are allowed to automatically cache
459 * files for offline use and file-by-file
460 * reintegration is allowed.
461 * SMB_CSC_CACHE_VDO Clients are allowed to automatically cache files
462 * for offline use, file-by-file reintegration is
463 * allowed and clients are permitted to work from
464 * their local cache even while offline.
645 #define SMB_OFUN_CREATE_FAIL 0x00
646 #define SMB_OFUN_CREATE_CREATE 0x10
647
648 /*
649 * The Action field of OpenAndX has the following format:
650 *
651 * 1111 11
652 * 5432 1098 7654 3210
653 * Lrrr rrrr rrrr rrOO
654 *
655 * where:
656 *
657 * L - Opportunistic lock. 1 if lock granted, else 0.
658 *
659 * O - Open action:
660 * 1 - The file existed and was opened
661 * 2 - The file did not exist but was created
662 * 3 - The file existed and was truncated
663 */
664
665 #define SMB_OACT_OPENED 0x01
666 #define SMB_OACT_CREATED 0x02
667 #define SMB_OACT_TRUNCATED 0x03
668 #define SMB_OACT_OPLOCK 0x8000
669
670 #define SMB_FTYPE_DISK 0
671 #define SMB_FTYPE_BYTE_PIPE 1
672 #define SMB_FTYPE_MESG_PIPE 2
673 #define SMB_FTYPE_PRINTER 3
674 #define SMB_FTYPE_UNKNOWN 0xFFFF
675
676 #define SMB_DEVST_BLOCKING 0x8000
677 #define SMB_DEVST_ENDPOINT 0x4000
678 #define SMB_DEVST_TYPE_MASK 0x0C00
679 #define SMB_DEVST_TYPE_BYTE_PIPE 0x0000
680 #define SMB_DEVST_TYPE_MESG_PIPE 0x0400
681 #define SMB_DEVST_RMODE_MASK 0x0300
682 #define SMB_DEVST_RMODE_BYTES 0x0000
683 #define SMB_DEVST_RMODE_MESGS 0x0100
684 #define SMB_DEVST_ICOUNT_MASK 0x00FF /* not used */
685
686 #define SMB_FTYPE_IS_DISK(F) ((F) == SMB_FTYPE_DISK)
687 #define SMB_FTYPE_IS_PIPE(F) \
|