d584a9db45e4951f53b19709e935fa707a252f9f
[kai/samba-autobuild/.git] / source3 / 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 3 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, see <http://www.gnu.org/licenses/>.
24 */
25
26 #ifndef _SMB_H
27 #define _SMB_H
28
29 #include "libcli/smb/smb_common.h"
30 #include "libds/common/roles.h"
31
32 /* logged when starting the various Samba daemons */
33 #define COPYRIGHT_STARTUP_MESSAGE       "Copyright Andrew Tridgell and the Samba Team 1992-2011"
34
35
36 #if defined(LARGE_SMB_OFF_T)
37 #define BUFFER_SIZE (128*1024)
38 #else /* no large readwrite possible */
39 #define BUFFER_SIZE (0xFFFF)
40 #endif
41
42 #define SAFETY_MARGIN 1024
43 #define LARGE_WRITEX_HDR_SIZE 65
44
45 #define NMB_PORT 137
46 #define DGRAM_PORT 138
47 #define SMB_PORT1 445
48 #define SMB_PORT2 139
49 #define SMB_PORTS "445 139"
50
51 #define Undefined (-1)
52 #define False false
53 #define True true
54 #define Auto (2)
55 #define Required (3)
56
57 #define SIZEOFWORD 2
58
59 #ifndef DEF_CREATE_MASK
60 #define DEF_CREATE_MASK (0755)
61 #endif
62
63 /* string manipulation flags - see clistr.c and srvstr.c */
64 #define STR_TERMINATE 1
65 #define STR_UPPER 2
66 #define STR_ASCII 4
67 #define STR_UNICODE 8
68 #define STR_NOALIGN 16
69 #define STR_TERMINATE_ASCII 128
70
71 /* how long to wait for secondary SMB packets (milli-seconds) */
72 #define SMB_SECONDARY_WAIT (60*1000)
73
74 /* this defines the error codes that receive_smb can put in smb_read_error */
75 enum smb_read_errors {
76         SMB_READ_OK = 0,
77         SMB_READ_TIMEOUT,
78         SMB_READ_EOF,
79         SMB_READ_ERROR,
80         SMB_WRITE_ERROR, /* This error code can go into the client smb_rw_error. */
81         SMB_READ_BAD_SIG,
82         SMB_NO_MEMORY,
83         SMB_DO_NOT_DO_TDIS, /* cli_close_connection() check for this when smbfs wants to keep tree connected */
84         SMB_READ_BAD_DECRYPT
85 };
86
87 #define DIR_STRUCT_SIZE 43
88
89 /* deny modes */
90 #define DENY_DOS 0
91 #define DENY_ALL 1
92 #define DENY_WRITE 2
93 #define DENY_READ 3
94 #define DENY_NONE 4
95 #define DENY_FCB 7
96
97 /* open modes */
98 #define DOS_OPEN_RDONLY 0
99 #define DOS_OPEN_WRONLY 1
100 #define DOS_OPEN_RDWR 2
101 #define DOS_OPEN_EXEC 3
102 #define DOS_OPEN_FCB 0xF
103
104 /* define shifts and masks for share and open modes. */
105 #define OPENX_MODE_MASK 0xF
106 #define DENY_MODE_SHIFT 4
107 #define DENY_MODE_MASK 0x7
108 #define GET_OPENX_MODE(x) ((x) & OPENX_MODE_MASK)
109 #define SET_OPENX_MODE(x) ((x) & OPENX_MODE_MASK)
110 #define GET_DENY_MODE(x) (((x)>>DENY_MODE_SHIFT) & DENY_MODE_MASK)
111 #define SET_DENY_MODE(x) (((x) & DENY_MODE_MASK) <<DENY_MODE_SHIFT)
112
113 /* Sync on open file (not sure if used anymore... ?) */
114 #define FILE_SYNC_OPENMODE (1<<14)
115 #define GET_FILE_SYNC_OPENMODE(x) (((x) & FILE_SYNC_OPENMODE) ? True : False)
116
117 /* open disposition values */
118 #define OPENX_FILE_EXISTS_FAIL 0
119 #define OPENX_FILE_EXISTS_OPEN 1
120 #define OPENX_FILE_EXISTS_TRUNCATE 2
121
122 /* mask for open disposition. */
123 #define OPENX_FILE_OPEN_MASK 0x3
124
125 #define GET_FILE_OPENX_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
126 #define SET_FILE_OPENX_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
127
128 /* The above can be OR'ed with... */
129 #define OPENX_FILE_CREATE_IF_NOT_EXIST 0x10
130 #define OPENX_FILE_FAIL_IF_NOT_EXIST 0
131
132 typedef union unid_t {
133         uid_t uid;
134         gid_t gid;
135 } unid_t;
136
137 /* pipe string names */
138
139 #ifndef MAXSUBAUTHS
140 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
141 #endif
142
143 #define SID_MAX_SIZE ((size_t)(8+(MAXSUBAUTHS*4)))
144
145 #include "librpc/gen_ndr/security.h"
146
147 /*
148  * The complete list of SIDS belonging to this user.
149  * Created when a vuid is registered.
150  * The definition of the user_sids array is as follows :
151  *
152  * token->user_sids[0] = primary user SID.
153  * token->user_sids[1] = primary group SID.
154  * token->user_sids[2..num_sids] = supplementary group SIDS.
155  */
156
157 #define PRIMARY_USER_SID_INDEX 0
158 #define PRIMARY_GROUP_SID_INDEX 1
159
160 typedef struct write_cache {
161         SMB_OFF_T file_size;
162         SMB_OFF_T offset;
163         size_t alloc_size;
164         size_t data_size;
165         char *data;
166 } write_cache;
167
168 struct fd_handle {
169         size_t ref_count;
170         int fd;
171         uint64_t position_information;
172         SMB_OFF_T pos;
173         uint32 private_options; /* NT Create options, but we only look at
174                                  * NTCREATEX_OPTIONS_PRIVATE_DENY_DOS and
175                                  * NTCREATEX_OPTIONS_PRIVATE_DENY_FCB and
176                                  * NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE
177                                  * for print files *only*, where
178                                  * DELETE_ON_CLOSE is not stored in the share
179                                  * mode database.
180                                  */
181         unsigned long gen_id;
182 };
183
184 struct idle_event;
185 struct share_mode_entry;
186 struct uuid;
187 struct named_mutex;
188 struct wb_context;
189 struct rpc_cli_smbd_conn;
190 struct fncall_context;
191
192 struct vfs_fsp_data {
193     struct vfs_fsp_data *next;
194     struct vfs_handle_struct *owner;
195     void (*destroy)(void *p_data);
196     void *_dummy_;
197     /* NOTE: This structure contains four pointers so that we can guarantee
198      * that the end of the structure is always both 4-byte and 8-byte aligned.
199      */
200 };
201
202 /* the basic packet size, assuming no words or bytes */
203 #define smb_size 39
204
205 struct notify_change {
206         uint32_t action;
207         const char *name;
208 };
209
210 struct notify_mid_map;
211 struct notify_entry;
212 struct notify_event;
213 struct notify_change_request;
214 struct sys_notify_backend;
215 struct sys_notify_context {
216         struct event_context *ev;
217         struct connection_struct *conn;
218         void *private_data;     /* For use by the system backend */
219 };
220
221 struct notify_change_buf {
222         /*
223          * If no requests are pending, changes are queued here. Simple array,
224          * we only append.
225          */
226
227         /*
228          * num_changes == -1 means that we have got a catch-all change, when
229          * asked we just return NT_STATUS_OK without specific changes.
230          */
231         int num_changes;
232         struct notify_change *changes;
233
234         /*
235          * If no changes are around requests are queued here. Using a linked
236          * list, because we have to append at the end and delete from the top.
237          */
238         struct notify_change_request *requests;
239 };
240
241 struct print_file_data {
242         char *svcname;
243         char *docname;
244         char *filename;
245         struct policy_handle handle;
246         uint32_t jobid;
247         uint16 rap_jobid;
248 };
249
250 typedef struct files_struct {
251         struct files_struct *next, *prev;
252         int fnum;
253         struct connection_struct *conn;
254         struct fd_handle *fh;
255         unsigned int num_smb_operations;
256         struct file_id file_id;
257         uint64_t initial_allocation_size; /* Faked up initial allocation on disk. */
258         mode_t mode;
259         uint16 file_pid;
260         uint16 vuid;
261         write_cache *wcp;
262         struct timeval open_time;
263         uint32 access_mask;             /* NTCreateX access bits (FILE_READ_DATA etc.) */
264         uint32 share_access;            /* NTCreateX share constants (FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE). */
265
266         bool update_write_time_triggered;
267         struct timed_event *update_write_time_event;
268         bool update_write_time_on_close;
269         struct timespec close_write_time;
270         bool write_time_forced;
271
272         int oplock_type;
273         int sent_oplock_break;
274         struct timed_event *oplock_timeout;
275         struct lock_struct last_lock_failure;
276         int current_lock_count; /* Count the number of outstanding locks and pending locks. */
277
278         struct share_mode_entry *pending_break_messages;
279         int num_pending_break_messages;
280
281         bool can_lock;
282         bool can_read;
283         bool can_write;
284         bool modified;
285         bool is_directory;
286         bool aio_write_behind;
287         bool lockdb_clean;
288         bool initial_delete_on_close; /* Only set at NTCreateX if file was created. */
289         bool delete_on_close;
290         bool posix_open;
291         bool is_sparse;
292         struct smb_filename *fsp_name;
293         uint32_t name_hash;             /* Jenkins hash of full pathname. */
294
295         struct vfs_fsp_data *vfs_extension;
296         struct fake_file_handle *fake_file_handle;
297
298         struct notify_change_buf *notify;
299
300         struct files_struct *base_fsp; /* placeholder for delete on close */
301
302         /*
303          * Read-only cached brlock record, thrown away when the
304          * brlock.tdb seqnum changes. This avoids fetching data from
305          * the brlock.tdb on every read/write call.
306          */
307         int brlock_seqnum;
308         struct byte_range_lock *brlock_rec;
309
310         struct dptr_struct *dptr;
311
312         /* if not NULL, means this is a print file */
313         struct print_file_data *print_file;
314
315 } files_struct;
316
317 #include "ntquotas.h"
318 #include "sysquotas.h"
319
320 struct client_address {
321         char addr[INET6_ADDRSTRLEN];
322         const char *name;
323 };
324
325 struct vuid_cache_entry {
326         struct auth_serversupplied_info *session_info;
327         uint16_t vuid;
328         bool read_only;
329 };
330
331 struct vuid_cache {
332         unsigned int next_entry;
333         struct vuid_cache_entry array[VUID_CACHE_SIZE];
334 };
335
336 typedef struct {
337         char *name;
338         bool is_wild;
339 } name_compare_entry;
340
341 struct trans_state {
342         struct trans_state *next, *prev;
343         uint16 vuid;
344         uint64_t mid;
345
346         uint32 max_param_return;
347         uint32 max_data_return;
348         uint32 max_setup_return;
349
350         uint8 cmd;              /* SMBtrans or SMBtrans2 */
351
352         char *name;             /* for trans requests */
353         uint16 call;            /* for trans2 and nttrans requests */
354
355         bool close_on_completion;
356         bool one_way;
357
358         unsigned int setup_count;
359         uint16 *setup;
360
361         size_t received_data;
362         size_t received_param;
363
364         size_t total_param;
365         char *param;
366
367         size_t total_data;
368         char *data;
369 };
370
371 /*
372  * Info about an alternate data stream
373  */
374
375 struct stream_struct {
376         SMB_OFF_T size;
377         SMB_OFF_T alloc_size;
378         char *name;
379 };
380
381 /* Include VFS stuff */
382
383 #include "smb_acls.h"
384 #include "vfs.h"
385
386 struct dfree_cached_info {
387         time_t last_dfree_time;
388         uint64_t dfree_ret;
389         uint64_t bsize;
390         uint64_t dfree;
391         uint64_t dsize;
392 };
393
394 struct dptr_struct;
395
396 struct share_params {
397         int service;
398 };
399
400 struct share_iterator {
401         int next_id;
402 };
403
404 typedef struct connection_struct {
405         struct connection_struct *next, *prev;
406         struct smbd_server_connection *sconn; /* can be NULL */
407         unsigned cnum; /* an index passed over the wire */
408         struct share_params *params;
409         bool force_user;
410         struct vuid_cache vuid_cache;
411         bool printer;
412         bool ipc;
413         bool read_only; /* Attributes for the current user of the share. */
414         /* Does this filesystem honor
415            sub second timestamps on files
416            and directories when setting time ? */
417         enum timestamp_set_resolution ts_res;
418         char *connectpath;
419         char *origpath;
420
421         struct vfs_handle_struct *vfs_handles;          /* for the new plugins */
422
423         /*
424          * This represents the user information on this connection. Depending
425          * on the vuid using this tid, this might change per SMB request.
426          */
427         struct auth_serversupplied_info *session_info;
428
429         /*
430          * If the "force group" parameter is set, this is the primary gid that
431          * may be used in the users token, depending on the vuid using this tid.
432          */
433         gid_t force_group_gid;
434
435         uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
436
437         time_t lastused;
438         time_t lastused_count;
439         bool used;
440         int num_files_open;
441         unsigned int num_smb_operations; /* Count of smb operations on this tree. */
442         int encrypt_level;
443         bool encrypted_tid;
444
445         /* Semantics requested by the client or forced by the server config. */
446         bool case_sensitive;
447         bool case_preserve;
448         bool short_case_preserve;
449
450         /* Semantics provided by the underlying filesystem. */
451         int fs_capabilities;
452         /* Device number of the directory of the share mount.
453            Used to ensure unique FileIndex returns. */
454         SMB_DEV_T base_share_dev;
455
456         name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
457         name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
458         name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */       
459         name_compare_entry *aio_write_behind_list; /* Per-share list of files to use aio write behind on. */       
460         struct dfree_cached_info *dfree_info;
461         struct trans_state *pending_trans;
462         struct notify_context *notify_ctx;
463
464         struct rpc_pipe_client *spoolss_pipe;
465
466 } connection_struct;
467
468 struct current_user {
469         connection_struct *conn;
470         uint16 vuid;
471         struct security_unix_token ut;
472         struct security_token *nt_user_token;
473 };
474
475 struct smbd_smb2_request;
476
477 struct smb_request {
478         uint8_t cmd;
479         uint16 flags2;
480         uint16 smbpid;
481         uint64_t mid; /* For compatibility with SMB2. */
482         uint32_t seqnum;
483         uint16 vuid;
484         uint16 tid;
485         uint8  wct;
486         uint16_t *vwv;
487         uint16_t buflen;
488         const uint8_t *buf;
489         const uint8 *inbuf;
490
491         /*
492          * Async handling in the main smb processing loop is directed by
493          * outbuf: reply_xxx routines indicate sync behaviour by putting their
494          * reply into "outbuf". If they leave it as NULL, they take of it
495          * themselves, possibly later.
496          *
497          * If async handling is wanted, the reply_xxx routine must make sure
498          * that it talloc_move()s the smb_req somewhere else.
499          */
500         uint8 *outbuf;
501
502         size_t unread_bytes;
503         bool encrypted;
504         connection_struct *conn;
505         struct smbd_server_connection *sconn;
506         struct smb_perfcount_data pcd;
507
508         /*
509          * Chained request handling
510          */
511         struct files_struct *chain_fsp;
512
513         /*
514          * Here we collect the outbufs from the chain handlers
515          */
516         uint8_t *chain_outbuf;
517
518         /*
519          * state information for async smb handling
520          */
521         void *async_priv;
522
523         bool done;
524
525         /*
526          * Back pointer to smb2 request.
527          */
528         struct smbd_smb2_request *smb2req;
529 };
530
531 /* Defines for the sent_oplock_break field above. */
532 #define NO_BREAK_SENT 0
533 #define BREAK_TO_NONE_SENT 1
534 #define LEVEL_II_BREAK_SENT 2
535
536 typedef struct {
537         fstring smb_name; /* user name from the client */
538         fstring unix_name; /* unix user name of a validated user */
539         fstring domain; /* domain that the client specified */
540 } userdom_struct;
541
542 /* used for server information: client, nameserv and ipc */
543 struct server_info_struct {
544         fstring name;
545         uint32 type;
546         fstring comment;
547         fstring domain; /* used ONLY in ipc.c NOT namework.c */
548         bool server_added; /* used ONLY in ipc.c NOT namework.c */
549 };
550
551 /* used for network interfaces */
552 struct interface {
553         struct interface *next, *prev;
554         char *name;
555         int flags;
556         struct sockaddr_storage ip;
557         struct sockaddr_storage netmask;
558         struct sockaddr_storage bcast;
559 };
560
561 /* Internal message queue for deferred opens. */
562 struct pending_message_list {
563         struct pending_message_list *next, *prev;
564         struct timeval request_time; /* When was this first issued? */
565         struct timed_event *te;
566         struct smb_perfcount_data pcd;
567         uint32_t seqnum;
568         bool encrypted;
569         bool processed;
570         DATA_BLOB buf;
571         DATA_BLOB private_data;
572 };
573
574 #define SHARE_MODE_FLAG_POSIX_OPEN      0x1
575
576 #include "librpc/gen_ndr/server_id.h"
577
578 /* struct returned by get_share_modes */
579 struct share_mode_entry {
580         struct server_id pid;
581         uint64_t op_mid;        /* For compatibility with SMB2 opens. */
582         uint16 op_type;
583         uint32 access_mask;             /* NTCreateX access bits (FILE_READ_DATA etc.) */
584         uint32 share_access;            /* NTCreateX share constants (FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE). */
585         uint32 private_options; /* NT Create options, but we only look at
586                                  * NTCREATEX_OPTIONS_PRIVATE_DENY_DOS and
587                                  * NTCREATEX_OPTIONS_PRIVATE_DENY_FCB for
588                                  * smbstatus and swat */
589         struct timeval time;
590         struct file_id id;
591         unsigned long share_file_id;
592         uint32 uid;             /* uid of file opener. */
593         uint16 flags;           /* See SHARE_MODE_XX above. */
594         uint32_t name_hash;             /* Jenkins hash of full pathname. */
595 };
596
597 /* oplock break message definition - linearization of share_mode_entry.
598
599 Offset  Data                    length.
600 0       struct server_id pid    4
601 4       uint16 op_mid           8
602 12      uint16 op_type          2
603 14      uint32 access_mask      4
604 18      uint32 share_access     4
605 22      uint32 private_options  4
606 26      uint32 time sec         4
607 30      uint32 time usec        4
608 34      uint64 dev              8 bytes
609 42      uint64 inode            8 bytes
610 50      uint64 extid            8 bytes
611 58      unsigned long file_id   4 bytes
612 62      uint32 uid              4 bytes
613 66      uint16 flags            2 bytes
614 68      uint32 name_hash        4 bytes
615 72
616
617 */
618
619 #define OP_BREAK_MSG_PID_OFFSET 0
620 #define OP_BREAK_MSG_MID_OFFSET 4
621 #define OP_BREAK_MSG_OP_TYPE_OFFSET 12
622 #define OP_BREAK_MSG_ACCESS_MASK_OFFSET 14
623 #define OP_BREAK_MSG_SHARE_ACCESS_OFFSET 18
624 #define OP_BREAK_MSG_PRIV_OFFSET 22
625 #define OP_BREAK_MSG_TIME_SEC_OFFSET 26
626 #define OP_BREAK_MSG_TIME_USEC_OFFSET 30
627 #define OP_BREAK_MSG_DEV_OFFSET 34
628 #define OP_BREAK_MSG_INO_OFFSET 42
629 #define OP_BREAK_MSG_EXTID_OFFSET 50
630 #define OP_BREAK_MSG_FILE_ID_OFFSET 58
631 #define OP_BREAK_MSG_UID_OFFSET 62
632 #define OP_BREAK_MSG_FLAGS_OFFSET 66
633 #define OP_BREAK_MSG_NAME_HASH_OFFSET 68
634
635 #define OP_BREAK_MSG_VNN_OFFSET 72
636 #define MSG_SMB_SHARE_MODE_ENTRY_SIZE 76
637
638 struct delete_token_list {
639         struct delete_token_list *next, *prev;
640         uint32_t name_hash;
641         struct security_unix_token *delete_token;
642 };
643
644 struct share_mode_lock {
645         const char *servicepath; /* canonicalized. */
646         const char *base_name;
647         const char *stream_name;
648         struct file_id id;
649         int num_share_modes;
650         struct share_mode_entry *share_modes;
651         struct delete_token_list *delete_tokens;
652         struct timespec old_write_time;
653         struct timespec changed_write_time;
654         bool fresh;
655         bool modified;
656         struct db_record *record;
657 };
658
659 /*
660  * Internal structure of locking.tdb share mode db.
661  * Used by locking.c and libsmbsharemodes.c
662  */
663
664 struct locking_data {
665         union {
666                 struct {
667                         int num_share_mode_entries;
668                         struct timespec old_write_time;
669                         struct timespec changed_write_time;
670                         uint32 num_delete_token_entries;
671                 } s;
672                 struct share_mode_entry dummy; /* Needed for alignment. */
673         } u;
674         /* The following four entries are implicit
675
676            (1) struct share_mode_entry modes[num_share_mode_entries];
677
678            (2) A num_delete_token_entries of structs {
679                 uint32_t len_delete_token;
680                 char unix_token[len_delete_token] (divisible by 4).
681            };
682
683            (3) char share_name[];
684            (4) char file_name[];
685         */
686 };
687
688 #define NT_HASH_LEN 16
689 #define LM_HASH_LEN 16
690
691 /* key and data in the connections database - used in smbstatus and smbd */
692 struct connections_key {
693         struct server_id pid;
694         int cnum;
695         fstring name;
696 };
697
698 struct connections_data {
699         int magic;
700         struct server_id pid;
701         int cnum;
702         uid_t uid;
703         gid_t gid;
704         char servicename[FSTRING_LEN];
705         char addr[24];
706         char machine[FSTRING_LEN];
707         time_t start;
708
709         /*
710          * This field used to hold the msg_flags. For compatibility reasons,
711          * keep the data structure in the tdb file the same.
712          */
713         uint32 unused_compatitibility_field;
714 };
715
716
717 /* the following are used by loadparm for option lists */
718 typedef enum {
719         P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,P_LIST,
720         P_STRING,P_USTRING,P_ENUM,P_SEP
721 } parm_type;
722
723 typedef enum {
724         P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
725 } parm_class;
726
727 struct enum_list {
728         int value;
729         const char *name;
730 };
731
732 struct parm_struct {
733         const char *label;
734         parm_type type;
735         parm_class p_class;
736         void *ptr;
737         bool (*special)(int snum, const char *, char **);
738         const struct enum_list *enum_list;
739         unsigned flags;
740         union {
741                 bool bvalue;
742                 int ivalue;
743                 char *svalue;
744                 char cvalue;
745                 char **lvalue;
746         } def;
747 };
748
749 /* The following flags are used in SWAT */
750 #define FLAG_BASIC      0x0001 /* Display only in BASIC view */
751 #define FLAG_SHARE      0x0002 /* file sharing options */
752 #define FLAG_PRINT      0x0004 /* printing options */
753 #define FLAG_GLOBAL     0x0008 /* local options that should be globally settable in SWAT */
754 #define FLAG_WIZARD     0x0010 /* Parameters that the wizard will operate on */
755 #define FLAG_ADVANCED   0x0020 /* Parameters that will be visible in advanced view */
756 #define FLAG_DEVELOPER  0x0040 /* No longer used */
757 #define FLAG_DEPRECATED 0x1000 /* options that should no longer be used */
758 #define FLAG_HIDE       0x2000 /* options that should be hidden in SWAT */
759 #define FLAG_DOS_STRING 0x4000 /* convert from UNIX to DOS codepage when reading this string. */
760 #define FLAG_META       0x8000 /* A meta directive - not a real parameter */
761 #define FLAG_CMDLINE    0x10000 /* option has been overridden */
762
763 struct bitmap {
764         uint32 *b;
765         unsigned int n;
766 };
767
768 /* offsets into message for common items */
769 #define smb_com 8
770 #define smb_rcls 9
771 #define smb_reh 10
772 #define smb_err 11
773 #define smb_flg 13
774 #define smb_flg2 14
775 #define smb_pidhigh 16
776 #define smb_ss_field 18
777 #define smb_tid 28
778 #define smb_pid 30
779 #define smb_uid 32
780 #define smb_mid 34
781 #define smb_wct 36
782 #define smb_vwv 37
783 #define smb_vwv0 37
784 #define smb_vwv1 39
785 #define smb_vwv2 41
786 #define smb_vwv3 43
787 #define smb_vwv4 45
788 #define smb_vwv5 47
789 #define smb_vwv6 49
790 #define smb_vwv7 51
791 #define smb_vwv8 53
792 #define smb_vwv9 55
793 #define smb_vwv10 57
794 #define smb_vwv11 59
795 #define smb_vwv12 61
796 #define smb_vwv13 63
797 #define smb_vwv14 65
798 #define smb_vwv15 67
799 #define smb_vwv16 69
800 #define smb_vwv17 71
801
802 /* flag defines. CIFS spec 3.1.1 */
803 #define FLAG_SUPPORT_LOCKREAD       0x01
804 #define FLAG_CLIENT_BUF_AVAIL       0x02
805 #define FLAG_RESERVED               0x04
806 #define FLAG_CASELESS_PATHNAMES     0x08
807 #define FLAG_CANONICAL_PATHNAMES    0x10
808 #define FLAG_REQUEST_OPLOCK         0x20
809 #define FLAG_REQUEST_BATCH_OPLOCK   0x40
810 #define FLAG_REPLY                  0x80
811
812 /* the complete */
813 #define SMBmkdir      0x00   /* create directory */
814 #define SMBrmdir      0x01   /* delete directory */
815 #define SMBopen       0x02   /* open file */
816 #define SMBcreate     0x03   /* create file */
817 #define SMBclose      0x04   /* close file */
818 #define SMBflush      0x05   /* flush file */
819 #define SMBunlink     0x06   /* delete file */
820 #define SMBmv         0x07   /* rename file */
821 #define SMBgetatr     0x08   /* get file attributes */
822 #define SMBsetatr     0x09   /* set file attributes */
823 #define SMBread       0x0A   /* read from file */
824 #define SMBwrite      0x0B   /* write to file */
825 #define SMBlock       0x0C   /* lock byte range */
826 #define SMBunlock     0x0D   /* unlock byte range */
827 #define SMBctemp      0x0E   /* create temporary file */
828 #define SMBmknew      0x0F   /* make new file */
829 #define SMBcheckpath  0x10   /* check directory path */
830 #define SMBexit       0x11   /* process exit */
831 #define SMBlseek      0x12   /* seek */
832 #define SMBtcon       0x70   /* tree connect */
833 #define SMBtconX      0x75   /* tree connect and X*/
834 #define SMBtdis       0x71   /* tree disconnect */
835 #define SMBnegprot    0x72   /* negotiate protocol */
836 #define SMBdskattr    0x80   /* get disk attributes */
837 #define SMBsearch     0x81   /* search directory */
838 #define SMBsplopen    0xC0   /* open print spool file */
839 #define SMBsplwr      0xC1   /* write to print spool file */
840 #define SMBsplclose   0xC2   /* close print spool file */
841 #define SMBsplretq    0xC3   /* return print queue */
842 #define SMBsends      0xD0   /* send single block message */
843 #define SMBsendb      0xD1   /* send broadcast message */
844 #define SMBfwdname    0xD2   /* forward user name */
845 #define SMBcancelf    0xD3   /* cancel forward */
846 #define SMBgetmac     0xD4   /* get machine name */
847 #define SMBsendstrt   0xD5   /* send start of multi-block message */
848 #define SMBsendend    0xD6   /* send end of multi-block message */
849 #define SMBsendtxt    0xD7   /* send text of multi-block message */
850
851 /* Core+ protocol */
852 #define SMBlockread       0x13   /* Lock a range and read */
853 #define SMBwriteunlock 0x14 /* Unlock a range then write */
854 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
855 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
856 #define SMBwritec     0x20  /* secondary write request */
857 #define SMBwriteclose 0x2c  /* write a file then close it */
858
859 /* dos extended protocol */
860 #define SMBreadBraw      0x1A   /* read block raw */
861 #define SMBreadBmpx      0x1B   /* read block multiplexed */
862 #define SMBreadBs        0x1C   /* read block (secondary response) */
863 #define SMBwriteBraw     0x1D   /* write block raw */
864 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
865 #define SMBwriteBs       0x1F   /* write block (secondary request) */
866 #define SMBwriteC        0x20   /* write complete response */
867 #define SMBsetattrE      0x22   /* set file attributes expanded */
868 #define SMBgetattrE      0x23   /* get file attributes expanded */
869 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
870 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
871 #define SMBtranss        0x26   /* transaction (secondary request/response) */
872 #define SMBioctl         0x27   /* IOCTL */
873 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
874 #define SMBcopy          0x29   /* copy */
875 #define SMBmove          0x2A   /* move */
876 #define SMBecho          0x2B   /* echo */
877 #define SMBopenX         0x2D   /* open and X */
878 #define SMBreadX         0x2E   /* read and X */
879 #define SMBwriteX        0x2F   /* write and X */
880 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
881 #define SMBffirst        0x82   /* find first */
882 #define SMBfunique       0x83   /* find unique */
883 #define SMBfclose        0x84   /* find close */
884 #define SMBkeepalive     0x85   /* keepalive */
885 #define SMBinvalid       0xFE   /* invalid command */
886
887 /* Extended 2.0 protocol */
888 #define SMBtrans2        0x32   /* TRANS2 protocol set */
889 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
890 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
891 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
892 #define SMBulogoffX      0x74   /* user logoff */
893
894 /* NT SMB extensions. */
895 #define SMBnttrans       0xA0   /* NT transact */
896 #define SMBnttranss      0xA1   /* NT transact secondary */
897 #define SMBntcreateX     0xA2   /* NT create and X */
898 #define SMBntcancel      0xA4   /* NT cancel */
899 #define SMBntrename      0xA5   /* NT rename */
900
901 /* These are the trans subcommands */
902 #define TRANSACT_SETNAMEDPIPEHANDLESTATE  0x01 
903 #define TRANSACT_DCERPCCMD                0x26
904 #define TRANSACT_WAITNAMEDPIPEHANDLESTATE 0x53
905
906 /* These are the TRANS2 sub commands */
907 #define TRANSACT2_OPEN                          0x00
908 #define TRANSACT2_FINDFIRST                     0x01
909 #define TRANSACT2_FINDNEXT                      0x02
910 #define TRANSACT2_QFSINFO                       0x03
911 #define TRANSACT2_SETFSINFO                     0x04
912 #define TRANSACT2_QPATHINFO                     0x05
913 #define TRANSACT2_SETPATHINFO                   0x06
914 #define TRANSACT2_QFILEINFO                     0x07
915 #define TRANSACT2_SETFILEINFO                   0x08
916 #define TRANSACT2_FSCTL                         0x09
917 #define TRANSACT2_IOCTL                         0x0A
918 #define TRANSACT2_FINDNOTIFYFIRST               0x0B
919 #define TRANSACT2_FINDNOTIFYNEXT                0x0C
920 #define TRANSACT2_MKDIR                         0x0D
921 #define TRANSACT2_SESSION_SETUP                 0x0E
922 #define TRANSACT2_GET_DFS_REFERRAL              0x10
923 #define TRANSACT2_REPORT_DFS_INCONSISTANCY      0x11
924
925 /* These are the NT transact sub commands. */
926 #define NT_TRANSACT_CREATE                1
927 #define NT_TRANSACT_IOCTL                 2
928 #define NT_TRANSACT_SET_SECURITY_DESC     3
929 #define NT_TRANSACT_NOTIFY_CHANGE         4
930 #define NT_TRANSACT_RENAME                5
931 #define NT_TRANSACT_QUERY_SECURITY_DESC   6
932 #define NT_TRANSACT_GET_USER_QUOTA        7
933 #define NT_TRANSACT_SET_USER_QUOTA        8
934
935 /* These are the NT transact_get_user_quota sub commands */
936 #define TRANSACT_GET_USER_QUOTA_LIST_CONTINUE   0x0000
937 #define TRANSACT_GET_USER_QUOTA_LIST_START      0x0100
938 #define TRANSACT_GET_USER_QUOTA_FOR_SID         0x0101
939
940 /* Relevant IOCTL codes */
941 #define IOCTL_QUERY_JOB_INFO      0x530060
942
943 /* these are the trans2 sub fields for primary requests */
944 #define smb_tpscnt smb_vwv0
945 #define smb_tdscnt smb_vwv1
946 #define smb_mprcnt smb_vwv2
947 #define smb_mdrcnt smb_vwv3
948 #define smb_msrcnt smb_vwv4
949 #define smb_flags smb_vwv5
950 #define smb_timeout smb_vwv6
951 #define smb_pscnt smb_vwv9
952 #define smb_psoff smb_vwv10
953 #define smb_dscnt smb_vwv11
954 #define smb_dsoff smb_vwv12
955 #define smb_suwcnt smb_vwv13
956 #define smb_setup smb_vwv14
957 #define smb_setup0 smb_setup
958 #define smb_setup1 (smb_setup+2)
959 #define smb_setup2 (smb_setup+4)
960
961 /* these are for the secondary requests */
962 #define smb_spscnt smb_vwv2
963 #define smb_spsoff smb_vwv3
964 #define smb_spsdisp smb_vwv4
965 #define smb_sdscnt smb_vwv5
966 #define smb_sdsoff smb_vwv6
967 #define smb_sdsdisp smb_vwv7
968 #define smb_sfid smb_vwv8
969
970 /* and these for responses */
971 #define smb_tprcnt smb_vwv0
972 #define smb_tdrcnt smb_vwv1
973 #define smb_prcnt smb_vwv3
974 #define smb_proff smb_vwv4
975 #define smb_prdisp smb_vwv5
976 #define smb_drcnt smb_vwv6
977 #define smb_droff smb_vwv7
978 #define smb_drdisp smb_vwv8
979
980 /* these are for the NT trans primary request. */
981 #define smb_nt_MaxSetupCount smb_vwv0
982 #define smb_nt_Flags (smb_vwv0 + 1)
983 #define smb_nt_TotalParameterCount (smb_vwv0 + 3)
984 #define smb_nt_TotalDataCount (smb_vwv0 + 7)
985 #define smb_nt_MaxParameterCount (smb_vwv0 + 11)
986 #define smb_nt_MaxDataCount (smb_vwv0 + 15)
987 #define smb_nt_ParameterCount (smb_vwv0 + 19)
988 #define smb_nt_ParameterOffset (smb_vwv0 + 23)
989 #define smb_nt_DataCount (smb_vwv0 + 27)
990 #define smb_nt_DataOffset (smb_vwv0 + 31)
991 #define smb_nt_SetupCount (smb_vwv0 + 35)
992 #define smb_nt_Function (smb_vwv0 + 36)
993 #define smb_nt_SetupStart (smb_vwv0 + 38)
994
995 /* these are for the NT trans secondary request. */
996 #define smb_nts_TotalParameterCount (smb_vwv0 + 3)
997 #define smb_nts_TotalDataCount (smb_vwv0 + 7)
998 #define smb_nts_ParameterCount (smb_vwv0 + 11)
999 #define smb_nts_ParameterOffset (smb_vwv0 + 15)
1000 #define smb_nts_ParameterDisplacement (smb_vwv0 + 19)
1001 #define smb_nts_DataCount (smb_vwv0 + 23)
1002 #define smb_nts_DataOffset (smb_vwv0 + 27)
1003 #define smb_nts_DataDisplacement (smb_vwv0 + 31)
1004
1005 /* these are for the NT trans reply. */
1006 #define smb_ntr_TotalParameterCount (smb_vwv0 + 3)
1007 #define smb_ntr_TotalDataCount (smb_vwv0 + 7)
1008 #define smb_ntr_ParameterCount (smb_vwv0 + 11)
1009 #define smb_ntr_ParameterOffset (smb_vwv0 + 15)
1010 #define smb_ntr_ParameterDisplacement (smb_vwv0 + 19)
1011 #define smb_ntr_DataCount (smb_vwv0 + 23)
1012 #define smb_ntr_DataOffset (smb_vwv0 + 27)
1013 #define smb_ntr_DataDisplacement (smb_vwv0 + 31)
1014
1015 /* these are for the NT create_and_X */
1016 #define smb_ntcreate_NameLength (smb_vwv0 + 5)
1017 #define smb_ntcreate_Flags (smb_vwv0 + 7)
1018 #define smb_ntcreate_RootDirectoryFid (smb_vwv0 + 11)
1019 #define smb_ntcreate_DesiredAccess (smb_vwv0 + 15)
1020 #define smb_ntcreate_AllocationSize (smb_vwv0 + 19)
1021 #define smb_ntcreate_FileAttributes (smb_vwv0 + 27)
1022 #define smb_ntcreate_ShareAccess (smb_vwv0 + 31)
1023 #define smb_ntcreate_CreateDisposition (smb_vwv0 + 35)
1024 #define smb_ntcreate_CreateOptions (smb_vwv0 + 39)
1025 #define smb_ntcreate_ImpersonationLevel (smb_vwv0 + 43)
1026 #define smb_ntcreate_SecurityFlags (smb_vwv0 + 47)
1027
1028 /* this is used on a TConX. I'm not sure the name is very helpful though */
1029 #define SMB_SUPPORT_SEARCH_BITS        0x0001
1030 #define SMB_SHARE_IN_DFS               0x0002
1031
1032 /* Named pipe write mode flags. Used in writeX calls. */
1033 #define PIPE_RAW_MODE 0x4
1034 #define PIPE_START_MESSAGE 0x8
1035
1036 /* the desired access to use when opening a pipe */
1037 #define DESIRED_ACCESS_PIPE 0x2019f
1038  
1039 /* Mapping of access rights to UNIX perms. */
1040 #define UNIX_ACCESS_RWX         FILE_GENERIC_ALL
1041 #define UNIX_ACCESS_R           FILE_GENERIC_READ
1042 #define UNIX_ACCESS_W           FILE_GENERIC_WRITE
1043 #define UNIX_ACCESS_X           FILE_GENERIC_EXECUTE
1044
1045 /* Mapping of access rights to UNIX perms. for a UNIX directory. */
1046 #define UNIX_DIRECTORY_ACCESS_RWX               FILE_GENERIC_ALL
1047 #define UNIX_DIRECTORY_ACCESS_R                 FILE_GENERIC_READ
1048 #define UNIX_DIRECTORY_ACCESS_W                 (FILE_GENERIC_WRITE|FILE_DELETE_CHILD)
1049 #define UNIX_DIRECTORY_ACCESS_X                 FILE_GENERIC_EXECUTE
1050
1051 #if 0
1052 /*
1053  * This is the old mapping we used to use. To get W2KSP2 profiles
1054  * working we need to map to the canonical file perms.
1055  */
1056 #define UNIX_ACCESS_RWX (UNIX_ACCESS_R|UNIX_ACCESS_W|UNIX_ACCESS_X)
1057 #define UNIX_ACCESS_R (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
1058                         FILE_READ_ATTRIBUTES|FILE_READ_EA|FILE_READ_DATA)
1059 #define UNIX_ACCESS_W (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
1060                         FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|\
1061                         FILE_APPEND_DATA|FILE_WRITE_DATA)
1062 #define UNIX_ACCESS_X (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
1063                         FILE_EXECUTE|FILE_READ_ATTRIBUTES)
1064 #endif
1065
1066 #define UNIX_ACCESS_NONE (WRITE_OWNER_ACCESS)
1067
1068 /* Flags field. */
1069 #define REQUEST_OPLOCK 2
1070 #define REQUEST_BATCH_OPLOCK 4
1071 #define OPEN_DIRECTORY 8
1072 #define EXTENDED_RESPONSE_REQUIRED 0x10
1073
1074 /* ShareAccess field. */
1075 #define FILE_SHARE_NONE 0 /* Cannot be used in bitmask. */
1076 #define FILE_SHARE_READ 1
1077 #define FILE_SHARE_WRITE 2
1078 #define FILE_SHARE_DELETE 4
1079
1080 /* Flags - combined with attributes. */
1081 #define FILE_FLAG_WRITE_THROUGH    0x80000000L
1082 #define FILE_FLAG_NO_BUFFERING     0x20000000L
1083 #define FILE_FLAG_RANDOM_ACCESS    0x10000000L
1084 #define FILE_FLAG_SEQUENTIAL_SCAN  0x08000000L
1085 #define FILE_FLAG_DELETE_ON_CLOSE  0x04000000L
1086 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L
1087 #define FILE_FLAG_POSIX_SEMANTICS  0x01000000L
1088
1089 /* CreateDisposition field. */
1090 #define FILE_SUPERSEDE 0                /* File exists overwrite/supersede. File not exist create. */
1091 #define FILE_OPEN 1                     /* File exists open. File not exist fail. */
1092 #define FILE_CREATE 2                   /* File exists fail. File not exist create. */
1093 #define FILE_OPEN_IF 3                  /* File exists open. File not exist create. */
1094 #define FILE_OVERWRITE 4                /* File exists overwrite. File not exist fail. */
1095 #define FILE_OVERWRITE_IF 5             /* File exists overwrite. File not exist create. */
1096
1097 /* CreateOptions field. */
1098 #define FILE_DIRECTORY_FILE       0x0001
1099 #define FILE_WRITE_THROUGH        0x0002
1100 #define FILE_SEQUENTIAL_ONLY      0x0004
1101 #define FILE_NO_INTERMEDIATE_BUFFERING 0x0008
1102 #define FILE_SYNCHRONOUS_IO_ALERT      0x0010   /* may be ignored */
1103 #define FILE_SYNCHRONOUS_IO_NONALERT   0x0020   /* may be ignored */
1104 #define FILE_NON_DIRECTORY_FILE   0x0040
1105 #define FILE_CREATE_TREE_CONNECTION    0x0080   /* ignore, should be zero */
1106 #define FILE_COMPLETE_IF_OPLOCKED      0x0100   /* ignore, should be zero */
1107 #define FILE_NO_EA_KNOWLEDGE      0x0200
1108 #define FILE_EIGHT_DOT_THREE_ONLY 0x0400 /* aka OPEN_FOR_RECOVERY: ignore, should be zero */
1109 #define FILE_RANDOM_ACCESS        0x0800
1110 #define FILE_DELETE_ON_CLOSE      0x1000
1111 #define FILE_OPEN_BY_FILE_ID      0x2000
1112 #define FILE_OPEN_FOR_BACKUP_INTENT    0x4000
1113 #define FILE_NO_COMPRESSION       0x8000
1114 #define FILE_RESERVER_OPFILTER    0x00100000    /* ignore, should be zero */
1115 #define FILE_OPEN_REPARSE_POINT   0x00200000
1116 #define FILE_OPEN_NO_RECALL       0x00400000
1117 #define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000 /* ignore should be zero */
1118
1119 #define NTCREATEX_OPTIONS_MUST_IGNORE_MASK      (0x008F0480)
1120
1121 #define NTCREATEX_OPTIONS_INVALID_PARAM_MASK    (0xFF100030)
1122
1123 /*
1124  * Private create options used by the ntcreatex processing code. From Samba4.
1125  * We reuse some ignored flags for private use. Passed in the private_flags
1126  * argument.
1127  */
1128 #define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS     0x0001
1129 #define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB     0x0002
1130
1131 /* Private options for streams support */
1132 #define NTCREATEX_OPTIONS_PRIVATE_STREAM_DELETE 0x0004
1133
1134 /* Private options for printer support */
1135 #define NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE 0x0008
1136
1137 /* Responses when opening a file. */
1138 #define FILE_WAS_SUPERSEDED 0
1139 #define FILE_WAS_OPENED 1
1140 #define FILE_WAS_CREATED 2
1141 #define FILE_WAS_OVERWRITTEN 3
1142
1143 /* File type flags */
1144 #define FILE_TYPE_DISK  0
1145 #define FILE_TYPE_BYTE_MODE_PIPE 1
1146 #define FILE_TYPE_MESSAGE_MODE_PIPE 2
1147 #define FILE_TYPE_PRINTER 3
1148 #define FILE_TYPE_COMM_DEVICE 4
1149 #define FILE_TYPE_UNKNOWN 0xFFFF
1150
1151 /* Flag for NT transact rename call. */
1152 #define RENAME_REPLACE_IF_EXISTS 1
1153
1154 /* flags for SMBntrename call (from Samba4) */
1155 #define RENAME_FLAG_MOVE_CLUSTER_INFORMATION 0x102 /* ???? */
1156 #define RENAME_FLAG_HARD_LINK                0x103
1157 #define RENAME_FLAG_RENAME                   0x104
1158 #define RENAME_FLAG_COPY                     0x105
1159
1160 /* Filesystem Attributes. */
1161 #define FILE_CASE_SENSITIVE_SEARCH      0x00000001
1162 #define FILE_CASE_PRESERVED_NAMES       0x00000002
1163 #define FILE_UNICODE_ON_DISK            0x00000004
1164 /* According to cifs9f, this is 4, not 8 */
1165 /* Acconding to testing, this actually sets the security attribute! */
1166 #define FILE_PERSISTENT_ACLS            0x00000008
1167 #define FILE_FILE_COMPRESSION           0x00000010
1168 #define FILE_VOLUME_QUOTAS              0x00000020
1169 #define FILE_SUPPORTS_SPARSE_FILES      0x00000040
1170 #define FILE_SUPPORTS_REPARSE_POINTS    0x00000080
1171 #define FILE_SUPPORTS_REMOTE_STORAGE    0x00000100
1172 #define FS_LFN_APIS                     0x00004000
1173 #define FILE_VOLUME_IS_COMPRESSED       0x00008000
1174 #define FILE_SUPPORTS_OBJECT_IDS        0x00010000
1175 #define FILE_SUPPORTS_ENCRYPTION        0x00020000
1176 #define FILE_NAMED_STREAMS              0x00040000
1177 #define FILE_READ_ONLY_VOLUME           0x00080000
1178
1179 /* ChangeNotify flags. */
1180 #define FILE_NOTIFY_CHANGE_FILE_NAME   0x001
1181 #define FILE_NOTIFY_CHANGE_DIR_NAME    0x002
1182 #define FILE_NOTIFY_CHANGE_ATTRIBUTES  0x004
1183 #define FILE_NOTIFY_CHANGE_SIZE        0x008
1184 #define FILE_NOTIFY_CHANGE_LAST_WRITE  0x010
1185 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x020
1186 #define FILE_NOTIFY_CHANGE_CREATION    0x040
1187 #define FILE_NOTIFY_CHANGE_EA          0x080
1188 #define FILE_NOTIFY_CHANGE_SECURITY    0x100
1189 #define FILE_NOTIFY_CHANGE_STREAM_NAME  0x00000200
1190 #define FILE_NOTIFY_CHANGE_STREAM_SIZE  0x00000400
1191 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
1192
1193 #define FILE_NOTIFY_CHANGE_NAME \
1194         (FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME)
1195
1196 /* change notify action results */
1197 #define NOTIFY_ACTION_ADDED 1
1198 #define NOTIFY_ACTION_REMOVED 2
1199 #define NOTIFY_ACTION_MODIFIED 3
1200 #define NOTIFY_ACTION_OLD_NAME 4
1201 #define NOTIFY_ACTION_NEW_NAME 5
1202 #define NOTIFY_ACTION_ADDED_STREAM 6
1203 #define NOTIFY_ACTION_REMOVED_STREAM 7
1204 #define NOTIFY_ACTION_MODIFIED_STREAM 8
1205
1206
1207 /* where to find the base of the SMB packet proper */
1208 #define smb_base(buf) (((const char *)(buf))+4)
1209
1210 /* we don't allow server strings to be longer than 48 characters as
1211    otherwise NT will not honour the announce packets */
1212 #define MAX_SERVER_STRING_LENGTH 48
1213
1214
1215 #define SMB_SUCCESS 0  /* The request was successful. */
1216
1217 #ifdef WITH_DFS
1218 void dfs_unlogin(void);
1219 extern int dcelogin_atmost_once;
1220 #endif
1221
1222 #ifdef NOSTRDUP
1223 char *strdup(char *s);
1224 #endif
1225
1226 #ifndef SELECT_CAST
1227 #define SELECT_CAST
1228 #endif
1229
1230 /* This was set by JHT in liaison with Jeremy Allison early 1997
1231  * History:
1232  * Version 4.0 - never made public
1233  * Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9
1234  *              - Reappeared in 1.9.16p11 with fixed smbd services
1235  * Version 4.20 - To indicate that nmbd and browsing now works better
1236  * Version 4.50 - Set at release of samba-2.2.0 by JHT
1237  *
1238  *  Note: In the presence of NT4.X do not set above 4.9
1239  *        Setting this above 4.9 can have undesired side-effects.
1240  *        This may change again in Samba-3.0 after further testing. JHT
1241  */
1242  
1243 #define DEFAULT_MAJOR_VERSION 0x04
1244 #define DEFAULT_MINOR_VERSION 0x09
1245
1246 /* Browser Election Values */
1247 #define BROWSER_ELECTION_VERSION        0x010f
1248 #define BROWSER_CONSTANT        0xaa55
1249
1250 /* Sercurity mode bits. */
1251 #define NEGOTIATE_SECURITY_USER_LEVEL           0x01
1252 #define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE   0x02
1253 #define NEGOTIATE_SECURITY_SIGNATURES_ENABLED   0x04
1254 #define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED  0x08
1255
1256 /* TCONX Flag (smb_vwv2). */
1257 #define TCONX_FLAG_EXTENDED_RESPONSE    0x8
1258
1259 /* File Status Flags. See:
1260
1261 http://msdn.microsoft.com/en-us/library/cc246334(PROT.13).aspx
1262 */
1263
1264 #define NO_EAS                  0x1
1265 #define NO_SUBSTREAMS           0x2
1266 #define NO_REPARSETAG           0x4
1267
1268 /* Capabilities.  see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
1269
1270 #define CAP_RAW_MODE         0x0001
1271 #define CAP_MPX_MODE         0x0002
1272 #define CAP_UNICODE          0x0004
1273 #define CAP_LARGE_FILES      0x0008
1274 #define CAP_NT_SMBS          0x0010
1275 #define CAP_RPC_REMOTE_APIS  0x0020
1276 #define CAP_STATUS32         0x0040
1277 #define CAP_LEVEL_II_OPLOCKS 0x0080
1278 #define CAP_LOCK_AND_READ    0x0100
1279 #define CAP_NT_FIND          0x0200
1280 #define CAP_DFS              0x1000
1281 #define CAP_W2K_SMBS         0x2000
1282 #define CAP_LARGE_READX      0x4000
1283 #define CAP_LARGE_WRITEX     0x8000
1284 #define CAP_UNIX             0x800000 /* Capabilities for UNIX extensions. Created by HP. */
1285 #define CAP_EXTENDED_SECURITY 0x80000000
1286
1287 /* protocol types. It assumes that higher protocols include lower protocols
1288    as subsets */
1289 enum protocol_types {
1290         PROTOCOL_NONE,
1291         PROTOCOL_CORE,
1292         PROTOCOL_COREPLUS,
1293         PROTOCOL_LANMAN1,
1294         PROTOCOL_LANMAN2,
1295         PROTOCOL_NT1,
1296         PROTOCOL_SMB2
1297 };
1298
1299 /* security levels */
1300 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER,SEC_DOMAIN,SEC_ADS};
1301
1302 /* printing types */
1303 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
1304                      PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ,
1305                      PRINT_CUPS,PRINT_LPRNT,PRINT_LPROS2,PRINT_IPRINT
1306 #if defined(DEVELOPER) || defined(ENABLE_BUILD_FARM_HACKS)
1307 ,PRINT_TEST,PRINT_VLP
1308 #endif /* DEVELOPER */
1309 };
1310
1311 /* LDAP SSL options */
1312 enum ldap_ssl_types {LDAP_SSL_OFF, LDAP_SSL_START_TLS};
1313
1314 /* LDAP PASSWD SYNC methods */
1315 enum ldap_passwd_sync_types {LDAP_PASSWD_SYNC_ON, LDAP_PASSWD_SYNC_OFF, LDAP_PASSWD_SYNC_ONLY};
1316
1317 /*
1318  * This should be under the HAVE_KRB5 flag but since they're used
1319  * in lp_kerberos_method(), they ned to be always available
1320  * If you add any entries to KERBEROS_VERIFY defines, please modify USE.*KEYTAB macros
1321  * so they remain accurate.
1322  */
1323
1324 #define KERBEROS_VERIFY_SECRETS 0
1325 #define KERBEROS_VERIFY_SYSTEM_KEYTAB 1
1326 #define KERBEROS_VERIFY_DEDICATED_KEYTAB 2
1327 #define KERBEROS_VERIFY_SECRETS_AND_KEYTAB 3
1328
1329 /* Remote architectures we know about. */
1330 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT,
1331                         RA_WIN2K, RA_WINXP, RA_WIN2K3, RA_VISTA,
1332                         RA_SAMBA, RA_CIFSFS, RA_WINXP64, RA_OSX};
1333
1334 /* case handling */
1335 enum case_handling {CASE_LOWER,CASE_UPPER};
1336
1337 /* ACL compatibility */
1338 enum acl_compatibility {ACL_COMPAT_AUTO, ACL_COMPAT_WINNT, ACL_COMPAT_WIN2K};
1339 /*
1340  * Global value meaing that the smb_uid field should be
1341  * ingored (in share level security and protocol level == CORE)
1342  */
1343
1344 #define UID_FIELD_INVALID 0
1345 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
1346
1347 /* 
1348  * Size of buffer to use when moving files across filesystems. 
1349  */
1350 #define COPYBUF_SIZE (8*1024)
1351
1352 /*
1353  * Map the Core and Extended Oplock requesst bits down
1354  * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
1355  */
1356
1357 /*
1358  * Core protocol.
1359  */
1360 #define CORE_OPLOCK_REQUEST(inbuf) \
1361     ((CVAL(inbuf,smb_flg)&(FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK))>>5)
1362
1363 /*
1364  * Extended protocol.
1365  */
1366 #define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
1367
1368 /* Lock types. */
1369 #define LOCKING_ANDX_SHARED_LOCK 0x1
1370 #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
1371 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
1372 #define LOCKING_ANDX_CANCEL_LOCK 0x8
1373 #define LOCKING_ANDX_LARGE_FILES 0x10
1374
1375 /*
1376  * Bits we test with.
1377  * Note these must fit into 16-bits.
1378  */
1379
1380 #define NO_OPLOCK                       0x0
1381 #define EXCLUSIVE_OPLOCK                0x1
1382 #define BATCH_OPLOCK                    0x2
1383 #define LEVEL_II_OPLOCK                 0x4
1384
1385 /* The following are Samba-private. */
1386 #define INTERNAL_OPEN_ONLY              0x8
1387 #define FAKE_LEVEL_II_OPLOCK            0x10    /* Client requested no_oplock, but we have to
1388                                  * inform potential level2 holders on
1389                                  * write. */
1390 #define DEFERRED_OPEN_ENTRY             0x20
1391 #define UNUSED_SHARE_MODE_ENTRY         0x40
1392 #define FORCE_OPLOCK_BREAK_TO_NONE      0x80
1393
1394 /* None of the following should ever appear in fsp->oplock_request. */
1395 #define SAMBA_PRIVATE_OPLOCK_MASK (INTERNAL_OPEN_ONLY|DEFERRED_OPEN_ENTRY|UNUSED_SHARE_MODE_ENTRY|FORCE_OPLOCK_BREAK_TO_NONE)
1396
1397 #define EXCLUSIVE_OPLOCK_TYPE(lck) ((lck) & ((unsigned int)EXCLUSIVE_OPLOCK|(unsigned int)BATCH_OPLOCK))
1398 #define BATCH_OPLOCK_TYPE(lck) ((lck) & (unsigned int)BATCH_OPLOCK)
1399 #define LEVEL_II_OPLOCK_TYPE(lck) ((lck) & ((unsigned int)LEVEL_II_OPLOCK|(unsigned int)FAKE_LEVEL_II_OPLOCK))
1400
1401 /* kernel_oplock_message definition.
1402
1403 struct kernel_oplock_message {
1404         uint64_t dev;
1405         uint64_t inode;
1406         unit64_t extid;
1407         unsigned long file_id;
1408 };
1409
1410 Offset  Data                  length.
1411 0     uint64_t dev            8 bytes
1412 8     uint64_t inode          8 bytes
1413 16    uint64_t extid          8 bytes
1414 24    unsigned long file_id   4 bytes
1415 28
1416
1417 */
1418 #define MSG_SMB_KERNEL_BREAK_SIZE 28
1419
1420 /* file_renamed_message definition.
1421
1422 struct file_renamed_message {
1423         uint64_t dev;
1424         uint64_t inode;
1425         char names[1]; A variable area containing sharepath and filename.
1426 };
1427
1428 Offset  Data                    length.
1429 0       uint64_t dev            8 bytes
1430 8       uint64_t inode          8 bytes
1431 16      unit64_t extid          8 bytes
1432 24      char [] name            zero terminated namelen bytes
1433 minimum length == 24.
1434
1435 */
1436
1437 #define MSG_FILE_RENAMED_MIN_SIZE 24
1438
1439 /*
1440  * On the wire return values for oplock types.
1441  */
1442
1443 #define CORE_OPLOCK_GRANTED (1<<5)
1444 #define EXTENDED_OPLOCK_GRANTED (1<<15)
1445
1446 #define NO_OPLOCK_RETURN 0
1447 #define EXCLUSIVE_OPLOCK_RETURN 1
1448 #define BATCH_OPLOCK_RETURN 2
1449 #define LEVEL_II_OPLOCK_RETURN 3
1450
1451 /* Oplock levels */
1452 #define OPLOCKLEVEL_NONE 0
1453 #define OPLOCKLEVEL_II 1
1454
1455 /*
1456  * Capabilities abstracted for different systems.
1457  */
1458
1459 enum smbd_capability {
1460     KERNEL_OPLOCK_CAPABILITY,
1461     DMAPI_ACCESS_CAPABILITY,
1462     LEASE_CAPABILITY
1463 };
1464
1465 /*
1466  * Kernel oplocks capability flags.
1467  */
1468
1469 /* Level 2 oplocks are supported natively by kernel oplocks. */
1470 #define KOPLOCKS_LEVEL2_SUPPORTED               0x1
1471
1472 /* The kernel notifies deferred openers when they can retry the open. */
1473 #define KOPLOCKS_DEFERRED_OPEN_NOTIFICATION     0x2
1474
1475 /* The kernel notifies smbds when an oplock break times out. */
1476 #define KOPLOCKS_TIMEOUT_NOTIFICATION           0x4
1477
1478 /* The kernel notifies smbds when an oplock is broken. */
1479 #define KOPLOCKS_OPLOCK_BROKEN_NOTIFICATION     0x8
1480
1481 struct kernel_oplocks_ops;
1482 struct kernel_oplocks {
1483         const struct kernel_oplocks_ops *ops;
1484         uint32_t flags;
1485         void *private_data;
1486 };
1487
1488 enum level2_contention_type {
1489         LEVEL2_CONTEND_ALLOC_SHRINK,
1490         LEVEL2_CONTEND_ALLOC_GROW,
1491         LEVEL2_CONTEND_SET_FILE_LEN,
1492         LEVEL2_CONTEND_FILL_SPARSE,
1493         LEVEL2_CONTEND_WRITE,
1494         LEVEL2_CONTEND_WINDOWS_BRL,
1495         LEVEL2_CONTEND_POSIX_BRL
1496 };
1497
1498 /* if a kernel does support oplocks then a structure of the following
1499    typee is used to describe how to interact with the kernel */
1500 struct kernel_oplocks_ops {
1501         bool (*set_oplock)(struct kernel_oplocks *ctx,
1502                            files_struct *fsp, int oplock_type);
1503         void (*release_oplock)(struct kernel_oplocks *ctx,
1504                                files_struct *fsp, int oplock_type);
1505         void (*contend_level2_oplocks_begin)(files_struct *fsp,
1506                                              enum level2_contention_type type);
1507         void (*contend_level2_oplocks_end)(files_struct *fsp,
1508                                            enum level2_contention_type type);
1509 };
1510
1511 #include "smb_macros.h"
1512
1513 #define MAX_NETBIOSNAME_LEN 16
1514 /* DOS character, NetBIOS namestring. Type used on the wire. */
1515 typedef char nstring[MAX_NETBIOSNAME_LEN];
1516 /* Unix character, NetBIOS namestring. Type used to manipulate name in nmbd. */
1517 typedef char unstring[MAX_NETBIOSNAME_LEN*4];
1518
1519 /* A netbios name structure. */
1520 struct nmb_name {
1521         nstring      name;
1522         char         scope[64];
1523         unsigned int name_type;
1524 };
1525
1526 /* A netbios node status array element. */
1527 struct node_status {
1528         nstring name;
1529         unsigned char type;
1530         unsigned char flags;
1531 };
1532
1533 /* The extra info from a NetBIOS node status query */
1534 struct node_status_extra {
1535         unsigned char mac_addr[6];
1536         /* There really is more here ... */ 
1537 };
1538
1539 typedef struct user_struct {
1540         struct user_struct *next, *prev;
1541         uint16 vuid; /* Tag for this entry. */
1542
1543         char *session_keystr; /* used by utmp and pam session code.  
1544                                  TDB key string */
1545         int homes_snum;
1546
1547         struct auth_serversupplied_info *session_info;
1548
1549         struct auth_ntlmssp_state *auth_ntlmssp_state;
1550 } user_struct;
1551
1552 /*
1553    Do you want session setups at user level security with a invalid
1554    password to be rejected or allowed in as guest? WinNT rejects them
1555    but it can be a pain as it means "net view" needs to use a password
1556
1557    You have 3 choices in the setting of map_to_guest:
1558
1559    "NEVER_MAP_TO_GUEST" means session setups with an invalid password
1560    are rejected. This is the default.
1561
1562    "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
1563    are rejected, unless the username does not exist, in which case it
1564    is treated as a guest login
1565
1566    "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
1567    are treated as a guest login
1568
1569    Note that map_to_guest only has an effect in user or server
1570    level security.
1571 */
1572
1573 #define NEVER_MAP_TO_GUEST              0
1574 #define MAP_TO_GUEST_ON_BAD_USER        1
1575 #define MAP_TO_GUEST_ON_BAD_PASSWORD    2
1576 #define MAP_TO_GUEST_ON_BAD_UID         3
1577
1578 #define SAFE_NETBIOS_CHARS ". -_"
1579
1580 /* The maximum length of a trust account password.
1581    Used when we randomly create it, 15 char passwords
1582    exceed NT4's max password length */
1583
1584 #define DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH 14
1585
1586 #define PORT_NONE       0
1587 #ifndef LDAP_PORT
1588 #define LDAP_PORT       389
1589 #endif
1590 #define LDAP_GC_PORT    3268
1591
1592 /* used by the IP comparison function */
1593 struct ip_service {
1594         struct sockaddr_storage ss;
1595         unsigned port;
1596 };
1597
1598 struct ea_struct {
1599         uint8 flags;
1600         char *name;
1601         DATA_BLOB value;
1602 };
1603
1604 struct ea_list {
1605         struct ea_list *next, *prev;
1606         struct ea_struct ea;
1607 };
1608
1609 /* EA names used internally in Samba. KEEP UP TO DATE with prohibited_ea_names in trans2.c !. */
1610 #define SAMBA_POSIX_INHERITANCE_EA_NAME "user.SAMBA_PAI"
1611 /* EA to use for DOS attributes */
1612 #define SAMBA_XATTR_DOS_ATTRIB "user.DOSATTRIB"
1613 /* Prefix for DosStreams in the vfs_streams_xattr module */
1614 #define SAMBA_XATTR_DOSSTREAM_PREFIX "user.DosStream."
1615 /* Prefix for xattrs storing streams. */
1616 #define SAMBA_XATTR_MARKER "user.SAMBA_STREAMS"
1617
1618 /* map readonly options */
1619 enum mapreadonly_options {MAP_READONLY_NO, MAP_READONLY_YES, MAP_READONLY_PERMISSIONS};
1620
1621 /* usershare error codes. */
1622 enum usershare_err {
1623                 USERSHARE_OK=0,
1624                 USERSHARE_MALFORMED_FILE,
1625                 USERSHARE_BAD_VERSION,
1626                 USERSHARE_MALFORMED_PATH,
1627                 USERSHARE_MALFORMED_COMMENT_DEF,
1628                 USERSHARE_MALFORMED_ACL_DEF,
1629                 USERSHARE_ACL_ERR,
1630                 USERSHARE_PATH_NOT_ABSOLUTE,
1631                 USERSHARE_PATH_IS_DENIED,
1632                 USERSHARE_PATH_NOT_ALLOWED,
1633                 USERSHARE_PATH_NOT_DIRECTORY,
1634                 USERSHARE_POSIX_ERR,
1635                 USERSHARE_MALFORMED_SHARENAME_DEF,
1636                 USERSHARE_BAD_SHARENAME
1637 };
1638
1639 /* Different reasons for closing a file. */
1640 enum file_close_type {NORMAL_CLOSE=0,SHUTDOWN_CLOSE,ERROR_CLOSE};
1641
1642 /* Used in SMB_FS_OBJECTID_INFORMATION requests.  Must be exactly 48 bytes. */
1643 #define SAMBA_EXTENDED_INFO_MAGIC 0x536d4261 /* "SmBa" */
1644 #define SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH 28
1645 struct smb_extended_info {
1646         uint32 samba_magic;             /* Always SAMBA_EXTRA_INFO_MAGIC */
1647         uint32 samba_version;           /* Major/Minor/Release/Revision */
1648         uint32 samba_subversion;        /* Prerelease/RC/Vendor patch */
1649         NTTIME samba_gitcommitdate;
1650         char   samba_version_string[SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH];
1651 };
1652
1653 /* time info */
1654 struct smb_file_time {
1655         struct timespec mtime;
1656         struct timespec atime;
1657         struct timespec ctime;
1658         struct timespec create_time;
1659 };
1660
1661 /*
1662  * unix_convert_flags
1663  */
1664 #define UCF_SAVE_LCOMP                  0x00000001
1665 #define UCF_ALWAYS_ALLOW_WCARD_LCOMP    0x00000002
1666 #define UCF_COND_ALLOW_WCARD_LCOMP      0x00000004
1667 #define UCF_POSIX_PATHNAMES             0x00000008
1668
1669 /*
1670  * smb_filename
1671  */
1672 struct smb_filename {
1673         char *base_name;
1674         char *stream_name;
1675         char *original_lcomp;
1676         SMB_STRUCT_STAT st;
1677 };
1678
1679 /* struct for maintaining the child processes that get spawned from smbd */
1680 struct child_pid {
1681         struct child_pid *prev, *next;
1682         pid_t pid;
1683 };
1684
1685 /* Used to keep track of deferred opens. */
1686 struct deferred_open_record;
1687
1688 /* Client-side offline caching policy types */
1689 #define CSC_POLICY_MANUAL 0
1690 #define CSC_POLICY_DOCUMENTS 1
1691 #define CSC_POLICY_PROGRAMS 2
1692 #define CSC_POLICY_DISABLE 3
1693
1694 /* Used inside aio code. */
1695 struct aio_extra;
1696
1697 /*
1698  * Reasons for cache flush.
1699  */
1700
1701 enum flush_reason_enum {
1702     SEEK_FLUSH,
1703     READ_FLUSH,
1704     WRITE_FLUSH,
1705     READRAW_FLUSH,
1706     OPLOCK_RELEASE_FLUSH,
1707     CLOSE_FLUSH,
1708     SYNC_FLUSH,
1709     SIZECHANGE_FLUSH,
1710     /* NUM_FLUSH_REASONS must remain the last value in the enumeration. */
1711     NUM_FLUSH_REASONS};
1712
1713 #endif /* _SMB_H */