r943: change samba4 to use 'uint8_t' instead of 'unsigned char'
[samba.git] / source4 / include / smb.h
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB parameters and setup, plus a whole lot more.
4    
5    Copyright (C) Andrew Tridgell              1992-2000
6    Copyright (C) John H Terpstra              1996-2002
7    Copyright (C) Luke Kenneth Casson Leighton 1996-2000
8    Copyright (C) Paul Ashton                  1998-2000
9    Copyright (C) Simo Sorce                   2001-2002
10    Copyright (C) Martin Pool                  2002
11    
12    This program is free software; you can redistribute it and/or modify
13    it under the terms of the GNU General Public License as published by
14    the Free Software Foundation; either version 2 of the License, or
15    (at your option) any later version.
16    
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20    GNU General Public License for more details.
21    
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27 #ifndef _SMB_H
28 #define _SMB_H
29
30 #define NMB_PORT 137
31 #define DGRAM_PORT 138
32 #define SMB_PORT1 445
33 #define SMB_PORT2 139
34 #define SMB_PORTS "445 139"
35
36 #define False (0)
37 #define True (1)
38 #define Auto (2)
39
40 enum smb_signing_state {SMB_SIGNING_OFF, SMB_SIGNING_SUPPORTED, SMB_SIGNING_REQUIRED};
41
42 #ifndef _BOOL
43 typedef int BOOL;
44 #define _BOOL       /* So we don't typedef BOOL again in vfs.h */
45 #endif
46
47 /* string manipulation flags - see clistr.c and srvstr.c */
48 #define STR_TERMINATE 1
49 #define STR_UPPER 2
50 #define STR_ASCII 4
51 #define STR_UNICODE 8
52 #define STR_NOALIGN 16
53 #define STR_NO_RANGE_CHECK 32
54 #define STR_LEN8BIT 64
55 #define STR_TERMINATE_ASCII 128 /* only terminate if ascii */
56 #define STR_LEN_NOTERM 256 /* the length field is the unterminated length */
57
58 /* Debugging stuff */
59 #include "debug.h"
60
61 /* types of socket errors */
62 enum socket_error {SOCKET_READ_TIMEOUT,
63                    SOCKET_READ_EOF,
64                    SOCKET_READ_ERROR,
65                    SOCKET_WRITE_ERROR,
66                    SOCKET_READ_BAD_SIG};
67
68 /* deny modes */
69 #define DENY_DOS 0
70 #define DENY_ALL 1
71 #define DENY_WRITE 2
72 #define DENY_READ 3
73 #define DENY_NONE 4
74 #define DENY_FCB 7
75
76 /* open modes */
77 #define DOS_OPEN_RDONLY 0
78 #define DOS_OPEN_WRONLY 1
79 #define DOS_OPEN_RDWR 2
80 #define DOS_OPEN_FCB 0xF
81
82
83 /**********************************/
84 /* SMBopen field definitions      */
85 #define OPEN_FLAGS_DENY_MASK  0x70
86 #define OPEN_FLAGS_DENY_DOS   0x00
87 #define OPEN_FLAGS_DENY_ALL   0x10
88 #define OPEN_FLAGS_DENY_WRITE 0x20
89 #define OPEN_FLAGS_DENY_READ  0x30
90 #define OPEN_FLAGS_DENY_NONE  0x40
91
92 #define OPEN_FLAGS_MODE_MASK  0x0F
93 #define OPEN_FLAGS_OPEN_READ     0
94 #define OPEN_FLAGS_OPEN_WRITE    1
95 #define OPEN_FLAGS_OPEN_RDWR     2
96 #define OPEN_FLAGS_FCB        0xFF
97
98
99 /**********************************/
100 /* SMBopenX field definitions     */
101
102 /* OpenX Flags field. */
103 #define OPENX_FLAGS_ADDITIONAL_INFO      0x01
104 #define OPENX_FLAGS_REQUEST_OPLOCK       0x02
105 #define OPENX_FLAGS_REQUEST_BATCH_OPLOCK 0x04
106 #define OPENX_FLAGS_EA_LEN               0x08
107 #define OPENX_FLAGS_EXTENDED_RETURN      0x10
108
109 /* desired access (open_mode), split info 4 4-bit nibbles */
110 #define OPENX_MODE_ACCESS_MASK   0x000F
111 #define OPENX_MODE_ACCESS_READ   0x0000
112 #define OPENX_MODE_ACCESS_WRITE  0x0001
113 #define OPENX_MODE_ACCESS_RDWR   0x0002
114 #define OPENX_MODE_ACCESS_EXEC   0x0003
115 #define OPENX_MODE_ACCESS_FCB    0x000F
116
117 #define OPENX_MODE_DENY_SHIFT    4
118 #define OPENX_MODE_DENY_MASK     (0xF        << OPENX_MODE_DENY_SHIFT)
119 #define OPENX_MODE_DENY_DOS      (DENY_DOS   << OPENX_MODE_DENY_SHIFT)
120 #define OPENX_MODE_DENY_ALL      (DENY_ALL   << OPENX_MODE_DENY_SHIFT)
121 #define OPENX_MODE_DENY_WRITE    (DENY_WRITE << OPENX_MODE_DENY_SHIFT)
122 #define OPENX_MODE_DENY_READ     (DENY_READ  << OPENX_MODE_DENY_SHIFT)
123 #define OPENX_MODE_DENY_NONE     (DENY_NONE  << OPENX_MODE_DENY_SHIFT)
124 #define OPENX_MODE_DENY_FCB      (0xF        << OPENX_MODE_DENY_SHIFT)
125
126 #define OPENX_MODE_LOCALITY_MASK 0x0F00 /* what does this do? */
127
128 #define OPENX_MODE_NO_CACHE      0x1000
129 #define OPENX_MODE_WRITE_THRU    0x4000
130
131 /* open function values */
132 #define OPENX_OPEN_FUNC_MASK  0x3
133 #define OPENX_OPEN_FUNC_FAIL  0x0
134 #define OPENX_OPEN_FUNC_OPEN  0x1
135 #define OPENX_OPEN_FUNC_TRUNC 0x2
136
137 /* The above can be OR'ed with... */
138 #define OPENX_OPEN_FUNC_CREATE 0x10
139
140 /* openx action in reply */
141 #define OPENX_ACTION_EXISTED    1
142 #define OPENX_ACTION_CREATED    2
143 #define OPENX_ACTION_TRUNCATED  3
144
145
146 /**********************************/
147 /* SMBntcreateX field definitions */
148
149 /* ntcreatex flags field. */
150 #define NTCREATEX_FLAGS_REQUEST_OPLOCK       0x02
151 #define NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK 0x04
152 #define NTCREATEX_FLAGS_OPEN_DIRECTORY       0x08
153 #define NTCREATEX_FLAGS_EXTENDED             0x10
154
155 /* the ntcreatex access_mask field 
156    this is split into 4 pieces
157    AAAABBBBCCCCCCCCDDDDDDDDDDDDDDDD
158    A -> GENERIC_RIGHT_*
159    B -> SEC_RIGHT_*
160    C -> STD_RIGHT_*
161    D -> SA_RIGHT_*
162    
163    which set of SA_RIGHT_* bits is applicable depends on the type
164    of object.
165 */
166
167
168
169 /* ntcreatex share_access field */
170 #define NTCREATEX_SHARE_ACCESS_NONE   0
171 #define NTCREATEX_SHARE_ACCESS_READ   1
172 #define NTCREATEX_SHARE_ACCESS_WRITE  2
173 #define NTCREATEX_SHARE_ACCESS_DELETE 4
174
175 /* ntcreatex open_disposition field */
176 #define NTCREATEX_DISP_SUPERSEDE 0     /* supersede existing file (if it exists) */
177 #define NTCREATEX_DISP_OPEN 1          /* if file exists open it, else fail */
178 #define NTCREATEX_DISP_CREATE 2        /* if file exists fail, else create it */
179 #define NTCREATEX_DISP_OPEN_IF 3       /* if file exists open it, else create it */
180 #define NTCREATEX_DISP_OVERWRITE 4     /* if exists overwrite, else fail */
181 #define NTCREATEX_DISP_OVERWRITE_IF 5  /* if exists overwrite, else create */
182
183 /* ntcreatex create_options field */
184 #define NTCREATEX_OPTIONS_DIRECTORY            0x0001
185 #define NTCREATEX_OPTIONS_WRITE_THROUGH        0x0002
186 #define NTCREATEX_OPTIONS_SEQUENTIAL_ONLY      0x0004
187 #define NTCREATEX_OPTIONS_SYNC_ALERT           0x0010
188 #define NTCREATEX_OPTIONS_ASYNC_ALERT          0x0020
189 #define NTCREATEX_OPTIONS_NON_DIRECTORY_FILE   0x0040
190 #define NTCREATEX_OPTIONS_NO_EA_KNOWLEDGE      0x0200
191 #define NTCREATEX_OPTIONS_EIGHT_DOT_THREE_ONLY 0x0400
192 #define NTCREATEX_OPTIONS_RANDOM_ACCESS        0x0800
193 #define NTCREATEX_OPTIONS_DELETE_ON_CLOSE      0x1000
194 #define NTCREATEX_OPTIONS_OPEN_BY_FILE_ID      0x2000
195
196 /* ntcreatex impersonation field */
197 #define NTCREATEX_IMPERSONATION_ANONYMOUS      0
198 #define NTCREATEX_IMPERSONATION_IDENTIFICATION 1
199 #define NTCREATEX_IMPERSONATION_IMPERSONATION  2
200 #define NTCREATEX_IMPERSONATION_DELEGATION     3
201
202 /* ntcreatex security flags bit field */
203 #define NTCREATEX_SECURITY_DYNAMIC             1
204 #define NTCREATEX_SECURITY_ALL                 2
205
206 /* ntcreatex create_action in reply */
207 #define NTCREATEX_ACTION_EXISTED     1
208 #define NTCREATEX_ACTION_CREATED     2
209 #define NTCREATEX_ACTION_TRUNCATED   3
210 /* the value 5 can also be returned when you try to create a directory with
211    incorrect parameters - what does it mean? maybe created temporary file? */
212 #define NTCREATEX_ACTION_UNKNOWN 5
213
214 #include "doserr.h"
215
216 /*
217  * SMB UCS2 (16-bit unicode) internal type.
218  */
219
220 typedef uint16_t smb_ucs2_t;
221
222 /* ucs2 string types. */
223 typedef smb_ucs2_t wpstring[PSTRING_LEN];
224 typedef smb_ucs2_t wfstring[FSTRING_LEN];
225
226 #ifdef WORDS_BIGENDIAN
227 #define UCS2_SHIFT 8
228 #else
229 #define UCS2_SHIFT 0
230 #endif
231
232 /* turn a 7 bit character into a ucs2 character */
233 #define UCS2_CHAR(c) ((c) << UCS2_SHIFT)
234
235 /* for compatibility */
236 #define SID_NAME_USE samr_SidType
237
238 /*
239  * The complete list of SIDS belonging to this user.
240  * Created when a vuid is registered.
241  * The definition of the user_sids array is as follows :
242  *
243  * token->user_sids[0] = primary user SID.
244  * token->user_sids[1] = primary group SID.
245  * token->user_sids[2..num_sids] = supplementary group SIDS.
246  */
247
248 #define PRIMARY_USER_SID_INDEX 0
249 #define PRIMARY_GROUP_SID_INDEX 1
250
251 typedef struct nt_user_token {
252         size_t num_sids;
253         struct dom_sid **user_sids;
254 } NT_USER_TOKEN;
255
256 /* used to hold an arbitrary blob of data */
257 typedef struct data_blob {
258         uint8_t *data;
259         size_t length;
260         void (*free)(struct data_blob *data_blob);
261 } DATA_BLOB;
262
263 #include "enums.h"
264 #include "events.h"
265 #include "librpc/gen_ndr/ndr_misc.h"
266 #include "smb_interfaces.h"
267 #include "librpc/ndr/libndr.h"
268
269 typedef struct userdom_struct {
270         fstring smb_name; /* user name from the client */
271         fstring unix_name; /* unix user name of a validated user */
272         fstring full_name; /* to store full name (such as "Joe Bloggs") from gecos field of password file */
273         fstring domain; /* domain that the client specified */
274 } userdom_struct;
275
276
277 /* used for server information: client, nameserv and ipc */
278 struct server_info_struct
279 {
280   fstring name;
281   uint32_t type;
282   fstring comment;
283   fstring domain; /* used ONLY in ipc.c NOT namework.c */
284   BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
285 };
286
287
288 /* used for network interfaces */
289 struct interface
290 {
291         struct interface *next, *prev;
292         struct in_addr ip;
293         struct in_addr bcast;
294         struct in_addr nmask;
295 };
296
297 #define NT_HASH_LEN 16
298 #define LM_HASH_LEN 16
299
300 /*
301  * Flags for account policy.
302  */
303 #define AP_MIN_PASSWORD_LEN             1
304 #define AP_PASSWORD_HISTORY             2
305 #define AP_USER_MUST_LOGON_TO_CHG_PASS  3
306 #define AP_MAX_PASSWORD_AGE             4
307 #define AP_MIN_PASSWORD_AGE             5
308 #define AP_LOCK_ACCOUNT_DURATION        6
309 #define AP_RESET_COUNT_TIME             7
310 #define AP_BAD_ATTEMPT_LOCKOUT          8
311 #define AP_TIME_TO_LOGOUT               9
312
313
314 /*
315  * Flags for local user manipulation.
316  */
317
318 #define LOCAL_ADD_USER 0x1
319 #define LOCAL_DELETE_USER 0x2
320 #define LOCAL_DISABLE_USER 0x4
321 #define LOCAL_ENABLE_USER 0x8
322 #define LOCAL_TRUST_ACCOUNT 0x10
323 #define LOCAL_SET_NO_PASSWORD 0x20
324 #define LOCAL_SET_PASSWORD 0x40
325 #define LOCAL_SET_LDAP_ADMIN_PW 0x80
326 #define LOCAL_INTERDOM_ACCOUNT 0x100
327 #define LOCAL_AM_ROOT 0x200  /* Act as root */
328
329 /* key and data in the connections database - used in smbstatus and smbd */
330 struct connections_key {
331         pid_t pid;
332         int cnum;
333         fstring name;
334 };
335
336 struct connections_data {
337         int magic;
338         pid_t pid;
339         int cnum;
340         uid_t uid;
341         gid_t gid;
342         char name[24];
343         char addr[24];
344         char machine[FSTRING_LEN];
345         time_t start;
346         uint32_t bcast_msg_flags;
347 };
348
349 /* the following are used by loadparm for option lists */
350 typedef enum
351 {
352   P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,P_LIST,
353   P_STRING,P_USTRING,P_ENUM,P_SEP
354 } parm_type;
355
356 typedef enum
357 {
358   P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
359 } parm_class;
360
361 struct enum_list {
362         int value;
363         const char *name;
364 };
365
366 struct parm_struct
367 {
368         const char *label;
369         parm_type type;
370         parm_class class;
371         void *ptr;
372         BOOL (*special)(const char *, char **);
373         const struct enum_list *enum_list;
374         unsigned flags;
375         union {
376                 BOOL bvalue;
377                 int ivalue;
378                 char *svalue;
379                 char cvalue;
380                 char **lvalue;
381         } def;
382 };
383
384 struct bitmap {
385         uint32_t *b;
386         unsigned int n;
387 };
388
389 #define FLAG_BASIC      0x0001 /* fundamental options */
390 #define FLAG_SHARE      0x0002 /* file sharing options */
391 #define FLAG_PRINT      0x0004 /* printing options */
392 #define FLAG_GLOBAL     0x0008 /* local options that should be globally settable in SWAT */
393 #define FLAG_WIZARD     0x0010 /* Parameters that the wizard will operate on */
394 #define FLAG_ADVANCED   0x0020 /* Parameters that the wizard will operate on */
395 #define FLAG_DEVELOPER  0x0040 /* Parameters that the wizard will operate on */
396 #define FLAG_DEPRECATED 0x1000 /* options that should no longer be used */
397 #define FLAG_HIDE       0x2000 /* options that should be hidden in SWAT */
398 #define FLAG_DOS_STRING 0x4000 /* convert from UNIX to DOS codepage when reading this string. */
399 #define FLAG_CMDLINE    0x8000 /* this option was set from the command line */
400
401 #ifndef LOCKING_VERSION
402 #define LOCKING_VERSION 4
403 #endif /* LOCKING_VERSION */
404
405
406 /* the basic packet size, assuming no words or bytes. Does not include the NBT header */
407 #define MIN_SMB_SIZE 35
408
409 /* when using NBT encapsulation every packet has a 4 byte header */
410 #define NBT_HDR_SIZE 4
411
412 /* offsets into message header for common items - NOTE: These have
413    changed from being offsets from the base of the NBT packet to the base of the SMB packet.
414    this has reduced all these values by 4
415 */
416 #define HDR_COM 4
417 #define HDR_RCLS 5
418 #define HDR_REH 6
419 #define HDR_ERR 7
420 #define HDR_FLG 9
421 #define HDR_FLG2 10
422 #define HDR_PIDHIGH 12
423 #define HDR_SS_FIELD 14
424 #define HDR_TID 24
425 #define HDR_PID 26
426 #define HDR_UID 28
427 #define HDR_MID 30
428 #define HDR_WCT 32
429 #define HDR_VWV 33
430
431
432 /* types of buffers in core SMB protocol */
433 #define SMB_DATA_BLOCK 0x1
434 #define SMB_ASCII4     0x4
435
436
437 /* flag defines. CIFS spec 3.1.1 */
438 #define FLAG_SUPPORT_LOCKREAD       0x01
439 #define FLAG_CLIENT_BUF_AVAIL       0x02
440 #define FLAG_RESERVED               0x04
441 #define FLAG_CASELESS_PATHNAMES     0x08
442 #define FLAG_CANONICAL_PATHNAMES    0x10
443 #define FLAG_REQUEST_OPLOCK         0x20
444 #define FLAG_REQUEST_BATCH_OPLOCK   0x40
445 #define FLAG_REPLY                  0x80
446
447 /* the complete */
448 #define SMBmkdir      0x00   /* create directory */
449 #define SMBrmdir      0x01   /* delete directory */
450 #define SMBopen       0x02   /* open file */
451 #define SMBcreate     0x03   /* create file */
452 #define SMBclose      0x04   /* close file */
453 #define SMBflush      0x05   /* flush file */
454 #define SMBunlink     0x06   /* delete file */
455 #define SMBmv         0x07   /* rename file */
456 #define SMBgetatr     0x08   /* get file attributes */
457 #define SMBsetatr     0x09   /* set file attributes */
458 #define SMBread       0x0A   /* read from file */
459 #define SMBwrite      0x0B   /* write to file */
460 #define SMBlock       0x0C   /* lock byte range */
461 #define SMBunlock     0x0D   /* unlock byte range */
462 #define SMBctemp      0x0E   /* create temporary file */
463 #define SMBmknew      0x0F   /* make new file */
464 #define SMBchkpth     0x10   /* check directory path */
465 #define SMBexit       0x11   /* process exit */
466 #define SMBlseek      0x12   /* seek */
467 #define SMBtcon       0x70   /* tree connect */
468 #define SMBtconX      0x75   /* tree connect and X*/
469 #define SMBtdis       0x71   /* tree disconnect */
470 #define SMBnegprot    0x72   /* negotiate protocol */
471 #define SMBdskattr    0x80   /* get disk attributes */
472 #define SMBsearch     0x81   /* search directory */
473 #define SMBsplopen    0xC0   /* open print spool file */
474 #define SMBsplwr      0xC1   /* write to print spool file */
475 #define SMBsplclose   0xC2   /* close print spool file */
476 #define SMBsplretq    0xC3   /* return print queue */
477 #define SMBsends      0xD0   /* send single block message */
478 #define SMBsendb      0xD1   /* send broadcast message */
479 #define SMBfwdname    0xD2   /* forward user name */
480 #define SMBcancelf    0xD3   /* cancel forward */
481 #define SMBgetmac     0xD4   /* get machine name */
482 #define SMBsendstrt   0xD5   /* send start of multi-block message */
483 #define SMBsendend    0xD6   /* send end of multi-block message */
484 #define SMBsendtxt    0xD7   /* send text of multi-block message */
485
486 /* Core+ protocol */
487 #define SMBlockread       0x13   /* Lock a range and read */
488 #define SMBwriteunlock 0x14 /* write then range then unlock it */
489 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
490 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
491 #define SMBwritec     0x20  /* secondary write request */
492 #define SMBwriteclose 0x2c  /* write a file then close it */
493
494 /* dos extended protocol */
495 #define SMBreadBraw      0x1A   /* read block raw */
496 #define SMBreadBmpx      0x1B   /* read block multiplexed */
497 #define SMBreadBs        0x1C   /* read block (secondary response) */
498 #define SMBwriteBraw     0x1D   /* write block raw */
499 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
500 #define SMBwriteBs       0x1F   /* write block (secondary request) */
501 #define SMBwriteC        0x20   /* write complete response */
502 #define SMBsetattrE      0x22   /* set file attributes expanded */
503 #define SMBgetattrE      0x23   /* get file attributes expanded */
504 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
505 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
506 #define SMBtranss        0x26   /* transaction (secondary request/response) */
507 #define SMBioctl         0x27   /* IOCTL */
508 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
509 #define SMBcopy          0x29   /* copy */
510 #define SMBmove          0x2A   /* move */
511 #define SMBecho          0x2B   /* echo */
512 #define SMBopenX         0x2D   /* open and X */
513 #define SMBreadX         0x2E   /* read and X */
514 #define SMBwriteX        0x2F   /* write and X */
515 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
516 #define SMBffirst        0x82   /* find first */
517 #define SMBfunique       0x83   /* find unique */
518 #define SMBfclose        0x84   /* find close */
519 #define SMBkeepalive     0x85   /* keepalive */
520 #define SMBinvalid       0xFE   /* invalid command */
521
522 /* Extended 2.0 protocol */
523 #define SMBtrans2        0x32   /* TRANS2 protocol set */
524 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
525 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
526 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
527 #define SMBulogoffX      0x74   /* user logoff */
528
529 /* NT SMB extensions. */
530 #define SMBnttrans       0xA0   /* NT transact */
531 #define SMBnttranss      0xA1   /* NT transact secondary */
532 #define SMBntcreateX     0xA2   /* NT create and X */
533 #define SMBntcancel      0xA4   /* NT cancel */
534 #define SMBntrename      0xA5   /* NT rename */
535
536 /* used to indicate end of chain */
537 #define SMB_CHAIN_NONE   0xFF
538
539 /* These are the trans subcommands */
540 #define TRANSACT_SETNAMEDPIPEHANDLESTATE  0x01 
541 #define TRANSACT_DCERPCCMD                0x26
542 #define TRANSACT_WAITNAMEDPIPEHANDLESTATE 0x53
543
544 /* These are the NT transact sub commands. */
545 #define NT_TRANSACT_CREATE                1
546 #define NT_TRANSACT_IOCTL                 2
547 #define NT_TRANSACT_SET_SECURITY_DESC     3
548 #define NT_TRANSACT_NOTIFY_CHANGE         4
549 #define NT_TRANSACT_RENAME                5
550 #define NT_TRANSACT_QUERY_SECURITY_DESC   6
551
552 /* this is used on a TConX. I'm not sure the name is very helpful though */
553 #define SMB_SUPPORT_SEARCH_BITS        0x0001
554 #define SMB_SHARE_IN_DFS               0x0002
555
556 /* Named pipe write mode flags. Used in writeX calls. */
557 #define PIPE_RAW_MODE 0x4
558 #define PIPE_START_MESSAGE 0x8
559
560 /* the desired access to use when opening a pipe */
561 #define DESIRED_ACCESS_PIPE 0x2019f
562  
563
564 /* Mapping of generic access rights for files to specific rights. */
565 #define FILE_GENERIC_ALL (STANDARD_RIGHTS_REQUIRED_ACCESS| NT_ACCESS_SYNCHRONIZE_ACCESS|FILE_ALL_ACCESS)
566
567 #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ_ACCESS|FILE_READ_DATA|FILE_READ_ATTRIBUTES|\
568                                                         FILE_READ_EA|NT_ACCESS_SYNCHRONIZE_ACCESS)
569
570 #define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE_ACCESS|FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|\
571                             FILE_WRITE_EA|FILE_APPEND_DATA|NT_ACCESS_SYNCHRONIZE_ACCESS)
572
573 #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE_ACCESS|FILE_READ_ATTRIBUTES|\
574                             FILE_EXECUTE|NT_ACCESS_SYNCHRONIZE_ACCESS)
575
576
577 /* FileAttributes (search attributes) field */
578 #define FILE_ATTRIBUTE_READONLY         0x0001
579 #define FILE_ATTRIBUTE_HIDDEN           0x0002
580 #define FILE_ATTRIBUTE_SYSTEM           0x0004
581 #define FILE_ATTRIBUTE_VOLUME           0x0008
582 #define FILE_ATTRIBUTE_DIRECTORY        0x0010
583 #define FILE_ATTRIBUTE_ARCHIVE          0x0020
584 #define FILE_ATTRIBUTE_DEVICE           0x0040
585 #define FILE_ATTRIBUTE_NORMAL           0x0080
586 #define FILE_ATTRIBUTE_TEMPORARY        0x0100
587 #define FILE_ATTRIBUTE_SPARSE           0x0200
588 #define FILE_ATTRIBUTE_REPARSE_POINT    0x0400
589 #define FILE_ATTRIBUTE_COMPRESSED       0x0800
590 #define FILE_ATTRIBUTE_OFFLINE          0x1000
591 #define FILE_ATTRIBUTE_NONINDEXED       0x2000
592 #define FILE_ATTRIBUTE_ENCRYPTED        0x4000
593
594 /* Flags - combined with attributes. */
595 #define FILE_FLAG_WRITE_THROUGH    0x80000000L
596 #define FILE_FLAG_NO_BUFFERING     0x20000000L
597 #define FILE_FLAG_RANDOM_ACCESS    0x10000000L
598 #define FILE_FLAG_SEQUENTIAL_SCAN  0x08000000L
599 #define FILE_FLAG_DELETE_ON_CLOSE  0x04000000L
600 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L
601 #define FILE_FLAG_POSIX_SEMANTICS  0x01000000L
602
603 /* Responses when opening a file. */
604 #define FILE_WAS_SUPERSEDED 0
605 #define FILE_WAS_OPENED 1
606 #define FILE_WAS_CREATED 2
607 #define FILE_WAS_OVERWRITTEN 3
608
609 /* File type flags */
610 #define FILE_TYPE_DISK  0
611 #define FILE_TYPE_BYTE_MODE_PIPE 1
612 #define FILE_TYPE_MESSAGE_MODE_PIPE 2
613 #define FILE_TYPE_PRINTER 3
614 #define FILE_TYPE_COMM_DEVICE 4
615 #define FILE_TYPE_UNKNOWN 0xFFFF
616
617 /* Flag for NT transact rename call. */
618 #define RENAME_REPLACE_IF_EXISTS 1
619
620 /* flags for SMBntrename call */
621 #define RENAME_FLAG_MOVE_CLUSTER_INFORMATION 0x102 /* ???? */
622 #define RENAME_FLAG_HARD_LINK                0x103
623 #define RENAME_FLAG_RENAME                   0x104
624 #define RENAME_FLAG_COPY                     0x105
625
626 /* Filesystem Attributes. */
627 #define FILE_CASE_SENSITIVE_SEARCH 0x01
628 #define FILE_CASE_PRESERVED_NAMES 0x02
629 #define FILE_UNICODE_ON_DISK 0x04
630 /* According to cifs9f, this is 4, not 8 */
631 /* Acconding to testing, this actually sets the security attribute! */
632 #define FILE_PERSISTENT_ACLS 0x08
633 /* These entries added from cifs9f --tsb */
634 #define FILE_FILE_COMPRESSION 0x10
635 #define FILE_VOLUME_QUOTAS 0x20
636 /* I think this is wrong. JRA #define FILE_DEVICE_IS_MOUNTED 0x20 */
637 #define FILE_VOLUME_SPARSE_FILE 0x40
638 #define FILE_VOLUME_IS_COMPRESSED 0x8000
639
640 /* ChangeNotify flags. */
641 #define FILE_NOTIFY_CHANGE_FILE        0x001
642 #define FILE_NOTIFY_CHANGE_DIR_NAME    0x002
643 #define FILE_NOTIFY_CHANGE_ATTRIBUTES  0x004
644 #define FILE_NOTIFY_CHANGE_SIZE        0x008
645 #define FILE_NOTIFY_CHANGE_LAST_WRITE  0x010
646 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x020
647 #define FILE_NOTIFY_CHANGE_CREATION    0x040
648 #define FILE_NOTIFY_CHANGE_EA          0x080
649 #define FILE_NOTIFY_CHANGE_SECURITY    0x100
650 #define FILE_NOTIFY_CHANGE_FILE_NAME   0x200
651
652 /* change notify action results */
653 #define NOTIFY_ACTION_ADDED 1
654 #define NOTIFY_ACTION_REMOVED 2
655 #define NOTIFY_ACTION_MODIFIED 3
656 #define NOTIFY_ACTION_OLD_NAME 4
657 #define NOTIFY_ACTION_NEW_NAME 5
658 #define NOTIFY_ACTION_ADDED_STREAM 6
659 #define NOTIFY_ACTION_REMOVED_STREAM 7
660 #define NOTIFY_ACTION_MODIFIED_STREAM 8
661
662 /* seek modes for smb_seek */
663 #define SEEK_MODE_START   0
664 #define SEEK_MODE_CURRENT 1
665 #define SEEK_MODE_END     2
666
667 /* where to find the base of the SMB packet proper */
668 /* REWRITE TODO: smb_base needs to be removed */
669 #define smb_base(buf) (((char *)(buf))+4)
670
671 /* we don't allow server strings to be longer than 48 characters as
672    otherwise NT will not honour the announce packets */
673 #define MAX_SERVER_STRING_LENGTH 48
674
675 #ifndef SIGNAL_CAST
676 #define SIGNAL_CAST (RETSIGTYPE (*)(int))
677 #endif
678
679 #ifndef SELECT_CAST
680 #define SELECT_CAST
681 #endif
682
683 /* these are used in NetServerEnum to choose what to receive */
684 #define SV_TYPE_WORKSTATION         0x00000001
685 #define SV_TYPE_SERVER              0x00000002
686 #define SV_TYPE_SQLSERVER           0x00000004
687 #define SV_TYPE_DOMAIN_CTRL         0x00000008
688 #define SV_TYPE_DOMAIN_BAKCTRL      0x00000010
689 #define SV_TYPE_TIME_SOURCE         0x00000020
690 #define SV_TYPE_AFP                 0x00000040
691 #define SV_TYPE_NOVELL              0x00000080
692 #define SV_TYPE_DOMAIN_MEMBER       0x00000100
693 #define SV_TYPE_PRINTQ_SERVER       0x00000200
694 #define SV_TYPE_DIALIN_SERVER       0x00000400
695 #define SV_TYPE_SERVER_UNIX         0x00000800
696 #define SV_TYPE_NT                  0x00001000
697 #define SV_TYPE_WFW                 0x00002000
698 #define SV_TYPE_SERVER_MFPN         0x00004000
699 #define SV_TYPE_SERVER_NT           0x00008000
700 #define SV_TYPE_POTENTIAL_BROWSER   0x00010000
701 #define SV_TYPE_BACKUP_BROWSER      0x00020000
702 #define SV_TYPE_MASTER_BROWSER      0x00040000
703 #define SV_TYPE_DOMAIN_MASTER       0x00080000
704 #define SV_TYPE_SERVER_OSF          0x00100000
705 #define SV_TYPE_SERVER_VMS          0x00200000
706 #define SV_TYPE_WIN95_PLUS          0x00400000
707 #define SV_TYPE_DFS_SERVER          0x00800000
708 #define SV_TYPE_ALTERNATE_XPORT     0x20000000  
709 #define SV_TYPE_LOCAL_LIST_ONLY     0x40000000  
710 #define SV_TYPE_DOMAIN_ENUM         0x80000000
711 #define SV_TYPE_ALL                 0xFFFFFFFF  
712
713 /* This was set by JHT in liaison with Jeremy Allison early 1997
714  * History:
715  * Version 4.0 - never made public
716  * Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9
717  *              - Reappeared in 1.9.16p11 with fixed smbd services
718  * Version 4.20 - To indicate that nmbd and browsing now works better
719  * Version 4.50 - Set at release of samba-2.2.0 by JHT
720  *
721  *  Note: In the presence of NT4.X do not set above 4.9
722  *        Setting this above 4.9 can have undesired side-effects.
723  *        This may change again in Samba-3.0 after further testing. JHT
724  */
725  
726 #define DEFAULT_MAJOR_VERSION 0x04
727 #define DEFAULT_MINOR_VERSION 0x09
728
729 /* Browser Election Values */
730 #define BROWSER_ELECTION_VERSION        0x010f
731 #define BROWSER_CONSTANT        0xaa55
732
733 /* Sercurity mode bits. */
734 #define NEGOTIATE_SECURITY_USER_LEVEL           0x01
735 #define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE   0x02
736 #define NEGOTIATE_SECURITY_SIGNATURES_ENABLED   0x04
737 #define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED  0x08
738
739 /* NT Flags2 bits - cifs6.txt section 3.1.2 */
740    
741 #define FLAGS2_LONG_PATH_COMPONENTS    0x0001
742 #define FLAGS2_EXTENDED_ATTRIBUTES     0x0002
743 #define FLAGS2_SMB_SECURITY_SIGNATURES 0x0004
744 #define FLAGS2_IS_LONG_NAME            0x0040
745 #define FLAGS2_EXTENDED_SECURITY       0x0800 
746 #define FLAGS2_DFS_PATHNAMES           0x1000
747 #define FLAGS2_READ_PERMIT_NO_EXECUTE  0x2000
748 #define FLAGS2_32_BIT_ERROR_CODES      0x4000 
749 #define FLAGS2_UNICODE_STRINGS         0x8000
750
751 #define FLAGS2_WIN2K_SIGNATURE         0xC852 /* Hack alert ! For now... JRA. */
752
753 /* Capabilities.  see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
754
755 #define CAP_RAW_MODE         0x0001
756 #define CAP_MPX_MODE         0x0002
757 #define CAP_UNICODE          0x0004
758 #define CAP_LARGE_FILES      0x0008
759 #define CAP_NT_SMBS          0x0010
760 #define CAP_RPC_REMOTE_APIS  0x0020
761 #define CAP_STATUS32         0x0040
762 #define CAP_LEVEL_II_OPLOCKS 0x0080
763 #define CAP_LOCK_AND_READ    0x0100
764 #define CAP_NT_FIND          0x0200
765 #define CAP_DFS              0x1000
766 #define CAP_W2K_SMBS         0x2000
767 #define CAP_LARGE_READX      0x4000
768 #define CAP_LARGE_WRITEX     0x8000
769 #define CAP_UNIX             0x800000 /* Capabilities for UNIX extensions. Created by HP. */
770 #define CAP_EXTENDED_SECURITY 0x80000000
771
772 /*
773  * Global value meaing that the smb_uid field should be
774  * ingored (in share level security and protocol level == CORE)
775  */
776
777 #define UID_FIELD_INVALID 0
778 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
779
780 /* Lock types. */
781 #define LOCKING_ANDX_SHARED_LOCK 0x1
782 #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
783 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
784 #define LOCKING_ANDX_CANCEL_LOCK 0x8
785 #define LOCKING_ANDX_LARGE_FILES 0x10
786
787 /* Oplock levels */
788 #define OPLOCKLEVEL_NONE 0
789 #define OPLOCKLEVEL_II 1
790
791 /*
792  * Bits we test with.
793  */
794
795 #define NO_OPLOCK 0
796 #define EXCLUSIVE_OPLOCK 1
797 #define BATCH_OPLOCK 2
798 #define LEVEL_II_OPLOCK 4
799
800 #define CORE_OPLOCK_GRANTED (1<<5)
801 #define EXTENDED_OPLOCK_GRANTED (1<<15)
802
803 /*
804  * Return values for oplock types.
805  */
806
807 #define NO_OPLOCK_RETURN 0
808 #define EXCLUSIVE_OPLOCK_RETURN 1
809 #define BATCH_OPLOCK_RETURN 2
810 #define LEVEL_II_OPLOCK_RETURN 3
811
812 /*
813  * Loopback command offsets.
814  */
815
816 #define OPBRK_CMD_LEN_OFFSET 0
817 #define OPBRK_CMD_PORT_OFFSET 4
818 #define OPBRK_CMD_HEADER_LEN 6
819
820 #define OPBRK_MESSAGE_CMD_OFFSET 0
821
822 /* Message types */
823 #define OPLOCK_BREAK_CMD 0x1
824 #define KERNEL_OPLOCK_BREAK_CMD 0x2
825 #define LEVEL_II_OPLOCK_BREAK_CMD 0x3
826 #define ASYNC_LEVEL_II_OPLOCK_BREAK_CMD 0x4
827
828 /*
829  * Capabilities abstracted for different systems.
830  */
831
832 #define KERNEL_OPLOCK_CAPABILITY 0x1
833
834 /*
835  * Oplock break command code sent via the kernel interface (if it exists).
836  *
837  * Form of this is :
838  *
839  *  0     2       2+devsize 2+devsize+inodesize
840  *  +----+--------+--------+----------+
841  *  | cmd| dev    |  inode |  fileid  |
842  *  +----+--------+--------+----------+
843  */
844 #define KERNEL_OPLOCK_BREAK_DEV_OFFSET 2
845 #define KERNEL_OPLOCK_BREAK_INODE_OFFSET (KERNEL_OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
846 #define KERNEL_OPLOCK_BREAK_FILEID_OFFSET (KERNEL_OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
847 #define KERNEL_OPLOCK_BREAK_MSG_LEN (KERNEL_OPLOCK_BREAK_FILEID_OFFSET + sizeof(unsigned long))
848
849
850 #define CMD_REPLY 0x8000
851
852 #include "smb_macros.h"
853
854 /* A netbios name structure. */
855 struct nmb_name {
856         char         name[17];
857         char         scope[64];
858         unsigned int name_type;
859 };
860
861
862 /* A netbios node status array element. */
863 struct node_status {
864         char name[16];
865         uint8_t type;
866         uint8_t flags;
867 };
868
869 #include "rpc_secdes.h"
870
871 typedef struct user_struct
872 {
873         struct user_struct *next, *prev;
874         uint16_t vuid; /* Tag for this entry. */
875
876         DATA_BLOB session_key;
877
878         char *session_keystr; /* used by utmp and pam session code.  
879                                  TDB key string */
880         int homes_snum;
881
882         struct auth_serversupplied_info *server_info;
883
884 } user_struct;
885
886 #include "client.h"
887
888 /*
889    Do you want session setups at user level security with a invalid
890    password to be rejected or allowed in as guest? WinNT rejects them
891    but it can be a pain as it means "net view" needs to use a password
892
893    You have 3 choices in the setting of map_to_guest:
894
895    "NEVER_MAP_TO_GUEST" means session setups with an invalid password
896    are rejected. This is the default.
897
898    "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
899    are rejected, unless the username does not exist, in which case it
900    is treated as a guest login
901
902    "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
903    are treated as a guest login
904
905    Note that map_to_guest only has an effect in user or server
906    level security.
907 */
908
909 #define NEVER_MAP_TO_GUEST 0
910 #define MAP_TO_GUEST_ON_BAD_USER 1
911 #define MAP_TO_GUEST_ON_BAD_PASSWORD 2
912
913 #define SAFE_NETBIOS_CHARS ". -_"
914
915 /* generic iconv conversion structure */
916 typedef struct {
917         size_t (*direct)(void *cd, const char **inbuf, size_t *inbytesleft,
918                          char **outbuf, size_t *outbytesleft);
919         size_t (*pull)(void *cd, const char **inbuf, size_t *inbytesleft,
920                        char **outbuf, size_t *outbytesleft);
921         size_t (*push)(void *cd, const char **inbuf, size_t *inbytesleft,
922                        char **outbuf, size_t *outbytesleft);
923         void *cd_direct, *cd_pull, *cd_push;
924         char *from_name, *to_name;
925 } *smb_iconv_t;
926
927 /* The maximum length of a trust account password.
928    Used when we randomly create it, 15 char passwords
929    exceed NT4's max password length */
930
931 #define DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH 14
932
933
934 /* a set of flags to control handling of request structures */
935 #define REQ_CONTROL_PROTECTED (1<<0) /* don't destroy this request */
936 #define REQ_CONTROL_LARGE     (1<<1) /* allow replies larger than max_xmit */
937 #define REQ_CONTROL_ASYNC     (1<<2) /* the backend will answer this one later */
938
939 /* passed to br lock code */
940 enum brl_type {READ_LOCK, WRITE_LOCK, PENDING_LOCK};
941
942 #include "popt_common.h"
943
944 #endif /* _SMB_H */