smbd: Remove an unnecessary call to SMB_VFS_STAT()
[samba4-gss.git] / libcli / smb / smb_unix_ext.h
blob72944d475af6d49e5f63f045993f4bf2bd9c43b9
1 /*
2 Unix SMB/CIFS implementation.
3 SMB transaction2 handling
5 Copyright (C) James Peach 2007
6 Copyright (C) Jeremy Allison 1994-2002.
8 Extensively modified by Andrew Tridgell, 1995
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef __SMB_UNIX_EXT_H__
25 #define __SMB_UNIX_EXT_H__
27 #include <replace.h>
28 #include "librpc/gen_ndr/smb3posix.h"
30 /* UNIX CIFS Extensions - created by HP */
32 * UNIX CIFS Extensions have the range 0x200 - 0x2FF reserved.
33 * Supposedly Microsoft have agreed to this.
36 #define MIN_UNIX_INFO_LEVEL 0x200
37 #define MAX_UNIX_INFO_LEVEL 0x2FF
39 #define SMB_QUERY_FILE_UNIX_BASIC 0x200 /* UNIX File Info*/
40 #define SMB_SET_FILE_UNIX_BASIC 0x200
41 #define SMB_SET_FILE_UNIX_INFO2 0x20B /* UNIX File Info2 */
43 #define SMB_MODE_NO_CHANGE 0xFFFFFFFF /* file mode value which */
44 /* means "don't change it" */
45 #define SMB_UID_NO_CHANGE 0xFFFFFFFF
46 #define SMB_GID_NO_CHANGE 0xFFFFFFFF
48 #define SMB_SIZE_NO_CHANGE_LO 0xFFFFFFFF
49 #define SMB_SIZE_NO_CHANGE_HI 0xFFFFFFFF
51 #define SMB_TIME_NO_CHANGE_LO 0xFFFFFFFF
52 #define SMB_TIME_NO_CHANGE_HI 0xFFFFFFFF
55 Offset Size Name
56 0 LARGE_INTEGER EndOfFile File size
57 8 LARGE_INTEGER Blocks Number of bytes used on disk (st_blocks).
58 16 LARGE_INTEGER CreationTime Creation time
59 24 LARGE_INTEGER LastAccessTime Last access time
60 32 LARGE_INTEGER LastModificationTime Last modification time
61 40 LARGE_INTEGER Uid Numeric user id for the owner
62 48 LARGE_INTEGER Gid Numeric group id of owner
63 56 ULONG Type Enumeration specifying the pathname type:
64 0 -- File
65 1 -- Directory
66 2 -- Symbolic link
67 3 -- Character device
68 4 -- Block device
69 5 -- FIFO (named pipe)
70 6 -- Unix domain socket
72 60 LARGE_INTEGER devmajor Major device number if type is device
73 68 LARGE_INTEGER devminor Minor device number if type is device
74 76 LARGE_INTEGER uniqueid This is a server-assigned unique id for the file. The client
75 will typically map this onto an inode number. The scope of
76 uniqueness is the share.
77 84 LARGE_INTEGER permissions Standard UNIX file permissions - see below.
78 92 LARGE_INTEGER nlinks The number of directory entries that map to this entry
79 (number of hard links)
81 100 - end.
84 #define SMB_FILE_UNIX_BASIC_SIZE 100
86 /* Flags for chflags (CIFS_UNIX_EXTATTR_CAP capability) and
87 * SMB_QUERY_FILE_UNIX_INFO2.
89 #define EXT_SECURE_DELETE 0x00000001
90 #define EXT_ENABLE_UNDELETE 0x00000002
91 #define EXT_SYNCHRONOUS 0x00000004
92 #define EXT_IMMUTABLE 0x00000008
93 #define EXT_OPEN_APPEND_ONLY 0x00000010
94 #define EXT_DO_NOT_BACKUP 0x00000020
95 #define EXT_NO_UPDATE_ATIME 0x00000040
96 #define EXT_HIDDEN 0x00000080
98 #define SMB_QUERY_FILE_UNIX_LINK 0x201
99 #define SMB_SET_FILE_UNIX_LINK 0x201
100 #define SMB_SET_FILE_UNIX_HLINK 0x203
101 /* SMB_QUERY_POSIX_ACL 0x204 see below */
102 #define SMB_QUERY_XATTR 0x205 /* need for non-user XATTRs */
103 #define SMB_QUERY_ATTR_FLAGS 0x206 /* chflags, chattr */
104 #define SMB_SET_ATTR_FLAGS 0x206
105 #define SMB_QUERY_POSIX_PERMISSION 0x207
106 /* Only valid for qfileinfo */
107 #define SMB_QUERY_POSIX_LOCK 0x208
108 /* Only valid for setfileinfo */
109 #define SMB_SET_POSIX_LOCK 0x208
111 /* The set info levels for POSIX path operations. */
112 #define SMB_POSIX_PATH_OPEN 0x209
113 #define SMB_POSIX_PATH_UNLINK 0x20A
115 #define SMB_QUERY_FILE_UNIX_INFO2 0x20B /* UNIX File Info2 */
116 #define SMB_SET_FILE_UNIX_INFO2 0x20B
119 SMB_QUERY_FILE_UNIX_INFO2 is SMB_QUERY_FILE_UNIX_BASIC with create
120 time and file flags appended. The corresponding info level for
121 findfirst/findnext is SMB_FIND_FILE_UNIX_INFO2.
122 Size Offset Value
123 ---------------------
124 0 LARGE_INTEGER EndOfFile File size
125 8 LARGE_INTEGER Blocks Number of blocks used on disk
126 16 LARGE_INTEGER ChangeTime Attribute change time
127 24 LARGE_INTEGER LastAccessTime Last access time
128 32 LARGE_INTEGER LastModificationTime Last modification time
129 40 LARGE_INTEGER Uid Numeric user id for the owner
130 48 LARGE_INTEGER Gid Numeric group id of owner
131 56 ULONG Type Enumeration specifying the file type
132 60 LARGE_INTEGER devmajor Major device number if type is device
133 68 LARGE_INTEGER devminor Minor device number if type is device
134 76 LARGE_INTEGER uniqueid This is a server-assigned unique id
135 84 LARGE_INTEGER permissions Standard UNIX permissions
136 92 LARGE_INTEGER nlinks Number of hard links
137 100 LARGE_INTEGER CreationTime Create/birth time
138 108 ULONG FileFlags File flags enumeration
139 112 ULONG FileFlagsMask Mask of valid flags
142 /* Transact 2 Find First levels */
143 #define SMB_FIND_FILE_UNIX 0x202
144 #define SMB_FIND_FILE_UNIX_INFO2 0x20B /* UNIX File Info2 */
146 #define SMB_FILE_UNIX_INFO2_SIZE 116
149 Info level for TRANS2_QFSINFO - returns version of CIFS UNIX extensions, plus
150 64-bits worth of capability fun :-).
151 Use the same info level for TRANS2_SETFSINFO
154 #define SMB_QUERY_CIFS_UNIX_INFO 0x200
155 #define SMB_SET_CIFS_UNIX_INFO 0x200
157 /* Returns or sets the following.
159 UINT16 major version number
160 UINT16 minor version number
161 LARGE_INTEGER capability bitfield
165 #define CIFS_UNIX_MAJOR_VERSION 1
166 #define CIFS_UNIX_MINOR_VERSION 0
168 #define CIFS_UNIX_FCNTL_LOCKS_CAP 0x1
169 #define CIFS_UNIX_POSIX_ACLS_CAP 0x2
170 #define CIFS_UNIX_XATTTR_CAP 0x4 /* for support of other xattr
171 namespaces such as system,
172 security and trusted */
173 #define CIFS_UNIX_EXTATTR_CAP 0x8 /* for support of chattr
174 (chflags) and lsattr */
175 #define CIFS_UNIX_POSIX_PATHNAMES_CAP 0x10 /* Use POSIX pathnames on the wire. */
176 #define CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP 0x20 /* We can cope with POSIX open/mkdir/unlink etc. */
177 #define CIFS_UNIX_LARGE_READ_CAP 0x40 /* We can cope with 24 bit reads in readX. */
178 #define CIFS_UNIX_LARGE_WRITE_CAP 0x80 /* We can cope with 24 bit writes in writeX. */
179 #define CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP 0x100 /* We can do SPNEGO negotiations for encryption. */
180 #define CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP 0x200 /* We *must* SPNEGO negotiations for encryption. */
182 #define SMB_QUERY_POSIX_FS_INFO 0x201
184 /* Returns FILE_SYSTEM_POSIX_INFO struct as follows
185 (NB For undefined values return -1 in that field)
186 le32 OptimalTransferSize; bsize on some os, iosize on other os, This
187 is a hint to the client about best size. Server
188 can return -1 if no preference, ie if SMB
189 negotiated size is adequate for optimal
190 read/write performance
191 le32 BlockSize; (often 512 bytes) NB: BlockSize * TotalBlocks = disk space
192 le64 TotalBlocks; redundant with other infolevels but easy to ret here
193 le64 BlocksAvail; although redundant, easy to return
194 le64 UserBlocksAvail; bavail
195 le64 TotalFileNodes;
196 le64 FreeFileNodes;
197 le64 FileSysIdentifier; fsid
198 (NB statfs field Namelen comes from FILE_SYSTEM_ATTRIBUTE_INFO call)
199 (NB statfs field flags can come from FILE_SYSTEM_DEVICE_INFO call)
202 #define SMB_QUERY_POSIX_WHO_AM_I 0x202 /* QFS Info */
203 /* returns:
204 __u32 flags; 0 = Authenticated user 1 = GUEST
205 __u32 mask; which flags bits server understands ie 0x0001
206 __u64 unix_user_id;
207 __u64 unix_user_gid;
208 __u32 number_of_supplementary_gids; may be zero
209 __u32 number_of_sids; may be zero
210 __u32 length_of_sid_array; in bytes - may be zero
211 __u32 pad; reserved - MBZ
212 __u64 gid_array[0]; may be empty
213 __u8 * psid_list may be empty
216 /* ... more as we think of them :-). */
218 /* SMB POSIX ACL definitions. */
219 /* Wire format is (all little endian) :
221 [2 bytes] - Version number.
222 [2 bytes] - Number of ACE entries to follow.
223 [2 bytes] - Number of default ACE entries to follow.
224 -------------------------------------
227 ACE entries
230 -------------------------------------
233 Default ACE entries
236 -------------------------------------
238 Where an ACE entry looks like :
240 [1 byte] - Entry type.
242 Entry types are :
244 ACL_USER_OBJ 0x01
245 ACL_USER 0x02
246 ACL_GROUP_OBJ 0x04
247 ACL_GROUP 0x08
248 ACL_MASK 0x10
249 ACL_OTHER 0x20
251 [1 byte] - permissions (perm_t)
253 perm_t types are :
255 ACL_READ 0x04
256 ACL_WRITE 0x02
257 ACL_EXECUTE 0x01
259 [8 bytes] - uid/gid to apply this permission to.
261 In the same format as the uid/gid fields in the other
262 UNIX extensions definitions. Use 0xFFFFFFFFFFFFFFFF for
263 the MASK and OTHER entry types.
265 If the Number of ACE entries for either file or default ACE's
266 is set to 0xFFFF this means ignore this kind of ACE (and the
267 number of entries sent will be zero.
271 #define SMB_QUERY_POSIX_WHOAMI 0x202
273 enum smb_whoami_flags {
274 SMB_WHOAMI_GUEST = 0x1 /* Logged in as (or squashed to) guest */
277 /* Mask of which WHOAMI bits are valid. This should make it easier for clients
278 * to cope with servers that have different sets of WHOAMI flags (as more get
279 * added).
281 #define SMB_WHOAMI_MASK 0x00000001
284 SMBWhoami - Query the user mapping performed by the server for the
285 connected tree. This is a subcommand of the TRANS2_QFSINFO.
287 Returns:
288 4 bytes unsigned - mapping flags (smb_whoami_flags)
289 4 bytes unsigned - flags mask
291 8 bytes unsigned - primary UID
292 8 bytes unsigned - primary GID
293 4 bytes unsigned - number of supplementary GIDs
294 4 bytes unsigned - number of SIDs
295 4 bytes unsigned - SID list byte count
296 4 bytes - pad / reserved (must be zero)
298 8 bytes unsigned[] - list of GIDs (may be empty)
299 struct dom_sid[] - list of SIDs (may be empty)
303 * The following trans2 is done between client and server
304 * as a FSINFO call to set up the encryption state for transport
305 * encryption.
306 * This is a subcommand of the TRANS2_QFSINFO.
308 * The request looks like :
310 * [data block] -> SPNEGO framed GSSAPI request.
312 * The reply looks like :
314 * [data block] -> SPNEGO framed GSSAPI reply - if error
315 * is NT_STATUS_OK then we're done, if it's
316 * NT_STATUS_MORE_PROCESSING_REQUIRED then the
317 * client needs to keep going. If it's an
318 * error it can be any NT_STATUS error.
322 #define SMB_REQUEST_TRANSPORT_ENCRYPTION 0x203 /* QFSINFO */
323 #define SMB_ENCRYPTION_GSSAPI 0x8000
325 /* The query/set info levels for POSIX ACLs. */
326 #define SMB_QUERY_POSIX_ACL 0x204
327 #define SMB_SET_POSIX_ACL 0x204
329 /* Current on the wire ACL version. */
330 #define SMB_POSIX_ACL_VERSION 1
332 /* ACE entry type. */
333 #define SMB_POSIX_ACL_USER_OBJ 0x01
334 #define SMB_POSIX_ACL_USER 0x02
335 #define SMB_POSIX_ACL_GROUP_OBJ 0x04
336 #define SMB_POSIX_ACL_GROUP 0x08
337 #define SMB_POSIX_ACL_MASK 0x10
338 #define SMB_POSIX_ACL_OTHER 0x20
340 /* perm_t types. */
341 #define SMB_POSIX_ACL_READ 0x04
342 #define SMB_POSIX_ACL_WRITE 0x02
343 #define SMB_POSIX_ACL_EXECUTE 0x01
345 #define SMB_POSIX_ACL_HEADER_SIZE 6
346 #define SMB_POSIX_ACL_ENTRY_SIZE 10
348 #define SMB_POSIX_IGNORE_ACE_ENTRIES 0xFFFF
350 /* Definition of data block of SMB_SET_POSIX_LOCK */
352 [2 bytes] lock_type - 0 = Read, 1 = Write, 2 = Unlock
353 [2 bytes] lock_flags - 1 = Wait (only valid for setlock)
354 [4 bytes] pid = locking context.
355 [8 bytes] start = unsigned 64 bits.
356 [8 bytes] length = unsigned 64 bits.
359 #define POSIX_LOCK_TYPE_OFFSET 0
360 #define POSIX_LOCK_FLAGS_OFFSET 2
361 #define POSIX_LOCK_PID_OFFSET 4
362 #define POSIX_LOCK_START_OFFSET 8
363 #define POSIX_LOCK_LEN_OFFSET 16
364 #define POSIX_LOCK_DATA_SIZE 24
366 #define POSIX_LOCK_FLAG_NOWAIT 0
367 #define POSIX_LOCK_FLAG_WAIT 1
369 #define POSIX_LOCK_TYPE_READ 0
370 #define POSIX_LOCK_TYPE_WRITE 1
371 #define POSIX_LOCK_TYPE_UNLOCK 2
373 /* SMB_POSIX_PATH_OPEN "open_mode" definitions. */
374 #define SMB_O_RDONLY 0x1
375 #define SMB_O_WRONLY 0x2
376 #define SMB_O_RDWR 0x4
378 #define SMB_ACCMODE 0x7
380 #define SMB_O_CREAT 0x10
381 #define SMB_O_EXCL 0x20
382 #define SMB_O_TRUNC 0x40
383 #define SMB_O_APPEND 0x80
384 #define SMB_O_SYNC 0x100
385 #define SMB_O_DIRECTORY 0x200
386 #define SMB_O_NOFOLLOW 0x400
387 #define SMB_O_DIRECT 0x800
389 /* Definition of request data block for SMB_POSIX_PATH_OPEN */
391 [4 bytes] flags (as smb_ntcreate_Flags).
392 [4 bytes] open_mode - SMB_O_xxx flags above.
393 [8 bytes] mode_t (permissions) - same encoding as "Standard UNIX permissions" above in SMB_SET_FILE_UNIX_BASIC.
394 [2 bytes] ret_info_level - optimization. Info level to be returned.
397 /* Definition of reply data block for SMB_POSIX_PATH_OPEN */
399 #define SMB_NO_INFO_LEVEL_RETURNED 0xFFFF
402 [2 bytes] - flags field. Identical to flags reply for oplock response field in SMBNTCreateX)
403 [2 bytes] - FID returned.
404 [4 bytes] - CreateAction (same as in NTCreateX response).
405 [2 bytes] - reply info level - as requested or 0xFFFF if not available.
406 [2 bytes] - padding (must be zero)
407 [n bytes] - info level reply - if available.
410 /* Definition of request data block for SMB_POSIX_UNLINK */
412 [2 bytes] flags (defined below).
415 #define SMB_POSIX_UNLINK_FILE_TARGET 0
416 #define SMB_POSIX_UNLINK_DIRECTORY_TARGET 1
418 #define INFO_LEVEL_IS_UNIX(level) ((((level) >= MIN_UNIX_INFO_LEVEL) && \
419 ((level) <= MAX_UNIX_INFO_LEVEL)) || \
420 ((level) == FSCC_FILE_POSIX_INFORMATION))
422 #endif /* __SMB_UNIX_EXT_H__ */