]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - fs/cifs/cifspdu.h
Merge remote-tracking branch 'driver-core/driver-core-next'
[karo-tx-linux.git] / fs / cifs / cifspdu.h
1 /*
2  *   fs/cifs/cifspdu.h
3  *
4  *   Copyright (c) International Business Machines  Corp., 2002,2009
5  *   Author(s): Steve French (sfrench@us.ibm.com)
6  *
7  *   This library is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU Lesser General Public License as published
9  *   by the Free Software Foundation; either version 2.1 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This library is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
15  *   the GNU Lesser General Public License for more details.
16  *
17  *   You should have received a copy of the GNU Lesser General Public License
18  *   along with this library; if not, write to the Free Software
19  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21
22 #ifndef _CIFSPDU_H
23 #define _CIFSPDU_H
24
25 #include <net/sock.h>
26 #include <asm/unaligned.h>
27 #include "smbfsctl.h"
28
29 #ifdef CONFIG_CIFS_WEAK_PW_HASH
30 #define LANMAN_PROT 0
31 #define LANMAN2_PROT 1
32 #define CIFS_PROT   2
33 #else
34 #define CIFS_PROT   0
35 #endif
36 #define POSIX_PROT  (CIFS_PROT+1)
37 #define BAD_PROT 0xFFFF
38
39 /* SMB command codes:
40  * Note some commands have minimal (wct=0,bcc=0), or uninteresting, responses
41  * (ie which include no useful data other than the SMB error code itself).
42  * This can allow us to avoid response buffer allocations and copy in some cases
43  */
44 #define SMB_COM_CREATE_DIRECTORY      0x00 /* trivial response */
45 #define SMB_COM_DELETE_DIRECTORY      0x01 /* trivial response */
46 #define SMB_COM_CLOSE                 0x04 /* triv req/rsp, timestamp ignored */
47 #define SMB_COM_FLUSH                 0x05 /* triv req/rsp */
48 #define SMB_COM_DELETE                0x06 /* trivial response */
49 #define SMB_COM_RENAME                0x07 /* trivial response */
50 #define SMB_COM_QUERY_INFORMATION     0x08 /* aka getattr */
51 #define SMB_COM_SETATTR               0x09 /* trivial response */
52 #define SMB_COM_LOCKING_ANDX          0x24 /* trivial response */
53 #define SMB_COM_COPY                  0x29 /* trivial rsp, fail filename ignrd*/
54 #define SMB_COM_ECHO                  0x2B /* echo request */
55 #define SMB_COM_OPEN_ANDX             0x2D /* Legacy open for old servers */
56 #define SMB_COM_READ_ANDX             0x2E
57 #define SMB_COM_WRITE_ANDX            0x2F
58 #define SMB_COM_TRANSACTION2          0x32
59 #define SMB_COM_TRANSACTION2_SECONDARY 0x33
60 #define SMB_COM_FIND_CLOSE2           0x34 /* trivial response */
61 #define SMB_COM_TREE_DISCONNECT       0x71 /* trivial response */
62 #define SMB_COM_NEGOTIATE             0x72
63 #define SMB_COM_SESSION_SETUP_ANDX    0x73
64 #define SMB_COM_LOGOFF_ANDX           0x74 /* trivial response */
65 #define SMB_COM_TREE_CONNECT_ANDX     0x75
66 #define SMB_COM_NT_TRANSACT           0xA0
67 #define SMB_COM_NT_TRANSACT_SECONDARY 0xA1
68 #define SMB_COM_NT_CREATE_ANDX        0xA2
69 #define SMB_COM_NT_CANCEL             0xA4 /* no response */
70 #define SMB_COM_NT_RENAME             0xA5 /* trivial response */
71
72 /* Transact2 subcommand codes */
73 #define TRANS2_OPEN                   0x00
74 #define TRANS2_FIND_FIRST             0x01
75 #define TRANS2_FIND_NEXT              0x02
76 #define TRANS2_QUERY_FS_INFORMATION   0x03
77 #define TRANS2_SET_FS_INFORMATION     0x04
78 #define TRANS2_QUERY_PATH_INFORMATION 0x05
79 #define TRANS2_SET_PATH_INFORMATION   0x06
80 #define TRANS2_QUERY_FILE_INFORMATION 0x07
81 #define TRANS2_SET_FILE_INFORMATION   0x08
82 #define TRANS2_GET_DFS_REFERRAL       0x10
83 #define TRANS2_REPORT_DFS_INCOSISTENCY 0x11
84
85 /* SMB Transact (Named Pipe) subcommand codes */
86 #define TRANS_SET_NMPIPE_STATE      0x0001
87 #define TRANS_RAW_READ_NMPIPE       0x0011
88 #define TRANS_QUERY_NMPIPE_STATE    0x0021
89 #define TRANS_QUERY_NMPIPE_INFO     0x0022
90 #define TRANS_PEEK_NMPIPE           0x0023
91 #define TRANS_TRANSACT_NMPIPE       0x0026
92 #define TRANS_RAW_WRITE_NMPIPE      0x0031
93 #define TRANS_READ_NMPIPE           0x0036
94 #define TRANS_WRITE_NMPIPE          0x0037
95 #define TRANS_WAIT_NMPIPE           0x0053
96 #define TRANS_CALL_NMPIPE           0x0054
97
98 /* NT Transact subcommand codes */
99 #define NT_TRANSACT_CREATE            0x01
100 #define NT_TRANSACT_IOCTL             0x02
101 #define NT_TRANSACT_SET_SECURITY_DESC 0x03
102 #define NT_TRANSACT_NOTIFY_CHANGE     0x04
103 #define NT_TRANSACT_RENAME            0x05
104 #define NT_TRANSACT_QUERY_SECURITY_DESC 0x06
105 #define NT_TRANSACT_GET_USER_QUOTA    0x07
106 #define NT_TRANSACT_SET_USER_QUOTA    0x08
107
108 #define MAX_CIFS_SMALL_BUFFER_SIZE 448 /* big enough for most */
109 /* future chained NTCreateXReadX bigger, but for time being NTCreateX biggest */
110 /* among the requests (NTCreateX response is bigger with wct of 34) */
111 #define MAX_CIFS_HDR_SIZE 0x58 /* 4 len + 32 hdr + (2*24 wct) + 2 bct + 2 pad */
112 #define CIFS_SMALL_PATH 120 /* allows for (448-88)/3 */
113
114 /* internal cifs vfs structures */
115 /*****************************************************************
116  * All constants go here
117  *****************************************************************
118  */
119
120 /*
121  * Starting value for maximum SMB size negotiation
122  */
123 #define CIFS_MAX_MSGSIZE (4*4096)
124
125 /*
126  * Size of encrypted user password in bytes
127  */
128 #define CIFS_ENCPWD_SIZE (16)
129
130 /*
131  * Size of the crypto key returned on the negotiate SMB in bytes
132  */
133 #define CIFS_CRYPTO_KEY_SIZE (8)
134
135 /*
136  * Size of the ntlm client response
137  */
138 #define CIFS_AUTH_RESP_SIZE (24)
139
140 /*
141  * Size of the session key (crypto key encrypted with the password
142  */
143 #define CIFS_SESS_KEY_SIZE (16)
144
145 /*
146  * Size of the smb3 signing key
147  */
148 #define SMB3_SIGN_KEY_SIZE (16)
149
150 #define CIFS_CLIENT_CHALLENGE_SIZE (8)
151 #define CIFS_SERVER_CHALLENGE_SIZE (8)
152 #define CIFS_HMAC_MD5_HASH_SIZE (16)
153 #define CIFS_CPHTXT_SIZE (16)
154 #define CIFS_NTHASH_SIZE (16)
155
156 /*
157  * Maximum user name length
158  */
159 #define CIFS_UNLEN (20)
160
161 /*
162  * Flags on SMB open
163  */
164 #define SMBOPEN_WRITE_THROUGH 0x4000
165 #define SMBOPEN_DENY_ALL      0x0010
166 #define SMBOPEN_DENY_WRITE    0x0020
167 #define SMBOPEN_DENY_READ     0x0030
168 #define SMBOPEN_DENY_NONE     0x0040
169 #define SMBOPEN_READ          0x0000
170 #define SMBOPEN_WRITE         0x0001
171 #define SMBOPEN_READWRITE     0x0002
172 #define SMBOPEN_EXECUTE       0x0003
173
174 #define SMBOPEN_OCREATE       0x0010
175 #define SMBOPEN_OTRUNC        0x0002
176 #define SMBOPEN_OAPPEND       0x0001
177
178 /*
179  * SMB flag definitions
180  */
181 #define SMBFLG_EXTD_LOCK 0x01   /* server supports lock-read write-unlock smb */
182 #define SMBFLG_RCV_POSTED 0x02  /* obsolete */
183 #define SMBFLG_RSVD 0x04
184 #define SMBFLG_CASELESS 0x08    /* all pathnames treated as caseless (off
185                                 implies case sensitive file handling request) */
186 #define SMBFLG_CANONICAL_PATH_FORMAT 0x10       /* obsolete */
187 #define SMBFLG_OLD_OPLOCK 0x20  /* obsolete */
188 #define SMBFLG_OLD_OPLOCK_NOTIFY 0x40   /* obsolete */
189 #define SMBFLG_RESPONSE 0x80    /* this PDU is a response from server */
190
191 /*
192  * SMB flag2 definitions
193  */
194 #define SMBFLG2_KNOWS_LONG_NAMES cpu_to_le16(1) /* can send long (non-8.3)
195                                                    path names in response */
196 #define SMBFLG2_KNOWS_EAS cpu_to_le16(2)
197 #define SMBFLG2_SECURITY_SIGNATURE cpu_to_le16(4)
198 #define SMBFLG2_COMPRESSED (8)
199 #define SMBFLG2_SECURITY_SIGNATURE_REQUIRED (0x10)
200 #define SMBFLG2_IS_LONG_NAME cpu_to_le16(0x40)
201 #define SMBFLG2_REPARSE_PATH (0x400)
202 #define SMBFLG2_EXT_SEC cpu_to_le16(0x800)
203 #define SMBFLG2_DFS cpu_to_le16(0x1000)
204 #define SMBFLG2_PAGING_IO cpu_to_le16(0x2000)
205 #define SMBFLG2_ERR_STATUS cpu_to_le16(0x4000)
206 #define SMBFLG2_UNICODE cpu_to_le16(0x8000)
207
208 /*
209  * These are the file access permission bits defined in CIFS for the
210  * NTCreateAndX as well as the level 0x107
211  * TRANS2_QUERY_PATH_INFORMATION API.  The level 0x107, SMB_QUERY_FILE_ALL_INFO
212  * responds with the AccessFlags.
213  * The AccessFlags specifies the access permissions a caller has to the
214  * file and can have any suitable combination of the following values:
215  */
216
217 #define FILE_READ_DATA        0x00000001  /* Data can be read from the file   */
218 #define FILE_WRITE_DATA       0x00000002  /* Data can be written to the file  */
219 #define FILE_APPEND_DATA      0x00000004  /* Data can be appended to the file */
220 #define FILE_READ_EA          0x00000008  /* Extended attributes associated   */
221                                           /* with the file can be read        */
222 #define FILE_WRITE_EA         0x00000010  /* Extended attributes associated   */
223                                           /* with the file can be written     */
224 #define FILE_EXECUTE          0x00000020  /*Data can be read into memory from */
225                                           /* the file using system paging I/O */
226 #define FILE_DELETE_CHILD     0x00000040
227 #define FILE_READ_ATTRIBUTES  0x00000080  /* Attributes associated with the   */
228                                           /* file can be read                 */
229 #define FILE_WRITE_ATTRIBUTES 0x00000100  /* Attributes associated with the   */
230                                           /* file can be written              */
231 #define DELETE                0x00010000  /* The file can be deleted          */
232 #define READ_CONTROL          0x00020000  /* The access control list and      */
233                                           /* ownership associated with the    */
234                                           /* file can be read                 */
235 #define WRITE_DAC             0x00040000  /* The access control list and      */
236                                           /* ownership associated with the    */
237                                           /* file can be written.             */
238 #define WRITE_OWNER           0x00080000  /* Ownership information associated */
239                                           /* with the file can be written     */
240 #define SYNCHRONIZE           0x00100000  /* The file handle can waited on to */
241                                           /* synchronize with the completion  */
242                                           /* of an input/output request       */
243 #define GENERIC_ALL           0x10000000
244 #define GENERIC_EXECUTE       0x20000000
245 #define GENERIC_WRITE         0x40000000
246 #define GENERIC_READ          0x80000000
247                                          /* In summary - Relevant file       */
248                                          /* access flags from CIFS are       */
249                                          /* file_read_data, file_write_data  */
250                                          /* file_execute, file_read_attributes*/
251                                          /* write_dac, and delete.           */
252
253 #define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES)
254 #define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
255                                 | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
256 #define FILE_EXEC_RIGHTS (FILE_EXECUTE)
257
258 #define SET_FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA | FILE_WRITE_EA \
259                                 | FILE_READ_ATTRIBUTES \
260                                 | FILE_WRITE_ATTRIBUTES \
261                                 | DELETE | READ_CONTROL | WRITE_DAC \
262                                 | WRITE_OWNER | SYNCHRONIZE)
263 #define SET_FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
264                                 | FILE_READ_EA | FILE_WRITE_EA \
265                                 | FILE_DELETE_CHILD | FILE_READ_ATTRIBUTES \
266                                 | FILE_WRITE_ATTRIBUTES \
267                                 | DELETE | READ_CONTROL | WRITE_DAC \
268                                 | WRITE_OWNER | SYNCHRONIZE)
269 #define SET_FILE_EXEC_RIGHTS (FILE_READ_EA | FILE_WRITE_EA | FILE_EXECUTE \
270                                 | FILE_READ_ATTRIBUTES \
271                                 | FILE_WRITE_ATTRIBUTES \
272                                 | DELETE | READ_CONTROL | WRITE_DAC \
273                                 | WRITE_OWNER | SYNCHRONIZE)
274
275 #define SET_MINIMUM_RIGHTS (FILE_READ_EA | FILE_READ_ATTRIBUTES \
276                                 | READ_CONTROL | SYNCHRONIZE)
277
278
279 /*
280  * Invalid readdir handle
281  */
282 #define CIFS_NO_HANDLE        0xFFFF
283
284 #define NO_CHANGE_64          0xFFFFFFFFFFFFFFFFULL
285
286 /* IPC$ in ASCII */
287 #define CIFS_IPC_RESOURCE "\x49\x50\x43\x24"
288
289 /* IPC$ in Unicode */
290 #define CIFS_IPC_UNICODE_RESOURCE "\x00\x49\x00\x50\x00\x43\x00\x24\x00\x00"
291
292 /* Unicode Null terminate 2 bytes of 0 */
293 #define UNICODE_NULL "\x00\x00"
294 #define ASCII_NULL 0x00
295
296 /*
297  * Server type values (returned on EnumServer API
298  */
299 #define CIFS_SV_TYPE_DC     0x00000008
300 #define CIFS_SV_TYPE_BACKDC 0x00000010
301
302 /*
303  * Alias type flags (From EnumAlias API call
304  */
305 #define CIFS_ALIAS_TYPE_FILE 0x0001
306 #define CIFS_SHARE_TYPE_FILE 0x0000
307
308 /*
309  * File Attribute flags
310  */
311 #define ATTR_READONLY  0x0001
312 #define ATTR_HIDDEN    0x0002
313 #define ATTR_SYSTEM    0x0004
314 #define ATTR_VOLUME    0x0008
315 #define ATTR_DIRECTORY 0x0010
316 #define ATTR_ARCHIVE   0x0020
317 #define ATTR_DEVICE    0x0040
318 #define ATTR_NORMAL    0x0080
319 #define ATTR_TEMPORARY 0x0100
320 #define ATTR_SPARSE    0x0200
321 #define ATTR_REPARSE   0x0400
322 #define ATTR_COMPRESSED 0x0800
323 #define ATTR_OFFLINE    0x1000  /* ie file not immediately available -
324                                         on offline storage */
325 #define ATTR_NOT_CONTENT_INDEXED 0x2000
326 #define ATTR_ENCRYPTED  0x4000
327 #define ATTR_POSIX_SEMANTICS 0x01000000
328 #define ATTR_BACKUP_SEMANTICS 0x02000000
329 #define ATTR_DELETE_ON_CLOSE 0x04000000
330 #define ATTR_SEQUENTIAL_SCAN 0x08000000
331 #define ATTR_RANDOM_ACCESS   0x10000000
332 #define ATTR_NO_BUFFERING    0x20000000
333 #define ATTR_WRITE_THROUGH   0x80000000
334
335 /* ShareAccess flags */
336 #define FILE_NO_SHARE     0x00000000
337 #define FILE_SHARE_READ   0x00000001
338 #define FILE_SHARE_WRITE  0x00000002
339 #define FILE_SHARE_DELETE 0x00000004
340 #define FILE_SHARE_ALL    0x00000007
341
342 /* CreateDisposition flags, similar to CreateAction as well */
343 #define FILE_SUPERSEDE    0x00000000
344 #define FILE_OPEN         0x00000001
345 #define FILE_CREATE       0x00000002
346 #define FILE_OPEN_IF      0x00000003
347 #define FILE_OVERWRITE    0x00000004
348 #define FILE_OVERWRITE_IF 0x00000005
349
350 /* CreateOptions */
351 #define CREATE_NOT_FILE         0x00000001      /* if set must not be file */
352 #define CREATE_WRITE_THROUGH    0x00000002
353 #define CREATE_SEQUENTIAL       0x00000004
354 #define CREATE_NO_BUFFER        0x00000008      /* should not buffer on srv */
355 #define CREATE_SYNC_ALERT       0x00000010      /* MBZ */
356 #define CREATE_ASYNC_ALERT      0x00000020      /* MBZ */
357 #define CREATE_NOT_DIR          0x00000040    /* if set must not be directory */
358 #define CREATE_TREE_CONNECTION  0x00000080      /* should be zero */
359 #define CREATE_COMPLETE_IF_OPLK 0x00000100      /* should be zero */
360 #define CREATE_NO_EA_KNOWLEDGE  0x00000200
361 #define CREATE_EIGHT_DOT_THREE  0x00000400      /* doc says this is obsolete
362                                                  "open for recovery" flag should
363                                                  be zero in any case */
364 #define CREATE_OPEN_FOR_RECOVERY 0x00000400
365 #define CREATE_RANDOM_ACCESS    0x00000800
366 #define CREATE_DELETE_ON_CLOSE  0x00001000
367 #define CREATE_OPEN_BY_ID       0x00002000
368 #define CREATE_OPEN_BACKUP_INTENT 0x00004000
369 #define CREATE_NO_COMPRESSION   0x00008000
370 #define CREATE_RESERVE_OPFILTER 0x00100000      /* should be zero */
371 #define OPEN_REPARSE_POINT      0x00200000
372 #define OPEN_NO_RECALL          0x00400000
373 #define OPEN_FREE_SPACE_QUERY   0x00800000      /* should be zero */
374 #define CREATE_OPTIONS_MASK     0x007FFFFF
375 #define CREATE_OPTION_READONLY  0x10000000
376 #define CREATE_OPTION_SPECIAL   0x20000000   /* system. NB not sent over wire */
377
378 /* ImpersonationLevel flags */
379 #define SECURITY_ANONYMOUS      0
380 #define SECURITY_IDENTIFICATION 1
381 #define SECURITY_IMPERSONATION  2
382 #define SECURITY_DELEGATION     3
383
384 /* SecurityFlags */
385 #define SECURITY_CONTEXT_TRACKING 0x01
386 #define SECURITY_EFFECTIVE_ONLY   0x02
387
388 /*
389  * Default PID value, used in all SMBs where the PID is not important
390  */
391 #define CIFS_DFT_PID  0x1234
392
393 /*
394  * We use the same routine for Copy and Move SMBs.  This flag is used to
395  * distinguish
396  */
397 #define CIFS_COPY_OP 1
398 #define CIFS_RENAME_OP 2
399
400 #define GETU16(var)  (*((__u16 *)var))  /* BB check for endian issues */
401 #define GETU32(var)  (*((__u32 *)var))  /* BB check for endian issues */
402
403 struct smb_hdr {
404         __be32 smb_buf_length;  /* BB length is only two (rarely three) bytes,
405                 with one or two byte "type" preceding it that will be
406                 zero - we could mask the type byte off */
407         __u8 Protocol[4];
408         __u8 Command;
409         union {
410                 struct {
411                         __u8 ErrorClass;
412                         __u8 Reserved;
413                         __le16 Error;
414                 } __attribute__((packed)) DosError;
415                 __le32 CifsError;
416         } __attribute__((packed)) Status;
417         __u8 Flags;
418         __le16 Flags2;          /* note: le */
419         __le16 PidHigh;
420         union {
421                 struct {
422                         __le32 SequenceNumber;  /* le */
423                         __u32 Reserved; /* zero */
424                 } __attribute__((packed)) Sequence;
425                 __u8 SecuritySignature[8];      /* le */
426         } __attribute__((packed)) Signature;
427         __u8 pad[2];
428         __u16 Tid;
429         __le16 Pid;
430         __u16 Uid;
431         __u16 Mid;
432         __u8 WordCount;
433 } __attribute__((packed));
434
435 /* given a pointer to an smb_hdr, retrieve a void pointer to the ByteCount */
436 static inline void *
437 BCC(struct smb_hdr *smb)
438 {
439         return (void *)smb + sizeof(*smb) + 2 * smb->WordCount;
440 }
441
442 /* given a pointer to an smb_hdr retrieve the pointer to the byte area */
443 #define pByteArea(smb_var) (BCC(smb_var) + 2)
444
445 /* get the unconverted ByteCount for a SMB packet and return it */
446 static inline __u16
447 get_bcc(struct smb_hdr *hdr)
448 {
449         __le16 *bc_ptr = (__le16 *)BCC(hdr);
450
451         return get_unaligned_le16(bc_ptr);
452 }
453
454 /* set the ByteCount for a SMB packet in little-endian */
455 static inline void
456 put_bcc(__u16 count, struct smb_hdr *hdr)
457 {
458         __le16 *bc_ptr = (__le16 *)BCC(hdr);
459
460         put_unaligned_le16(count, bc_ptr);
461 }
462
463 /*
464  * Computer Name Length (since Netbios name was length 16 with last byte 0x20)
465  * No longer as important, now that TCP names are more commonly used to
466  * resolve hosts.
467  */
468 #define CNLEN 15
469
470 /*
471  * Share Name Length (SNLEN)
472  * Note:  This length was limited by the SMB used to get
473  *        the Share info.   NetShareEnum only returned 13
474  *        chars, including the null termination.
475  * This was removed because it no longer is limiting.
476  */
477
478 /*
479  * Comment Length
480  */
481 #define MAXCOMMENTLEN 40
482
483 /*
484  * The OS/2 maximum path name
485  */
486 #define MAX_PATHCONF 256
487
488 /*
489  *  SMB frame definitions  (following must be packed structs)
490  *  See the SNIA CIFS Specification for details.
491  *
492  *  The Naming convention is the lower case version of the
493  *  smb command code name for the struct and this is typedef to the
494  *  uppercase version of the same name with the prefix SMB_ removed
495  *  for brevity.  Although typedefs are not commonly used for
496  *  structure definitions in the Linux kernel, their use in the
497  *  CIFS standards document, which this code is based on, may
498  *  make this one of the cases where typedefs for structures make
499  *  sense to improve readability for readers of the standards doc.
500  *  Typedefs can always be removed later if they are too distracting
501  *  and they are only used for the CIFSs PDUs themselves, not
502  *  internal cifs vfs structures
503  *
504  */
505
506 typedef struct negotiate_req {
507         struct smb_hdr hdr;     /* wct = 0 */
508         __le16 ByteCount;
509         unsigned char DialectsArray[1];
510 } __attribute__((packed)) NEGOTIATE_REQ;
511
512 /* Dialect index is 13 for LANMAN */
513
514 #define MIN_TZ_ADJ (15 * 60) /* minimum grid for timezones in seconds */
515
516 typedef struct lanman_neg_rsp {
517         struct smb_hdr hdr;     /* wct = 13 */
518         __le16 DialectIndex;
519         __le16 SecurityMode;
520         __le16 MaxBufSize;
521         __le16 MaxMpxCount;
522         __le16 MaxNumberVcs;
523         __le16 RawMode;
524         __le32 SessionKey;
525         struct {
526                 __le16 Time;
527                 __le16 Date;
528         } __attribute__((packed)) SrvTime;
529         __le16 ServerTimeZone;
530         __le16 EncryptionKeyLength;
531         __le16 Reserved;
532         __u16  ByteCount;
533         unsigned char EncryptionKey[1];
534 } __attribute__((packed)) LANMAN_NEG_RSP;
535
536 #define READ_RAW_ENABLE 1
537 #define WRITE_RAW_ENABLE 2
538 #define RAW_ENABLE (READ_RAW_ENABLE | WRITE_RAW_ENABLE)
539 #define SMB1_CLIENT_GUID_SIZE (16)
540 typedef struct negotiate_rsp {
541         struct smb_hdr hdr;     /* wct = 17 */
542         __le16 DialectIndex; /* 0xFFFF = no dialect acceptable */
543         __u8 SecurityMode;
544         __le16 MaxMpxCount;
545         __le16 MaxNumberVcs;
546         __le32 MaxBufferSize;
547         __le32 MaxRawSize;
548         __le32 SessionKey;
549         __le32 Capabilities;    /* see below */
550         __le32 SystemTimeLow;
551         __le32 SystemTimeHigh;
552         __le16 ServerTimeZone;
553         __u8 EncryptionKeyLength;
554         __u16 ByteCount;
555         union {
556                 unsigned char EncryptionKey[1]; /* cap extended security off */
557                 /* followed by Domain name - if extended security is off */
558                 /* followed by 16 bytes of server GUID */
559                 /* then security blob if cap_extended_security negotiated */
560                 struct {
561                         unsigned char GUID[SMB1_CLIENT_GUID_SIZE];
562                         unsigned char SecurityBlob[1];
563                 } __attribute__((packed)) extended_response;
564         } __attribute__((packed)) u;
565 } __attribute__((packed)) NEGOTIATE_RSP;
566
567 /* SecurityMode bits */
568 #define SECMODE_USER          0x01      /* off indicates share level security */
569 #define SECMODE_PW_ENCRYPT    0x02
570 #define SECMODE_SIGN_ENABLED  0x04      /* SMB security signatures enabled */
571 #define SECMODE_SIGN_REQUIRED 0x08      /* SMB security signatures required */
572
573 /* Negotiate response Capabilities */
574 #define CAP_RAW_MODE           0x00000001
575 #define CAP_MPX_MODE           0x00000002
576 #define CAP_UNICODE            0x00000004
577 #define CAP_LARGE_FILES        0x00000008
578 #define CAP_NT_SMBS            0x00000010       /* implies CAP_NT_FIND */
579 #define CAP_RPC_REMOTE_APIS    0x00000020
580 #define CAP_STATUS32           0x00000040
581 #define CAP_LEVEL_II_OPLOCKS   0x00000080
582 #define CAP_LOCK_AND_READ      0x00000100
583 #define CAP_NT_FIND            0x00000200
584 #define CAP_DFS                0x00001000
585 #define CAP_INFOLEVEL_PASSTHRU 0x00002000
586 #define CAP_LARGE_READ_X       0x00004000
587 #define CAP_LARGE_WRITE_X      0x00008000
588 #define CAP_LWIO               0x00010000 /* support fctl_srv_req_resume_key */
589 #define CAP_UNIX               0x00800000
590 #define CAP_COMPRESSED_DATA    0x02000000
591 #define CAP_DYNAMIC_REAUTH     0x20000000
592 #define CAP_PERSISTENT_HANDLES 0x40000000
593 #define CAP_EXTENDED_SECURITY  0x80000000
594
595 typedef union smb_com_session_setup_andx {
596         struct {                /* request format */
597                 struct smb_hdr hdr;     /* wct = 12 */
598                 __u8 AndXCommand;
599                 __u8 AndXReserved;
600                 __le16 AndXOffset;
601                 __le16 MaxBufferSize;
602                 __le16 MaxMpxCount;
603                 __le16 VcNumber;
604                 __u32 SessionKey;
605                 __le16 SecurityBlobLength;
606                 __u32 Reserved;
607                 __le32 Capabilities;    /* see below */
608                 __le16 ByteCount;
609                 unsigned char SecurityBlob[1];  /* followed by */
610                 /* STRING NativeOS */
611                 /* STRING NativeLanMan */
612         } __attribute__((packed)) req;  /* NTLM request format (with
613                                         extended security */
614
615         struct {                /* request format */
616                 struct smb_hdr hdr;     /* wct = 13 */
617                 __u8 AndXCommand;
618                 __u8 AndXReserved;
619                 __le16 AndXOffset;
620                 __le16 MaxBufferSize;
621                 __le16 MaxMpxCount;
622                 __le16 VcNumber;
623                 __u32 SessionKey;
624                 __le16 CaseInsensitivePasswordLength; /* ASCII password len */
625                 __le16 CaseSensitivePasswordLength; /* Unicode password length*/
626                 __u32 Reserved; /* see below */
627                 __le32 Capabilities;
628                 __le16 ByteCount;
629                 unsigned char CaseInsensitivePassword[1];     /* followed by: */
630                 /* unsigned char * CaseSensitivePassword; */
631                 /* STRING AccountName */
632                 /* STRING PrimaryDomain */
633                 /* STRING NativeOS */
634                 /* STRING NativeLanMan */
635         } __attribute__((packed)) req_no_secext; /* NTLM request format (without
636                                                         extended security */
637
638         struct {                /* default (NTLM) response format */
639                 struct smb_hdr hdr;     /* wct = 4 */
640                 __u8 AndXCommand;
641                 __u8 AndXReserved;
642                 __le16 AndXOffset;
643                 __le16 Action;  /* see below */
644                 __le16 SecurityBlobLength;
645                 __u16 ByteCount;
646                 unsigned char SecurityBlob[1];  /* followed by */
647 /*      unsigned char  * NativeOS;      */
648 /*      unsigned char  * NativeLanMan;  */
649 /*      unsigned char  * PrimaryDomain; */
650         } __attribute__((packed)) resp; /* NTLM response
651                                            (with or without extended sec) */
652
653         struct {                /* request format */
654                 struct smb_hdr hdr;     /* wct = 10 */
655                 __u8 AndXCommand;
656                 __u8 AndXReserved;
657                 __le16 AndXOffset;
658                 __le16 MaxBufferSize;
659                 __le16 MaxMpxCount;
660                 __le16 VcNumber;
661                 __u32 SessionKey;
662                 __le16 PasswordLength;
663                 __u32 Reserved; /* encrypt key len and offset */
664                 __le16 ByteCount;
665                 unsigned char AccountPassword[1];       /* followed by */
666                 /* STRING AccountName */
667                 /* STRING PrimaryDomain */
668                 /* STRING NativeOS */
669                 /* STRING NativeLanMan */
670         } __attribute__((packed)) old_req; /* pre-NTLM (LANMAN2.1) req format */
671
672         struct {                /* default (NTLM) response format */
673                 struct smb_hdr hdr;     /* wct = 3 */
674                 __u8 AndXCommand;
675                 __u8 AndXReserved;
676                 __le16 AndXOffset;
677                 __le16 Action;  /* see below */
678                 __u16 ByteCount;
679                 unsigned char NativeOS[1];      /* followed by */
680 /*      unsigned char * NativeLanMan; */
681 /*      unsigned char * PrimaryDomain; */
682         } __attribute__((packed)) old_resp; /* pre-NTLM (LANMAN2.1) response */
683 } __attribute__((packed)) SESSION_SETUP_ANDX;
684
685 /* format of NLTMv2 Response ie "case sensitive password" hash when NTLMv2 */
686
687 #define NTLMSSP_SERVER_TYPE     1
688 #define NTLMSSP_DOMAIN_TYPE     2
689 #define NTLMSSP_FQ_DOMAIN_TYPE  3
690 #define NTLMSSP_DNS_DOMAIN_TYPE 4
691 #define NTLMSSP_DNS_PARENT_TYPE 5
692
693 struct ntlmssp2_name {
694         __le16 type;
695         __le16 length;
696 /*      char   name[length]; */
697 } __attribute__((packed));
698
699 struct ntlmv2_resp {
700         char ntlmv2_hash[CIFS_ENCPWD_SIZE];
701         __le32 blob_signature;
702         __u32  reserved;
703         __le64  time;
704         __u64  client_chal; /* random */
705         __u32  reserved2;
706         /* array of name entries could follow ending in minimum 4 byte struct */
707 } __attribute__((packed));
708
709
710 #define CIFS_NETWORK_OPSYS "CIFS VFS Client for Linux"
711
712 /* Capabilities bits (for NTLM SessSetup request) */
713 #define CAP_UNICODE            0x00000004
714 #define CAP_LARGE_FILES        0x00000008
715 #define CAP_NT_SMBS            0x00000010
716 #define CAP_STATUS32           0x00000040
717 #define CAP_LEVEL_II_OPLOCKS   0x00000080
718 #define CAP_NT_FIND            0x00000200       /* reserved should be zero
719                                 (because NT_SMBs implies the same thing?) */
720 #define CAP_BULK_TRANSFER      0x20000000
721 #define CAP_EXTENDED_SECURITY  0x80000000
722
723 /* Action bits */
724 #define GUEST_LOGIN 1
725
726 typedef struct smb_com_tconx_req {
727         struct smb_hdr hdr;     /* wct = 4 */
728         __u8 AndXCommand;
729         __u8 AndXReserved;
730         __le16 AndXOffset;
731         __le16 Flags;           /* see below */
732         __le16 PasswordLength;
733         __le16 ByteCount;
734         unsigned char Password[1];      /* followed by */
735 /* STRING Path    *//* \\server\share name */
736         /* STRING Service */
737 } __attribute__((packed)) TCONX_REQ;
738
739 typedef struct smb_com_tconx_rsp {
740         struct smb_hdr hdr;     /* wct = 3 , not extended response */
741         __u8 AndXCommand;
742         __u8 AndXReserved;
743         __le16 AndXOffset;
744         __le16 OptionalSupport; /* see below */
745         __u16 ByteCount;
746         unsigned char Service[1];       /* always ASCII, not Unicode */
747         /* STRING NativeFileSystem */
748 } __attribute__((packed)) TCONX_RSP;
749
750 typedef struct smb_com_tconx_rsp_ext {
751         struct smb_hdr hdr;     /* wct = 7, extended response */
752         __u8 AndXCommand;
753         __u8 AndXReserved;
754         __le16 AndXOffset;
755         __le16 OptionalSupport; /* see below */
756         __le32 MaximalShareAccessRights;
757         __le32 GuestMaximalShareAccessRights;
758         __u16 ByteCount;
759         unsigned char Service[1];       /* always ASCII, not Unicode */
760         /* STRING NativeFileSystem */
761 } __attribute__((packed)) TCONX_RSP_EXT;
762
763
764 /* tree connect Flags */
765 #define DISCONNECT_TID          0x0001
766 #define TCON_EXTENDED_SIGNATURES 0x0004
767 #define TCON_EXTENDED_SECINFO   0x0008
768
769 /* OptionalSupport bits */
770 #define SMB_SUPPORT_SEARCH_BITS 0x0001  /* "must have" directory search bits
771                                          (exclusive searches supported) */
772 #define SMB_SHARE_IS_IN_DFS     0x0002
773 #define SMB_CSC_MASK               0x000C
774 /* CSC flags defined as follows */
775 #define SMB_CSC_CACHE_MANUAL_REINT 0x0000
776 #define SMB_CSC_CACHE_AUTO_REINT   0x0004
777 #define SMB_CSC_CACHE_VDO          0x0008
778 #define SMB_CSC_NO_CACHING         0x000C
779 #define SMB_UNIQUE_FILE_NAME    0x0010
780 #define SMB_EXTENDED_SIGNATURES 0x0020
781
782 /* services
783  *
784  * A:       ie disk
785  * LPT1:    ie printer
786  * IPC      ie named pipe
787  * COMM
788  * ?????    ie any type
789  *
790  */
791
792 typedef struct smb_com_echo_req {
793         struct  smb_hdr hdr;
794         __le16  EchoCount;
795         __le16  ByteCount;
796         char    Data[1];
797 } __attribute__((packed)) ECHO_REQ;
798
799 typedef struct smb_com_echo_rsp {
800         struct  smb_hdr hdr;
801         __le16  SequenceNumber;
802         __le16  ByteCount;
803         char    Data[1];
804 } __attribute__((packed)) ECHO_RSP;
805
806 typedef struct smb_com_logoff_andx_req {
807         struct smb_hdr hdr;     /* wct = 2 */
808         __u8 AndXCommand;
809         __u8 AndXReserved;
810         __u16 AndXOffset;
811         __u16 ByteCount;
812 } __attribute__((packed)) LOGOFF_ANDX_REQ;
813
814 typedef struct smb_com_logoff_andx_rsp {
815         struct smb_hdr hdr;     /* wct = 2 */
816         __u8 AndXCommand;
817         __u8 AndXReserved;
818         __u16 AndXOffset;
819         __u16 ByteCount;
820 } __attribute__((packed)) LOGOFF_ANDX_RSP;
821
822 typedef union smb_com_tree_disconnect { /* as an altetnative can use flag on
823                                         tree_connect PDU to effect disconnect */
824                                         /* tdis is probably simplest SMB PDU */
825         struct {
826                 struct smb_hdr hdr;     /* wct = 0 */
827                 __u16 ByteCount;        /* bcc = 0 */
828         } __attribute__((packed)) req;
829         struct {
830                 struct smb_hdr hdr;     /* wct = 0 */
831                 __u16 ByteCount;        /* bcc = 0 */
832         } __attribute__((packed)) resp;
833 } __attribute__((packed)) TREE_DISCONNECT;
834
835 typedef struct smb_com_close_req {
836         struct smb_hdr hdr;     /* wct = 3 */
837         __u16 FileID;
838         __u32 LastWriteTime;    /* should be zero or -1 */
839         __u16 ByteCount;        /* 0 */
840 } __attribute__((packed)) CLOSE_REQ;
841
842 typedef struct smb_com_close_rsp {
843         struct smb_hdr hdr;     /* wct = 0 */
844         __u16 ByteCount;        /* bct = 0 */
845 } __attribute__((packed)) CLOSE_RSP;
846
847 typedef struct smb_com_flush_req {
848         struct smb_hdr hdr;     /* wct = 1 */
849         __u16 FileID;
850         __u16 ByteCount;        /* 0 */
851 } __attribute__((packed)) FLUSH_REQ;
852
853 typedef struct smb_com_findclose_req {
854         struct smb_hdr hdr; /* wct = 1 */
855         __u16 FileID;
856         __u16 ByteCount;    /* 0 */
857 } __attribute__((packed)) FINDCLOSE_REQ;
858
859 /* OpenFlags */
860 #define REQ_MORE_INFO      0x00000001  /* legacy (OPEN_AND_X) only */
861 #define REQ_OPLOCK         0x00000002
862 #define REQ_BATCHOPLOCK    0x00000004
863 #define REQ_OPENDIRONLY    0x00000008
864 #define REQ_EXTENDED_INFO  0x00000010
865
866 /* File type */
867 #define DISK_TYPE               0x0000
868 #define BYTE_PIPE_TYPE          0x0001
869 #define MESSAGE_PIPE_TYPE       0x0002
870 #define PRINTER_TYPE            0x0003
871 #define COMM_DEV_TYPE           0x0004
872 #define UNKNOWN_TYPE            0xFFFF
873
874 /* Device Type or File Status Flags */
875 #define NO_EAS                  0x0001
876 #define NO_SUBSTREAMS           0x0002
877 #define NO_REPARSETAG           0x0004
878 /* following flags can apply if pipe */
879 #define ICOUNT_MASK             0x00FF
880 #define PIPE_READ_MODE          0x0100
881 #define NAMED_PIPE_TYPE         0x0400
882 #define PIPE_END_POINT          0x4000
883 #define BLOCKING_NAMED_PIPE     0x8000
884
885 typedef struct smb_com_open_req {       /* also handles create */
886         struct smb_hdr hdr;     /* wct = 24 */
887         __u8 AndXCommand;
888         __u8 AndXReserved;
889         __le16 AndXOffset;
890         __u8 Reserved;          /* Must Be Zero */
891         __le16 NameLength;
892         __le32 OpenFlags;
893         __u32  RootDirectoryFid;
894         __le32 DesiredAccess;
895         __le64 AllocationSize;
896         __le32 FileAttributes;
897         __le32 ShareAccess;
898         __le32 CreateDisposition;
899         __le32 CreateOptions;
900         __le32 ImpersonationLevel;
901         __u8 SecurityFlags;
902         __le16 ByteCount;
903         char fileName[1];
904 } __attribute__((packed)) OPEN_REQ;
905
906 /* open response: oplock levels */
907 #define OPLOCK_NONE      0
908 #define OPLOCK_EXCLUSIVE 1
909 #define OPLOCK_BATCH     2
910 #define OPLOCK_READ      3  /* level 2 oplock */
911
912 /* open response for CreateAction shifted left */
913 #define CIFS_CREATE_ACTION 0x20000 /* file created */
914
915 typedef struct smb_com_open_rsp {
916         struct smb_hdr hdr;     /* wct = 34 BB */
917         __u8 AndXCommand;
918         __u8 AndXReserved;
919         __le16 AndXOffset;
920         __u8 OplockLevel;
921         __u16 Fid;
922         __le32 CreateAction;
923         __le64 CreationTime;
924         __le64 LastAccessTime;
925         __le64 LastWriteTime;
926         __le64 ChangeTime;
927         __le32 FileAttributes;
928         __le64 AllocationSize;
929         __le64 EndOfFile;
930         __le16 FileType;
931         __le16 DeviceState;
932         __u8 DirectoryFlag;
933         __u16 ByteCount;        /* bct = 0 */
934 } __attribute__((packed)) OPEN_RSP;
935
936 typedef struct smb_com_open_rsp_ext {
937         struct smb_hdr hdr;     /* wct = 42 but meaningless due to MS bug? */
938         __u8 AndXCommand;
939         __u8 AndXReserved;
940         __le16 AndXOffset;
941         __u8 OplockLevel;
942         __u16 Fid;
943         __le32 CreateAction;
944         __le64 CreationTime;
945         __le64 LastAccessTime;
946         __le64 LastWriteTime;
947         __le64 ChangeTime;
948         __le32 FileAttributes;
949         __le64 AllocationSize;
950         __le64 EndOfFile;
951         __le16 FileType;
952         __le16 DeviceState;
953         __u8 DirectoryFlag;
954         __u8 VolumeGUID[16];
955         __u64 FileId; /* note no endian conversion - is opaque UniqueID */
956         __le32 MaximalAccessRights;
957         __le32 GuestMaximalAccessRights;
958         __u16 ByteCount;        /* bct = 0 */
959 } __attribute__((packed)) OPEN_RSP_EXT;
960
961
962 /* format of legacy open request */
963 typedef struct smb_com_openx_req {
964         struct smb_hdr  hdr;    /* wct = 15 */
965         __u8 AndXCommand;
966         __u8 AndXReserved;
967         __le16 AndXOffset;
968         __le16 OpenFlags;
969         __le16 Mode;
970         __le16 Sattr; /* search attributes */
971         __le16 FileAttributes;  /* dos attrs */
972         __le32 CreateTime; /* os2 format */
973         __le16 OpenFunction;
974         __le32 EndOfFile;
975         __le32 Timeout;
976         __le32 Reserved;
977         __le16  ByteCount;  /* file name follows */
978         char   fileName[1];
979 } __attribute__((packed)) OPENX_REQ;
980
981 typedef struct smb_com_openx_rsp {
982         struct smb_hdr  hdr;    /* wct = 15 */
983         __u8 AndXCommand;
984         __u8 AndXReserved;
985         __le16 AndXOffset;
986         __u16  Fid;
987         __le16 FileAttributes;
988         __le32 LastWriteTime; /* os2 format */
989         __le32 EndOfFile;
990         __le16 Access;
991         __le16 FileType;
992         __le16 IPCState;
993         __le16 Action;
994         __u32  FileId;
995         __u16  Reserved;
996         __u16  ByteCount;
997 } __attribute__((packed)) OPENX_RSP;
998
999 /* For encoding of POSIX Open Request - see trans2 function 0x209 data struct */
1000
1001 /* Legacy write request for older servers */
1002 typedef struct smb_com_writex_req {
1003         struct smb_hdr hdr;     /* wct = 12 */
1004         __u8 AndXCommand;
1005         __u8 AndXReserved;
1006         __le16 AndXOffset;
1007         __u16 Fid;
1008         __le32 OffsetLow;
1009         __u32 Reserved; /* Timeout */
1010         __le16 WriteMode; /* 1 = write through */
1011         __le16 Remaining;
1012         __le16 Reserved2;
1013         __le16 DataLengthLow;
1014         __le16 DataOffset;
1015         __le16 ByteCount;
1016         __u8 Pad;               /* BB check for whether padded to DWORD
1017                                    boundary and optimum performance here */
1018         char Data[0];
1019 } __attribute__((packed)) WRITEX_REQ;
1020
1021 typedef struct smb_com_write_req {
1022         struct smb_hdr hdr;     /* wct = 14 */
1023         __u8 AndXCommand;
1024         __u8 AndXReserved;
1025         __le16 AndXOffset;
1026         __u16 Fid;
1027         __le32 OffsetLow;
1028         __u32 Reserved;
1029         __le16 WriteMode;
1030         __le16 Remaining;
1031         __le16 DataLengthHigh;
1032         __le16 DataLengthLow;
1033         __le16 DataOffset;
1034         __le32 OffsetHigh;
1035         __le16 ByteCount;
1036         __u8 Pad;               /* BB check for whether padded to DWORD
1037                                    boundary and optimum performance here */
1038         char Data[0];
1039 } __attribute__((packed)) WRITE_REQ;
1040
1041 typedef struct smb_com_write_rsp {
1042         struct smb_hdr hdr;     /* wct = 6 */
1043         __u8 AndXCommand;
1044         __u8 AndXReserved;
1045         __le16 AndXOffset;
1046         __le16 Count;
1047         __le16 Remaining;
1048         __le16 CountHigh;
1049         __u16  Reserved;
1050         __u16 ByteCount;
1051 } __attribute__((packed)) WRITE_RSP;
1052
1053 /* legacy read request for older servers */
1054 typedef struct smb_com_readx_req {
1055         struct smb_hdr hdr;     /* wct = 10 */
1056         __u8 AndXCommand;
1057         __u8 AndXReserved;
1058         __le16 AndXOffset;
1059         __u16 Fid;
1060         __le32 OffsetLow;
1061         __le16 MaxCount;
1062         __le16 MinCount;        /* obsolete */
1063         __le32 Reserved;
1064         __le16 Remaining;
1065         __le16 ByteCount;
1066 } __attribute__((packed)) READX_REQ;
1067
1068 typedef struct smb_com_read_req {
1069         struct smb_hdr hdr;     /* wct = 12 */
1070         __u8 AndXCommand;
1071         __u8 AndXReserved;
1072         __le16 AndXOffset;
1073         __u16 Fid;
1074         __le32 OffsetLow;
1075         __le16 MaxCount;
1076         __le16 MinCount;                /* obsolete */
1077         __le32 MaxCountHigh;
1078         __le16 Remaining;
1079         __le32 OffsetHigh;
1080         __le16 ByteCount;
1081 } __attribute__((packed)) READ_REQ;
1082
1083 typedef struct smb_com_read_rsp {
1084         struct smb_hdr hdr;     /* wct = 12 */
1085         __u8 AndXCommand;
1086         __u8 AndXReserved;
1087         __le16 AndXOffset;
1088         __le16 Remaining;
1089         __le16 DataCompactionMode;
1090         __le16 Reserved;
1091         __le16 DataLength;
1092         __le16 DataOffset;
1093         __le16 DataLengthHigh;
1094         __u64 Reserved2;
1095         __u16 ByteCount;
1096         /* read response data immediately follows */
1097 } __attribute__((packed)) READ_RSP;
1098
1099 typedef struct locking_andx_range {
1100         __le16 Pid;
1101         __le16 Pad;
1102         __le32 OffsetHigh;
1103         __le32 OffsetLow;
1104         __le32 LengthHigh;
1105         __le32 LengthLow;
1106 } __attribute__((packed)) LOCKING_ANDX_RANGE;
1107
1108 #define LOCKING_ANDX_SHARED_LOCK     0x01
1109 #define LOCKING_ANDX_OPLOCK_RELEASE  0x02
1110 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x04
1111 #define LOCKING_ANDX_CANCEL_LOCK     0x08
1112 #define LOCKING_ANDX_LARGE_FILES     0x10       /* always on for us */
1113
1114 typedef struct smb_com_lock_req {
1115         struct smb_hdr hdr;     /* wct = 8 */
1116         __u8 AndXCommand;
1117         __u8 AndXReserved;
1118         __le16 AndXOffset;
1119         __u16 Fid;
1120         __u8 LockType;
1121         __u8 OplockLevel;
1122         __le32 Timeout;
1123         __le16 NumberOfUnlocks;
1124         __le16 NumberOfLocks;
1125         __le16 ByteCount;
1126         LOCKING_ANDX_RANGE Locks[1];
1127 } __attribute__((packed)) LOCK_REQ;
1128
1129 /* lock type */
1130 #define CIFS_RDLCK      0
1131 #define CIFS_WRLCK      1
1132 #define CIFS_UNLCK      2
1133 typedef struct cifs_posix_lock {
1134         __le16  lock_type;  /* 0 = Read, 1 = Write, 2 = Unlock */
1135         __le16  lock_flags; /* 1 = Wait (only valid for setlock) */
1136         __le32  pid;
1137         __le64  start;
1138         __le64  length;
1139         /* BB what about additional owner info to identify network client */
1140 } __attribute__((packed)) CIFS_POSIX_LOCK;
1141
1142 typedef struct smb_com_lock_rsp {
1143         struct smb_hdr hdr;     /* wct = 2 */
1144         __u8 AndXCommand;
1145         __u8 AndXReserved;
1146         __le16 AndXOffset;
1147         __u16 ByteCount;
1148 } __attribute__((packed)) LOCK_RSP;
1149
1150 typedef struct smb_com_rename_req {
1151         struct smb_hdr hdr;     /* wct = 1 */
1152         __le16 SearchAttributes;        /* target file attributes */
1153         __le16 ByteCount;
1154         __u8 BufferFormat;      /* 4 = ASCII or Unicode */
1155         unsigned char OldFileName[1];
1156         /* followed by __u8 BufferFormat2 */
1157         /* followed by NewFileName */
1158 } __attribute__((packed)) RENAME_REQ;
1159
1160         /* copy request flags */
1161 #define COPY_MUST_BE_FILE      0x0001
1162 #define COPY_MUST_BE_DIR       0x0002
1163 #define COPY_TARGET_MODE_ASCII 0x0004 /* if not set, binary */
1164 #define COPY_SOURCE_MODE_ASCII 0x0008 /* if not set, binary */
1165 #define COPY_VERIFY_WRITES     0x0010
1166 #define COPY_TREE              0x0020
1167
1168 typedef struct smb_com_copy_req {
1169         struct smb_hdr hdr;     /* wct = 3 */
1170         __u16 Tid2;
1171         __le16 OpenFunction;
1172         __le16 Flags;
1173         __le16 ByteCount;
1174         __u8 BufferFormat;      /* 4 = ASCII or Unicode */
1175         unsigned char OldFileName[1];
1176         /* followed by __u8 BufferFormat2 */
1177         /* followed by NewFileName string */
1178 } __attribute__((packed)) COPY_REQ;
1179
1180 typedef struct smb_com_copy_rsp {
1181         struct smb_hdr hdr;     /* wct = 1 */
1182         __le16 CopyCount;    /* number of files copied */
1183         __u16 ByteCount;    /* may be zero */
1184         __u8 BufferFormat;  /* 0x04 - only present if errored file follows */
1185         unsigned char ErrorFileName[1]; /* only present if error in copy */
1186 } __attribute__((packed)) COPY_RSP;
1187
1188 #define CREATE_HARD_LINK                0x103
1189 #define MOVEFILE_COPY_ALLOWED           0x0002
1190 #define MOVEFILE_REPLACE_EXISTING       0x0001
1191
1192 typedef struct smb_com_nt_rename_req {  /* A5 - also used for create hardlink */
1193         struct smb_hdr hdr;     /* wct = 4 */
1194         __le16 SearchAttributes;        /* target file attributes */
1195         __le16 Flags;           /* spec says Information Level */
1196         __le32 ClusterCount;
1197         __le16 ByteCount;
1198         __u8 BufferFormat;      /* 4 = ASCII or Unicode */
1199         unsigned char OldFileName[1];
1200         /* followed by __u8 BufferFormat2 */
1201         /* followed by NewFileName */
1202 } __attribute__((packed)) NT_RENAME_REQ;
1203
1204 typedef struct smb_com_rename_rsp {
1205         struct smb_hdr hdr;     /* wct = 0 */
1206         __u16 ByteCount;        /* bct = 0 */
1207 } __attribute__((packed)) RENAME_RSP;
1208
1209 typedef struct smb_com_delete_file_req {
1210         struct smb_hdr hdr;     /* wct = 1 */
1211         __le16 SearchAttributes;
1212         __le16 ByteCount;
1213         __u8 BufferFormat;      /* 4 = ASCII */
1214         unsigned char fileName[1];
1215 } __attribute__((packed)) DELETE_FILE_REQ;
1216
1217 typedef struct smb_com_delete_file_rsp {
1218         struct smb_hdr hdr;     /* wct = 0 */
1219         __u16 ByteCount;        /* bct = 0 */
1220 } __attribute__((packed)) DELETE_FILE_RSP;
1221
1222 typedef struct smb_com_delete_directory_req {
1223         struct smb_hdr hdr;     /* wct = 0 */
1224         __le16 ByteCount;
1225         __u8 BufferFormat;      /* 4 = ASCII */
1226         unsigned char DirName[1];
1227 } __attribute__((packed)) DELETE_DIRECTORY_REQ;
1228
1229 typedef struct smb_com_delete_directory_rsp {
1230         struct smb_hdr hdr;     /* wct = 0 */
1231         __u16 ByteCount;        /* bct = 0 */
1232 } __attribute__((packed)) DELETE_DIRECTORY_RSP;
1233
1234 typedef struct smb_com_create_directory_req {
1235         struct smb_hdr hdr;     /* wct = 0 */
1236         __le16 ByteCount;
1237         __u8 BufferFormat;      /* 4 = ASCII */
1238         unsigned char DirName[1];
1239 } __attribute__((packed)) CREATE_DIRECTORY_REQ;
1240
1241 typedef struct smb_com_create_directory_rsp {
1242         struct smb_hdr hdr;     /* wct = 0 */
1243         __u16 ByteCount;        /* bct = 0 */
1244 } __attribute__((packed)) CREATE_DIRECTORY_RSP;
1245
1246 typedef struct smb_com_query_information_req {
1247         struct smb_hdr hdr;     /* wct = 0 */
1248         __le16 ByteCount;       /* 1 + namelen + 1 */
1249         __u8 BufferFormat;      /* 4 = ASCII */
1250         unsigned char FileName[1];
1251 } __attribute__((packed)) QUERY_INFORMATION_REQ;
1252
1253 typedef struct smb_com_query_information_rsp {
1254         struct smb_hdr hdr;     /* wct = 10 */
1255         __le16 attr;
1256         __le32  last_write_time;
1257         __le32 size;
1258         __u16  reserved[5];
1259         __le16 ByteCount;       /* bcc = 0 */
1260 } __attribute__((packed)) QUERY_INFORMATION_RSP;
1261
1262 typedef struct smb_com_setattr_req {
1263         struct smb_hdr hdr; /* wct = 8 */
1264         __le16 attr;
1265         __le16 time_low;
1266         __le16 time_high;
1267         __le16 reserved[5]; /* must be zero */
1268         __u16  ByteCount;
1269         __u8   BufferFormat; /* 4 = ASCII */
1270         unsigned char fileName[1];
1271 } __attribute__((packed)) SETATTR_REQ;
1272
1273 typedef struct smb_com_setattr_rsp {
1274         struct smb_hdr hdr;     /* wct = 0 */
1275         __u16 ByteCount;        /* bct = 0 */
1276 } __attribute__((packed)) SETATTR_RSP;
1277
1278 /* empty wct response to setattr */
1279
1280 /*******************************************************/
1281 /* NT Transact structure definitions follow            */
1282 /* Currently only ioctl, acl (get security descriptor) */
1283 /* and notify are implemented                          */
1284 /*******************************************************/
1285 typedef struct smb_com_ntransact_req {
1286         struct smb_hdr hdr; /* wct >= 19 */
1287         __u8 MaxSetupCount;
1288         __u16 Reserved;
1289         __le32 TotalParameterCount;
1290         __le32 TotalDataCount;
1291         __le32 MaxParameterCount;
1292         __le32 MaxDataCount;
1293         __le32 ParameterCount;
1294         __le32 ParameterOffset;
1295         __le32 DataCount;
1296         __le32 DataOffset;
1297         __u8 SetupCount; /* four setup words follow subcommand */
1298         /* SNIA spec incorrectly included spurious pad here */
1299         __le16 SubCommand; /* 2 = IOCTL/FSCTL */
1300         /* SetupCount words follow then */
1301         __le16 ByteCount;
1302         __u8 Pad[3];
1303         __u8 Parms[0];
1304 } __attribute__((packed)) NTRANSACT_REQ;
1305
1306 typedef struct smb_com_ntransact_rsp {
1307         struct smb_hdr hdr;     /* wct = 18 */
1308         __u8 Reserved[3];
1309         __le32 TotalParameterCount;
1310         __le32 TotalDataCount;
1311         __le32 ParameterCount;
1312         __le32 ParameterOffset;
1313         __le32 ParameterDisplacement;
1314         __le32 DataCount;
1315         __le32 DataOffset;
1316         __le32 DataDisplacement;
1317         __u8 SetupCount;   /* 0 */
1318         __u16 ByteCount;
1319         /* __u8 Pad[3]; */
1320         /* parms and data follow */
1321 } __attribute__((packed)) NTRANSACT_RSP;
1322
1323 /* See MS-SMB 2.2.7.2.1.1 */
1324 struct srv_copychunk {
1325         __le64 SourceOffset;
1326         __le64 DestinationOffset;
1327         __le32 CopyLength;
1328         __u32  Reserved;
1329 } __packed;
1330
1331 typedef struct smb_com_transaction_ioctl_req {
1332         struct smb_hdr hdr;     /* wct = 23 */
1333         __u8 MaxSetupCount;
1334         __u16 Reserved;
1335         __le32 TotalParameterCount;
1336         __le32 TotalDataCount;
1337         __le32 MaxParameterCount;
1338         __le32 MaxDataCount;
1339         __le32 ParameterCount;
1340         __le32 ParameterOffset;
1341         __le32 DataCount;
1342         __le32 DataOffset;
1343         __u8 SetupCount; /* four setup words follow subcommand */
1344         /* SNIA spec incorrectly included spurious pad here */
1345         __le16 SubCommand; /* 2 = IOCTL/FSCTL */
1346         __le32 FunctionCode;
1347         __u16 Fid;
1348         __u8 IsFsctl;  /* 1 = File System Control 0 = device control (IOCTL) */
1349         __u8 IsRootFlag; /* 1 = apply command to root of share (must be DFS) */
1350         __le16 ByteCount;
1351         __u8 Pad[3];
1352         __u8 Data[1];
1353 } __attribute__((packed)) TRANSACT_IOCTL_REQ;
1354
1355 typedef struct smb_com_transaction_compr_ioctl_req {
1356         struct smb_hdr hdr;     /* wct = 23 */
1357         __u8 MaxSetupCount;
1358         __u16 Reserved;
1359         __le32 TotalParameterCount;
1360         __le32 TotalDataCount;
1361         __le32 MaxParameterCount;
1362         __le32 MaxDataCount;
1363         __le32 ParameterCount;
1364         __le32 ParameterOffset;
1365         __le32 DataCount;
1366         __le32 DataOffset;
1367         __u8 SetupCount; /* four setup words follow subcommand */
1368         /* SNIA spec incorrectly included spurious pad here */
1369         __le16 SubCommand; /* 2 = IOCTL/FSCTL */
1370         __le32 FunctionCode;
1371         __u16 Fid;
1372         __u8 IsFsctl;  /* 1 = File System Control 0 = device control (IOCTL) */
1373         __u8 IsRootFlag; /* 1 = apply command to root of share (must be DFS) */
1374         __le16 ByteCount;
1375         __u8 Pad[3];
1376         __le16 compression_state;  /* See below for valid flags */
1377 } __attribute__((packed)) TRANSACT_COMPR_IOCTL_REQ;
1378
1379 /* compression state flags */
1380 #define COMPRESSION_FORMAT_NONE         0x0000
1381 #define COMPRESSION_FORMAT_DEFAULT      0x0001
1382 #define COMPRESSION_FORMAT_LZNT1        0x0002
1383
1384 typedef struct smb_com_transaction_ioctl_rsp {
1385         struct smb_hdr hdr;     /* wct = 19 */
1386         __u8 Reserved[3];
1387         __le32 TotalParameterCount;
1388         __le32 TotalDataCount;
1389         __le32 ParameterCount;
1390         __le32 ParameterOffset;
1391         __le32 ParameterDisplacement;
1392         __le32 DataCount;
1393         __le32 DataOffset;
1394         __le32 DataDisplacement;
1395         __u8 SetupCount;        /* 1 */
1396         __le16 ReturnedDataLen;
1397         __u16 ByteCount;
1398 } __attribute__((packed)) TRANSACT_IOCTL_RSP;
1399
1400 #define CIFS_ACL_OWNER 1
1401 #define CIFS_ACL_GROUP 2
1402 #define CIFS_ACL_DACL  4
1403 #define CIFS_ACL_SACL  8
1404
1405 typedef struct smb_com_transaction_qsec_req {
1406         struct smb_hdr hdr;     /* wct = 19 */
1407         __u8 MaxSetupCount;
1408         __u16 Reserved;
1409         __le32 TotalParameterCount;
1410         __le32 TotalDataCount;
1411         __le32 MaxParameterCount;
1412         __le32 MaxDataCount;
1413         __le32 ParameterCount;
1414         __le32 ParameterOffset;
1415         __le32 DataCount;
1416         __le32 DataOffset;
1417         __u8 SetupCount; /* no setup words follow subcommand */
1418         /* SNIA spec incorrectly included spurious pad here */
1419         __le16 SubCommand; /* 6 = QUERY_SECURITY_DESC */
1420         __le16 ByteCount; /* bcc = 3 + 8 */
1421         __u8 Pad[3];
1422         __u16 Fid;
1423         __u16 Reserved2;
1424         __le32 AclFlags;
1425 } __attribute__((packed)) QUERY_SEC_DESC_REQ;
1426
1427
1428 typedef struct smb_com_transaction_ssec_req {
1429         struct smb_hdr hdr;     /* wct = 19 */
1430         __u8 MaxSetupCount;
1431         __u16 Reserved;
1432         __le32 TotalParameterCount;
1433         __le32 TotalDataCount;
1434         __le32 MaxParameterCount;
1435         __le32 MaxDataCount;
1436         __le32 ParameterCount;
1437         __le32 ParameterOffset;
1438         __le32 DataCount;
1439         __le32 DataOffset;
1440         __u8 SetupCount; /* no setup words follow subcommand */
1441         /* SNIA spec incorrectly included spurious pad here */
1442         __le16 SubCommand; /* 3 = SET_SECURITY_DESC */
1443         __le16 ByteCount; /* bcc = 3 + 8 */
1444         __u8 Pad[3];
1445         __u16 Fid;
1446         __u16 Reserved2;
1447         __le32 AclFlags;
1448 } __attribute__((packed)) SET_SEC_DESC_REQ;
1449
1450 typedef struct smb_com_transaction_change_notify_req {
1451         struct smb_hdr hdr;     /* wct = 23 */
1452         __u8 MaxSetupCount;
1453         __u16 Reserved;
1454         __le32 TotalParameterCount;
1455         __le32 TotalDataCount;
1456         __le32 MaxParameterCount;
1457         __le32 MaxDataCount;
1458         __le32 ParameterCount;
1459         __le32 ParameterOffset;
1460         __le32 DataCount;
1461         __le32 DataOffset;
1462         __u8 SetupCount; /* four setup words follow subcommand */
1463         /* SNIA spec incorrectly included spurious pad here */
1464         __le16 SubCommand;/* 4 = Change Notify */
1465         __le32 CompletionFilter;  /* operation to monitor */
1466         __u16 Fid;
1467         __u8 WatchTree;  /* 1 = Monitor subdirectories */
1468         __u8 Reserved2;
1469         __le16 ByteCount;
1470 /*      __u8 Pad[3];*/
1471 /*      __u8 Data[1];*/
1472 } __attribute__((packed)) TRANSACT_CHANGE_NOTIFY_REQ;
1473
1474 /* BB eventually change to use generic ntransact rsp struct
1475       and validation routine */
1476 typedef struct smb_com_transaction_change_notify_rsp {
1477         struct smb_hdr hdr;     /* wct = 18 */
1478         __u8 Reserved[3];
1479         __le32 TotalParameterCount;
1480         __le32 TotalDataCount;
1481         __le32 ParameterCount;
1482         __le32 ParameterOffset;
1483         __le32 ParameterDisplacement;
1484         __le32 DataCount;
1485         __le32 DataOffset;
1486         __le32 DataDisplacement;
1487         __u8 SetupCount;   /* 0 */
1488         __u16 ByteCount;
1489         /* __u8 Pad[3]; */
1490 } __attribute__((packed)) TRANSACT_CHANGE_NOTIFY_RSP;
1491 /* Completion Filter flags for Notify */
1492 #define FILE_NOTIFY_CHANGE_FILE_NAME    0x00000001
1493 #define FILE_NOTIFY_CHANGE_DIR_NAME     0x00000002
1494 #define FILE_NOTIFY_CHANGE_NAME         0x00000003
1495 #define FILE_NOTIFY_CHANGE_ATTRIBUTES   0x00000004
1496 #define FILE_NOTIFY_CHANGE_SIZE         0x00000008
1497 #define FILE_NOTIFY_CHANGE_LAST_WRITE   0x00000010
1498 #define FILE_NOTIFY_CHANGE_LAST_ACCESS  0x00000020
1499 #define FILE_NOTIFY_CHANGE_CREATION     0x00000040
1500 #define FILE_NOTIFY_CHANGE_EA           0x00000080
1501 #define FILE_NOTIFY_CHANGE_SECURITY     0x00000100
1502 #define FILE_NOTIFY_CHANGE_STREAM_NAME  0x00000200
1503 #define FILE_NOTIFY_CHANGE_STREAM_SIZE  0x00000400
1504 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
1505
1506 #define FILE_ACTION_ADDED               0x00000001
1507 #define FILE_ACTION_REMOVED             0x00000002
1508 #define FILE_ACTION_MODIFIED            0x00000003
1509 #define FILE_ACTION_RENAMED_OLD_NAME    0x00000004
1510 #define FILE_ACTION_RENAMED_NEW_NAME    0x00000005
1511 #define FILE_ACTION_ADDED_STREAM        0x00000006
1512 #define FILE_ACTION_REMOVED_STREAM      0x00000007
1513 #define FILE_ACTION_MODIFIED_STREAM     0x00000008
1514
1515 /* response contains array of the following structures */
1516 struct file_notify_information {
1517         __le32 NextEntryOffset;
1518         __le32 Action;
1519         __le32 FileNameLength;
1520         __u8  FileName[0];
1521 } __attribute__((packed));
1522
1523 /* For IO_REPARSE_TAG_SYMLINK */
1524 struct reparse_symlink_data {
1525         __le32  ReparseTag;
1526         __le16  ReparseDataLength;
1527         __u16   Reserved;
1528         __le16  SubstituteNameOffset;
1529         __le16  SubstituteNameLength;
1530         __le16  PrintNameOffset;
1531         __le16  PrintNameLength;
1532         __le32  Flags;
1533         char    PathBuffer[0];
1534 } __attribute__((packed));
1535
1536 /* For IO_REPARSE_TAG_NFS */
1537 #define NFS_SPECFILE_LNK        0x00000000014B4E4C
1538 #define NFS_SPECFILE_CHR        0x0000000000524843
1539 #define NFS_SPECFILE_BLK        0x00000000004B4C42
1540 #define NFS_SPECFILE_FIFO       0x000000004F464946
1541 #define NFS_SPECFILE_SOCK       0x000000004B434F53
1542 struct reparse_posix_data {
1543         __le32  ReparseTag;
1544         __le16  ReparseDataLength;
1545         __u16   Reserved;
1546         __le64  InodeType; /* LNK, FIFO, CHR etc. */
1547         char    PathBuffer[0];
1548 } __attribute__((packed));
1549
1550 struct cifs_quota_data {
1551         __u32   rsrvd1;  /* 0 */
1552         __u32   sid_size;
1553         __u64   rsrvd2;  /* 0 */
1554         __u64   space_used;
1555         __u64   soft_limit;
1556         __u64   hard_limit;
1557         char    sid[1];  /* variable size? */
1558 } __attribute__((packed));
1559
1560 /* quota sub commands */
1561 #define QUOTA_LIST_CONTINUE         0
1562 #define QUOTA_LIST_START        0x100
1563 #define QUOTA_FOR_SID           0x101
1564
1565 struct trans2_req {
1566         /* struct smb_hdr hdr precedes. Set wct = 14+ */
1567         __le16 TotalParameterCount;
1568         __le16 TotalDataCount;
1569         __le16 MaxParameterCount;
1570         __le16 MaxDataCount;
1571         __u8 MaxSetupCount;
1572         __u8 Reserved;
1573         __le16 Flags;
1574         __le32 Timeout;
1575         __u16 Reserved2;
1576         __le16 ParameterCount;
1577         __le16 ParameterOffset;
1578         __le16 DataCount;
1579         __le16 DataOffset;
1580         __u8 SetupCount;
1581         __u8 Reserved3;
1582         __le16 SubCommand; /* 1st setup word - SetupCount words follow */
1583         __le16 ByteCount;
1584 } __attribute__((packed));
1585
1586 struct smb_t2_req {
1587         struct smb_hdr hdr;
1588         struct trans2_req t2_req;
1589 } __attribute__((packed));
1590
1591 struct trans2_resp {
1592         /* struct smb_hdr hdr precedes. Note wct = 10 + setup count */
1593         __le16 TotalParameterCount;
1594         __le16 TotalDataCount;
1595         __u16 Reserved;
1596         __le16 ParameterCount;
1597         __le16 ParameterOffset;
1598         __le16 ParameterDisplacement;
1599         __le16 DataCount;
1600         __le16 DataOffset;
1601         __le16 DataDisplacement;
1602         __u8 SetupCount;
1603         __u8 Reserved1;
1604         /* SetupWords[SetupCount];
1605         __u16 ByteCount;
1606         __u16 Reserved2;*/
1607         /* data area follows */
1608 } __attribute__((packed));
1609
1610 struct smb_t2_rsp {
1611         struct smb_hdr hdr;
1612         struct trans2_resp t2_rsp;
1613 } __attribute__((packed));
1614
1615 /* PathInfo/FileInfo infolevels */
1616 #define SMB_INFO_STANDARD                   1
1617 #define SMB_SET_FILE_EA                     2
1618 #define SMB_QUERY_FILE_EA_SIZE              2
1619 #define SMB_INFO_QUERY_EAS_FROM_LIST        3
1620 #define SMB_INFO_QUERY_ALL_EAS              4
1621 #define SMB_INFO_IS_NAME_VALID              6
1622 #define SMB_QUERY_FILE_BASIC_INFO       0x101
1623 #define SMB_QUERY_FILE_STANDARD_INFO    0x102
1624 #define SMB_QUERY_FILE_EA_INFO          0x103
1625 #define SMB_QUERY_FILE_NAME_INFO        0x104
1626 #define SMB_QUERY_FILE_ALLOCATION_INFO  0x105
1627 #define SMB_QUERY_FILE_END_OF_FILEINFO  0x106
1628 #define SMB_QUERY_FILE_ALL_INFO         0x107
1629 #define SMB_QUERY_ALT_NAME_INFO         0x108
1630 #define SMB_QUERY_FILE_STREAM_INFO      0x109
1631 #define SMB_QUERY_FILE_COMPRESSION_INFO 0x10B
1632 #define SMB_QUERY_FILE_UNIX_BASIC       0x200
1633 #define SMB_QUERY_FILE_UNIX_LINK        0x201
1634 #define SMB_QUERY_POSIX_ACL             0x204
1635 #define SMB_QUERY_XATTR                 0x205  /* e.g. system EA name space */
1636 #define SMB_QUERY_ATTR_FLAGS            0x206  /* append,immutable etc. */
1637 #define SMB_QUERY_POSIX_PERMISSION      0x207
1638 #define SMB_QUERY_POSIX_LOCK            0x208
1639 /* #define SMB_POSIX_OPEN               0x209 */
1640 /* #define SMB_POSIX_UNLINK             0x20a */
1641 #define SMB_QUERY_FILE__UNIX_INFO2      0x20b
1642 #define SMB_QUERY_FILE_INTERNAL_INFO    0x3ee
1643 #define SMB_QUERY_FILE_ACCESS_INFO      0x3f0
1644 #define SMB_QUERY_FILE_NAME_INFO2       0x3f1 /* 0x30 bytes */
1645 #define SMB_QUERY_FILE_POSITION_INFO    0x3f6
1646 #define SMB_QUERY_FILE_MODE_INFO        0x3f8
1647 #define SMB_QUERY_FILE_ALGN_INFO        0x3f9
1648
1649
1650 #define SMB_SET_FILE_BASIC_INFO         0x101
1651 #define SMB_SET_FILE_DISPOSITION_INFO   0x102
1652 #define SMB_SET_FILE_ALLOCATION_INFO    0x103
1653 #define SMB_SET_FILE_END_OF_FILE_INFO   0x104
1654 #define SMB_SET_FILE_UNIX_BASIC         0x200
1655 #define SMB_SET_FILE_UNIX_LINK          0x201
1656 #define SMB_SET_FILE_UNIX_HLINK         0x203
1657 #define SMB_SET_POSIX_ACL               0x204
1658 #define SMB_SET_XATTR                   0x205
1659 #define SMB_SET_ATTR_FLAGS              0x206  /* append, immutable etc. */
1660 #define SMB_SET_POSIX_LOCK              0x208
1661 #define SMB_POSIX_OPEN                  0x209
1662 #define SMB_POSIX_UNLINK                0x20a
1663 #define SMB_SET_FILE_UNIX_INFO2         0x20b
1664 #define SMB_SET_FILE_BASIC_INFO2        0x3ec
1665 #define SMB_SET_FILE_RENAME_INFORMATION 0x3f2 /* BB check if qpathinfo too */
1666 #define SMB_FILE_ALL_INFO2              0x3fa
1667 #define SMB_SET_FILE_ALLOCATION_INFO2   0x3fb
1668 #define SMB_SET_FILE_END_OF_FILE_INFO2  0x3fc
1669 #define SMB_FILE_MOVE_CLUSTER_INFO      0x407
1670 #define SMB_FILE_QUOTA_INFO             0x408
1671 #define SMB_FILE_REPARSEPOINT_INFO      0x409
1672 #define SMB_FILE_MAXIMUM_INFO           0x40d
1673
1674 /* Find File infolevels */
1675 #define SMB_FIND_FILE_INFO_STANDARD       0x001
1676 #define SMB_FIND_FILE_QUERY_EA_SIZE       0x002
1677 #define SMB_FIND_FILE_QUERY_EAS_FROM_LIST 0x003
1678 #define SMB_FIND_FILE_DIRECTORY_INFO      0x101
1679 #define SMB_FIND_FILE_FULL_DIRECTORY_INFO 0x102
1680 #define SMB_FIND_FILE_NAMES_INFO          0x103
1681 #define SMB_FIND_FILE_BOTH_DIRECTORY_INFO 0x104
1682 #define SMB_FIND_FILE_ID_FULL_DIR_INFO    0x105
1683 #define SMB_FIND_FILE_ID_BOTH_DIR_INFO    0x106
1684 #define SMB_FIND_FILE_UNIX                0x202
1685
1686 typedef struct smb_com_transaction2_qpi_req {
1687         struct smb_hdr hdr;     /* wct = 14+ */
1688         __le16 TotalParameterCount;
1689         __le16 TotalDataCount;
1690         __le16 MaxParameterCount;
1691         __le16 MaxDataCount;
1692         __u8 MaxSetupCount;
1693         __u8 Reserved;
1694         __le16 Flags;
1695         __le32 Timeout;
1696         __u16 Reserved2;
1697         __le16 ParameterCount;
1698         __le16 ParameterOffset;
1699         __le16 DataCount;
1700         __le16 DataOffset;
1701         __u8 SetupCount;
1702         __u8 Reserved3;
1703         __le16 SubCommand;      /* one setup word */
1704         __le16 ByteCount;
1705         __u8 Pad;
1706         __le16 InformationLevel;
1707         __u32 Reserved4;
1708         char FileName[1];
1709 } __attribute__((packed)) TRANSACTION2_QPI_REQ;
1710
1711 typedef struct smb_com_transaction2_qpi_rsp {
1712         struct smb_hdr hdr;     /* wct = 10 + SetupCount */
1713         struct trans2_resp t2;
1714         __u16 ByteCount;
1715         __u16 Reserved2; /* parameter word is present for infolevels > 100 */
1716 } __attribute__((packed)) TRANSACTION2_QPI_RSP;
1717
1718 typedef struct smb_com_transaction2_spi_req {
1719         struct smb_hdr hdr;     /* wct = 15 */
1720         __le16 TotalParameterCount;
1721         __le16 TotalDataCount;
1722         __le16 MaxParameterCount;
1723         __le16 MaxDataCount;
1724         __u8 MaxSetupCount;
1725         __u8 Reserved;
1726         __le16 Flags;
1727         __le32 Timeout;
1728         __u16 Reserved2;
1729         __le16 ParameterCount;
1730         __le16 ParameterOffset;
1731         __le16 DataCount;
1732         __le16 DataOffset;
1733         __u8 SetupCount;
1734         __u8 Reserved3;
1735         __le16 SubCommand;      /* one setup word */
1736         __le16 ByteCount;
1737         __u8 Pad;
1738         __u16 Pad1;
1739         __le16 InformationLevel;
1740         __u32 Reserved4;
1741         char FileName[1];
1742 } __attribute__((packed)) TRANSACTION2_SPI_REQ;
1743
1744 typedef struct smb_com_transaction2_spi_rsp {
1745         struct smb_hdr hdr;     /* wct = 10 + SetupCount */
1746         struct trans2_resp t2;
1747         __u16 ByteCount;
1748         __u16 Reserved2; /* parameter word is present for infolevels > 100 */
1749 } __attribute__((packed)) TRANSACTION2_SPI_RSP;
1750
1751 struct set_file_rename {
1752         __le32 overwrite;   /* 1 = overwrite dest */
1753         __u32 root_fid;   /* zero */
1754         __le32 target_name_len;
1755         char  target_name[0];  /* Must be unicode */
1756 } __attribute__((packed));
1757
1758 struct smb_com_transaction2_sfi_req {
1759         struct smb_hdr hdr;     /* wct = 15 */
1760         __le16 TotalParameterCount;
1761         __le16 TotalDataCount;
1762         __le16 MaxParameterCount;
1763         __le16 MaxDataCount;
1764         __u8 MaxSetupCount;
1765         __u8 Reserved;
1766         __le16 Flags;
1767         __le32 Timeout;
1768         __u16 Reserved2;
1769         __le16 ParameterCount;
1770         __le16 ParameterOffset;
1771         __le16 DataCount;
1772         __le16 DataOffset;
1773         __u8 SetupCount;
1774         __u8 Reserved3;
1775         __le16 SubCommand;      /* one setup word */
1776         __le16 ByteCount;
1777         __u8 Pad;
1778         __u16 Pad1;
1779         __u16 Fid;
1780         __le16 InformationLevel;
1781         __u16 Reserved4;
1782 } __attribute__((packed));
1783
1784 struct smb_com_transaction2_sfi_rsp {
1785         struct smb_hdr hdr;     /* wct = 10 + SetupCount */
1786         struct trans2_resp t2;
1787         __u16 ByteCount;
1788         __u16 Reserved2;        /* parameter word reserved -
1789                                         present for infolevels > 100 */
1790 } __attribute__((packed));
1791
1792 struct smb_t2_qfi_req {
1793         struct  smb_hdr hdr;
1794         struct  trans2_req t2;
1795         __u8    Pad;
1796         __u16   Fid;
1797         __le16  InformationLevel;
1798 } __attribute__((packed));
1799
1800 struct smb_t2_qfi_rsp {
1801         struct smb_hdr hdr;     /* wct = 10 + SetupCount */
1802         struct trans2_resp t2;
1803         __u16 ByteCount;
1804         __u16 Reserved2;        /* parameter word reserved -
1805                                    present for infolevels > 100 */
1806 } __attribute__((packed));
1807
1808 /*
1809  * Flags on T2 FINDFIRST and FINDNEXT
1810  */
1811 #define CIFS_SEARCH_CLOSE_ALWAYS  0x0001
1812 #define CIFS_SEARCH_CLOSE_AT_END  0x0002
1813 #define CIFS_SEARCH_RETURN_RESUME 0x0004
1814 #define CIFS_SEARCH_CONTINUE_FROM_LAST 0x0008
1815 #define CIFS_SEARCH_BACKUP_SEARCH 0x0010
1816
1817 /*
1818  * Size of the resume key on FINDFIRST and FINDNEXT calls
1819  */
1820 #define CIFS_SMB_RESUME_KEY_SIZE 4
1821
1822 typedef struct smb_com_transaction2_ffirst_req {
1823         struct smb_hdr hdr;     /* wct = 15 */
1824         __le16 TotalParameterCount;
1825         __le16 TotalDataCount;
1826         __le16 MaxParameterCount;
1827         __le16 MaxDataCount;
1828         __u8 MaxSetupCount;
1829         __u8 Reserved;
1830         __le16 Flags;
1831         __le32 Timeout;
1832         __u16 Reserved2;
1833         __le16 ParameterCount;
1834         __le16 ParameterOffset;
1835         __le16 DataCount;
1836         __le16 DataOffset;
1837         __u8 SetupCount;        /* one */
1838         __u8 Reserved3;
1839         __le16 SubCommand;      /* TRANS2_FIND_FIRST */
1840         __le16 ByteCount;
1841         __u8 Pad;
1842         __le16 SearchAttributes;
1843         __le16 SearchCount;
1844         __le16 SearchFlags;
1845         __le16 InformationLevel;
1846         __le32 SearchStorageType;
1847         char FileName[1];
1848 } __attribute__((packed)) TRANSACTION2_FFIRST_REQ;
1849
1850 typedef struct smb_com_transaction2_ffirst_rsp {
1851         struct smb_hdr hdr;     /* wct = 10 */
1852         struct trans2_resp t2;
1853         __u16 ByteCount;
1854 } __attribute__((packed)) TRANSACTION2_FFIRST_RSP;
1855
1856 typedef struct smb_com_transaction2_ffirst_rsp_parms {
1857         __u16 SearchHandle;
1858         __le16 SearchCount;
1859         __le16 EndofSearch;
1860         __le16 EAErrorOffset;
1861         __le16 LastNameOffset;
1862 } __attribute__((packed)) T2_FFIRST_RSP_PARMS;
1863
1864 typedef struct smb_com_transaction2_fnext_req {
1865         struct smb_hdr hdr;     /* wct = 15 */
1866         __le16 TotalParameterCount;
1867         __le16 TotalDataCount;
1868         __le16 MaxParameterCount;
1869         __le16 MaxDataCount;
1870         __u8 MaxSetupCount;
1871         __u8 Reserved;
1872         __le16 Flags;
1873         __le32 Timeout;
1874         __u16 Reserved2;
1875         __le16 ParameterCount;
1876         __le16 ParameterOffset;
1877         __le16 DataCount;
1878         __le16 DataOffset;
1879         __u8 SetupCount;        /* one */
1880         __u8 Reserved3;
1881         __le16 SubCommand;      /* TRANS2_FIND_NEXT */
1882         __le16 ByteCount;
1883         __u8 Pad;
1884         __u16 SearchHandle;
1885         __le16 SearchCount;
1886         __le16 InformationLevel;
1887         __u32 ResumeKey;
1888         __le16 SearchFlags;
1889         char ResumeFileName[1];
1890 } __attribute__((packed)) TRANSACTION2_FNEXT_REQ;
1891
1892 typedef struct smb_com_transaction2_fnext_rsp {
1893         struct smb_hdr hdr;     /* wct = 10 */
1894         struct trans2_resp t2;
1895         __u16 ByteCount;
1896 } __attribute__((packed)) TRANSACTION2_FNEXT_RSP;
1897
1898 typedef struct smb_com_transaction2_fnext_rsp_parms {
1899         __le16 SearchCount;
1900         __le16 EndofSearch;
1901         __le16 EAErrorOffset;
1902         __le16 LastNameOffset;
1903 } __attribute__((packed)) T2_FNEXT_RSP_PARMS;
1904
1905 /* QFSInfo Levels */
1906 #define SMB_INFO_ALLOCATION         1
1907 #define SMB_INFO_VOLUME             2
1908 #define SMB_QUERY_FS_VOLUME_INFO    0x102
1909 #define SMB_QUERY_FS_SIZE_INFO      0x103
1910 #define SMB_QUERY_FS_DEVICE_INFO    0x104
1911 #define SMB_QUERY_FS_ATTRIBUTE_INFO 0x105
1912 #define SMB_QUERY_CIFS_UNIX_INFO    0x200
1913 #define SMB_QUERY_POSIX_FS_INFO     0x201
1914 #define SMB_QUERY_POSIX_WHO_AM_I    0x202
1915 #define SMB_REQUEST_TRANSPORT_ENCRYPTION 0x203
1916 #define SMB_QUERY_FS_PROXY          0x204 /* WAFS enabled. Returns structure
1917                                             FILE_SYSTEM__UNIX_INFO to tell
1918                                             whether new NTIOCTL available
1919                                             (0xACE) for WAN friendly SMB
1920                                             operations to be carried */
1921 #define SMB_QUERY_LABEL_INFO        0x3ea
1922 #define SMB_QUERY_FS_QUOTA_INFO     0x3ee
1923 #define SMB_QUERY_FS_FULL_SIZE_INFO 0x3ef
1924 #define SMB_QUERY_OBJECTID_INFO     0x3f0
1925
1926 typedef struct smb_com_transaction2_qfsi_req {
1927         struct smb_hdr hdr;     /* wct = 14+ */
1928         __le16 TotalParameterCount;
1929         __le16 TotalDataCount;
1930         __le16 MaxParameterCount;
1931         __le16 MaxDataCount;
1932         __u8 MaxSetupCount;
1933         __u8 Reserved;
1934         __le16 Flags;
1935         __le32 Timeout;
1936         __u16 Reserved2;
1937         __le16 ParameterCount;
1938         __le16 ParameterOffset;
1939         __le16 DataCount;
1940         __le16 DataOffset;
1941         __u8 SetupCount;
1942         __u8 Reserved3;
1943         __le16 SubCommand;      /* one setup word */
1944         __le16 ByteCount;
1945         __u8 Pad;
1946         __le16 InformationLevel;
1947 } __attribute__((packed)) TRANSACTION2_QFSI_REQ;
1948
1949 typedef struct smb_com_transaction_qfsi_rsp {
1950         struct smb_hdr hdr;     /* wct = 10 + SetupCount */
1951         struct trans2_resp t2;
1952         __u16 ByteCount;
1953         __u8 Pad;       /* may be three bytes? *//* followed by data area */
1954 } __attribute__((packed)) TRANSACTION2_QFSI_RSP;
1955
1956 typedef struct whoami_rsp_data { /* Query level 0x202 */
1957         __u32 flags; /* 0 = Authenticated user 1 = GUEST */
1958         __u32 mask; /* which flags bits server understands ie 0x0001 */
1959         __u64 unix_user_id;
1960         __u64 unix_user_gid;
1961         __u32 number_of_supplementary_gids; /* may be zero */
1962         __u32 number_of_sids; /* may be zero */
1963         __u32 length_of_sid_array; /* in bytes - may be zero */
1964         __u32 pad; /* reserved - MBZ */
1965         /* __u64 gid_array[0]; */  /* may be empty */
1966         /* __u8 * psid_list */  /* may be empty */
1967 } __attribute__((packed)) WHOAMI_RSP_DATA;
1968
1969 /* SETFSInfo Levels */
1970 #define SMB_SET_CIFS_UNIX_INFO    0x200
1971 /* level 0x203 is defined above in list of QFS info levels */
1972 /* #define SMB_REQUEST_TRANSPORT_ENCRYPTION 0x203 */
1973
1974 /* Level 0x200 request structure follows */
1975 typedef struct smb_com_transaction2_setfsi_req {
1976         struct smb_hdr hdr;     /* wct = 15 */
1977         __le16 TotalParameterCount;
1978         __le16 TotalDataCount;
1979         __le16 MaxParameterCount;
1980         __le16 MaxDataCount;
1981         __u8 MaxSetupCount;
1982         __u8 Reserved;
1983         __le16 Flags;
1984         __le32 Timeout;
1985         __u16 Reserved2;
1986         __le16 ParameterCount;  /* 4 */
1987         __le16 ParameterOffset;
1988         __le16 DataCount;       /* 12 */
1989         __le16 DataOffset;
1990         __u8 SetupCount;        /* one */
1991         __u8 Reserved3;
1992         __le16 SubCommand;      /* TRANS2_SET_FS_INFORMATION */
1993         __le16 ByteCount;
1994         __u8 Pad;
1995         __u16 FileNum;          /* Parameters start. */
1996         __le16 InformationLevel;/* Parameters end. */
1997         __le16 ClientUnixMajor; /* Data start. */
1998         __le16 ClientUnixMinor;
1999         __le64 ClientUnixCap;   /* Data end */
2000 } __attribute__((packed)) TRANSACTION2_SETFSI_REQ;
2001
2002 /* level 0x203 request structure follows */
2003 typedef struct smb_com_transaction2_setfs_enc_req {
2004         struct smb_hdr hdr;     /* wct = 15 */
2005         __le16 TotalParameterCount;
2006         __le16 TotalDataCount;
2007         __le16 MaxParameterCount;
2008         __le16 MaxDataCount;
2009         __u8 MaxSetupCount;
2010         __u8 Reserved;
2011         __le16 Flags;
2012         __le32 Timeout;
2013         __u16 Reserved2;
2014         __le16 ParameterCount;  /* 4 */
2015         __le16 ParameterOffset;
2016         __le16 DataCount;       /* 12 */
2017         __le16 DataOffset;
2018         __u8 SetupCount;        /* one */
2019         __u8 Reserved3;
2020         __le16 SubCommand;      /* TRANS2_SET_FS_INFORMATION */
2021         __le16 ByteCount;
2022         __u8 Pad;
2023         __u16  Reserved4;       /* Parameters start. */
2024         __le16 InformationLevel;/* Parameters end. */
2025         /* NTLMSSP Blob, Data start. */
2026 } __attribute__((packed)) TRANSACTION2_SETFSI_ENC_REQ;
2027
2028 /* response for setfsinfo levels 0x200 and 0x203 */
2029 typedef struct smb_com_transaction2_setfsi_rsp {
2030         struct smb_hdr hdr;     /* wct = 10 */
2031         struct trans2_resp t2;
2032         __u16 ByteCount;
2033 } __attribute__((packed)) TRANSACTION2_SETFSI_RSP;
2034
2035 typedef struct smb_com_transaction2_get_dfs_refer_req {
2036         struct smb_hdr hdr;     /* wct = 15 */
2037         __le16 TotalParameterCount;
2038         __le16 TotalDataCount;
2039         __le16 MaxParameterCount;
2040         __le16 MaxDataCount;
2041         __u8 MaxSetupCount;
2042         __u8 Reserved;
2043         __le16 Flags;
2044         __le32 Timeout;
2045         __u16 Reserved2;
2046         __le16 ParameterCount;
2047         __le16 ParameterOffset;
2048         __le16 DataCount;
2049         __le16 DataOffset;
2050         __u8 SetupCount;
2051         __u8 Reserved3;
2052         __le16 SubCommand;      /* one setup word */
2053         __le16 ByteCount;
2054         __u8 Pad[3];            /* Win2K has sent 0x0F01 (max response length
2055                                    perhaps?) followed by one byte pad - doesn't
2056                                    seem to matter though */
2057         __le16 MaxReferralLevel;
2058         char RequestFileName[1];
2059 } __attribute__((packed)) TRANSACTION2_GET_DFS_REFER_REQ;
2060
2061 #define DFS_VERSION cpu_to_le16(0x0003)
2062
2063 /* DFS server target type */
2064 #define DFS_TYPE_LINK 0x0000  /* also for sysvol targets */
2065 #define DFS_TYPE_ROOT 0x0001
2066
2067 /* Referral Entry Flags */
2068 #define DFS_NAME_LIST_REF 0x0200 /* set for domain or DC referral responses */
2069 #define DFS_TARGET_SET_BOUNDARY 0x0400 /* only valid with version 4 dfs req */
2070
2071 typedef struct dfs_referral_level_3 { /* version 4 is same, + one flag bit */
2072         __le16 VersionNumber;  /* must be 3 or 4 */
2073         __le16 Size;
2074         __le16 ServerType; /* 0x0001 = root targets; 0x0000 = link targets */
2075         __le16 ReferralEntryFlags;
2076         __le32 TimeToLive;
2077         __le16 DfsPathOffset;
2078         __le16 DfsAlternatePathOffset;
2079         __le16 NetworkAddressOffset; /* offset of the link target */
2080         __u8   ServiceSiteGuid[16];  /* MBZ, ignored */
2081 } __attribute__((packed)) REFERRAL3;
2082
2083 typedef struct smb_com_transaction_get_dfs_refer_rsp {
2084         struct smb_hdr hdr;     /* wct = 10 */
2085         struct trans2_resp t2;
2086         __u16 ByteCount;
2087         __u8 Pad;
2088         __le16 PathConsumed;
2089         __le16 NumberOfReferrals;
2090         __le32 DFSFlags;
2091         REFERRAL3 referrals[1]; /* array of level 3 dfs_referral structures */
2092         /* followed by the strings pointed to by the referral structures */
2093 } __attribute__((packed)) TRANSACTION2_GET_DFS_REFER_RSP;
2094
2095 /* DFS Flags */
2096 #define DFSREF_REFERRAL_SERVER  0x00000001 /* all targets are DFS roots */
2097 #define DFSREF_STORAGE_SERVER   0x00000002 /* no further ref requests needed */
2098 #define DFSREF_TARGET_FAILBACK  0x00000004 /* only for DFS referral version 4 */
2099
2100 /*
2101  ************************************************************************
2102  * All structs for everything above the SMB PDUs themselves
2103  * (such as the T2 level specific data) go here
2104  ************************************************************************
2105  */
2106
2107 /*
2108  * Information on a server
2109  */
2110
2111 struct serverInfo {
2112         char name[16];
2113         unsigned char versionMajor;
2114         unsigned char versionMinor;
2115         unsigned long type;
2116         unsigned int commentOffset;
2117 } __attribute__((packed));
2118
2119 /*
2120  * The following structure is the format of the data returned on a NetShareEnum
2121  * with level "90" (x5A)
2122  */
2123
2124 struct shareInfo {
2125         char shareName[13];
2126         char pad;
2127         unsigned short type;
2128         unsigned int commentOffset;
2129 } __attribute__((packed));
2130
2131 struct aliasInfo {
2132         char aliasName[9];
2133         char pad;
2134         unsigned int commentOffset;
2135         unsigned char type[2];
2136 } __attribute__((packed));
2137
2138 struct aliasInfo92 {
2139         int aliasNameOffset;
2140         int serverNameOffset;
2141         int shareNameOffset;
2142 } __attribute__((packed));
2143
2144 typedef struct {
2145         __le64 TotalAllocationUnits;
2146         __le64 FreeAllocationUnits;
2147         __le32 SectorsPerAllocationUnit;
2148         __le32 BytesPerSector;
2149 } __attribute__((packed)) FILE_SYSTEM_INFO;     /* size info, level 0x103 */
2150
2151 typedef struct {
2152         __le32 fsid;
2153         __le32 SectorsPerAllocationUnit;
2154         __le32 TotalAllocationUnits;
2155         __le32 FreeAllocationUnits;
2156         __le16  BytesPerSector;
2157 } __attribute__((packed)) FILE_SYSTEM_ALLOC_INFO;
2158
2159 typedef struct {
2160         __le16 MajorVersionNumber;
2161         __le16 MinorVersionNumber;
2162         __le64 Capability;
2163 } __attribute__((packed)) FILE_SYSTEM_UNIX_INFO; /* Unix extension level 0x200*/
2164
2165 /* Version numbers for CIFS UNIX major and minor. */
2166 #define CIFS_UNIX_MAJOR_VERSION 1
2167 #define CIFS_UNIX_MINOR_VERSION 0
2168
2169 /* Linux/Unix extensions capability flags */
2170 #define CIFS_UNIX_FCNTL_CAP             0x00000001 /* support for fcntl locks */
2171 #define CIFS_UNIX_POSIX_ACL_CAP         0x00000002 /* support getfacl/setfacl */
2172 #define CIFS_UNIX_XATTR_CAP             0x00000004 /* support new namespace   */
2173 #define CIFS_UNIX_EXTATTR_CAP           0x00000008 /* support chattr/chflag   */
2174 #define CIFS_UNIX_POSIX_PATHNAMES_CAP   0x00000010 /* Allow POSIX path chars  */
2175 #define CIFS_UNIX_POSIX_PATH_OPS_CAP    0x00000020 /* Allow new POSIX path based
2176                                                       calls including posix open
2177                                                       and posix unlink */
2178 #define CIFS_UNIX_LARGE_READ_CAP        0x00000040 /* support reads >128K (up
2179                                                       to 0xFFFF00 */
2180 #define CIFS_UNIX_LARGE_WRITE_CAP       0x00000080
2181 #define CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP 0x00000100 /* can do SPNEGO crypt */
2182 #define CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP  0x00000200 /* must do  */
2183 #define CIFS_UNIX_PROXY_CAP             0x00000400 /* Proxy cap: 0xACE ioctl and
2184                                                       QFS PROXY call */
2185 #ifdef CONFIG_CIFS_POSIX
2186 /* presumably don't need the 0x20 POSIX_PATH_OPS_CAP since we never send
2187    LockingX instead of posix locking call on unix sess (and we do not expect
2188    LockingX to use different (ie Windows) semantics than posix locking on
2189    the same session (if WINE needs to do this later, we can add this cap
2190    back in later */
2191 /* #define CIFS_UNIX_CAP_MASK              0x000000fb */
2192 #define CIFS_UNIX_CAP_MASK              0x000003db
2193 #else
2194 #define CIFS_UNIX_CAP_MASK              0x00000013
2195 #endif /* CONFIG_CIFS_POSIX */
2196
2197
2198 #define CIFS_POSIX_EXTENSIONS           0x00000010 /* support for new QFSInfo */
2199
2200 typedef struct {
2201         /* For undefined recommended transfer size return -1 in that field */
2202         __le32 OptimalTransferSize;  /* bsize on some os, iosize on other os */
2203         __le32 BlockSize;
2204     /* The next three fields are in terms of the block size.
2205         (above). If block size is unknown, 4096 would be a
2206         reasonable block size for a server to report.
2207         Note that returning the blocks/blocksavail removes need
2208         to make a second call (to QFSInfo level 0x103 to get this info.
2209         UserBlockAvail is typically less than or equal to BlocksAvail,
2210         if no distinction is made return the same value in each */
2211         __le64 TotalBlocks;
2212         __le64 BlocksAvail;       /* bfree */
2213         __le64 UserBlocksAvail;   /* bavail */
2214     /* For undefined Node fields or FSID return -1 */
2215         __le64 TotalFileNodes;
2216         __le64 FreeFileNodes;
2217         __le64 FileSysIdentifier;   /* fsid */
2218         /* NB Namelen comes from FILE_SYSTEM_ATTRIBUTE_INFO call */
2219         /* NB flags can come from FILE_SYSTEM_DEVICE_INFO call   */
2220 } __attribute__((packed)) FILE_SYSTEM_POSIX_INFO;
2221
2222 /* DeviceType Flags */
2223 #define FILE_DEVICE_CD_ROM              0x00000002
2224 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM  0x00000003
2225 #define FILE_DEVICE_DFS                 0x00000006
2226 #define FILE_DEVICE_DISK                0x00000007
2227 #define FILE_DEVICE_DISK_FILE_SYSTEM    0x00000008
2228 #define FILE_DEVICE_FILE_SYSTEM         0x00000009
2229 #define FILE_DEVICE_NAMED_PIPE          0x00000011
2230 #define FILE_DEVICE_NETWORK             0x00000012
2231 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
2232 #define FILE_DEVICE_NULL                0x00000015
2233 #define FILE_DEVICE_PARALLEL_PORT       0x00000016
2234 #define FILE_DEVICE_PRINTER             0x00000018
2235 #define FILE_DEVICE_SERIAL_PORT         0x0000001b
2236 #define FILE_DEVICE_STREAMS             0x0000001e
2237 #define FILE_DEVICE_TAPE                0x0000001f
2238 #define FILE_DEVICE_TAPE_FILE_SYSTEM    0x00000020
2239 #define FILE_DEVICE_VIRTUAL_DISK        0x00000024
2240 #define FILE_DEVICE_NETWORK_REDIRECTOR  0x00000028
2241
2242 typedef struct {
2243         __le32 DeviceType;
2244         __le32 DeviceCharacteristics;
2245 } __attribute__((packed)) FILE_SYSTEM_DEVICE_INFO; /* device info level 0x104 */
2246
2247 /* minimum includes first three fields, and empty FS Name */
2248 #define MIN_FS_ATTR_INFO_SIZE 12
2249
2250 typedef struct {
2251         __le32 Attributes;
2252         __le32 MaxPathNameComponentLength;
2253         __le32 FileSystemNameLen;
2254         char FileSystemName[52]; /* do not have to save this - get subset? */
2255 } __attribute__((packed)) FILE_SYSTEM_ATTRIBUTE_INFO;
2256
2257 /******************************************************************************/
2258 /* QueryFileInfo/QueryPathinfo (also for SetPath/SetFile) data buffer formats */
2259 /******************************************************************************/
2260 typedef struct { /* data block encoding of response to level 263 QPathInfo */
2261         __le64 CreationTime;
2262         __le64 LastAccessTime;
2263         __le64 LastWriteTime;
2264         __le64 ChangeTime;
2265         __le32 Attributes;
2266         __u32 Pad1;
2267         __le64 AllocationSize;
2268         __le64 EndOfFile;       /* size ie offset to first free byte in file */
2269         __le32 NumberOfLinks;   /* hard links */
2270         __u8 DeletePending;
2271         __u8 Directory;
2272         __u16 Pad2;
2273         __le64 IndexNumber;
2274         __le32 EASize;
2275         __le32 AccessFlags;
2276         __u64 IndexNumber1;
2277         __le64 CurrentByteOffset;
2278         __le32 Mode;
2279         __le32 AlignmentRequirement;
2280         __le32 FileNameLength;
2281         char FileName[1];
2282 } __attribute__((packed)) FILE_ALL_INFO;        /* level 0x107 QPathInfo */
2283
2284 /* defines for enumerating possible values of the Unix type field below */
2285 #define UNIX_FILE      0
2286 #define UNIX_DIR       1
2287 #define UNIX_SYMLINK   2
2288 #define UNIX_CHARDEV   3
2289 #define UNIX_BLOCKDEV  4
2290 #define UNIX_FIFO      5
2291 #define UNIX_SOCKET    6
2292 typedef struct {
2293         __le64 EndOfFile;
2294         __le64 NumOfBytes;
2295         __le64 LastStatusChange; /*SNIA specs DCE time for the 3 time fields */
2296         __le64 LastAccessTime;
2297         __le64 LastModificationTime;
2298         __le64 Uid;
2299         __le64 Gid;
2300         __le32 Type;
2301         __le64 DevMajor;
2302         __le64 DevMinor;
2303         __le64 UniqueId;
2304         __le64 Permissions;
2305         __le64 Nlinks;
2306 } __attribute__((packed)) FILE_UNIX_BASIC_INFO; /* level 0x200 QPathInfo */
2307
2308 typedef struct {
2309         char LinkDest[1];
2310 } __attribute__((packed)) FILE_UNIX_LINK_INFO;  /* level 0x201 QPathInfo */
2311
2312 /* The following three structures are needed only for
2313         setting time to NT4 and some older servers via
2314         the primitive DOS time format */
2315 typedef struct {
2316         __u16 Day:5;
2317         __u16 Month:4;
2318         __u16 Year:7;
2319 } __attribute__((packed)) SMB_DATE;
2320
2321 typedef struct {
2322         __u16 TwoSeconds:5;
2323         __u16 Minutes:6;
2324         __u16 Hours:5;
2325 } __attribute__((packed)) SMB_TIME;
2326
2327 typedef struct {
2328         __le16 CreationDate; /* SMB Date see above */
2329         __le16 CreationTime; /* SMB Time */
2330         __le16 LastAccessDate;
2331         __le16 LastAccessTime;
2332         __le16 LastWriteDate;
2333         __le16 LastWriteTime;
2334         __le32 DataSize; /* File Size (EOF) */
2335         __le32 AllocationSize;
2336         __le16 Attributes; /* verify not u32 */
2337         __le32 EASize;
2338 } __attribute__((packed)) FILE_INFO_STANDARD;  /* level 1 SetPath/FileInfo */
2339
2340 typedef struct {
2341         __le64 CreationTime;
2342         __le64 LastAccessTime;
2343         __le64 LastWriteTime;
2344         __le64 ChangeTime;
2345         __le32 Attributes;
2346         __u32 Pad;
2347 } __attribute__((packed)) FILE_BASIC_INFO;      /* size info, level 0x101 */
2348
2349 struct file_allocation_info {
2350         __le64 AllocationSize; /* Note old Samba srvr rounds this up too much */
2351 } __attribute__((packed));      /* size used on disk, for level 0x103 for set,
2352                                    0x105 for query */
2353
2354 struct file_end_of_file_info {
2355         __le64 FileSize;                /* offset to end of file */
2356 } __attribute__((packed)); /* size info, level 0x104 for set, 0x106 for query */
2357
2358 struct file_alt_name_info {
2359         __u8   alt_name[1];
2360 } __attribute__((packed));      /* level 0x0108 */
2361
2362 struct file_stream_info {
2363         __le32 number_of_streams;  /* BB check sizes and verify location */
2364         /* followed by info on streams themselves
2365                 u64 size;
2366                 u64 allocation_size
2367                 stream info */
2368 };      /* level 0x109 */
2369
2370 struct file_compression_info {
2371         __le64 compressed_size;
2372         __le16 format;
2373         __u8   unit_shift;
2374         __u8   ch_shift;
2375         __u8   cl_shift;
2376         __u8   pad[3];
2377 } __attribute__((packed));      /* level 0x10b */
2378
2379 /* POSIX ACL set/query path info structures */
2380 #define CIFS_ACL_VERSION 1
2381 struct cifs_posix_ace { /* access control entry (ACE) */
2382         __u8  cifs_e_tag;
2383         __u8  cifs_e_perm;
2384         __le64 cifs_uid; /* or gid */
2385 } __attribute__((packed));
2386
2387 struct cifs_posix_acl { /* access conrol list  (ACL) */
2388         __le16  version;
2389         __le16  access_entry_count;  /* access ACL - count of entries */
2390         __le16  default_entry_count; /* default ACL - count of entries */
2391         struct cifs_posix_ace ace_array[0];
2392         /* followed by
2393         struct cifs_posix_ace default_ace_arraay[] */
2394 } __attribute__((packed));  /* level 0x204 */
2395
2396 /* types of access control entries already defined in posix_acl.h */
2397 /* #define CIFS_POSIX_ACL_USER_OBJ       0x01
2398 #define CIFS_POSIX_ACL_USER      0x02
2399 #define CIFS_POSIX_ACL_GROUP_OBJ 0x04
2400 #define CIFS_POSIX_ACL_GROUP     0x08
2401 #define CIFS_POSIX_ACL_MASK      0x10
2402 #define CIFS_POSIX_ACL_OTHER     0x20 */
2403
2404 /* types of perms */
2405 /* #define CIFS_POSIX_ACL_EXECUTE   0x01
2406 #define CIFS_POSIX_ACL_WRITE     0x02
2407 #define CIFS_POSIX_ACL_READ          0x04 */
2408
2409 /* end of POSIX ACL definitions */
2410
2411 /* POSIX Open Flags */
2412 #define SMB_O_RDONLY     0x1
2413 #define SMB_O_WRONLY    0x2
2414 #define SMB_O_RDWR      0x4
2415 #define SMB_O_CREAT     0x10
2416 #define SMB_O_EXCL      0x20
2417 #define SMB_O_TRUNC     0x40
2418 #define SMB_O_APPEND    0x80
2419 #define SMB_O_SYNC      0x100
2420 #define SMB_O_DIRECTORY 0x200
2421 #define SMB_O_NOFOLLOW  0x400
2422 #define SMB_O_DIRECT    0x800
2423
2424 typedef struct {
2425         __le32 OpenFlags; /* same as NT CreateX */
2426         __le32 PosixOpenFlags;
2427         __le64 Permissions;
2428         __le16 Level; /* reply level requested (see QPathInfo levels) */
2429 } __attribute__((packed)) OPEN_PSX_REQ; /* level 0x209 SetPathInfo data */
2430
2431 typedef struct {
2432         __le16 OplockFlags;
2433         __u16 Fid;
2434         __le32 CreateAction;
2435         __le16 ReturnedLevel;
2436         __le16 Pad;
2437         /* struct following varies based on requested level */
2438 } __attribute__((packed)) OPEN_PSX_RSP; /* level 0x209 SetPathInfo data */
2439
2440 #define SMB_POSIX_UNLINK_FILE_TARGET            0
2441 #define SMB_POSIX_UNLINK_DIRECTORY_TARGET       1
2442
2443 struct unlink_psx_rq { /* level 0x20a SetPathInfo */
2444         __le16 type;
2445 } __attribute__((packed));
2446
2447 struct file_internal_info {
2448         __le64  UniqueId; /* inode number */
2449 } __attribute__((packed));      /* level 0x3ee */
2450
2451 struct file_mode_info {
2452         __le32  Mode;
2453 } __attribute__((packed));      /* level 0x3f8 */
2454
2455 struct file_attrib_tag {
2456         __le32 Attribute;
2457         __le32 ReparseTag;
2458 } __attribute__((packed));      /* level 0x40b */
2459
2460
2461 /********************************************************/
2462 /*  FindFirst/FindNext transact2 data buffer formats    */
2463 /********************************************************/
2464
2465 typedef struct {
2466         __le32 NextEntryOffset;
2467         __u32 ResumeKey; /* as with FileIndex - no need to convert */
2468         FILE_UNIX_BASIC_INFO basic;
2469         char FileName[1];
2470 } __attribute__((packed)) FILE_UNIX_INFO; /* level 0x202 */
2471
2472 typedef struct {
2473         __le32 NextEntryOffset;
2474         __u32 FileIndex;
2475         __le64 CreationTime;
2476         __le64 LastAccessTime;
2477         __le64 LastWriteTime;
2478         __le64 ChangeTime;
2479         __le64 EndOfFile;
2480         __le64 AllocationSize;
2481         __le32 ExtFileAttributes;
2482         __le32 FileNameLength;
2483         char FileName[1];
2484 } __attribute__((packed)) FILE_DIRECTORY_INFO;   /* level 0x101 FF resp data */
2485
2486 typedef struct {
2487         __le32 NextEntryOffset;
2488         __u32 FileIndex;
2489         __le64 CreationTime;
2490         __le64 LastAccessTime;
2491         __le64 LastWriteTime;
2492         __le64 ChangeTime;
2493         __le64 EndOfFile;
2494         __le64 AllocationSize;
2495         __le32 ExtFileAttributes;
2496         __le32 FileNameLength;
2497         __le32 EaSize; /* length of the xattrs */
2498         char FileName[1];
2499 } __attribute__((packed)) FILE_FULL_DIRECTORY_INFO; /* level 0x102 rsp data */
2500
2501 typedef struct {
2502         __le32 NextEntryOffset;
2503         __u32 FileIndex;
2504         __le64 CreationTime;
2505         __le64 LastAccessTime;
2506         __le64 LastWriteTime;
2507         __le64 ChangeTime;
2508         __le64 EndOfFile;
2509         __le64 AllocationSize;
2510         __le32 ExtFileAttributes;
2511         __le32 FileNameLength;
2512         __le32 EaSize; /* EA size */
2513         __le32 Reserved;
2514         __le64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit*/
2515         char FileName[1];
2516 } __attribute__((packed)) SEARCH_ID_FULL_DIR_INFO; /* level 0x105 FF rsp data */
2517
2518 typedef struct {
2519         __le32 NextEntryOffset;
2520         __u32 FileIndex;
2521         __le64 CreationTime;
2522         __le64 LastAccessTime;
2523         __le64 LastWriteTime;
2524         __le64 ChangeTime;
2525         __le64 EndOfFile;
2526         __le64 AllocationSize;
2527         __le32 ExtFileAttributes;
2528         __le32 FileNameLength;
2529         __le32 EaSize; /* length of the xattrs */
2530         __u8   ShortNameLength;
2531         __u8   Reserved;
2532         __u8   ShortName[12];
2533         char FileName[1];
2534 } __attribute__((packed)) FILE_BOTH_DIRECTORY_INFO; /* level 0x104 FFrsp data */
2535
2536 typedef struct {
2537         __u32  ResumeKey;
2538         __le16 CreationDate; /* SMB Date */
2539         __le16 CreationTime; /* SMB Time */
2540         __le16 LastAccessDate;
2541         __le16 LastAccessTime;
2542         __le16 LastWriteDate;
2543         __le16 LastWriteTime;
2544         __le32 DataSize; /* File Size (EOF) */
2545         __le32 AllocationSize;
2546         __le16 Attributes; /* verify not u32 */
2547         __u8   FileNameLength;
2548         char FileName[1];
2549 } __attribute__((packed)) FIND_FILE_STANDARD_INFO; /* level 0x1 FF resp data */
2550
2551
2552 struct win_dev {
2553         unsigned char type[8]; /* IntxCHR or IntxBLK */
2554         __le64 major;
2555         __le64 minor;
2556 } __attribute__((packed));
2557
2558 struct gea {
2559         unsigned char name_len;
2560         char name[1];
2561 } __attribute__((packed));
2562
2563 struct gealist {
2564         unsigned long list_len;
2565         struct gea list[1];
2566 } __attribute__((packed));
2567
2568 struct fea {
2569         unsigned char EA_flags;
2570         __u8 name_len;
2571         __le16 value_len;
2572         char name[1];
2573         /* optionally followed by value */
2574 } __attribute__((packed));
2575 /* flags for _FEA.fEA */
2576 #define FEA_NEEDEA         0x80 /* need EA bit */
2577
2578 struct fealist {
2579         __le32 list_len;
2580         struct fea list[1];
2581 } __attribute__((packed));
2582
2583 /* used to hold an arbitrary blob of data */
2584 struct data_blob {
2585         __u8 *data;
2586         size_t length;
2587         void (*free) (struct data_blob *data_blob);
2588 } __attribute__((packed));
2589
2590
2591 #ifdef CONFIG_CIFS_POSIX
2592 /*
2593         For better POSIX semantics from Linux client, (even better
2594         than the existing CIFS Unix Extensions) we need updated PDUs for:
2595
2596         1) PosixCreateX - to set and return the mode, inode#, device info and
2597         perhaps add a CreateDevice - to create Pipes and other special .inodes
2598         Also note POSIX open flags
2599         2) Close - to return the last write time to do cache across close
2600                 more safely
2601         3) FindFirst return unique inode number - what about resume key, two
2602         forms short (matches readdir) and full (enough info to cache inodes)
2603         4) Mkdir - set mode
2604
2605         And under consideration:
2606         5) FindClose2 (return nanosecond timestamp ??)
2607         6) Use nanosecond timestamps throughout all time fields if
2608            corresponding attribute flag is set
2609         7) sendfile - handle based copy
2610
2611         what about fixing 64 bit alignment
2612
2613         There are also various legacy SMB/CIFS requests used as is
2614
2615         From existing Lanman and NTLM dialects:
2616         --------------------------------------
2617         NEGOTIATE
2618         SESSION_SETUP_ANDX (BB which?)
2619         TREE_CONNECT_ANDX (BB which wct?)
2620         TREE_DISCONNECT (BB add volume timestamp on response)
2621         LOGOFF_ANDX
2622         DELETE (note delete open file behavior)
2623         DELETE_DIRECTORY
2624         READ_AND_X
2625         WRITE_AND_X
2626         LOCKING_AND_X (note posix lock semantics)
2627         RENAME (note rename across dirs and open file rename posix behaviors)
2628         NT_RENAME (for hardlinks) Is this good enough for all features?
2629         FIND_CLOSE2
2630         TRANSACTION2 (18 cases)
2631                 SMB_SET_FILE_END_OF_FILE_INFO2 SMB_SET_PATH_END_OF_FILE_INFO2
2632                 (BB verify that never need to set allocation size)
2633                 SMB_SET_FILE_BASIC_INFO2 (setting times - BB can it be done via
2634                          Unix ext?)
2635
2636         COPY (note support for copy across directories) - FUTURE, OPTIONAL
2637         setting/getting OS/2 EAs - FUTURE (BB can this handle
2638         setting Linux xattrs perfectly)         - OPTIONAL
2639         dnotify                                 - FUTURE, OPTIONAL
2640         quota                                   - FUTURE, OPTIONAL
2641
2642         Note that various requests implemented for NT interop such as
2643                 NT_TRANSACT (IOCTL) QueryReparseInfo
2644         are unneeded to servers compliant with the CIFS POSIX extensions
2645
2646         From CIFS Unix Extensions:
2647         -------------------------
2648         T2 SET_PATH_INFO (SMB_SET_FILE_UNIX_LINK) for symlinks
2649         T2 SET_PATH_INFO (SMB_SET_FILE_BASIC_INFO2)
2650         T2 QUERY_PATH_INFO (SMB_QUERY_FILE_UNIX_LINK)
2651         T2 QUERY_PATH_INFO (SMB_QUERY_FILE_UNIX_BASIC)  BB check for missing
2652                                                         inode fields
2653                                 Actually a need QUERY_FILE_UNIX_INFO
2654                                 since has inode num
2655                                 BB what about a) blksize/blkbits/blocks
2656                                                           b) i_version
2657                                                           c) i_rdev
2658                                                           d) notify mask?
2659                                                           e) generation
2660                                                           f) size_seqcount
2661         T2 FIND_FIRST/FIND_NEXT FIND_FILE_UNIX
2662         TRANS2_GET_DFS_REFERRAL               - OPTIONAL but recommended
2663         T2_QFS_INFO QueryDevice/AttributeInfo - OPTIONAL
2664  */
2665
2666 /* xsymlink is a symlink format (used by MacOS) that can be used
2667    to save symlink info in a regular file when
2668    mounted to operating systems that do not
2669    support the cifs Unix extensions or EAs (for xattr
2670    based symlinks).  For such a file to be recognized
2671    as containing symlink data:
2672
2673    1) file size must be 1067,
2674    2) signature must begin file data,
2675    3) length field must be set to ASCII representation
2676         of a number which is less than or equal to 1024,
2677    4) md5 must match that of the path data */
2678
2679 struct xsymlink {
2680         /* 1067 bytes */
2681         char signature[4]; /* XSym */ /* not null terminated */
2682         char cr0;         /* \n */
2683 /* ASCII representation of length (4 bytes decimal) terminated by \n not null */
2684         char length[4];
2685         char cr1;         /* \n */
2686 /* md5 of valid subset of path ie path[0] through path[length-1] */
2687         __u8 md5[32];
2688         char cr2;        /* \n */
2689 /* if room left, then end with \n then 0x20s by convention but not required */
2690         char path[1024];
2691 } __attribute__((packed));
2692
2693 typedef struct file_xattr_info {
2694         /* BB do we need another field for flags? BB */
2695         __u32 xattr_name_len;
2696         __u32 xattr_value_len;
2697         char  xattr_name[0];
2698         /* followed by xattr_value[xattr_value_len], no pad */
2699 } __attribute__((packed)) FILE_XATTR_INFO; /* extended attribute info
2700                                               level 0x205 */
2701
2702 /* flags for lsattr and chflags commands removed arein uapi/linux/fs.h */
2703
2704 typedef struct file_chattr_info {
2705         __le64  mask; /* list of all possible attribute bits */
2706         __le64  mode; /* list of actual attribute bits on this inode */
2707 } __attribute__((packed)) FILE_CHATTR_INFO;  /* ext attributes
2708                                                 (chattr, chflags) level 0x206 */
2709 #endif                          /* POSIX */
2710 #endif                          /* _CIFSPDU_H */