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