7c4620aa43c6c58baee2946641f2b3f7e6cf578c
[mat/samba.git] / libcli / smb / smb_constants.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    SMB parameters and setup, plus a whole lot more.
5
6    Copyright (C) Andrew Tridgell              2011
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef _SMB_CONSTANTS_H
23 #define _SMB_CONSTANTS_H
24
25 /*
26  * Netbios over TCP (rfc 1002)
27  */
28 #define NBSSmessage     0x00   /* session message */
29 #define NBSSrequest     0x81   /* session request */
30 #define NBSSpositive    0x82   /* positiv session response */
31 #define NBSSnegative    0x83   /* negativ session response */
32 #define NBSSretarget    0x84   /* retarget session response */
33 #define NBSSkeepalive   0x85   /* keepalive */
34
35 #define SMB_MAGIC 0x424D53FF /* 0xFF 'S' 'M' 'B' */
36
37 /* the basic packet size, assuming no words or bytes. Does not include the NBT header */
38 #define MIN_SMB_SIZE 35
39
40 /* when using NBT encapsulation every packet has a 4 byte header */
41 #define NBT_HDR_SIZE 4
42
43 /* offsets into message header for common items - NOTE: These have
44    changed from being offsets from the base of the NBT packet to the base of the SMB packet.
45    this has reduced all these values by 4
46 */
47 #define HDR_COM 4
48 #define HDR_RCLS 5
49 #define HDR_REH 6
50 #define HDR_ERR 7
51 #define HDR_FLG 9
52 #define HDR_FLG2 10
53 #define HDR_PIDHIGH 12
54 #define HDR_SS_FIELD 14
55 #define HDR_TID 24
56 #define HDR_PID 26
57 #define HDR_UID 28
58 #define HDR_MID 30
59 #define HDR_WCT 32
60 #define HDR_VWV 33
61
62 #define smb_len_nbt(buf) (RIVAL(buf, 0) & 0x1FFFF)
63 #define _smb_setlen_nbt(buf,len) RSIVAL(buf, 0, (len) & 0x1FFFF)
64 #define smb_setlen_nbt(buf, len) do { \
65         _smb_setlen_nbt(buf, len); \
66         SIVAL(buf, 4, SMB_MAGIC); \
67 } while (0)
68
69 #define smb_len_tcp(buf) (RIVAL(buf, 0) & 0xFFFFFF)
70 #define _smb_setlen_tcp(buf,len) RSIVAL(buf, 0, (len) & 0xFFFFFF)
71 #define smb_setlen_tcp(buf, len) do { \
72         _smb_setlen_tcp(buf, len); \
73         SIVAL(buf, 4, SMB_MAGIC); \
74 } while (0)
75
76 /* protocol types. It assumes that higher protocols include lower protocols
77    as subsets. */
78 enum protocol_types {
79         PROTOCOL_NONE,
80         PROTOCOL_CORE,
81         PROTOCOL_COREPLUS,
82         PROTOCOL_LANMAN1,
83         PROTOCOL_LANMAN2,
84         PROTOCOL_NT1,
85         PROTOCOL_SMB2_02,
86         PROTOCOL_SMB2_10,
87         PROTOCOL_SMB2_22
88 };
89
90 enum smb_signing_setting {
91         SMB_SIGNING_DEFAULT = -1,
92         SMB_SIGNING_OFF = 0,
93         SMB_SIGNING_IF_REQUIRED = 1,
94         SMB_SIGNING_REQUIRED = 3,
95 };
96
97 /* types of buffers in core SMB protocol */
98 #define SMB_DATA_BLOCK 0x1
99 #define SMB_ASCII4     0x4
100
101 /* flag defines. CIFS spec 3.1.1 */
102 #define FLAG_SUPPORT_LOCKREAD       0x01
103 #define FLAG_CLIENT_BUF_AVAIL       0x02
104 #define FLAG_RESERVED               0x04
105 #define FLAG_CASELESS_PATHNAMES     0x08
106 #define FLAG_CANONICAL_PATHNAMES    0x10
107 #define FLAG_REQUEST_OPLOCK         0x20
108 #define FLAG_REQUEST_BATCH_OPLOCK   0x40
109 #define FLAG_REPLY                  0x80
110
111 /* the complete */
112 #define SMBmkdir      0x00   /* create directory */
113 #define SMBrmdir      0x01   /* delete directory */
114 #define SMBopen       0x02   /* open file */
115 #define SMBcreate     0x03   /* create file */
116 #define SMBclose      0x04   /* close file */
117 #define SMBflush      0x05   /* flush file */
118 #define SMBunlink     0x06   /* delete file */
119 #define SMBmv         0x07   /* rename file */
120 #define SMBgetatr     0x08   /* get file attributes */
121 #define SMBsetatr     0x09   /* set file attributes */
122 #define SMBread       0x0A   /* read from file */
123 #define SMBwrite      0x0B   /* write to file */
124 #define SMBlock       0x0C   /* lock byte range */
125 #define SMBunlock     0x0D   /* unlock byte range */
126 #define SMBctemp      0x0E   /* create temporary file */
127 #define SMBmknew      0x0F   /* make new file */
128 #define SMBcheckpath  0x10   /* check directory path */
129 #define SMBexit       0x11   /* process exit */
130 #define SMBlseek      0x12   /* seek */
131 #define SMBtcon       0x70   /* tree connect */
132 #define SMBtconX      0x75   /* tree connect and X*/
133 #define SMBtdis       0x71   /* tree disconnect */
134 #define SMBnegprot    0x72   /* negotiate protocol */
135 #define SMBdskattr    0x80   /* get disk attributes */
136 #define SMBsearch     0x81   /* search directory */
137 #define SMBsplopen    0xC0   /* open print spool file */
138 #define SMBsplwr      0xC1   /* write to print spool file */
139 #define SMBsplclose   0xC2   /* close print spool file */
140 #define SMBsplretq    0xC3   /* return print queue */
141 #define SMBsends      0xD0   /* send single block message */
142 #define SMBsendb      0xD1   /* send broadcast message */
143 #define SMBfwdname    0xD2   /* forward user name */
144 #define SMBcancelf    0xD3   /* cancel forward */
145 #define SMBgetmac     0xD4   /* get machine name */
146 #define SMBsendstrt   0xD5   /* send start of multi-block message */
147 #define SMBsendend    0xD6   /* send end of multi-block message */
148 #define SMBsendtxt    0xD7   /* send text of multi-block message */
149
150 /* Core+ protocol */
151 #define SMBlockread       0x13   /* Lock a range and read */
152 #define SMBwriteunlock 0x14 /* Unlock a range then write */
153 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
154 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
155 #define SMBwritec     0x20  /* secondary write request */
156 #define SMBwriteclose 0x2c  /* write a file then close it */
157
158 /* dos extended protocol */
159 #define SMBreadBraw      0x1A   /* read block raw */
160 #define SMBreadBmpx      0x1B   /* read block multiplexed */
161 #define SMBreadBs        0x1C   /* read block (secondary response) */
162 #define SMBwriteBraw     0x1D   /* write block raw */
163 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
164 #define SMBwriteBs       0x1F   /* write block (secondary request) */
165 #define SMBwriteC        0x20   /* write complete response */
166 #define SMBsetattrE      0x22   /* set file attributes expanded */
167 #define SMBgetattrE      0x23   /* get file attributes expanded */
168 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
169 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
170 #define SMBtranss        0x26   /* transaction (secondary request/response) */
171 #define SMBioctl         0x27   /* IOCTL */
172 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
173 #define SMBcopy          0x29   /* copy */
174 #define SMBmove          0x2A   /* move */
175 #define SMBecho          0x2B   /* echo */
176 #define SMBopenX         0x2D   /* open and X */
177 #define SMBreadX         0x2E   /* read and X */
178 #define SMBwriteX        0x2F   /* write and X */
179 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
180 #define SMBffirst        0x82   /* find first */
181 #define SMBfunique       0x83   /* find unique */
182 #define SMBfclose        0x84   /* find close */
183 #define SMBinvalid       0xFE   /* invalid command */
184
185 /* Extended 2.0 protocol */
186 #define SMBtrans2        0x32   /* TRANS2 protocol set */
187 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
188 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
189 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
190 #define SMBulogoffX      0x74   /* user logoff */
191
192 /* NT SMB extensions. */
193 #define SMBnttrans       0xA0   /* NT transact */
194 #define SMBnttranss      0xA1   /* NT transact secondary */
195 #define SMBntcreateX     0xA2   /* NT create and X */
196 #define SMBntcancel      0xA4   /* NT cancel */
197 #define SMBntrename      0xA5   /* NT rename */
198
199 /* used to indicate end of chain */
200 #define SMB_CHAIN_NONE   0xFF
201
202 /* Sercurity mode bits. */
203 #define NEGOTIATE_SECURITY_USER_LEVEL           0x01
204 #define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE   0x02
205 #define NEGOTIATE_SECURITY_SIGNATURES_ENABLED   0x04
206 #define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED  0x08
207
208 /* Capabilities.  see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
209
210 #define CAP_RAW_MODE            0x00000001
211 #define CAP_MPX_MODE            0x00000002
212 #define CAP_UNICODE             0x00000004
213 #define CAP_LARGE_FILES         0x00000008
214 #define CAP_NT_SMBS             0x00000010
215 #define CAP_RPC_REMOTE_APIS     0x00000020
216 #define CAP_STATUS32            0x00000040
217 #define CAP_LEVEL_II_OPLOCKS    0x00000080
218 #define CAP_LOCK_AND_READ       0x00000100
219 #define CAP_NT_FIND             0x00000200
220 #define CAP_DFS                 0x00001000
221 #define CAP_W2K_SMBS            0x00002000
222 #define CAP_LARGE_READX         0x00004000
223 #define CAP_LARGE_WRITEX        0x00008000
224 #define CAP_LWIO                0x00010000
225 #define CAP_UNIX                0x00800000 /* Capabilities for UNIX extensions. Created by HP. */
226 #define CAP_DYNAMIC_REAUTH      0x20000000
227 #define CAP_EXTENDED_SECURITY   0x80000000
228
229 #define SMB_CAP_BOTH_MASK ( \
230         CAP_UNICODE | \
231         CAP_NT_SMBS | \
232         CAP_STATUS32 | \
233         CAP_LEVEL_II_OPLOCKS | \
234         CAP_EXTENDED_SECURITY | \
235         0)
236 #define SMB_CAP_SERVER_MASK ( \
237         CAP_RAW_MODE | \
238         CAP_MPX_MODE | \
239         CAP_LARGE_FILES | \
240         CAP_RPC_REMOTE_APIS | \
241         CAP_LOCK_AND_READ | \
242         CAP_NT_FIND | \
243         CAP_DFS | \
244         CAP_W2K_SMBS | \
245         CAP_LARGE_READX | \
246         CAP_LARGE_WRITEX | \
247         CAP_LWIO | \
248         CAP_UNIX | \
249         0)
250 #define SMB_CAP_CLIENT_MASK ( \
251         CAP_DYNAMIC_REAUTH | \
252         0)
253
254 /* Client-side offline caching policy types */
255 enum csc_policy {
256         CSC_POLICY_MANUAL=0,
257         CSC_POLICY_DOCUMENTS=1,
258         CSC_POLICY_PROGRAMS=2,
259         CSC_POLICY_DISABLE=3
260 };
261
262 /* NT Flags2 bits - cifs6.txt section 3.1.2 */
263 #define FLAGS2_LONG_PATH_COMPONENTS    0x0001
264 #define FLAGS2_EXTENDED_ATTRIBUTES     0x0002
265 #define FLAGS2_SMB_SECURITY_SIGNATURES 0x0004
266 #define FLAGS2_SMB_SECURITY_SIGNATURES_REQUIRED 0x0010
267 #define FLAGS2_IS_LONG_NAME            0x0040
268 #define FLAGS2_EXTENDED_SECURITY       0x0800
269 #define FLAGS2_DFS_PATHNAMES           0x1000
270 #define FLAGS2_READ_PERMIT_EXECUTE     0x2000
271 #define FLAGS2_32_BIT_ERROR_CODES      0x4000
272 #define FLAGS2_UNICODE_STRINGS         0x8000
273 #define FLAGS2_WIN2K_SIGNATURE         0xC852 /* Hack alert ! For now... JRA. */
274
275 /* FileAttributes (search attributes) field */
276 #define FILE_ATTRIBUTE_READONLY         0x0001L
277 #define FILE_ATTRIBUTE_HIDDEN           0x0002L
278 #define FILE_ATTRIBUTE_SYSTEM           0x0004L
279 #define FILE_ATTRIBUTE_VOLUME           0x0008L
280 #define FILE_ATTRIBUTE_DIRECTORY        0x0010L
281 #define FILE_ATTRIBUTE_ARCHIVE          0x0020L
282 #define FILE_ATTRIBUTE_DEVICE           0x0040L
283 #define FILE_ATTRIBUTE_NORMAL           0x0080L
284 #define FILE_ATTRIBUTE_TEMPORARY        0x0100L
285 #define FILE_ATTRIBUTE_SPARSE           0x0200L
286 #define FILE_ATTRIBUTE_REPARSE_POINT    0x0400L
287 #define FILE_ATTRIBUTE_COMPRESSED       0x0800L
288 #define FILE_ATTRIBUTE_OFFLINE          0x1000L
289 #define FILE_ATTRIBUTE_NONINDEXED       0x2000L
290 #define FILE_ATTRIBUTE_ENCRYPTED        0x4000L
291 #define FILE_ATTRIBUTE_ALL_MASK         0x7FFFL
292
293 #define SAMBA_ATTRIBUTES_MASK           (FILE_ATTRIBUTE_READONLY|\
294                                         FILE_ATTRIBUTE_HIDDEN|\
295                                         FILE_ATTRIBUTE_SYSTEM|\
296                                         FILE_ATTRIBUTE_DIRECTORY|\
297                                         FILE_ATTRIBUTE_ARCHIVE)
298
299 /* File type flags */
300 #define FILE_TYPE_DISK  0
301 #define FILE_TYPE_BYTE_MODE_PIPE 1
302 #define FILE_TYPE_MESSAGE_MODE_PIPE 2
303 #define FILE_TYPE_PRINTER 3
304 #define FILE_TYPE_COMM_DEVICE 4
305 #define FILE_TYPE_UNKNOWN 0xFFFF
306
307 /* Lock types. */
308 #define LOCKING_ANDX_EXCLUSIVE_LOCK  0x00
309 #define LOCKING_ANDX_SHARED_LOCK     0x01
310 #define LOCKING_ANDX_OPLOCK_RELEASE  0x02
311 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x04
312 #define LOCKING_ANDX_CANCEL_LOCK     0x08
313 #define LOCKING_ANDX_LARGE_FILES     0x10
314
315 /*
316  * Bits we test with.
317  */
318
319 #define OPLOCK_NONE      0
320 #define OPLOCK_EXCLUSIVE 1
321 #define OPLOCK_BATCH     2
322 #define OPLOCK_LEVEL_II  4
323
324 #define CORE_OPLOCK_GRANTED (1<<5)
325 #define EXTENDED_OPLOCK_GRANTED (1<<15)
326
327 /*
328  * Return values for oplock types.
329  */
330
331 #define NO_OPLOCK_RETURN 0
332 #define EXCLUSIVE_OPLOCK_RETURN 1
333 #define BATCH_OPLOCK_RETURN 2
334 #define LEVEL_II_OPLOCK_RETURN 3
335
336 /* oplock levels sent in oplock break */
337 #define OPLOCK_BREAK_TO_NONE     0
338 #define OPLOCK_BREAK_TO_LEVEL_II 1
339
340
341 /* ioctl codes */
342 #define IOCTL_QUERY_JOB_INFO      0x530060
343
344 /* filesystem control codes */
345 #define FSCTL_METHOD_BUFFERED   0x00000000
346 #define FSCTL_METHOD_IN_DIRECT  0x00000001
347 #define FSCTL_METHOD_OUT_DIRECT 0x00000002
348 #define FSCTL_METHOD_NEITHER    0x00000003
349
350 #define FSCTL_ACCESS_ANY        0x00000000
351 #define FSCTL_ACCESS_READ       0x00004000
352 #define FSCTL_ACCESS_WRITE      0x00008000
353
354 #define FSCTL_DFS                       0x00060000
355 #define FSCTL_DFS_GET_REFERRALS         (FSCTL_DFS | FSCTL_ACCESS_ANY | 0x0194 | FSCTL_METHOD_BUFFERED)
356
357 #define FSCTL_FILESYSTEM                0x00090000
358 #define FSCTL_REQUEST_OPLOCK_LEVEL_1    (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0000 | FSCTL_METHOD_BUFFERED)
359 #define FSCTL_REQUEST_OPLOCK_LEVEL_2    (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0004 | FSCTL_METHOD_BUFFERED)
360 #define FSCTL_REQUEST_BATCH_OPLOCK      (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0008 | FSCTL_METHOD_BUFFERED)
361 #define FSCTL_OPLOCK_BREAK_ACKNOWLEDGE  (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x000C | FSCTL_METHOD_BUFFERED)
362 #define FSCTL_OPBATCH_ACK_CLOSE_PENDING (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0010 | FSCTL_METHOD_BUFFERED)
363 #define FSCTL_OPLOCK_BREAK_NOTIFY       (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0014 | FSCTL_METHOD_BUFFERED)
364 #define FSCTL_FILESYS_GET_STATISTICS    (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0060 | FSCTL_METHOD_BUFFERED)
365 #define FSCTL_GET_NTFS_VOLUME_DATA      (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0064 | FSCTL_METHOD_BUFFERED)
366 #define FSCTL_IS_VOLUME_DIRTY           (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0078 | FSCTL_METHOD_BUFFERED)
367 #define FSCTL_FIND_FILES_BY_SID         (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x008C | FSCTL_METHOD_NEITHER)
368 #define FSCTL_SET_OBJECT_ID             (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0098 | FSCTL_METHOD_BUFFERED)
369 #define FSCTL_GET_OBJECT_ID             (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x009C | FSCTL_METHOD_BUFFERED)
370 #define FSCTL_DELETE_OBJECT_ID          (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00A0 | FSCTL_METHOD_BUFFERED)
371 #define FSCTL_SET_REPARSE_POINT         (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00A4 | FSCTL_METHOD_BUFFERED)
372 #define FSCTL_GET_REPARSE_POINT         (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00A8 | FSCTL_METHOD_BUFFERED)
373 #define FSCTL_DELETE_REPARSE_POINT      (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00AC | FSCTL_METHOD_BUFFERED)
374 #define FSCTL_CREATE_OR_GET_OBJECT_ID   (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00C0 | FSCTL_METHOD_BUFFERED)
375 #define FSCTL_SET_SPARSE                (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00C4 | FSCTL_METHOD_BUFFERED)
376 #define FSCTL_QUERY_ALLOCATED_RANGES    (FSCTL_FILESYSTEM | FSCTL_ACCESS_READ | 0x00CC | FSCTL_METHOD_NEITHER)
377
378 #define FSCTL_NAMED_PIPE                0x00110000
379 #define FSCTL_PIPE_PEEK                 (FSCTL_NAMED_PIPE | FSCTL_ACCESS_READ | 0x000C | FSCTL_METHOD_BUFFERED)
380 #define FSCTL_NAMED_PIPE_READ_WRITE     (FSCTL_NAMED_PIPE | FSCTL_ACCESS_READ \
381                                                           | FSCTL_ACCESS_WRITE | 0x0014 | FSCTL_METHOD_NEITHER)
382 #define FSCTL_PIPE_TRANSCEIVE           FSCTL_NAMED_PIPE_READ_WRITE     /* SMB2 function name */
383 #define FSCTL_PIPE_WAIT                 (FSCTL_NAMED_PIPE | FSCTL_ACCESS_ANY | 0x0018 | FSCTL_METHOD_BUFFERED)
384
385 #define FSCTL_NETWORK_FILESYSTEM        0x00140000
386 #define FSCTL_GET_SHADOW_COPY_DATA      (FSCTL_NETWORK_FILESYSTEM | FSCTL_ACCESS_READ | 0x0064 | FSCTL_METHOD_BUFFERED)
387 #define FSCTL_SRV_ENUM_SNAPS            FSCTL_GET_SHADOW_COPY_DATA      /* SMB2 function name */
388 #define FSCTL_SRV_REQUEST_RESUME_KEY    (FSCTL_NETWORK_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0078 | FSCTL_METHOD_BUFFERED)
389 #define FSCTL_SRV_COPYCHUNK             (FSCTL_NETWORK_FILESYSTEM | FSCTL_ACCESS_READ | 0x00F0 | FSCTL_METHOD_OUT_DIRECT)
390 #define FSCTL_SRV_COPYCHUNK_WRITE       (FSCTL_NETWORK_FILESYSTEM | FSCTL_ACCESS_WRITE | 0x00F0 | FSCTL_METHOD_OUT_DIRECT)
391 #define FSCTL_SRV_READ_HASH             (FSCTL_NETWORK_FILESYSTEM | FSCTL_ACCESS_READ| 0x01B8 | FSCTL_METHOD_NEITHER)
392 #define FSCTL_LMR_REQ_RESILIENCY        (FSCTL_NETWORK_FILESYSTEM | FSCTL_ACCESS_ANY | 0x01D4 | FSCTL_METHOD_BUFFERED)
393
394 #endif /* _SMB_CONSTANTS_H */