xref: /illumos-gate/usr/src/uts/common/smbsrv/smb.h (revision 94047d49)
1da6c28aaSamw /*
2da6c28aaSamw  * CDDL HEADER START
3da6c28aaSamw  *
4da6c28aaSamw  * The contents of this file are subject to the terms of the
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * You may not use this file except in compliance with the License.
7da6c28aaSamw  *
8da6c28aaSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw  * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw  * See the License for the specific language governing permissions
11da6c28aaSamw  * and limitations under the License.
12da6c28aaSamw  *
13da6c28aaSamw  * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw  * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw  * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw  *
19da6c28aaSamw  * CDDL HEADER END
20da6c28aaSamw  */
21148c5f43SAlan Wright 
22da6c28aaSamw /*
23148c5f43SAlan Wright  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24adee6784SGordon Ross  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
25da6c28aaSamw  */
26da6c28aaSamw 
27da6c28aaSamw #ifndef _SMBSRV_SMB_H
28da6c28aaSamw #define	_SMBSRV_SMB_H
29da6c28aaSamw 
30da6c28aaSamw 
31da6c28aaSamw /*
32bbf6f00cSJordan Brown  * SMB definitions and interfaces, mostly defined in the SMB and CIFS specs.
33da6c28aaSamw  */
34da6c28aaSamw #include <sys/types.h>
35bbf6f00cSJordan Brown #include <smbsrv/string.h>
36da6c28aaSamw #include <smbsrv/msgbuf.h>
37da6c28aaSamw 
38148c5f43SAlan Wright #include <smb/ntstatus.h>
39148c5f43SAlan Wright #include <smb/nterror.h>
40148c5f43SAlan Wright #include <smb/lmerr.h>
41148c5f43SAlan Wright #include <smb/doserror.h>
42adee6784SGordon Ross #include <smb/ntaccess.h>
43da6c28aaSamw 
44bbf6f00cSJordan Brown /*
45bbf6f00cSJordan Brown  * Macintosh Extensions for CIFS
46bbf6f00cSJordan Brown  */
47bbf6f00cSJordan Brown #include <smbsrv/mac_cifs.h>
48da6c28aaSamw 
49da6c28aaSamw /*
50bbf6f00cSJordan Brown  * NT Installable File System (IFS) interface.
51da6c28aaSamw  */
52bbf6f00cSJordan Brown #include <smbsrv/ntifs.h>
53da6c28aaSamw 
54bbf6f00cSJordan Brown #ifdef __cplusplus
55bbf6f00cSJordan Brown extern "C" {
56bbf6f00cSJordan Brown #endif
57da6c28aaSamw 
58da6c28aaSamw /*
59da6c28aaSamw  * The msgbuf format and length of an SMB header.
60da6c28aaSamw  */
61da6c28aaSamw #define	SMB_HEADER_DOS_FMT	"Mbbbwbww10.wwww"
62da6c28aaSamw #define	SMB_HEADER_NT_FMT	"Mblbww#c2.wwww"
63da6c28aaSamw #define	SMB_HEADER_LEN		32
64da6c28aaSamw #define	SMB_SIG_SIZE		8	/* SMB signature size */
65da6c28aaSamw 
66bbf6f00cSJordan Brown #define	SMB_HEADER_ED_FMT	"Mbbbwbww8c2.wwww"
67bbf6f00cSJordan Brown #define	SMB_HEADER_ED_LEN	(4+1+1+1+2+1+2+12+2+2+2+2)
68bbf6f00cSJordan Brown #define	SMB_TRANSHDR_ED_FMT	"wwwwb.wl2.wwwwb."
69bbf6f00cSJordan Brown #define	SMB_TRANSHDR_ED_LEN	(2+2+2+2+1+1+2+4+2+2+2+2+2+1+1)
70bbf6f00cSJordan Brown #define	SMB_TRANSSHDR_ED_FMT	"wwwwwwwww"
71bbf6f00cSJordan Brown #define	SMB_TRANSSHDR_ED_LEN	(2+2+2+2+2+2+2+2)
72bbf6f00cSJordan Brown #define	SMB_TRANS2SHDR_ED_FMT	"wwwwwwwww"
73bbf6f00cSJordan Brown #define	SMB_TRANS2SHDR_ED_LEN	(2+2+2+2+2+2+2+2+2)
74bbf6f00cSJordan Brown /* There is something wrong with this. Should be 38 bytes. It is 37 bytes */
75bbf6f00cSJordan Brown #define	SMB_NT_TRANSHDR_ED_FMT	"b2.llllllllbw"
76bbf6f00cSJordan Brown #define	SMB_NT_TRANSHDR_ED_LEN	(1+2+4+4+4+4+4+4+4+4+1+2)
77bbf6f00cSJordan Brown 
78da6c28aaSamw /*
79da6c28aaSamw  * CIFS definition for the SMB header (CIFS Section 3.2). Note that the
80da6c28aaSamw  * pid_high field is not documented in the 1997 CIFS specificaction. This
81da6c28aaSamw  * is a decoded or memory-based definition, which may be padded to align
82da6c28aaSamw  * its elements on word boundaries. See smb_hdrbuf_t for the network
83da6c28aaSamw  * ready structure.
84da6c28aaSamw  */
85da6c28aaSamw typedef struct smb_hdr {
86bbf6f00cSJordan Brown 	uint8_t protocol[4];
87bbf6f00cSJordan Brown 	uint8_t command;
88da6c28aaSamw 
89da6c28aaSamw 	union {
90da6c28aaSamw 		struct {
91bbf6f00cSJordan Brown 			uint8_t error_class;
92bbf6f00cSJordan Brown 			uint8_t reserved;
93bbf6f00cSJordan Brown 			uint16_t error;
94da6c28aaSamw 		} dos_error;
95bbf6f00cSJordan Brown 		uint32_t ntstatus;
96bbf6f00cSJordan Brown 	} status;
97da6c28aaSamw 
98bbf6f00cSJordan Brown 	uint8_t flags;
99bbf6f00cSJordan Brown 	uint16_t flags2;
100bbf6f00cSJordan Brown 	uint16_t pid_high;
101da6c28aaSamw 
102da6c28aaSamw 	union {
103bbf6f00cSJordan Brown 		uint16_t pad[5];
104da6c28aaSamw 		struct {
105bbf6f00cSJordan Brown 			uint16_t reserved;
106bbf6f00cSJordan Brown 			uint8_t security_sig[SMB_SIG_SIZE];
107da6c28aaSamw 		} extra;
108da6c28aaSamw 	} extra;
109da6c28aaSamw 
110bbf6f00cSJordan Brown 	uint16_t tid;
111bbf6f00cSJordan Brown 	uint16_t pid;
112bbf6f00cSJordan Brown 	uint16_t uid;
113bbf6f00cSJordan Brown 	uint16_t mid;
114da6c28aaSamw } smb_hdr_t;
115da6c28aaSamw 
116da6c28aaSamw /*
117da6c28aaSamw  * Encoded or packed SMB header in network ready format.
118da6c28aaSamw  */
119da6c28aaSamw typedef struct smb_hdrbuf {
120bbf6f00cSJordan Brown 	uint8_t hdr[SMB_HEADER_LEN];
121da6c28aaSamw } smb_hdrbuf_t;
122da6c28aaSamw 
123da6c28aaSamw /*
124da6c28aaSamw  * Protocol magic value as a 32-bit.  This will be 0xff 0x53 0x4d 0x42 on
125da6c28aaSamw  * the wire.
126da6c28aaSamw  */
127da6c28aaSamw 
128da6c28aaSamw #define	SMB_PROTOCOL_MAGIC	0x424d53ff
129a90cf9f2SGordon Ross #define	SMB2_PROTOCOL_MAGIC	0x424d53fe
130da6c28aaSamw 
131da6c28aaSamw /*
132da6c28aaSamw  * Time and date encoding (CIFS Section 3.6). The date is encoded such
133da6c28aaSamw  * that the year has a range of 0-119, which represents 1980-2099. The
134da6c28aaSamw  * month range is 1-12, and the day range is 1-31.
135da6c28aaSamw  */
136da6c28aaSamw typedef struct smb_date {
137bbf6f00cSJordan Brown 	uint16_t day   : 5;
138bbf6f00cSJordan Brown 	uint16_t month : 4;
139bbf6f00cSJordan Brown 	uint16_t year  : 7;
140da6c28aaSamw } smb_date_t;
141da6c28aaSamw 
142da6c28aaSamw /*
143da6c28aaSamw  * The hours range is 0-23, the minutes range is 0-59 and the two_sec
144da6c28aaSamw  * range is 0-29.
145da6c28aaSamw  */
146da6c28aaSamw typedef struct smb_time {
147bbf6f00cSJordan Brown 	uint16_t two_sec : 5;
148bbf6f00cSJordan Brown 	uint16_t minutes : 6;
149bbf6f00cSJordan Brown 	uint16_t hours    : 5;
150da6c28aaSamw } smb_time_t;
151da6c28aaSamw 
152da6c28aaSamw /*
153da6c28aaSamw  * This is a 64-bit signed absolute time representing 100ns increments.
154da6c28aaSamw  * A positive value represents the absolute time since 1601AD. A
155da6c28aaSamw  * negative value represents a context specific relative time.
156da6c28aaSamw  */
157da6c28aaSamw typedef struct smb_time2 {
158bbf6f00cSJordan Brown 	uint32_t low_time;
159bbf6f00cSJordan Brown 	int32_t high_time;
160da6c28aaSamw } smb_time2_t;
161da6c28aaSamw 
162da6c28aaSamw /*
163da6c28aaSamw  * The number of seconds since Jan 1, 1970, 00:00:00.0.
164da6c28aaSamw  */
165da6c28aaSamw typedef uint32_t smb_utime_t;
166da6c28aaSamw 
167da6c28aaSamw #define	SMB_LM_NEGOTIATE_WORDCNT		13
168da6c28aaSamw #define	SMB_NT_NEGOTIATE_WORDCNT		17
169da6c28aaSamw 
170bbf6f00cSJordan Brown #define	SMB_NAME83_EXTLEN			3
171bbf6f00cSJordan Brown #define	SMB_NAME83_BASELEN			8
172bbf6f00cSJordan Brown #define	SMB_NAME83_LEN				12
173da6c28aaSamw 
174bbf6f00cSJordan Brown /* Share types */
175bbf6f00cSJordan Brown #ifndef _SHARE_TYPES_DEFINED_
176bbf6f00cSJordan Brown #define	_SHARE_TYPES_DEFINED_
177bbf6f00cSJordan Brown #define	STYPE_DISKTREE			0x00000000
178bbf6f00cSJordan Brown #define	STYPE_PRINTQ			0x00000001
179bbf6f00cSJordan Brown #define	STYPE_DEVICE			0x00000002
180bbf6f00cSJordan Brown #define	STYPE_IPC			0x00000003
181bbf6f00cSJordan Brown #define	STYPE_MASK			0x0000000F
182bbf6f00cSJordan Brown #define	STYPE_DFS			0x00000064
183bbf6f00cSJordan Brown #define	STYPE_HIDDEN			0x80000000
184bbf6f00cSJordan Brown #define	STYPE_SPECIAL			0x80000000
185bbf6f00cSJordan Brown #endif /* _SHARE_TYPES_DEFINED_ */
186bbf6f00cSJordan Brown 
187bbf6f00cSJordan Brown #define	STYPE_ISDSK(S)	(((S) & STYPE_MASK) == STYPE_DISKTREE)
188bbf6f00cSJordan Brown #define	STYPE_ISPRN(S)	(((S) & STYPE_MASK) == STYPE_PRINTQ)
189bbf6f00cSJordan Brown #define	STYPE_ISDEV(S)	(((S) & STYPE_MASK) == STYPE_DEVICE)
190bbf6f00cSJordan Brown #define	STYPE_ISIPC(S)	(((S) & STYPE_MASK) == STYPE_IPC)
191bbf6f00cSJordan Brown 
192bbf6f00cSJordan Brown /*
193bbf6f00cSJordan Brown  * NtCreateAndX and NtTransactCreate creation flags: defined in CIFS
194bbf6f00cSJordan Brown  * section 4.2.2
195bbf6f00cSJordan Brown  *
196bbf6f00cSJordan Brown  * Creation Flag Name         Value  Description
197bbf6f00cSJordan Brown  * ========================== ====== ==================================
198bbf6f00cSJordan Brown  * NT_CREATE_REQUEST_OPLOCK   0x02   Level I oplock requested
199bbf6f00cSJordan Brown  * NT_CREATE_REQUEST_OPBATCH  0x04   Batch oplock requested
200bbf6f00cSJordan Brown  * NT_CREATE_OPEN_TARGET_DIR  0x08   Target for open is a directory
201bbf6f00cSJordan Brown  */
202bbf6f00cSJordan Brown #define	NT_CREATE_FLAG_REQUEST_OPLOCK		0x02
203bbf6f00cSJordan Brown #define	NT_CREATE_FLAG_REQUEST_OPBATCH		0x04
204bbf6f00cSJordan Brown #define	NT_CREATE_FLAG_OPEN_TARGET_DIR		0x08
205c5f48fa5SGordon Ross #define	NT_CREATE_FLAG_EXTENDED_RESPONSE	0x10
206bbf6f00cSJordan Brown 
207c5f48fa5SGordon Ross /*
208c5f48fa5SGordon Ross  * The option flags valid in the SMB nt_create_andx call are a subset of
209c5f48fa5SGordon Ross  * those defined in ntifs.h (ditto SMB nt_transact_create)
210c5f48fa5SGordon Ross  */
211c5f48fa5SGordon Ross #define	SMB_NTCREATE_VALID_OPTIONS (FILE_VALID_OPTION_FLAGS & ~( \
212c5f48fa5SGordon Ross 	FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT |\
213c5f48fa5SGordon Ross 	FILE_RESERVE_OPFILTER))
214bbf6f00cSJordan Brown 
215*94047d49SGordon Ross /*
216*94047d49SGordon Ross  * Oplocks levels as expressed in the SMB procotol, i.e.
217*94047d49SGordon Ross  * in nt_create_andx and nt_transact_create responses.
218*94047d49SGordon Ross  * The FS-level oplock interface flags are in ntifs.h
219*94047d49SGordon Ross  * (See OPLOCK_LEVEL_...)
220*94047d49SGordon Ross  */
221*94047d49SGordon Ross #define	SMB_OPLOCK_NONE		0
222*94047d49SGordon Ross #define	SMB_OPLOCK_EXCLUSIVE	1
223*94047d49SGordon Ross #define	SMB_OPLOCK_BATCH	2
224*94047d49SGordon Ross #define	SMB_OPLOCK_LEVEL_II	3
225*94047d49SGordon Ross 
226bbf6f00cSJordan Brown /*
227