xref: /dragonfly/sys/netproto/smb/smb.h (revision 984263bc)
1 /*
2  * Copyright (c) 2000-2001 Boris Popov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *    This product includes software developed by Boris Popov.
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $FreeBSD: src/sys/netsmb/smb.h,v 1.1.2.3 2002/04/23 03:45:01 bp Exp $
33  */
34 
35 /*
36  * Common definintions and structures for SMB/CIFS protocol
37  */
38 
39 #ifndef _NETSMB_SMB_H_
40 #define _NETSMB_SMB_H_
41 
42 #define	SMB_TCP_PORT	139
43 /*
44  * SMB dialects that we have to deal with.
45  */
46 enum smb_dialects {
47 	SMB_DIALECT_NONE,
48 	SMB_DIALECT_CORE,		/* PC NETWORK PROGRAM 1.0, PCLAN1.0 */
49 	SMB_DIALECT_COREPLUS,		/* MICROSOFT NETWORKS 1.03 */
50 	SMB_DIALECT_LANMAN1_0,		/* MICROSOFT NETWORKS 3.0, LANMAN1.0 */
51 	SMB_DIALECT_LANMAN2_0,		/* LM1.2X002, DOS LM1.2X002, Samba */
52 	SMB_DIALECT_LANMAN2_1,		/* DOS LANMAN2.1, LANMAN2.1 */
53 	SMB_DIALECT_NTLM0_12		/* NT LM 0.12, Windows for Workgroups 3.1a,
54 					 * NT LANMAN 1.0 */
55 };
56 
57 /*
58  * Formats of data/string buffers
59  */
60 #define	SMB_DT_DATA		1
61 #define	SMB_DT_DIALECT		2
62 #define	SMB_DT_PATHNAME		3
63 #define	SMB_DT_ASCII		4
64 #define	SMB_DT_VARIABLE		5
65 
66 /*
67  * SMB header
68  */
69 #define	SMB_SIGNATURE		"\xFFSMB"
70 #define	SMB_SIGLEN		4
71 #define	SMB_HDRMID(p)		(*(u_short*)((u_char*)(p) + 30))
72 #define	SMB_HDRLEN		32
73 /*
74  * bits in the smb_flags field
75  */
76 #define	SMB_FLAGS_CASELESS	0x08
77 #define SMB_FLAGS_SERVER_RESP	0x80	/* indicates a response */
78 
79 /*
80  * bits in the smb_flags2 field
81  */
82 #define	SMB_FLAGS2_KNOWS_LONG_NAMES	0x0001
83 #define	SMB_FLAGS2_KNOWS_EAS		0x0002	/* client know about EAs */
84 #define	SMB_FLAGS2_SECURITY_SIGNATURE	0x0004	/* check SMB integrity */
85 #define	SMB_FLAGS2_IS_LONG_NAME		0x0040	/* any path name is a long name */
86 #define	SMB_FLAGS2_EXT_SEC		0x0800	/* client aware of Extended
87 						 * Security negotiation */
88 #define	SMB_FLAGS2_DFS			0x1000	/* resolve paths in DFS */
89 #define	SMB_FLAGS2_PAGING_IO		0x2000	/* for exec */
90 #define	SMB_FLAGS2_ERR_STATUS		0x4000	/* 1 - status.status */
91 #define	SMB_FLAGS2_UNICODE		0x8000	/* use Unicode for all strings */
92 
93 #define	SMB_UID_UNKNOWN		0xffff
94 #define	SMB_TID_UNKNOWN		0xffff
95 
96 /*
97  * Security mode bits
98  */
99 #define SMB_SM_USER		0x01		/* server in the user security mode */
100 #define	SMB_SM_ENCRYPT		0x02		/* use challenge/response */
101 
102 /*
103  * NTLM capabilities
104  */
105 #define	SMB_CAP_RAW_MODE	0x0001
106 #define	SMB_CAP_MPX_MODE	0x0002
107 #define	SMB_CAP_UNICODE		0x0004
108 #define	SMB_CAP_LARGE_FILES	0x0008		/* 64 bit offsets supported */
109 #define	SMB_CAP_NT_SMBS		0x0010
110 #define	SMB_CAP_NT_FIND		0x0200
111 #define	SMB_CAP_EXT_SECURITY	0x80000000
112 
113 /*
114  * File attributes
115  */
116 #define	SMB_FA_RDONLY		0x01
117 #define	SMB_FA_HIDDEN		0x02
118 #define	SMB_FA_SYSTEM		0x04
119 #define	SMB_FA_VOLUME		0x08
120 #define	SMB_FA_DIR		0x10
121 #define	SMB_FA_ARCHIVE		0x20
122 
123 /*
124  * Extended file attributes
125  */
126 #define	SMB_EFA_RDONLY		0x0001
127 #define	SMB_EFA_HIDDEN		0x0002
128 #define	SMB_EFA_SYSTEM		0x0004
129 #define	SMB_EFA_ARCHIVE		0x0020
130 #define	SMB_EFA_NORMAL		0x0080
131 #define	SMB_EFA_TEMPORARY	0x0100
132 #define	SMB_EFA_COMPRESSED	0x0800
133 #define	SMB_EFA_POSIX_SEMANTICS	0x00100000
134 #define	SMB_EFA_BACKUP_SEMANTICS 0x02000000
135 #define	SMB_EFA_DELETE_ON_CLOSE	0x04000000
136 #define	SMB_EFA_SEQUENTIAL_SCAN	0x08000000
137 #define	SMB_EFA_RANDOM_ACCESS	0x10000000
138 #define	SMB_EFA_NO_BUFFERING	0x20000000
139 #define	SMB_EFA_WRITE_THROUGH	0x80000000
140 
141 /*
142  * Access Mode Encoding
143  */
144 #define	SMB_AM_OPENREAD		0x0000
145 #define	SMB_AM_OPENWRITE	0x0001
146 #define	SMB_AM_OPENRW		0x0002
147 #define	SMB_AM_OPENEXEC		0x0003
148 #define	SMB_SM_COMPAT		0x0000
149 #define	SMB_SM_EXCLUSIVE	0x0010
150 #define	SMB_SM_DENYWRITE	0x0020
151 #define	SMB_SM_DENYREADEXEC	0x0030
152 #define	SMB_SM_DENYNONE		0x0040
153 
154 /*
155  * SMB commands
156  */
157 #define	SMB_COM_CREATE_DIRECTORY        0x00
158 #define	SMB_COM_DELETE_DIRECTORY        0x01
159 #define	SMB_COM_OPEN                    0x02
160 #define	SMB_COM_CREATE                  0x03
161 #define	SMB_COM_CLOSE                   0x04
162 #define	SMB_COM_FLUSH                   0x05
163 #define	SMB_COM_DELETE                  0x06
164 #define	SMB_COM_RENAME                  0x07
165 #define	SMB_COM_QUERY_INFORMATION       0x08
166 #define	SMB_COM_SET_INFORMATION         0x09
167 #define	SMB_COM_READ                    0x0A
168 #define	SMB_COM_WRITE                   0x0B
169 #define	SMB_COM_LOCK_BYTE_RANGE         0x0C
170 #define	SMB_COM_UNLOCK_BYTE_RANGE       0x0D
171 #define	SMB_COM_CREATE_TEMPORARY        0x0E
172 #define	SMB_COM_CREATE_NEW              0x0F
173 #define	SMB_COM_CHECK_DIRECTORY         0x10
174 #define	SMB_COM_PROCESS_EXIT            0x11
175 #define	SMB_COM_SEEK                    0x12
176 #define	SMB_COM_LOCK_AND_READ           0x13
177 #define	SMB_COM_WRITE_AND_UNLOCK        0x14
178 #define	SMB_COM_READ_RAW                0x1A
179 #define	SMB_COM_READ_MPX                0x1B
180 #define	SMB_COM_READ_MPX_SECONDARY      0x1C
181 #define	SMB_COM_WRITE_RAW               0x1D
182 #define	SMB_COM_WRITE_MPX               0x1E
183 #define	SMB_COM_WRITE_COMPLETE          0x20
184 #define	SMB_COM_SET_INFORMATION2        0x22
185 #define	SMB_COM_QUERY_INFORMATION2      0x23
186 #define	SMB_COM_LOCKING_ANDX            0x24
187 #define	SMB_COM_TRANSACTION             0x25
188 #define	SMB_COM_TRANSACTION_SECONDARY   0x26
189 #define	SMB_COM_IOCTL                   0x27
190 #define	SMB_COM_IOCTL_SECONDARY         0x28
191 #define	SMB_COM_COPY                    0x29
192 #define	SMB_COM_MOVE                    0x2A
193 #define	SMB_COM_ECHO                    0x2B
194 #define	SMB_COM_WRITE_AND_CLOSE         0x2C
195 #define	SMB_COM_OPEN_ANDX               0x2D
196 #define	SMB_COM_READ_ANDX               0x2E
197 #define	SMB_COM_WRITE_ANDX              0x2F
198 #define	SMB_COM_CLOSE_AND_TREE_DISC     0x31
199 #define	SMB_COM_TRANSACTION2            0x32
200 #define	SMB_COM_TRANSACTION2_SECONDARY  0x33
201 #define	SMB_COM_FIND_CLOSE2             0x34
202 #define	SMB_COM_FIND_NOTIFY_CLOSE       0x35
203 #define	SMB_COM_TREE_CONNECT		0x70
204 #define	SMB_COM_TREE_DISCONNECT         0x71
205 #define	SMB_COM_NEGOTIATE               0x72
206 #define	SMB_COM_SESSION_SETUP_ANDX      0x73
207 #define	SMB_COM_LOGOFF_ANDX             0x74
208 #define	SMB_COM_TREE_CONNECT_ANDX       0x75
209 #define	SMB_COM_QUERY_INFORMATION_DISK  0x80
210 #define	SMB_COM_SEARCH                  0x81
211 #define	SMB_COM_FIND                    0x82
212 #define	SMB_COM_FIND_UNIQUE             0x83
213 #define	SMB_COM_NT_TRANSACT             0xA0
214 #define	SMB_COM_NT_TRANSACT_SECONDARY   0xA1
215 #define	SMB_COM_NT_CREATE_ANDX          0xA2
216 #define	SMB_COM_NT_CANCEL               0xA4
217 #define	SMB_COM_OPEN_PRINT_FILE         0xC0
218 #define	SMB_COM_WRITE_PRINT_FILE        0xC1
219 #define	SMB_COM_CLOSE_PRINT_FILE        0xC2
220 #define	SMB_COM_GET_PRINT_QUEUE         0xC3
221 #define	SMB_COM_READ_BULK               0xD8
222 #define	SMB_COM_WRITE_BULK              0xD9
223 #define	SMB_COM_WRITE_BULK_DATA         0xDA
224 
225 /*
226  * TRANS2 commands
227  */
228 #define	SMB_TRANS2_OPEN2			0x00
229 #define	SMB_TRANS2_FIND_FIRST2			0x01
230 #define	SMB_TRANS2_FIND_NEXT2			0x02
231 #define	SMB_TRANS2_QUERY_FS_INFORMATION		0x03
232 #define	SMB_TRANS2_QUERY_PATH_INFORMATION	0x05
233 #define	SMB_TRANS2_SET_PATH_INFORMATION		0x06
234 #define	SMB_TRANS2_QUERY_FILE_INFORMATION	0x07
235 #define	SMB_TRANS2_SET_FILE_INFORMATION		0x08
236 #define	SMB_TRANS2_FSCTL			0x09
237 #define	SMB_TRANS2_IOCTL2			0x0A
238 #define	SMB_TRANS2_FIND_NOTIFY_FIRST		0x0B
239 #define	SMB_TRANS2_FIND_NOTIFY_NEXT		0x0C
240 #define	SMB_TRANS2_CREATE_DIRECTORY		0x0D
241 #define	SMB_TRANS2_SESSION_SETUP		0x0E
242 #define	SMB_TRANS2_GET_DFS_REFERRAL		0x10
243 #define	SMB_TRANS2_REPORT_DFS_INCONSISTENCY	0x11
244 
245 /*
246  * SMB_TRANS2_QUERY_FS_INFORMATION levels
247  */
248 #define SMB_INFO_ALLOCATION		1
249 #define SMB_INFO_VOLUME			2
250 #define SMB_QUERY_FS_VOLUME_INFO	0x102
251 #define SMB_QUERY_FS_SIZE_INFO		0x103
252 #define SMB_QUERY_FS_DEVICE_INFO	0x104
253 #define SMB_QUERY_FS_ATTRIBUTE_INFO	0x105
254 
255 /*
256  * SMB_TRANS2_FIND_FIRST2 information levels
257  */
258 #define SMB_INFO_STANDARD		1
259 #define SMB_INFO_QUERY_EA_SIZE		2
260 #define SMB_INFO_QUERY_EAS_FROM_LIST	3
261 #define SMB_FIND_FILE_DIRECTORY_INFO	0x101
262 #define SMB_FIND_FULL_DIRECTORY_INFO	0x102
263 #define SMB_FIND_FILE_NAMES_INFO	0x103
264 #define SMB_FIND_BOTH_DIRECTORY_INFO	0x104
265 
266 /*
267  * Set PATH/FILE information levels
268  */
269 #define	SMB_SET_FILE_BASIC_INFO		0x101
270 #define	SMB_SET_FILE_END_OF_FILE_INFO	0x104
271 
272 /*
273  * LOCKING_ANDX LockType flags
274  */
275 #define SMB_LOCKING_ANDX_SHARED_LOCK	0x01
276 #define SMB_LOCKING_ANDX_OPLOCK_RELEASE	0x02
277 #define SMB_LOCKING_ANDX_CHANGE_LOCKTYPE 0x04
278 #define SMB_LOCKING_ANDX_CANCEL_LOCK	0x08
279 #define SMB_LOCKING_ANDX_LARGE_FILES	0x10
280 
281 /*
282  * Some names length limitations. Some of them aren't declared by specs,
283  * but we need reasonable limits.
284  */
285 #define SMB_MAXSRVNAMELEN	15	/* NetBIOS limit */
286 #define SMB_MAXUSERNAMELEN	128
287 #define SMB_MAXPASSWORDLEN	128
288 #define	SMB_MAXSHARENAMELEN	128
289 #define	SMB_MAXPKTLEN		0x1FFFF
290 #define	SMB_MAXCHALLENGELEN	8
291 #define	SMB_MAXFNAMELEN		255	/* Keep in sync with MAXNAMLEN */
292 
293 #define	SMB_MAXRCN		3	/* number of reconnect attempts */
294 
295 /*
296  * Error classes
297  */
298 #define SMBSUCCESS	0x00
299 #define ERRDOS		0x01
300 #define ERRSRV		0x02
301 #define ERRHRD		0x03	/* Error is an hardware error. */
302 #define ERRCMD		0xFF	/* Command was not in the "SMB" format. */
303 
304 /*
305  * Error codes for the ERRDOS class
306  */
307 #define ERRbadfunc	1	/* Invalid function */
308 #define ERRbadfile	2	/* File not found (last component) */
309 #define ERRbadpath	3	/* Directory invalid */
310 #define ERRnofids	4	/* Too many open files */
311 #define ERRnoaccess	5	/* Access denied */
312 #define ERRbadfid	6	/* Invalid file handle */
313 #define ERRbadmcb	7	/* Memory control blocks destroyed (huh ?) */
314 #define ERRnomem	8	/* Insufficient memory */
315 #define ERRbadmem	9	/* Invalid memory block address */
316 #define ERRbadenv	10	/* Invalid environment */
317 #define ERRbadformat	11	/* Invalid format */
318 #define ERRbadaccess	12	/* Invalid open mode */
319 #define ERRbaddata	13	/* Invalid data */
320 #define ERRbaddrive	15	/* Invalid drive specified */
321 #define ERRremcd	16	/* An attempt to delete current directory */
322 #define ERRdiffdevice	17	/* cross fs rename/move */
323 #define ERRnofiles	18	/* no more files found in file search */
324 #define ERRbadshare	32	/* Share mode can't be granted */
325 #define ERRlock		33	/* A lock request conflicts with existing lock */
326 #define ERRfilexists	80	/* The file named in the request already exists */
327 
328 /*
329  * Error codes for the ERRSRV class
330  */
331 #define ERRerror	1	/* Non-specific error code */
332 #define ERRbadpw	2	/* Bad password */
333 #define ERRaccess	4	/* The client doesn't have enough access rights */
334 #define ERRinvnid	5	/* The Tid specified in a command is invalid */
335 #define ERRinvnetname	6	/* Invalid server name in the tree connect */
336 #define ERRinvdevice	7	/* Printer and not printer devices are mixed */
337 #define ERRqfull	49	/* Print queue full */
338 #define ERRqtoobig	50	/* Print queue full - no space */
339 #define ERRinvpfid	52	/* Invalid print file FID */
340 #define ERRsmbcmd	64	/* The server did not recognize the command */
341 #define ERRsrverror	65	/* The server encountered and internal error */
342 #define ERRfilespecs	67	/* The Fid and path name contains an invalid combination */
343 #define ERRbadpermits	69	/* Access mode invalid */
344 #define ERRsetattrmode	71	/* Attribute mode invalid */
345 #define ERRpaused	81	/* Server is paused */
346 #define ERRmsgoff	82	/* Not receiving messages */
347 #define ERRnoroom	83	/* No room to buffer message */
348 #define ERRrmuns	87	/* Too many remote user names */
349 #define ERRtimeout	88	/* Operation timed out */
350 #define ERRnoresource	89	/* No resources currently available for request */
351 #define ERRtoomanyuids	90      /* Too many UIDs active on this session */
352 #define ERRbaduid	91	/* The UID is not known in this session */
353 #define ERRusempx	250	/* Temporarily unable to support Raw, use MPX mode */
354 #define ERRusestd	251	/* Temporarily unable to support Raw, use standard r/w */
355 #define ERRcontmpx	252	/* Continue in MPX mode */
356 #define ERRnosupport	65535	/* Invalid function */
357 
358 /*
359  * Error codes for the ERRHRD class
360  */
361 #define ERRnowrite	19	/* write protected media */
362 #define ERRbadunit	20	/* Unknown unit */
363 #define ERRnotready	21	/* Drive not ready */
364 #define ERRbadcmd	22	/* Unknown command */
365 #define ERRdata		23	/* Data error (CRC) */
366 #define ERRbadreq	24	/* Bad request structure length */
367 #define ERRseek		25	/* Seek error */
368 #define ERRbadmedia	26	/* Unknown media type */
369 #define ERRbadsector	27	/* Sector not found */
370 #define ERRnopaper	28	/* Printer out of paper */
371 #define ERRwrite	29	/* Write fault */
372 #define ERRread		30	/* Read fault */
373 #define ERRgeneral	31	/* General failure */
374 #define	ERRbadshare	32	/* A open conflicts with an existing open */
375 #define	ERRlock		33	/* lock/unlock conflict */
376 #define ERRwrongdisk	34	/* The wrong disk was found in a drive */
377 #define ERRFCBunavail	35	/* No FCBs available */
378 #define ERRsharebufexc	36	/* A sharing buffer has been exceeded */
379 
380 /*
381  * RAP error codes (it seems that they returned not only by RAP)
382  */
383 #define	SMB_ERROR_ACCESS_DENIED		5
384 #define	SMB_ERROR_NETWORK_ACCESS_DENIED	65
385 #define	SMB_ERROR_MORE_DATA		234
386 
387 typedef u_int16_t	smbfh;
388 
389 #endif /* _NETSMB_SMB_H_ */
390