xref: /titanic_50/usr/src/uts/common/smbsrv/smb.h (revision 28c4d110d9dd87af1d9dcf1bf503cea2e7c03b91)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
25  */
26 
27 #ifndef _SMBSRV_SMB_H
28 #define	_SMBSRV_SMB_H
29 
30 
31 /*
32  * SMB definitions and interfaces, mostly defined in the SMB and CIFS specs.
33  */
34 #include <sys/types.h>
35 #include <smbsrv/string.h>
36 #include <smbsrv/msgbuf.h>
37 
38 #include <smb/ntstatus.h>
39 #include <smb/nterror.h>
40 #include <smb/lmerr.h>
41 #include <smb/doserror.h>
42 #include <smbsrv/ntaccess.h>
43 
44 /*
45  * Macintosh Extensions for CIFS
46  */
47 #include <smbsrv/mac_cifs.h>
48 
49 /*
50  * NT Installable File System (IFS) interface.
51  */
52 #include <smbsrv/ntifs.h>
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 /*
59  * The msgbuf format and length of an SMB header.
60  */
61 #define	SMB_HEADER_DOS_FMT	"Mbbbwbww10.wwww"
62 #define	SMB_HEADER_NT_FMT	"Mblbww#c2.wwww"
63 #define	SMB_HEADER_LEN		32
64 #define	SMB_SIG_SIZE		8	/* SMB signature size */
65 
66 #define	SMB_HEADER_ED_FMT	"Mbbbwbww8c2.wwww"
67 #define	SMB_HEADER_ED_LEN	(4+1+1+1+2+1+2+12+2+2+2+2)
68 #define	SMB_TRANSHDR_ED_FMT	"wwwwb.wl2.wwwwb."
69 #define	SMB_TRANSHDR_ED_LEN	(2+2+2+2+1+1+2+4+2+2+2+2+2+1+1)
70 #define	SMB_TRANSSHDR_ED_FMT	"wwwwwwwww"
71 #define	SMB_TRANSSHDR_ED_LEN	(2+2+2+2+2+2+2+2)
72 #define	SMB_TRANS2SHDR_ED_FMT	"wwwwwwwww"
73 #define	SMB_TRANS2SHDR_ED_LEN	(2+2+2+2+2+2+2+2+2)
74 /* There is something wrong with this. Should be 38 bytes. It is 37 bytes */
75 #define	SMB_NT_TRANSHDR_ED_FMT	"b2.llllllllbw"
76 #define	SMB_NT_TRANSHDR_ED_LEN	(1+2+4+4+4+4+4+4+4+4+1+2)
77 
78 /*
79  * CIFS definition for the SMB header (CIFS Section 3.2). Note that the
80  * pid_high field is not documented in the 1997 CIFS specificaction. This
81  * is a decoded or memory-based definition, which may be padded to align
82  * its elements on word boundaries. See smb_hdrbuf_t for the network
83  * ready structure.
84  */
85 typedef struct smb_hdr {
86 	uint8_t protocol[4];
87 	uint8_t command;
88 
89 	union {
90 		struct {
91 			uint8_t error_class;
92 			uint8_t reserved;
93 			uint16_t error;
94 		} dos_error;
95 		uint32_t ntstatus;
96 	} status;
97 
98 	uint8_t flags;
99 	uint16_t flags2;
100 	uint16_t pid_high;
101 
102 	union {
103 		uint16_t pad[5];
104 		struct {
105 			uint16_t reserved;
106 			uint8_t security_sig[SMB_SIG_SIZE];
107 		} extra;
108 	} extra;
109 
110 	uint16_t tid;
111 	uint16_t pid;
112 	uint16_t uid;
113 	uint16_t mid;
114 } smb_hdr_t;
115 
116 /*
117  * Encoded or packed SMB header in network ready format.
118  */
119 typedef struct smb_hdrbuf {
120 	uint8_t hdr[SMB_HEADER_LEN];
121 } smb_hdrbuf_t;
122 
123 /*
124  * Protocol magic value as a 32-bit.  This will be 0xff 0x53 0x4d 0x42 on
125  * the wire.
126  */
127 
128 #define	SMB_PROTOCOL_MAGIC	0x424d53ff
129 
130 /*
131  * Time and date encoding (CIFS Section 3.6). The date is encoded such
132  * that the year has a range of 0-119, which represents 1980-2099. The
133  * month range is 1-12, and the day range is 1-31.
134  */
135 typedef struct smb_date {
136 	uint16_t day   : 5;
137 	uint16_t month : 4;
138 	uint16_t year  : 7;
139 } smb_date_t;
140 
141 /*
142  * The hours range is 0-23, the minutes range is 0-59 and the two_sec
143  * range is 0-29.
144  */
145 typedef struct smb_time {
146 	uint16_t two_sec : 5;
147 	uint16_t minutes : 6;
148 	uint16_t hours    : 5;
149 } smb_time_t;
150 
151 /*
152  * This is a 64-bit signed absolute time representing 100ns increments.
153  * A positive value represents the absolute time since 1601AD. A
154  * negative value represents a context specific relative time.
155  */
156 typedef struct smb_time2 {
157 	uint32_t low_time;
158 	int32_t high_time;
159 } smb_time2_t;
160 
161 /*
162  * The number of seconds since Jan 1, 1970, 00:00:00.0.
163  */
164 typedef uint32_t smb_utime_t;
165 
166 #define	SMB_LM_NEGOTIATE_WORDCNT		13
167 #define	SMB_NT_NEGOTIATE_WORDCNT		17
168 
169 #define	SMB_NAME83_EXTLEN			3
170 #define	SMB_NAME83_BASELEN			8
171 #define	SMB_NAME83_LEN				12
172 
173 /* Share types */
174 #ifndef _SHARE_TYPES_DEFINED_
175 #define	_SHARE_TYPES_DEFINED_
176 #define	STYPE_DISKTREE			0x00000000
177 #define	STYPE_PRINTQ			0x00000001
178 #define	STYPE_DEVICE			0x00000002
179 #define	STYPE_IPC			0x00000003
180 #define	STYPE_MASK			0x0000000F
181 #define	STYPE_DFS			0x00000064
182 #define	STYPE_HIDDEN			0x80000000
183 #define	STYPE_SPECIAL			0x80000000
184 #endif /* _SHARE_TYPES_DEFINED_ */
185 
186 #define	STYPE_ISDSK(S)	(((S) & STYPE_MASK) == STYPE_DISKTREE)
187 #define	STYPE_ISPRN(S)	(((S) & STYPE_MASK) == STYPE_PRINTQ)
188 #define	STYPE_ISDEV(S)	(((S) & STYPE_MASK) == STYPE_DEVICE)
189 #define	STYPE_ISIPC(S)	(((S) & STYPE_MASK) == STYPE_IPC)
190 
191 /*
192  * NtCreateAndX and NtTransactCreate creation flags: defined in CIFS
193  * section 4.2.2
194  *
195  * Creation Flag Name         Value  Description
196  * ========================== ====== ==================================
197  * NT_CREATE_REQUEST_OPLOCK   0x02   Level I oplock requested
198  * NT_CREATE_REQUEST_OPBATCH  0x04   Batch oplock requested
199  * NT_CREATE_OPEN_TARGET_DIR  0x08   Target for open is a directory
200  */
201 #define	NT_CREATE_FLAG_REQUEST_OPLOCK		0x02
202 #define	NT_CREATE_FLAG_REQUEST_OPBATCH		0x04
203 #define	NT_CREATE_FLAG_OPEN_TARGET_DIR		0x08
204 
205 
206 /*
207  * Define the filter flags for NtNotifyChangeDirectoryFile
208  */
209 #define	FILE_NOTIFY_CHANGE_FILE_NAME	0x00000001
210 #define	FILE_NOTIFY_CHANGE_DIR_NAME	0x00000002
211 #define	FILE_NOTIFY_CHANGE_NAME		0x00000003
212 #define	FILE_NOTIFY_CHANGE_ATTRIBUTES	0x00000004
213 #define	FILE_NOTIFY_CHANGE_SIZE		0x00000008
214 #define	FILE_NOTIFY_CHANGE_LAST_WRITE	0x00000010
215 #define	FILE_NOTIFY_CHANGE_LAST_ACCESS	0x00000020
216 #define	FILE_NOTIFY_CHANGE_CREATION	0x00000040
217 #define	FILE_NOTIFY_CHANGE_EA		0x00000080
218 #define	FILE_NOTIFY_CHANGE_SECURITY	0x00000100
219 #define	FILE_NOTIFY_CHANGE_STREAM_NAME	0x00000200
220 #define	FILE_NOTIFY_CHANGE_STREAM_SIZE	0x00000400
221 #define	FILE_NOTIFY_CHANGE_STREAM_WRITE	0x00000800
222 #define	FILE_NOTIFY_VALID_MASK		0x00000fff
223 
224 
225 /*
226  * Define the file action type codes for NtNotifyChangeDirectoryFile
227  */
228 #define	FILE_ACTION_ADDED		0x00000001
229 #define	FILE_ACTION_REMOVED		0x00000002
230 #define	FILE_ACTION_MODIFIED		0x00000003
231 #define	FILE_ACTION_RENAMED_OLD_NAME	0x00000004
232 #define	FILE_ACTION_RENAMED_NEW_NAME	0x00000005
233 #define	FILE_ACTION_ADDED_STREAM	0x00000006
234 #define	FILE_ACTION_REMOVED_STREAM	0x00000007
235 #define	FILE_ACTION_MODIFIED_STREAM	0x00000008
236 
237 
238 /* Lock type flags */
239 #define	LOCKING_ANDX_NORMAL_LOCK	0x00
240 #define	LOCKING_ANDX_SHARED_LOCK	0x01
241 #define	LOCKING_ANDX_OPLOCK_RELEASE	0x02
242 #define	LOCKING_ANDX_CHANGE_LOCK_TYPE	0x04
243 #define	LOCKING_ANDX_CANCEL_LOCK	0x08
244 #define	LOCKING_ANDX_LARGE_FILES	0x10
245 
246 #define	SMB_COM_CREATE_DIRECTORY	0x00
247 #define	SMB_COM_DELETE_DIRECTORY	0x01
248 #define	SMB_COM_OPEN			0x02
249 #define	SMB_COM_CREATE			0x03
250 #define	SMB_COM_CLOSE			0x04
251 #define	SMB_COM_FLUSH			0x05
252 #define	SMB_COM_DELETE			0x06
253 #define	SMB_COM_RENAME			0x07
254 #define	SMB_COM_QUERY_INFORMATION	0x08
255 #define	SMB_COM_SET_INFORMATION		0x09
256 #define	SMB_COM_READ			0x0A
257 #define	SMB_COM_WRITE			0x0B
258 #define	SMB_COM_LOCK_BYTE_RANGE		0x0C
259 #define	SMB_COM_UNLOCK_BYTE_RANGE	0x0D
260 #define	SMB_COM_CREATE_TEMPORARY	0x0E
261 #define	SMB_COM_CREATE_NEW		0x0F
262 #define	SMB_COM_CHECK_DIRECTORY		0x10
263 #define	SMB_COM_PROCESS_EXIT		0x11
264 #define	SMB_COM_SEEK			0x12
265 #define	SMB_COM_LOCK_AND_READ		0x13
266 #define	SMB_COM_WRITE_AND_UNLOCK	0x14
267 
268 #define	SMB_COM_READ_RAW		0x1A
269 #define	SMB_COM_READ_MPX		0x1B
270 #define	SMB_COM_READ_MPX_SECONDARY	0x1C
271 #define	SMB_COM_WRITE_RAW		0x1D
272 #define	SMB_COM_WRITE_MPX		0x1E
273 #define	SMB_COM_WRITE_MPX_SECONDARY	0x1F
274 #define	SMB_COM_WRITE_COMPLETE		0x20
275 
276 #define	SMB_COM_SET_INFORMATION2	0x22
277 #define	SMB_COM_QUERY_INFORMATION2	0x23
278 #define	SMB_COM_LOCKING_ANDX		0x24
279 #define	SMB_COM_TRANSACTION		0x25
280 #define	SMB_COM_TRANSACTION_SECONDARY	0x26
281 #define	SMB_COM_IOCTL			0x27
282 #define	SMB_COM_IOCTL_SECONDARY		0x28
283 #define	SMB_COM_COPY			0x29
284 #define	SMB_COM_MOVE			0x2A
285 #define	SMB_COM_ECHO			0x2B
286 #define	SMB_COM_WRITE_AND_CLOSE		0x2C
287 #define	SMB_COM_OPEN_ANDX		0x2D
288 #define	SMB_COM_READ_ANDX		0x2E
289 #define	SMB_COM_WRITE_ANDX		0x2F
290 
291 #define	SMB_COM_CLOSE_AND_TREE_DISC	0x31
292 #define	SMB_COM_TRANSACTION2		0x32
293 #define	SMB_COM_TRANSACTION2_SECONDARY	0x33
294 #define	SMB_COM_FIND_CLOSE2		0x34
295 #define	SMB_COM_FIND_NOTIFY_CLOSE	0x35
296 
297 #define	SMB_COM_TREE_CONNECT		0x70
298 #define	SMB_COM_TREE_DISCONNECT		0x71
299 #define	SMB_COM_NEGOTIATE		0x72
300 #define	SMB_COM_SESSION_SETUP_ANDX	0x73
301 #define	SMB_COM_LOGOFF_ANDX		0x74
302 #define	SMB_COM_TREE_CONNECT_ANDX	0x75
303 
304 #define	SMB_COM_QUERY_INFORMATION_DISK	0x80
305 #define	SMB_COM_SEARCH			0x81
306 #define	SMB_COM_FIND			0x82
307 #define	SMB_COM_FIND_UNIQUE		0x83
308 #define	SMB_COM_FIND_CLOSE		0x84
309 
310 #define	SMB_COM_NT_TRANSACT		0xA0
311 #define	SMB_COM_NT_TRANSACT_SECONDARY	0xA1
312 #define	SMB_COM_NT_CREATE_ANDX		0xA2
313 #define	SMB_COM_NT_CANCEL		0xA4
314 
315 #define	SMB_COM_OPEN_PRINT_FILE		0xC0
316 #define	SMB_COM_WRITE_PRINT_FILE	0xC1
317 #define	SMB_COM_CLOSE_PRINT_FILE	0xC2
318 #define	SMB_COM_GET_PRINT_QUEUE		0xC3
319 
320 #define	SMB_COM_NUM			0x100
321 
322 /*
323  * Flags field of the SMB header. The names in parenthesis represent
324  * alternative names for the flags.
325  *
326  * SMB_FLAGS_LOCK_AND_READ_OK     If the server supports LockAndRead and
327  * (SMB_FLAGS_LOCKS_SUBDIALECT)   WriteAndUnlock, it sets this bit in the
328  *                                Negotiate response.
329  *
330  * SMB_FLAGS_SEND_NO_ACK          When on, the client guarantees that there
331  * (SMB_FLAGS_RCV_BUF_POSTED)     is a receive buffer posted such that a
332  *                                "Send-No-Ack" can be used by the server
333  *                                to respond to the client's request.
334  *
335  * SMB_FLAGS_CASE_INSENSITIVE     This is part of the Flags field of every
336  *                                SMB header. If this bit is set, then all
337  *                                pathnames in the SMB should be treated as
338  *                                case-insensitive. Otherwise pathnames are
339  *                                case-sensitive.
340  *
341  * SMB_FLAGS_CANONICALIZED_PATHS  When on in SessionSetupX, this indicates
342  *                                that all paths sent to the server are
343  *                                already in OS/2 canonicalized format.
344  *
345  * OS/2 canonical format means that file/directory names are in upper case,
346  * are valid characters, . and .. have been removed and single backslashes
347  * are used as separators.
348  *
349  * SMB_FLAGS_OPLOCK               When set in an open file request SMBs
350  *                                (Open, Create, OpenX, etc.) this bit
351  *                                indicates a request for an oplock on the
352  *                                file. When set in the response, this bit
353  *                                indicates that the oplock was granted.
354  *
355  * SMB_FLAGS_OPLOCK_NOTIFY_ANY    When on, this bit indicates that the server
356  *                                should notify the client on any request
357  *                                that could cause the file to be changed.
358  *                                If not set, the server only notifies the
359  *                                client on other open requests on the file.
360  *                                This bit is only relevant when
361  *                                SMB_FLAGS_OPLOCK is set.
362  *
363  * SMB_FLAGS_SERVER_TO_REDIR      This bit indicates that the SMB is being
364  * (SMB_FLAGS_REPLY)              sent from server to (client) redirector.
365  */
366 #define	SMB_FLAGS_LOCK_AND_READ_OK	0x01
367 #define	SMB_FLAGS_SEND_NO_ACK		0x02
368 #define	SMB_FLAGS_RESERVED		0x04
369 #define	SMB_FLAGS_CASE_INSENSITIVE	0x08
370 #define	SMB_FLAGS_CANONICALIZED_PATHS	0x10
371 #define	SMB_FLAGS_OPLOCK		0x20
372 #define	SMB_FLAGS_OPLOCK_NOTIFY_ANY	0x40
373 #define	SMB_FLAGS_REPLY			0x80
374 
375 
376 /*
377  * Flags2 field of the SMB header.
378  *
379  * SMB_FLAGS2_READ_IF_EXECUTE is also known as SMB_FLAGS2_PAGING_IO
380  */
381 #define	SMB_FLAGS2_KNOWS_LONG_NAMES		0x0001
382 #define	SMB_FLAGS2_KNOWS_EAS			0x0002
383 #define	SMB_FLAGS2_SMB_SECURITY_SIGNATURE	0x0004
384 #define	SMB_FLAGS2_IS_LONG_NAME			0x0040
385 #define	SMB_FLAGS2_REPARSE_PATH			0x0400
386 #define	SMB_FLAGS2_EXT_SEC			0x0800
387 #define	SMB_FLAGS2_DFS				0x1000
388 #define	SMB_FLAGS2_READ_IF_EXECUTE		0x2000
389 #define	SMB_FLAGS2_NT_STATUS			0x4000
390 #define	SMB_FLAGS2_UNICODE			0x8000
391 
392 #define	DIALECT_UNKNOWN		 0
393 #define	PC_NETWORK_PROGRAM_1_0	 1  /* The original MSNET SMB protocol */
394 #define	PCLAN1_0		 2  /* Some versions of the original MSNET */
395 #define	MICROSOFT_NETWORKS_1_03	 3  /* This is used for the MS-NET 1.03 */
396 #define	MICROSOFT_NETWORKS_3_0	 4  /* This is the  DOS LANMAN 1.0 specific */
397 #define	LANMAN1_0		 5  /* This is the first version of the full */
398 #define	LM1_2X002		 6  /* This is the first version of the full */
399 #define	DOS_LM1_2X002		 7  /* This is the dos equivalent of the */
400 #define	DOS_LANMAN2_1		 8  /* DOS LANMAN2.1 */
401 #define	LANMAN2_1		 9  /* OS/2 LANMAN2.1 */
402 #define	Windows_for_Workgroups_3_1a 10 /* Windows for Workgroups Version 1.0 */
403 #define	NT_LM_0_12		11  /* The SMB protocol designed for NT */
404 
405 /*
406  * SMB_TREE_CONNECT_ANDX OptionalSupport flags
407  *
408  * SMB_SUPPORT_SEARCH_BITS    The server supports SearchAttributes.
409  * SMB_SHARE_IS_IN_DFS        The share is managed by DFS.
410  * SMB_CSC_MASK               Offline-caching mask - see CSC values.
411  * SMB_UNIQUE_FILE_NAME       The server uses long names and does not support
412  *                            short names.  This indicates to clients that
413  *                            they may perform directory name-space caching.
414  * SMB_EXTENDED_SIGNATURES    The server will use signing key protection.
415  *
416  * SMB_CSC_CACHE_MANUAL_REINT Clients are allowed to cache files for offline
417  *                            use as requested by users but automatic
418  *                            file-by-file reintegration is not allowed.
419  * SMB_CSC_CACHE_AUTO_REINT   Clients are allowed to automatically cache
420  *                            files for offline use and file-by-file
421  *                            reintegration is allowed.
422  * SMB_CSC_CACHE_VDO          Clients are allowed to automatically cache files
423  *                            for offline use, file-by-file reintegration is
424  *                            allowed and clients are permitted to work from
425  *                            their local cache even while offline.
426  * SMB_CSC_CACHE_NONE         Client-side caching is disabled for this share.
427  *
428  * SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM
429  *			      The server will filter directory entries based
430  *			      on the access permissions of the client.
431  */
432 #define	SMB_SUPPORT_SEARCH_BITS		0x0001
433 #define	SMB_SHARE_IS_IN_DFS		0x0002
434 #define	SMB_CSC_MASK			0x000C
435 #define	SMB_UNIQUE_FILE_NAME		0x0010
436 #define	SMB_EXTENDED_SIGNATURES		0x0020
437 
438 #define	SMB_CSC_CACHE_MANUAL_REINT	0x0000
439 #define	SMB_CSC_CACHE_AUTO_REINT	0x0004
440 #define	SMB_CSC_CACHE_VDO		0x0008
441 #define	SMB_CSC_CACHE_NONE		0x000C
442 
443 #define	SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM	0x0800
444 #define	SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING		0x0400
445 
446 /*
447  * The subcommand codes, placed in SETUP[0], for named pipe operations are:
448  * SubCommand Code	Value Description
449  * ===================	===== =========================================
450  */
451 
452 #define	CallNamedPipe	0x54	/* open/write/read/close pipe */
453 #define	WaitNamedPipe	0x53	/* wait for pipe to be nonbusy */
454 #define	PeekNmPipe	0x23	/* read but don't remove data */
455 #define	QNmPHandState	0x21	/* query pipe handle modes */
456 #define	SetNmPHandState	0x01	/* set pipe handle modes */
457 #define	QNmPipeInfo	0x22	/* query pipe attributes */
458 #define	TransactNmPipe	0x26	/* write/read operation on pipe */
459 #define	RawReadNmPipe	0x11	/* read pipe in "raw" (non message mode) */
460 #define	RawWriteNmPipe	0x31	/* write pipe "raw" (non message mode) */
461 
462 
463 
464 /*
465  * Setup[0] Transaction2       Value  Description
466  * Subcommand Code
467  * ==========================  =====  =============================
468  */
469 
470 #define	TRANS2_OPEN2		0x00	/* Create file, extended attributes */
471 #define	TRANS2_FIND_FIRST2	0x01	/* Begin search for files */
472 #define	TRANS2_FIND_NEXT2	0x02	/* Resume search for files */
473 #define	TRANS2_QUERY_FS_INFORMATION 0x03 /* Get file system information */
474 #define	TRANS2_SET_FS_INFORMATION	0x04	/* Set file system info. */
475 #define	TRANS2_QUERY_PATH_INFORMATION 0x05 /* Get info, named file or dir */
476 #define	TRANS2_SET_PATH_INFORMATION 0x06 /* Set info, named file or dir */
477 #define	TRANS2_QUERY_FILE_INFORMATION 0x07 /* Get info, handle */
478 #define	TRANS2_SET_FILE_INFORMATION 0x08 /* Set info, handle */
479 #define	TRANS2_FSCTL		0x09	/* Not implemented by NT server */
480 #define	TRANS2_IOCTL2		0x0A	/* Not implemented by NT server */
481 #define	TRANS2_FIND_NOTIFY_FIRST 0x0B	/* Not implemented by NT server */
482 #define	TRANS2_FIND_NOTIFY_NEXT 0x0C	/* Not implemented by NT server */
483 #define	TRANS2_CREATE_DIRECTORY 0x0D	/* Create dir, extended attributes */
484 #define	TRANS2_SESSION_SETUP	0x0E	/* Session setup, extended security */
485 #define	TRANS2_GET_DFS_REFERRAL	0x10	/* Get a Dfs referral */
486 #define	TRANS2_REPORT_DFS_INCONSISTENCY 0x11 /* Report a Dfs inconsistency */
487 
488 /*
489  * Access Mode Encoding (CIFS/1.0 1996 Section 3.8).
490  *
491  * The desired access mode passed in SmbOpen and SmbOpenAndX has the following
492  * mapping:
493  *
494  *    1111 11
495  *    5432 1098 7654 3210
496  *    rWrC rLLL rSSS rAAA
497  *
498  * where:
499  *
500  *    W - Write through mode.  No read ahead or write behind allowed on
501  *        this file or device.  When protocol is returned, data is expected
502  *        to be on the disk or device.
503  *
504  *    S - Sharing mode:
505  *        0 - Compatibility mode (as in core open)
506  *        1 - Deny read/write/execute (exclusive)
507  *        2 - Deny write
508  *        3 - Deny read/execute
509  *        4 - Deny none
510  *
511  *    A - Access mode
512  *        0 - Open for reading
513  *        1 - Open for writing
514  *        2 - Open for reading and writing
515  *        3 - Open for execute
516  *
517  *    rSSSrAAA = 11111111 (hex FF) indicates FCB open (as in core protocol)
518  *
519  *    C - Cache mode
520  *        0 - Normal file
521  *        1 - Do not cache this file
522  *
523  *    L - Locality of reference
524  *        0 - Locality of reference is unknown
525  *        1 - Mainly sequential access
526  *        2 - Mainly random access
527  *        3 - Random access with some locality
528  *        4 to 7 - Currently undefined
529  */
530 
531 
532 #define	SMB_DA_SHARE_MASK		0x70
533 #define	SMB_DA_ACCESS_MASK		0x07
534 #define	SMB_DA_FCB_MASK			(UCHAR)0xFF
535 
536 #define	SMB_DA_ACCESS_READ		0x00
537 #define	SMB_DA_ACCESS_WRITE		0x01
538 #define	SMB_DA_ACCESS_READ_WRITE	0x02
539 #define	SMB_DA_ACCESS_EXECUTE		0x03
540 
541 #define	SMB_DA_SHARE_COMPATIBILITY	0x00
542 #define	SMB_DA_SHARE_EXCLUSIVE		0x10
543 #define	SMB_DA_SHARE_DENY_WRITE		0x20
544 #define	SMB_DA_SHARE_DENY_READ		0x30
545 #define	SMB_DA_SHARE_DENY_NONE		0x40
546 
547 #define	SMB_DA_FCB			(UCHAR)0xFF
548 
549 #define	SMB_CACHE_NORMAL		0x0000
550 #define	SMB_DO_NOT_CACHE		0x1000
551 
552 #define	SMB_LR_UNKNOWN			0x0000
553 #define	SMB_LR_SEQUENTIAL		0x0100
554 #define	SMB_LR_RANDOM			0x0200
555 #define	SMB_LR_RANDOM_WITH_LOCALITY	0x0300
556 #define	SMB_LR_MASK			0x0F00
557 
558 #define	SMB_DA_WRITE_THROUGH		0x4000
559 
560 /*
561  * Macros used for share reservation rule checking
562  */
563 
564 #define	SMB_DENY_READ(share_access) ((share_access & FILE_SHARE_READ) == 0)
565 
566 #define	SMB_DENY_WRITE(share_access) ((share_access & FILE_SHARE_WRITE) == 0)
567 
568 #define	SMB_DENY_DELETE(share_access) ((share_access & FILE_SHARE_DELETE) == 0)
569 
570 #define	SMB_DENY_RW(share_access) \
571 	((share_access & (FILE_SHARE_READ | FILE_SHARE_WRITE)) == 0)
572 
573 #define	SMB_DENY_ALL(share_access) (share_access == 0)
574 
575 #define	SMB_DENY_NONE(share_access) (share_access == FILE_SHARE_ALL)
576 
577 /*
578  * The SMB open function determines what action should be taken depending
579  * on the existence or lack thereof of files used in the operation.  It
580  * has the following mapping:
581  *
582  *    1111 1
583  *    5432 1098 7654 3210
584  *    rrrr rrrr rrrC rrOO
585  *
586  * where:
587  *
588  *    O - Open (action to be taken if the target file exists)
589  *        0 - Fail
590  *        1 - Open or Append file
591  *        2 - Truncate file
592  *
593  *    C - Create (action to be taken if the target file does not exist)
594  *        0 - Fail
595  *        1 - Create file
596  */
597 
598 #define	SMB_OFUN_OPEN_MASK		0x3
599 #define	SMB_OFUN_CREATE_MASK		0x10
600 
601 #define	SMB_OFUN_OPEN_FAIL		0
602 #define	SMB_OFUN_OPEN_APPEND		1
603 #define	SMB_OFUN_OPEN_OPEN		1
604 #define	SMB_OFUN_OPEN_TRUNCATE		2
605 
606 #define	SMB_OFUN_CREATE_FAIL		0x00
607 #define	SMB_OFUN_CREATE_CREATE		0x10
608 
609 /*
610  * The Action field of OpenAndX has the following format:
611  *
612  *    1111 11
613  *    5432 1098 7654 3210
614  *    Lrrr rrrr rrrr rrOO
615  *
616  * where:
617  *
618  *    L - Opportunistic lock.  1 if lock granted, else 0.
619  *
620  *    O - Open action:
621  *        1 - The file existed and was opened
622  *        2 - The file did not exist but was created
623  *        3 - The file existed and was truncated
624  */
625 
626 #define	SMB_OACT_LOCK			0x8000
627 #define	SMB_OACT_OPENED			0x01
628 #define	SMB_OACT_CREATED		0x02
629 #define	SMB_OACT_TRUNCATED		0x03
630 
631 #define	SMB_OACT_OPLOCK			0x8000
632 
633 #define	SMB_FTYPE_DISK			0
634 #define	SMB_FTYPE_BYTE_PIPE		1
635 #define	SMB_FTYPE_MESG_PIPE		2
636 #define	SMB_FTYPE_PRINTER		3
637 #define	SMB_FTYPE_UNKNOWN		0xFFFF
638 
639 #define	SMB_DEVST_BLOCKING		0x8000
640 #define	SMB_DEVST_ENDPOINT		0x4000
641 #define	SMB_DEVST_TYPE_MASK		0x0C00
642 #define	SMB_DEVST_TYPE_BYTE_PIPE	0x0000
643 #define	SMB_DEVST_TYPE_MESG_PIPE	0x0400
644 #define	SMB_DEVST_RMODE_MASK		0x0300
645 #define	SMB_DEVST_RMODE_BYTES		0x0000
646 #define	SMB_DEVST_RMODE_MESGS		0x0100
647 #define	SMB_DEVST_ICOUNT_MASK		0x00FF		/* not used */
648 
649 #define	SMB_FTYPE_IS_DISK(F)		((F) == SMB_FTYPE_DISK)
650 #define	SMB_FTYPE_IS_PIPE(F) \
651 	(((F) == SMB_FTYPE_BYTE_PIPE) || ((F) == SMB_FTYPE_MESG_PIPE))
652 #define	SMB_FTYPE_IS_PRINTER(F)		((F) == SMB_FTYPE_PRINTER)
653 
654 /*
655  * TRANS2_FIND
656  */
657 #define	SMB_FIND_FILE_DIRECTORY_INFO		0x101
658 #define	SMB_FIND_FILE_FULL_DIRECTORY_INFO	0x102
659 #define	SMB_FIND_FILE_NAMES_INFO		0x103
660 #define	SMB_FIND_FILE_BOTH_DIRECTORY_INFO	0x104
661 #define	SMB_FIND_FILE_ID_FULL_DIRECTORY_INFO	0x105
662 #define	SMB_FIND_FILE_ID_BOTH_DIRECTORY_INFO	0x106
663 #define	SMB_MAC_FIND_BOTH_HFS_INFO		MAC_FIND_BOTH_HFS_INFO
664 
665 
666 /*
667  * Flags for TRANS2_FIND_FIRST2 and TRANS2_FIND_NEXT2 (NTDDK).
668  *
669  * If SMB_FIND_RETURN_RESUME_KEYS was set in the request parameters,
670  * each entry is preceded by a four-byte resume key.
671  */
672 #define	SMB_FIND_CLOSE_AFTER_REQUEST	0x01
673 #define	SMB_FIND_CLOSE_AT_EOS		0x02
674 #define	SMB_FIND_RETURN_RESUME_KEYS	0x04
675 #define	SMB_FIND_CONTINUE_FROM_LAST	0x08
676 #define	SMB_FIND_WITH_BACKUP_INTENT	0x10
677 
678 
679 /*
680  * TRANS2_QUERY_FS_INFORMATION
681  *
682  * SMB_QUERY_FS_QUOTA_INFO, SMB_QUERY_FS_CONTROL_INFO are not used in Windows
683  * NT, and are not used in any post NT Windows operating systems. If a server
684  * receives these information levels from a client, it should handle them as
685  * invalid information levels.
686  */
687 #define	SMB_INFO_ALLOCATION		1
688 #define	SMB_INFO_VOLUME			2
689 #define	SMB_QUERY_FS_LABEL_INFO		0x101
690 #define	SMB_QUERY_FS_VOLUME_INFO	0x102
691 #define	SMB_QUERY_FS_SIZE_INFO		0x103
692 #define	SMB_QUERY_FS_DEVICE_INFO	0x104
693 #define	SMB_QUERY_FS_ATTRIBUTE_INFO	0x105
694 #define	SMB_QUERY_FS_QUOTA_INFO		0x106
695 #define	SMB_QUERY_FS_CONTROL_INFO	0x107
696 
697 #define	SMB_MAC_QUERY_FS_INFO		MAC_QUERY_FS_INFO
698 
699 /*
700  * Internal use only.
701  * Define information levels to represent the following requests:
702  *    smb_query_information
703  *    smb_query_information2
704  *    smb_set_information
705  *    smb_set_information2
706  */
707 #define	SMB_QUERY_INFORMATION	0x3001
708 #define	SMB_QUERY_INFORMATION2	0x3002
709 #define	SMB_SET_INFORMATION	0x3001
710 #define	SMB_SET_INFORMATION2	0x3002
711 
712 /* TRANS2_QUERY_{PATH,FILE}_INFORMATION */
713 #define	SMB_INFO_STANDARD		 1	/* query, set */
714 #define	SMB_INFO_QUERY_EA_SIZE		 2	/* query */
715 #define	SMB_INFO_SET_EAS		 2	/* set */
716 #define	SMB_INFO_QUERY_EAS_FROM_LIST	 3	/* query */
717 #define	SMB_INFO_QUERY_ALL_EAS		 4	/* query */
718 #define	SMB_INFO_QUERY_FULL_NAME	 5	/* unused */
719 #define	SMB_INFO_IS_NAME_VALID		 6	/* query */
720 
721 #define	SMB_QUERY_FILE_BASIC_INFO	 0x101
722 #define	SMB_QUERY_FILE_STANDARD_INFO	 0x102
723 #define	SMB_QUERY_FILE_EA_INFO		 0x103
724 #define	SMB_QUERY_FILE_NAME_INFO	 0x104
725 #define	SMB_QUERY_FILE_ALLOCATION_INFO	 0x105	/* unused */
726 #define	SMB_QUERY_FILE_END_OF_FILE_INFO	 0x106	/* unused */
727 #define	SMB_QUERY_FILE_ALL_INFO		 0x107
728 #define	SMB_QUERY_FILE_ALT_NAME_INFO	 0x108
729 #define	SMB_QUERY_FILE_STREAM_INFO	 0x109
730 #define	SMB_QUERY_FILE_COMPRESSION_INFO	 0x10B
731 
732 #define	SMB_MAC_SET_FINDER_INFO		MAC_SET_FINDER_INFO
733 #define	SMB_MAC_DT_ADD_APPL		MAC_DT_ADD_APPL
734 #define	SMB_MAC_DT_REMOVE_APPL		MAC_DT_REMOVE_APPL
735 #define	SMB_MAC_DT_GET_APPL		MAC_DT_GET_APPL
736 #define	SMB_MAC_DT_GET_ICON		MAC_DT_GET_ICON
737 #define	SMB_MAC_DT_GET_ICON_INFO	MAC_DT_GET_ICON_INFO
738 #define	SMB_MAC_DT_ADD_ICON		MAC_DT_ADD_ICON
739 
740 #define	SMB_SET_FILE_BASIC_INFO		0x101
741 #define	SMB_SET_FILE_DISPOSITION_INFO	0x102
742 #define	SMB_SET_FILE_ALLOCATION_INFO	0x103
743 #define	SMB_SET_FILE_END_OF_FILE_INFO	0x104
744 
745 
746 /* NT passthrough levels - see ntifs.h FILE_INFORMATION_CLASS */
747 #define	SMB_FILE_BASIC_INFORMATION		1004
748 #define	SMB_FILE_STANDARD_INFORMATION		1005
749 #define	SMB_FILE_INTERNAL_INFORMATION		1006
750 #define	SMB_FILE_EA_INFORMATION			1007
751 #define	SMB_FILE_ACCESS_INFORMATION		1008
752 #define	SMB_FILE_NAME_INFORMATION		1009
753 #define	SMB_FILE_RENAME_INFORMATION		1010
754 #define	SMB_FILE_LINK_INFORMATION		1011
755 #define	SMB_FILE_DISPOSITION_INFORMATION	1013
756 #define	SMB_FILE_ALL_INFORMATION		1018
757 #define	SMB_FILE_ALLOCATION_INFORMATION		1019
758 #define	SMB_FILE_END_OF_FILE_INFORMATION	1020
759 #define	SMB_FILE_ALT_NAME_INFORMATION		1021
760 #define	SMB_FILE_STREAM_INFORMATION		1022
761 #define	SMB_FILE_COMPRESSION_INFORMATION	1028
762 #define	SMB_FILE_NETWORK_OPEN_INFORMATION	1034
763 #define	SMB_FILE_ATTR_TAG_INFORMATION		1035
764 
765 /* NT passthrough levels - see ntifs.h FILE_FS_INFORMATION_CLASS */
766 #define	SMB_FILE_FS_VOLUME_INFORMATION		1001
767 #define	SMB_FILE_FS_LABEL_INFORMATION		1002
768 #define	SMB_FILE_FS_SIZE_INFORMATION		1003
769 #define	SMB_FILE_FS_DEVICE_INFORMATION		1004
770 #define	SMB_FILE_FS_ATTRIBUTE_INFORMATION	1005
771 #define	SMB_FILE_FS_CONTROL_INFORMATION		1006
772 #define	SMB_FILE_FS_FULLSIZE_INFORMATION	1007
773 #define	SMB_FILE_FS_OBJECTID_INFORMATION	1008
774 #define	SMB_FILE_FS_DRIVERPATH_INFORMATION	1009
775 
776 /*
777  * The following bits may be set in the SecurityMode field of the
778  * SMB_COM_NEGOTIATE response.
779  *
780  * Notes:
781  * NEGOTIATE_SECURITY_SHARE_LEVEL is a montana2 invention.
782  *
783  * The NTDDK definitions are:
784  * #define	NEGOTIATE_USER_SECURITY			    0x01
785  * #define	NEGOTIATE_ENCRYPT_PASSWORDS		    0x02
786  * #define	NEGOTIATE_SECURITY_SIGNATURES_ENABLED	    0x04
787  * #define	NEGOTIATE_SECURITY_SIGNATURES_REQUIRED	    0x08
788  */
789 #define	NEGOTIATE_SECURITY_SHARE_LEVEL		    0x00
790 #define	NEGOTIATE_SECURITY_USER_LEVEL		    0x01
791 #define	NEGOTIATE_SECURITY_CHALLENGE_RESPONSE	    0x02
792 #define	NEGOTIATE_SECURITY_SIGNATURES_ENABLED	    0x04
793 #define	NEGOTIATE_SECURITY_SIGNATURES_REQUIRED	    0x08
794 
795 
796 /*
797  * Negotiated Capabilities (CIFS/1.0 section 4.1.1)
798  *
799  * Capabilities allow the server to tell the client what it supports.
800  * Undefined bits MUST be set to zero by servers, and MUST be ignored
801  * by clients. The bit definitions are:
802  *
803  * Capability Name	 Encoding   Meaning
804  * ====================	 ========   ==================================
805  * CAP_RAW_MODE		 0x0001	    The server supports SMB_COM_READ_RAW and
806  *				    SMB_COM_WRITE_RAW (obsolescent)
807  * CAP_MPX_MODE		 0x0002	    The server supports SMB_COM_READ_MPX and
808  *				    SMB_COM_WRITE_MPX (obsolescent)
809  * CAP_UNICODE		 0x0004	    The server supports Unicode strings
810  * CAP_LARGE_FILES	 0x0008	    The server supports large files with 64
811  *				    bit offsets
812  * CAP_NT_SMBS		 0x0010	    The server supports the SMBs particular
813  *				    to the NT LM 0.12 dialect.
814  *				    Implies CAP_NT_FIND.
815  * CAP_RPC_REMOTE_APIS	 0x0020	    The server supports remote admin API
816  *				    requests via DCE RPC
817  * CAP_STATUS32		 0x0040	    The server can respond with 32 bit
818  *				    status codes in Status.Status
819  * CAP_LEVEL_II_OPLOCKS	 0x0080	    The server supports level 2 oplocks
820  * CAP_LOCK_AND_READ	 0x0100	    The server supports the
821  *				    SMB_COM_LOCK_AND_READ SMB
822  * CAP_NT_FIND		 0x0200
823  * CAP_BULK_TRANSFER	 0x0400
824  * CAP_COMPRESSED_BULK	 0x0800
825  * CAP_DFS		 0x1000	    The server is DFS aware
826  * CAP_INFOLEVEL_PASSTHRU 0x2000    The server supports passthru information
827  *				    level processing capability.
828  * CAP_LARGE_READX	 0x4000	    The server supports large
829  *				    SMB_COM_READ_ANDX
830  * CAP_LARGE_WRITEX	 0x8000	    The server supports large
831  *				    SMB_COM_WRITE_ANDX
832  * CAP_RESERVED		 0x02000000 Reserved for future use.
833  * CAP_EXTENDED_SECURITY 0x80000000 The server supports extended security
834  *				    exchanges.
835  *
836  * Extended security exchanges provides a means of supporting arbitrary
837  * authentication protocols within CIFS. Security blobs are opaque to the
838  * CIFS protocol; they are messages in some authentication protocol that
839  * has been agreed upon by client and server by some out of band mechanism,
840  * for which CIFS merely functions as a transport. When
841  * CAP_EXTENDED_SECURITY is negotiated, the server includes a first
842  * security blob in its response; subsequent security blobs are exchanged
843  * in SMB_COM_SESSION_SETUP_ANDX requests and responses until the
844  * authentication protocol terminates.
845  */
846 #define	CAP_RAW_MODE			0x0001
847 #define	CAP_MPX_MODE			0x0002
848 #define	CAP_UNICODE			0x0004
849 #define	CAP_LARGE_FILES			0x0008
850 #define	CAP_NT_SMBS			0x0010
851 #define	CAP_RPC_REMOTE_APIS		0x0020
852 #define	CAP_STATUS32			0x0040
853 #define	CAP_LEVEL_II_OPLOCKS		0x0080
854 #define	CAP_LOCK_AND_READ		0x0100
855 #define	CAP_NT_FIND			0x0200
856 #define	CAP_BULK_TRANSFER		0x0400
857 #define	CAP_COMPRESSED_BULK		0x0800
858 #define	CAP_DFS				0x1000
859 #define	CAP_INFOLEVEL_PASSTHRU		0x2000
860 #define	CAP_LARGE_READX			0x4000
861 #define	CAP_LARGE_WRITEX		0x8000
862 #define	CAP_RESERVED			0x02000000
863 #define	CAP_EXTENDED_SECURITY		0x80000000
864 
865 
866 /*
867  * Different device types according to NT
868  */
869 #define	FILE_DEVICE_BEEP		0x00000001
870 #define	FILE_DEVICE_CD_ROM		0x00000002
871 #define	FILE_DEVICE_CD_ROM_FILE_SYSTEM	0x00000003
872 #define	FILE_DEVICE_CONTROLLER		0x00000004
873 #define	FILE_DEVICE_DATALINK		0x00000005
874 #define	FILE_DEVICE_DFS			0x00000006
875 #define	FILE_DEVICE_DISK		0x00000007
876 #define	FILE_DEVICE_DISK_FILE_SYSTEM	0x00000008
877 #define	FILE_DEVICE_FILE_SYSTEM		0x00000009
878 #define	FILE_DEVICE_INPORT_PORT		0x0000000a
879 #define	FILE_DEVICE_KEYBOARD		0x0000000b
880 #define	FILE_DEVICE_MAILSLOT		0x0000000c
881 #define	FILE_DEVICE_MIDI_IN		0x0000000d
882 #define	FILE_DEVICE_MIDI_OUT		0x0000000e
883 #define	FILE_DEVICE_MOUSE		0x0000000f
884 #define	FILE_DEVICE_MULTI_UNC_PROVIDER	0x00000010
885 #define	FILE_DEVICE_NAMED_PIPE		0x00000011
886 #define	FILE_DEVICE_NETWORK		0x00000012
887 #define	FILE_DEVICE_NETWORK_BROWSER	0x00000013
888 #define	FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
889 #define	FILE_DEVICE_NULL		0x00000015
890 #define	FILE_DEVICE_PARALLEL_PORT	0x00000016
891 #define	FILE_DEVICE_PHYSICAL_NETCARD	0x00000017
892 #define	FILE_DEVICE_PRINTER		0x00000018
893 #define	FILE_DEVICE_SCANNER		0x00000019
894 #define	FILE_DEVICE_SERIAL_MOUSE_PORT	0x0000001a
895 #define	FILE_DEVICE_SERIAL_PORT		0x0000001b
896 #define	FILE_DEVICE_SCREEN		0x0000001c
897 #define	FILE_DEVICE_SOUND		0x0000001d
898 #define	FILE_DEVICE_STREAMS		0x0000001e
899 #define	FILE_DEVICE_TAPE		0x0000001f
900 #define	FILE_DEVICE_TAPE_FILE_SYSTEM	0x00000020
901 #define	FILE_DEVICE_TRANSPORT		0x00000021
902 #define	FILE_DEVICE_UNKNOWN		0x00000022
903 #define	FILE_DEVICE_VIDEO		0x00000023
904 #define	FILE_DEVICE_VIRTUAL_DISK	0x00000024
905 #define	FILE_DEVICE_WAVE_IN		0x00000025
906 #define	FILE_DEVICE_WAVE_OUT		0x00000026
907 #define	FILE_DEVICE_8042_PORT		0x00000027
908 #define	FILE_DEVICE_NETWORK_REDIRECTOR	0x00000028
909 #define	FILE_DEVICE_BATTERY		0x00000029
910 #define	FILE_DEVICE_BUS_EXTENDER	0x0000002a
911 #define	FILE_DEVICE_MODEM		0x0000002b
912 #define	FILE_DEVICE_VDM			0x0000002c
913 
914 /*
915  * Some of these device types are not currently accessible over the network
916  * and may never be accessible over the network. Some may change to be
917  *
918  * accessible over the network. The values for device types that may never
919  * be accessible over the network may be redefined to be just reserved at
920  * some date in the future.
921  *
922  * Characteristics is the sum of any of the following:
923  */
924 
925 #define	FILE_REMOVABLE_MEDIA		0x00000001
926 #define	FILE_READ_ONLY_DEVICE		0x00000002
927 #define	FILE_FLOPPY_DISKETTE		0x00000004
928 #define	FILE_WRITE_ONE_MEDIA		0x00000008
929 #define	FILE_REMOTE_DEVICE		0x00000010
930 #define	FILE_DEVICE_IS_MOUNTED		0x00000020
931 #define	FILE_VIRTUAL_VOLUME		0x00000040
932 
933 /*
934  * CREATE_ANDX ShareAccess Flags
935  */
936 
937 #define	FILE_SHARE_NONE			0x00000000
938 #define	FILE_SHARE_READ			0x00000001
939 #define	FILE_SHARE_WRITE		0x00000002
940 #define	FILE_SHARE_DELETE		0x00000004
941 #define	FILE_SHARE_ALL			0x00000007
942 #define	FILE_SHARE_VALID_FLAGS		0x00000007
943 
944 
945 /*
946  * CREATE_ANDX CreateDisposition flags
947  *
948  * FILE_SUPERSEDE     If the file already exists it should be superseded
949  *		      by the specified file. If the file does not already
950  *		      exist then it should be created.
951  *
952  * FILE_CREATE	      If the file already exists the operation should fail.
953  *		      If the file does not already exist then it should be
954  *		      created. (aka CREATE_NEW)
955  *
956  * FILE_OPEN	      If the file already exists then it should be opened.
957  *		      If the file does not already exist then the operation
958  *		      should fail. (aka OPEN_EXISTING)
959  *
960  * FILE_OPEN_IF	      If the file already exists then it should be opened.
961  *		      If the file does not already exist then it should be
962  *		      created. (aka OPEN_ALWAYS)
963  *
964  * FILE_OVERWRITE     If the file already exists, it should be opened and
965  *		      overwritten. If the file does not already exist then
966  *		      the operation should fail. (aka TRUNCATE_EXISTING)
967  *
968  * FILE_OVERWRITE_IF  If the file already exists, it should be opened and
969  *		      overwritten. If the file does not already exist then
970  *		      it should be created. (aka CREATE_ALWAYS)
971  */
972 #define	FILE_SUPERSEDE			0x00000000
973 #define	FILE_OPEN			0x00000001
974 #define	FILE_CREATE			0x00000002
975 #define	FILE_OPEN_IF			0x00000003
976 #define	FILE_OVERWRITE			0x00000004
977 #define	FILE_OVERWRITE_IF		0x00000005
978 #define	FILE_MAXIMUM_DISPOSITION	0x00000005
979 
980 /*
981  * CREATE_ANDX Impersonation levels
982  */
983 
984 #define	SECURITY_ANONYMOUS	0x00000001
985 #define	SECURITY_IDENTIFICATION	0x00000002
986 #define	SECURITY_IMPERSONATION	0x00000003
987 #define	SECURITY_DELEGATION	0x00000004
988 
989 /*
990  * CREATE_ANDX SecurityFlags
991  */
992 
993 #define	SECURITY_CONTEXT_TRACKING	0x00000001
994 #define	SECURITY_EFFECTIVE_ONLY		0x00000002
995 
996 /*
997  * Server types
998  */
999 #define	SV_WORKSTATION		0x00000001	/* All workstations */
1000 #define	SV_SERVER		0x00000002	/* All servers */
1001 #define	SV_SQLSERVER		0x00000004	/* running with SQL server */
1002 #define	SV_DOMAIN_CTRL		0x00000008	/* Primary domain controller */
1003 #define	SV_DOMAIN_BAKCTRL	0x00000010	/* Backup domain controller */
1004 #define	SV_TIME_SOURCE		0x00000020	/* running timesource service */
1005 #define	SV_AFP			0x00000040	/* Apple File Protocol */
1006 #define	SV_NOVELL		0x00000080	/* Novell servers */
1007 #define	SV_DOMAIN_MEMBER	0x00000100	/* Domain Member */
1008 #define	SV_PRINTQ_SERVER	0x00000200	/* Server sharing print queue */
1009 #define	SV_DIALIN_SERVER	0x00000400	/* Server running dialin */
1010 #define	SV_XENIX_SERVER		0x00000800	/* Xenix server */
1011 #define	SV_NT			0x00001000	/* NT server */
1012 #define	SV_WFW			0x00002000	/* Server running Windows for */
1013 #define	SV_SERVER_NT		0x00008000	/* Windows NT non DC server */
1014 #define	SV_POTENTIAL_BROWSER	0x00010000	/* can run browser service */
1015 #define	SV_BACKUP_BROWSER	0x00020000	/* Backup browser server */
1016 #define	SV_MASTER_BROWSER	0x00040000	/* Master browser server */
1017 #define	SV_DOMAIN_MASTER	0x00080000	/* Domain Master Browser */
1018 #define	SV_OSF			0x00100000	/* OSF operating system */
1019 #define	SV_VMS			0x00200000	/* VMS operating system */
1020 #define	SV_WINDOWS_95_PLUS	0x00400000	/* Windows 95 or better */
1021 
1022 #define	SV_LOCAL_LIST_ONLY	0x40000000	/* Enumerate only "local" */
1023 #define	SV_TYPE_DOMAIN_ENUM	0x80000000	/*  Enumerate Domains */
1024 
1025 #define	MY_SERVER_TYPE	(SV_SERVER | SV_NT | SV_SERVER_NT)
1026 
1027 
1028 #define	PRQ_ACTIVE	0	/* Active */
1029 #define	PRQ_PAUSE	1	/* Paused */
1030 #define	PRQ_ERROR	2	/* Error Occurred */
1031 #define	PRQ_PENDING	3	/* Deletion pending */
1032 
1033 #define	PRJ_QS_QUEUED	0	/* Active */
1034 #define	PRJ_QS_PAUSED	1	/* Paused */
1035 #define	PRJ_QS_SPOOLING	2	/* Paused */
1036 #define	PRJ_QS_PRINTING	3	/* Paused */
1037 
1038 
1039 #define	SHARE_ACCESS_READ	0x01	/* read & execute from resource	*/
1040 #define	SHARE_ACCESS_WRITE	0x02	/* write data to resource	*/
1041 #define	SHARE_ACCESS_CREATE	0x04	/* create an instance of	*/
1042 #define	SHARE_ACCESS_EXEC	0x08	/* execute from resource	*/
1043 #define	SHARE_ACCESS_DELETE	0x10	/* Permission to delete the resource */
1044 #define	SHARE_ACCESS_ATTRIB	0x20	/* Permission to modify the resource */
1045 #define	SHARE_ACCESS_PERM	0x40	/* Permission to change permissions */
1046 #define	SHARE_ACCESS_ALL	0x7F	/* All of the above permissions	*/
1047 
1048 
1049 /*
1050  * SMB_COM_NT_TRANSACTION sub-command codes (CIFS/1.0 section 5.3)
1051  *
1052  * SubCommand Code		   Value Description
1053  * =============================== ===== =================================
1054  * NT_TRANSACT_CREATE		   1	 File open/create
1055  * NT_TRANSACT_IOCTL		   2	 Device IOCTL
1056  * NT_TRANSACT_SET_SECURITY_DESC   3	 Set security descriptor
1057  * NT_TRANSACT_NOTIFY_CHANGE	   4	 Start directory watch
1058  * NT_TRANSACT_RENAME		   5	 Reserved (handle-based rename)
1059  * NT_TRANSACT_QUERY_SECURITY_DESC 6	 Retrieve security descriptor
1060  * NT_TRANSACT_QUERY_QUOTA	   7	 Retrieve quota information
1061  * NT_TRANSACT_SET_QUOTA	   8	 Set quota information
1062  */
1063 #define	NT_TRANSACT_MIN_FUNCTION	1
1064 
1065 #define	NT_TRANSACT_CREATE		1
1066 #define	NT_TRANSACT_IOCTL		2
1067 #define	NT_TRANSACT_SET_SECURITY_DESC	3
1068 #define	NT_TRANSACT_NOTIFY_CHANGE	4
1069 #define	NT_TRANSACT_RENAME		5
1070 #define	NT_TRANSACT_QUERY_SECURITY_DESC 6
1071 #define	NT_TRANSACT_QUERY_QUOTA		7
1072 #define	NT_TRANSACT_SET_QUOTA		8
1073 
1074 #define	NT_TRANSACT_MAX_FUNCTION	8
1075 
1076 
1077 /*
1078  * Pipe states
1079  */
1080 #define	SMB_PIPE_READMODE_BYTE		0x0000
1081 #define	SMB_PIPE_READMODE_MESSAGE	0x0100
1082 #define	SMB_PIPE_TYPE_BYTE		0x0000
1083 #define	SMB_PIPE_TYPE_MESSAGE		0x0400
1084 #define	SMB_PIPE_END_CLIENT		0x0000
1085 #define	SMB_PIPE_END_SERVER		0x4000
1086 #define	SMB_PIPE_WAIT			0x0000
1087 #define	SMB_PIPE_NOWAIT			0x8000
1088 #define	SMB_PIPE_UNLIMITED_INSTANCES	0x00FF
1089 
1090 /*
1091  * smb_com_seek request
1092  */
1093 #define	SMB_SEEK_SET	0 /* set file offset to specified offset */
1094 #define	SMB_SEEK_CUR	1 /* set file offset to current plus specified offset */
1095 #define	SMB_SEEK_END	2 /* set file offset to EOF plus specified offset */
1096 
1097 /*
1098  * API Numbers for Transact based RAP (Remote Administration Protocol) calls
1099  */
1100 #define	API_WshareEnum			0
1101 #define	API_WshareGetInfo		1
1102 #define	API_WshareSetInfo		2
1103 #define	API_WshareAdd			3
1104 #define	API_WshareDel			4
1105 #define	API_NetShareCheck		5
1106 #define	API_WsessionEnum		6
1107 #define	API_WsessionGetInfo		7
1108 #define	API_WsessionDel			8
1109 #define	API_WconnectionEnum		9
1110 #define	API_WfileEnum			10
1111 #define	API_WfileGetInfo		11
1112 #define	API_WfileClose			12
1113 #define	API_WserverGetInfo		13
1114 #define	API_WserverSetInfo		14
1115 #define	API_WserverDiskEnum		15
1116 #define	API_WserverAdminCommand		16
1117 #define	API_NetAuditOpen		17
1118 #define	API_WauditClear			18
1119 #define	API_NetErrorLogOpen		19
1120 #define	API_WerrorLogClear		20
1121 #define	API_NetCharDevEnum		21
1122 #define	API_NetCharDevGetInfo		22
1123 #define	API_WCharDevControl		23
1124 #define	API_NetCharDevQEnum		24
1125 #define	API_NetCharDevQGetInfo		25
1126 #define	API_WCharDevQSetInfo		26
1127 #define	API_WCharDevQPurge		27
1128 #define	API_WCharDevQPurgeSelf		28
1129 #define	API_WMessageNameEnum		29
1130 #define	API_WMessageNameGetInfo		30
1131 #define	API_WMessageNameAdd		31
1132 #define	API_WMessageNameDel		32
1133 #define	API_WMessageNameFwd		33
1134 #define	API_WMessageNameUnFwd		34
1135 #define	API_WMessageBufferSend		35
1136 #define	API_WMessageFileSend		36
1137 #define	API_WMessageLogFileSet		37
1138 #define	API_WMessageLogFileGet		38
1139 #define	API_WServiceEnum		39
1140 #define	API_WServiceInstall		40
1141 #define	API_WServiceControl		41
1142 #define	API_WAccessEnum			42
1143 #define	API_WAccessGetInfo		43
1144 #define	API_WAccessSetInfo		44
1145 #define	API_WAccessAdd			45
1146 #define	API_WAccessDel			46
1147 #define	API_WGroupEnum			47
1148 #define	API_WGroupAdd			48
1149 #define	API_WGroupDel			49
1150 #define	API_WGroupAddUser		50
1151 #define	API_WGroupDelUser		51
1152 #define	API_WGroupGetUsers		52
1153 #define	API_WUserEnum			53
1154 #define	API_WUserAdd			54
1155 #define	API_WUserDel			55
1156 #define	API_WUserGetInfo		56
1157 #define	API_WUserSetInfo		57
1158 #define	API_WUserPasswordSet		58
1159 #define	API_WUserGetGroups		59
1160 #define	API_DeadTableEntry		60
1161 #define	API_WWkstaSetUID		62
1162 #define	API_WWkstaGetInfo		63
1163 #define	API_WWkstaSetInfo		64
1164 #define	API_WUseEnum			65
1165 #define	API_WUseAdd			66
1166 #define	API_WUseDel			67
1167 #define	API_WUseGetInfo			68
1168 #define	API_WPrintQEnum			69
1169 #define	API_WPrintQGetInfo		70
1170 #define	API_WPrintQSetInfo		71
1171 #define	API_WPrintQAdd			72
1172 #define	API_WPrintQDel			73
1173 #define	API_WPrintQPause		74
1174 #define	API_WPrintQContinue		75
1175 #define	API_WPrintJobEnum		76
1176 #define	API_WPrintJobGetInfo		77
1177 #define	API_WPrintJobSetInfo_OLD	78
1178 #define	API_WPrintJobDel		81
1179 #define	API_WPrintJobPause		82
1180 #define	API_WPrintJobContinue		83
1181 #define	API_WPrintDestEnum		84
1182 #define	API_WPrintDestGetInfo		85
1183 #define	API_WPrintDestControl		86
1184 #define	API_WProfileSave		87
1185 #define	API_WProfileLoad		88
1186 #define	API_WStatisticsGet		89
1187 #define	API_WStatisticsClear		90
1188 #define	API_NetRemoteTOD		91
1189 #define	API_WNetBiosEnum		92
1190 #define	API_WNetBiosGetInfo		93
1191 #define	API_NetServerEnum		94
1192 #define	API_I_NetServerEnum		95
1193 #define	API_WServiceGetInfo		96
1194 #define	API_WPrintQPurge		103
1195 #define	API_NetServerEnum2		104
1196 #define	API_WAccessGetUserPerms		105
1197 #define	API_WGroupGetInfo		106
1198 #define	API_WGroupSetInfo		107
1199 #define	API_WGroupSetUsers		108
1200 #define	API_WUserSetGroups		109
1201 #define	API_WUserModalsGet		110
1202 #define	API_WUserModalsSet		111
1203 #define	API_WFileEnum2			112
1204 #define	API_WUserAdd2			113
1205 #define	API_WUserSetInfo2		114
1206 #define	API_WUserPasswordSet2		115
1207 #define	API_I_NetServerEnum2		116
1208 #define	API_WConfigGet2			117
1209 #define	API_WConfigGetAll2		118
1210 #define	API_WGetDCName			119
1211 #define	API_NetHandleGetInfo		120
1212 #define	API_NetHandleSetInfo		121
1213 #define	API_WStatisticsGet2		122
1214 #define	API_WBuildGetInfo		123
1215 #define	API_WFileGetInfo2		124
1216 #define	API_WFileClose2			125
1217 #define	API_WNetServerReqChallenge	126
1218 #define	API_WNetServerAuthenticate	127
1219 #define	API_WNetServerPasswordSet	128
1220 #define	API_WNetAccountDeltas		129
1221 #define	API_WNetAccountSync		130
1222 #define	API_WUserEnum2			131
1223 #define	API_WWkstaUserLogon		132
1224 #define	API_WWkstaUserLogoff		133
1225 #define	API_WLogonEnum			134
1226 #define	API_WErrorLogRead		135
1227 #define	API_WI_NetPathType		136
1228 #define	API_WI_NetPathCanonicalize	137
1229 #define	API_WI_NetPathCompare		138
1230 #define	API_WI_NetNameValidate		139
1231 #define	API_WI_NetNameCanonicalize	140
1232 #define	API_WI_NetNameCompare		141
1233 #define	API_WAuditRead			142
1234 #define	API_WPrintDestAdd		143
1235 #define	API_WPrintDestSetInfo		144
1236 #define	API_WPrintDestDel		145
1237 #define	API_WUserValidate2		146
1238 #define	API_WPrintJobSetInfo		147
1239 #define	API_TI_NetServerDiskEnum	148
1240 #define	API_TI_NetServerDiskGetInfo	149
1241 #define	API_TI_FTVerifyMirror		150
1242 #define	API_TI_FTAbortVerify		151
1243 #define	API_TI_FTGetInfo		152
1244 #define	API_TI_FTSetInfo		153
1245 #define	API_TI_FTLockDisk		154
1246 #define	API_TI_FTFixError		155
1247 #define	API_TI_FTAbortFix		156
1248 #define	API_TI_FTDiagnoseError		157
1249 #define	API_TI_FTGetDriveStats		158
1250 #define	API_TI_FTErrorGetInfo		160
1251 #define	API_NetAccessCheck		163
1252 #define	API_NetAlertRaise		164
1253 #define	API_NetAlertStart		165
1254 #define	API_NetAlertStop		166
1255 #define	API_NetAuditWrite		167
1256 #define	API_NetIRemoteAPI		168
1257 #define	API_NetServiceStatus		169
1258 #define	API_I_NetServerRegister		170
1259 #define	API_I_NetServerDeregister	171
1260 #define	API_I_NetSessionEntryMake	172
1261 #define	API_I_NetSessionEntryClear	173
1262 #define	API_I_NetSessionEntryGetInfo	174
1263 #define	API_I_NetSessionEntrySetInfo	175
1264 #define	API_I_NetConnectionEntryMake	176
1265 #define	API_I_NetConnectionEntryClear	177
1266 #define	API_I_NetConnectionEntrySetInfo	178
1267 #define	API_I_NetConnectionEntryGetInfo	179
1268 #define	API_I_NetFileEntryMake		180
1269 #define	API_I_NetFileEntryClear		181
1270 #define	API_I_NetFileEntrySetInfo	182
1271 #define	API_I_NetFileEntryGetInfo	183
1272 #define	API_AltSrvMessageBufferSend	184
1273 #define	API_AltSrvMessageFileSend	185
1274 #define	API_wI_NetRplWkstaEnum		186
1275 #define	API_wI_NetRplWkstaGetInfo	187
1276 #define	API_wI_NetRplWkstaSetInfo	188
1277 #define	API_wI_NetRplWkstaAdd		189
1278 #define	API_wI_NetRplWkstaDel		190
1279 #define	API_wI_NetRplProfileEnum	191
1280 #define	API_wI_NetRplProfileGetInfo	192
1281 #define	API_wI_NetRplProfileSetInfo	193
1282 #define	API_wI_NetRplProfileAdd		194
1283 #define	API_wI_NetRplProfileDel		195
1284 #define	API_wI_NetRplProfileClone	196
1285 #define	API_wI_NetRplBaseProfileEnum	197
1286 #define	API_WIServerSetInfo		201
1287 #define	API_WPrintDriverEnum		205
1288 #define	API_WPrintQProcessorEnum	206
1289 #define	API_WPrintPortEnum		207
1290 #define	API_WNetWriteUpdateLog		208
1291 #define	API_WNetAccountUpdate		209
1292 #define	API_WNetAccountConfirmUpdate	210
1293 #define	API_WConfigSet			211
1294 #define	API_WAccountsReplicate		212
1295 #define	API_SamOEMChgPasswordUser2_P	214
1296 #define	API_NetServerEnum3		215
1297 #define	API_WprintDriverGetInfo		250
1298 #define	API_WprintDriverSetInfo		251
1299 #define	API_WaliasAdd			252
1300 #define	API_WaliasDel			253
1301 #define	API_WaliasGetInfo		254
1302 #define	API_WaliasSetInfo		255
1303 #define	API_WaliasEnum			256
1304 #define	API_WuserGetLogonAsn		257
1305 #define	API_WuserSetLogonAsn		258
1306 #define	API_WuserGetAppSel		259
1307 #define	API_WuserSetAppSel		260
1308 #define	API_WappAdd			261
1309 #define	API_WappDel			262
1310 #define	API_WappGetInfo			263
1311 #define	API_WappSetInfo			264
1312 #define	API_WappEnum			265
1313 #define	API_WUserDCDBInit		266
1314 #define	API_WDASDAdd			267
1315 #define	API_WDASDDel			268
1316 #define	API_WDASDGetInfo		269
1317 #define	API_WDASDSetInfo		270
1318 #define	API_WDASDEnum			271
1319 #define	API_WDASDCheck			272
1320 #define	API_WDASDCtl			273
1321 #define	API_WuserRemoteLogonCheck	274
1322 #define	API_WUserPasswordSet3		275
1323 #define	API_WCreateRIPLMachine		276
1324 #define	API_WDeleteRIPLMachine		277
1325 #define	API_WGetRIPLMachineInfo		278
1326 #define	API_WSetRIPLMachineInfo		279
1327 #define	API_WEnumRIPLMachine		280
1328 #define	API_WI_ShareAdd			281
1329 #define	API_WI_AliasEnum		282
1330 #define	API_WaccessApply		283
1331 #define	API_WPrt16Query			284
1332 #define	API_WPrt16Set			285
1333 #define	API_WUserDel100			286
1334 #define	API_WUserRemoteLogonCheck2	287
1335 #define	API_WRemoteTODSet		294
1336 #define	API_WprintJobMoveAll		295
1337 #define	API_W16AppParmAdd		296
1338 #define	API_W16AppParmDel		297
1339 #define	API_W16AppParmGet		298
1340 #define	API_W16AppParmSet		299
1341 #define	API_W16RIPLMachineCreate	300
1342 #define	API_W16RIPLMachineGetInfo	301
1343 #define	API_W16RIPLMachineSetInfo	302
1344 #define	API_W16RIPLMachineEnum		303
1345 #define	API_W16RIPLMachineListParmEnum	304
1346 #define	API_W16RIPLMachClassGetInfo	305
1347 #define	API_W16RIPLMachClassEnum	306
1348 #define	API_W16RIPLMachClassCreate	307
1349 #define	API_W16RIPLMachClassSetInfo	308
1350 #define	API_W16RIPLMachClassDelete	309
1351 #define	API_W16RIPLMachClassLPEnum	310
1352 #define	API_W16RIPLMachineDelete	311
1353 #define	API_W16WSLevelGetInfo		312
1354 #define	API_WserverNameAdd		313
1355 #define	API_WserverNameDel		314
1356 #define	API_WserverNameEnum		315
1357 #define	API_I_WDASDEnum			316
1358 #define	API_I_WDASDEnumTerminate	317
1359 #define	API_I_WDASDSetInfo2		318
1360 #define	MAX_RAP_API			318
1361 
1362 #ifdef __cplusplus
1363 }
1364 #endif
1365 
1366 #endif /* _SMBSRV_SMB_H */
1367