2 Unix SMB/CIFS implementation.
3 SMB parameters and setup, plus a whole lot more.
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
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.
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.
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/>.
29 #include "libcli/smb/smb_common.h"
30 #include "libds/common/roles.h"
32 /* logged when starting the various Samba daemons */
33 #define COPYRIGHT_STARTUP_MESSAGE "Copyright Andrew Tridgell and the Samba Team 1992-2012"
36 #define BUFFER_SIZE (128*1024)
38 #define SAFETY_MARGIN 1024
39 #define LARGE_WRITEX_HDR_SIZE 65
42 #define DGRAM_PORT 138
43 #define NBT_SMB_PORT 139 /* Port for SMB over NBT transport (IETF STD#19). */
44 #define TCP_SMB_PORT 445 /* Port for SMB over naked TCP transport. */
45 #define SMB_PORTS "445 139"
47 #define Undefined (-1)
55 #ifndef DEF_CREATE_MASK
56 #define DEF_CREATE_MASK (0755)
59 /* string manipulation flags - see clistr.c and srvstr.c */
60 #define STR_TERMINATE 1
64 #define STR_NOALIGN 16
65 #define STR_TERMINATE_ASCII 128
67 /* how long to wait for secondary SMB packets (milli-seconds) */
68 #define SMB_SECONDARY_WAIT (60*1000)
70 #define DIR_STRUCT_SIZE 43
81 #define DOS_OPEN_RDONLY 0
82 #define DOS_OPEN_WRONLY 1
83 #define DOS_OPEN_RDWR 2
84 #define DOS_OPEN_EXEC 3
85 #define DOS_OPEN_FCB 0xF
87 /* define shifts and masks for share and open modes. */
88 #define OPENX_MODE_MASK 0xF
89 #define DENY_MODE_SHIFT 4
90 #define DENY_MODE_MASK 0x7
91 #define GET_OPENX_MODE(x) ((x) & OPENX_MODE_MASK)
92 #define SET_OPENX_MODE(x) ((x) & OPENX_MODE_MASK)
93 #define GET_DENY_MODE(x) (((x)>>DENY_MODE_SHIFT) & DENY_MODE_MASK)
94 #define SET_DENY_MODE(x) (((x) & DENY_MODE_MASK) <<DENY_MODE_SHIFT)
96 /* Sync on open file (not sure if used anymore... ?) */
97 #define FILE_SYNC_OPENMODE (1<<14)
98 #define GET_FILE_SYNC_OPENMODE(x) (((x) & FILE_SYNC_OPENMODE) ? True : False)
100 /* open disposition values */
101 #define OPENX_FILE_EXISTS_FAIL 0
102 #define OPENX_FILE_EXISTS_OPEN 1
103 #define OPENX_FILE_EXISTS_TRUNCATE 2
105 /* mask for open disposition. */
106 #define OPENX_FILE_OPEN_MASK 0x3
108 #define GET_FILE_OPENX_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
109 #define SET_FILE_OPENX_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
111 /* The above can be OR'ed with... */
112 #define OPENX_FILE_CREATE_IF_NOT_EXIST 0x10
113 #define OPENX_FILE_FAIL_IF_NOT_EXIST 0
115 /* pipe string names */
118 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
121 #define SID_MAX_SIZE ((size_t)(8+(MAXSUBAUTHS*4)))
123 #include "librpc/gen_ndr/security.h"
126 struct share_mode_entry
;
130 struct rpc_cli_smbd_conn
;
131 struct fncall_context
;
133 /* the basic packet size, assuming no words or bytes */
136 struct notify_change
{
141 struct notify_mid_map
;
142 struct notify_db_entry
;
144 struct notify_change_request
;
145 struct sys_notify_backend
;
146 struct sys_notify_context
{
147 struct event_context
*ev
;
148 void *private_data
; /* For use by the system backend */
151 #include "ntquotas.h"
152 #include "sysquotas.h"
154 struct vuid_cache_entry
{
155 struct auth_session_info
*session_info
;
161 unsigned int next_entry
;
162 struct vuid_cache_entry array
[VUID_CACHE_SIZE
];
168 } name_compare_entry
;
171 * Info about an alternate data stream
174 struct stream_struct
{
180 /* Include VFS stuff */
182 #include "smb_acls.h"
185 struct dfree_cached_info
{
186 time_t last_dfree_time
;
195 struct share_params
{
199 typedef struct connection_struct
{
200 struct connection_struct
*next
, *prev
;
201 struct smbd_server_connection
*sconn
; /* can be NULL */
202 unsigned cnum
; /* an index passed over the wire */
203 struct share_params
*params
;
205 struct vuid_cache vuid_cache
;
208 bool read_only
; /* Attributes for the current user of the share. */
209 uint32_t share_access
;
210 /* Does this filesystem honor
211 sub second timestamps on files
212 and directories when setting time ? */
213 enum timestamp_set_resolution ts_res
;
217 struct vfs_handle_struct
*vfs_handles
; /* for the new plugins */
220 * This represents the user information on this connection. Depending
221 * on the vuid using this tid, this might change per SMB request.
223 struct auth_session_info
*session_info
;
226 * If the "force group" parameter is set, this is the primary gid that
227 * may be used in the users token, depending on the vuid using this tid.
229 gid_t force_group_gid
;
231 uint16 vuid
; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
234 time_t lastused_count
;
236 unsigned int num_smb_operations
; /* Count of smb operations on this tree. */
240 /* Semantics requested by the client or forced by the server config. */
243 bool short_case_preserve
;
245 /* Semantics provided by the underlying filesystem. */
247 /* Device number of the directory of the share mount.
248 Used to ensure unique FileIndex returns. */
249 SMB_DEV_T base_share_dev
;
251 name_compare_entry
*hide_list
; /* Per-share list of files to return as hidden. */
252 name_compare_entry
*veto_list
; /* Per-share list of files to veto (never show). */
253 name_compare_entry
*veto_oplock_list
; /* Per-share list of files to refuse oplocks on. */
254 name_compare_entry
*aio_write_behind_list
; /* Per-share list of files to use aio write behind on. */
255 struct dfree_cached_info
*dfree_info
;
256 struct trans_state
*pending_trans
;
258 struct rpc_pipe_client
*spoolss_pipe
;
262 struct current_user
{
263 connection_struct
*conn
;
265 struct security_unix_token ut
;
266 struct security_token
*nt_user_token
;
269 struct smbd_smb2_request
;
270 struct privilege_paths
;
276 uint64_t mid
; /* For compatibility with SMB2. */
287 * Async handling in the main smb processing loop is directed by
288 * outbuf: reply_xxx routines indicate sync behaviour by putting their
289 * reply into "outbuf". If they leave it as NULL, they take care of it
290 * themselves, possibly later.
292 * If async handling is wanted, the reply_xxx routine must make sure
293 * that it talloc_move()s the smb_req somewhere else.
299 connection_struct
*conn
;
300 struct smbd_server_connection
*sconn
;
301 struct smb_perfcount_data pcd
;
304 * Chained request handling
306 struct files_struct
*chain_fsp
;
309 * state information for async smb handling
314 * Back pointer to smb2 request.
316 struct smbd_smb2_request
*smb2req
;
319 * Pathnames used if request done
322 struct privilege_paths
*priv_paths
;
325 * Request list for chained requests, we're part of it.
327 struct smb_request
**chain
;
330 /* Defines for the sent_oplock_break field above. */
331 #define NO_BREAK_SENT 0
332 #define BREAK_TO_NONE_SENT 1
333 #define LEVEL_II_BREAK_SENT 2
336 fstring smb_name
; /* user name from the client */
337 fstring unix_name
; /* unix user name of a validated user */
338 fstring domain
; /* domain that the client specified */
341 /* used for network interfaces */
343 struct interface
*next
, *prev
;
346 struct sockaddr_storage ip
;
347 struct sockaddr_storage netmask
;
348 struct sockaddr_storage bcast
;
351 #define SHARE_MODE_FLAG_POSIX_OPEN 0x1
353 #include "librpc/gen_ndr/server_id.h"
355 /* oplock break message definition - linearization of share_mode_entry.
358 0 struct server_id pid 4
361 14 uint32 access_mask 4
362 18 uint32 share_access 4
363 22 uint32 private_options 4
365 30 uint32 time usec 4
366 34 uint64 dev 8 bytes
367 42 uint64 inode 8 bytes
368 50 uint64 extid 8 bytes
369 58 unsigned long file_id 4 bytes
370 62 uint32 uid 4 bytes
371 66 uint16 flags 2 bytes
372 68 uint32 name_hash 4 bytes
377 #define OP_BREAK_MSG_PID_OFFSET 0
378 #define OP_BREAK_MSG_MID_OFFSET 4
379 #define OP_BREAK_MSG_OP_TYPE_OFFSET 12
380 #define OP_BREAK_MSG_ACCESS_MASK_OFFSET 14
381 #define OP_BREAK_MSG_SHARE_ACCESS_OFFSET 18
382 #define OP_BREAK_MSG_PRIV_OFFSET 22
383 #define OP_BREAK_MSG_TIME_SEC_OFFSET 26
384 #define OP_BREAK_MSG_TIME_USEC_OFFSET 30
385 #define OP_BREAK_MSG_DEV_OFFSET 34
386 #define OP_BREAK_MSG_INO_OFFSET 42
387 #define OP_BREAK_MSG_EXTID_OFFSET 50
388 #define OP_BREAK_MSG_FILE_ID_OFFSET 58
389 #define OP_BREAK_MSG_UID_OFFSET 62
390 #define OP_BREAK_MSG_FLAGS_OFFSET 66
391 #define OP_BREAK_MSG_NAME_HASH_OFFSET 68
393 #define OP_BREAK_MSG_VNN_OFFSET 72
394 #define MSG_SMB_SHARE_MODE_ENTRY_SIZE 76
396 #define NT_HASH_LEN 16
397 #define LM_HASH_LEN 16
399 /* offsets into message for common items */
400 #define smb_com (NBT_HDR_SIZE+HDR_COM)
401 #define smb_rcls (NBT_HDR_SIZE+HDR_RCLS)
402 #define smb_reh (NBT_HDR_SIZE+HDR_REH)
403 #define smb_err (NBT_HDR_SIZE+HDR_ERR)
404 #define smb_flg (NBT_HDR_SIZE+HDR_FLG)
405 #define smb_flg2 (NBT_HDR_SIZE+HDR_FLG2)
406 #define smb_pidhigh (NBT_HDR_SIZE+HDR_PIDHIGH)
407 #define smb_ss_field (NBT_HDR_SIZE+HDR_SS_FIELD)
408 #define smb_tid (NBT_HDR_SIZE+HDR_TID)
409 #define smb_pid (NBT_HDR_SIZE+HDR_PID)
410 #define smb_uid (NBT_HDR_SIZE+HDR_UID)
411 #define smb_mid (NBT_HDR_SIZE+HDR_MID)
412 #define smb_wct (NBT_HDR_SIZE+HDR_WCT)
413 #define smb_vwv (NBT_HDR_SIZE+HDR_VWV)
414 #define smb_vwv0 (smb_vwv+( 0*2))
415 #define smb_vwv1 (smb_vwv+( 1*2))
416 #define smb_vwv2 (smb_vwv+( 2*2))
417 #define smb_vwv3 (smb_vwv+( 3*2))
418 #define smb_vwv4 (smb_vwv+( 4*2))
419 #define smb_vwv5 (smb_vwv+( 5*2))
420 #define smb_vwv6 (smb_vwv+( 6*2))
421 #define smb_vwv7 (smb_vwv+( 7*2))
422 #define smb_vwv8 (smb_vwv+( 8*2))
423 #define smb_vwv9 (smb_vwv+( 9*2))
424 #define smb_vwv10 (smb_vwv+(10*2))
425 #define smb_vwv11 (smb_vwv+(11*2))
426 #define smb_vwv12 (smb_vwv+(12*2))
427 #define smb_vwv13 (smb_vwv+(13*2))
428 #define smb_vwv14 (smb_vwv+(14*2))
429 #define smb_vwv15 (smb_vwv+(15*2))
430 #define smb_vwv16 (smb_vwv+(16*2))
431 #define smb_vwv17 (smb_vwv+(17*2))
433 /* These are the trans subcommands */
434 #define TRANSACT_SETNAMEDPIPEHANDLESTATE 0x01
435 #define TRANSACT_DCERPCCMD 0x26
436 #define TRANSACT_WAITNAMEDPIPEHANDLESTATE 0x53
438 /* These are the TRANS2 sub commands */
439 #define TRANSACT2_OPEN 0x00
440 #define TRANSACT2_FINDFIRST 0x01
441 #define TRANSACT2_FINDNEXT 0x02
442 #define TRANSACT2_QFSINFO 0x03
443 #define TRANSACT2_SETFSINFO 0x04
444 #define TRANSACT2_QPATHINFO 0x05
445 #define TRANSACT2_SETPATHINFO 0x06
446 #define TRANSACT2_QFILEINFO 0x07
447 #define TRANSACT2_SETFILEINFO 0x08
448 #define TRANSACT2_FSCTL 0x09
449 #define TRANSACT2_IOCTL 0x0A
450 #define TRANSACT2_FINDNOTIFYFIRST 0x0B
451 #define TRANSACT2_FINDNOTIFYNEXT 0x0C
452 #define TRANSACT2_MKDIR 0x0D
453 #define TRANSACT2_SESSION_SETUP 0x0E
454 #define TRANSACT2_GET_DFS_REFERRAL 0x10
455 #define TRANSACT2_REPORT_DFS_INCONSISTANCY 0x11
457 /* These are the NT transact sub commands. */
458 #define NT_TRANSACT_CREATE 1
459 #define NT_TRANSACT_IOCTL 2
460 #define NT_TRANSACT_SET_SECURITY_DESC 3
461 #define NT_TRANSACT_NOTIFY_CHANGE 4
462 #define NT_TRANSACT_RENAME 5
463 #define NT_TRANSACT_QUERY_SECURITY_DESC 6
464 #define NT_TRANSACT_GET_USER_QUOTA 7
465 #define NT_TRANSACT_SET_USER_QUOTA 8
467 /* These are the NT transact_get_user_quota sub commands */
468 #define TRANSACT_GET_USER_QUOTA_LIST_CONTINUE 0x0000
469 #define TRANSACT_GET_USER_QUOTA_LIST_START 0x0100
470 #define TRANSACT_GET_USER_QUOTA_FOR_SID 0x0101
472 /* Relevant IOCTL codes */
473 #define IOCTL_QUERY_JOB_INFO 0x530060
475 /* these are the trans2 sub fields for primary requests */
476 #define smb_tpscnt smb_vwv0
477 #define smb_tdscnt smb_vwv1
478 #define smb_mprcnt smb_vwv2
479 #define smb_mdrcnt smb_vwv3
480 #define smb_msrcnt smb_vwv4
481 #define smb_flags smb_vwv5
482 #define smb_timeout smb_vwv6
483 #define smb_pscnt smb_vwv9
484 #define smb_psoff smb_vwv10
485 #define smb_dscnt smb_vwv11
486 #define smb_dsoff smb_vwv12
487 #define smb_suwcnt smb_vwv13
488 #define smb_setup smb_vwv14
489 #define smb_setup0 smb_setup
490 #define smb_setup1 (smb_setup+2)
491 #define smb_setup2 (smb_setup+4)
493 /* these are for the secondary requests */
494 #define smb_spscnt smb_vwv2
495 #define smb_spsoff smb_vwv3
496 #define smb_spsdisp smb_vwv4
497 #define smb_sdscnt smb_vwv5
498 #define smb_sdsoff smb_vwv6
499 #define smb_sdsdisp smb_vwv7
500 #define smb_sfid smb_vwv8
502 /* and these for responses */
503 #define smb_tprcnt smb_vwv0
504 #define smb_tdrcnt smb_vwv1
505 #define smb_prcnt smb_vwv3
506 #define smb_proff smb_vwv4
507 #define smb_prdisp smb_vwv5
508 #define smb_drcnt smb_vwv6
509 #define smb_droff smb_vwv7
510 #define smb_drdisp smb_vwv8
512 /* these are for the NT trans primary request. */
513 #define smb_nt_MaxSetupCount smb_vwv0
514 #define smb_nt_Flags (smb_vwv0 + 1)
515 #define smb_nt_TotalParameterCount (smb_vwv0 + 3)
516 #define smb_nt_TotalDataCount (smb_vwv0 + 7)
517 #define smb_nt_MaxParameterCount (smb_vwv0 + 11)
518 #define smb_nt_MaxDataCount (smb_vwv0 + 15)
519 #define smb_nt_ParameterCount (smb_vwv0 + 19)
520 #define smb_nt_ParameterOffset (smb_vwv0 + 23)
521 #define smb_nt_DataCount (smb_vwv0 + 27)
522 #define smb_nt_DataOffset (smb_vwv0 + 31)
523 #define smb_nt_SetupCount (smb_vwv0 + 35)
524 #define smb_nt_Function (smb_vwv0 + 36)
525 #define smb_nt_SetupStart (smb_vwv0 + 38)
527 /* these are for the NT trans secondary request. */
528 #define smb_nts_TotalParameterCount (smb_vwv0 + 3)
529 #define smb_nts_TotalDataCount (smb_vwv0 + 7)
530 #define smb_nts_ParameterCount (smb_vwv0 + 11)
531 #define smb_nts_ParameterOffset (smb_vwv0 + 15)
532 #define smb_nts_ParameterDisplacement (smb_vwv0 + 19)
533 #define smb_nts_DataCount (smb_vwv0 + 23)
534 #define smb_nts_DataOffset (smb_vwv0 + 27)
535 #define smb_nts_DataDisplacement (smb_vwv0 + 31)
537 /* these are for the NT trans reply. */
538 #define smb_ntr_TotalParameterCount (smb_vwv0 + 3)
539 #define smb_ntr_TotalDataCount (smb_vwv0 + 7)
540 #define smb_ntr_ParameterCount (smb_vwv0 + 11)
541 #define smb_ntr_ParameterOffset (smb_vwv0 + 15)
542 #define smb_ntr_ParameterDisplacement (smb_vwv0 + 19)
543 #define smb_ntr_DataCount (smb_vwv0 + 23)
544 #define smb_ntr_DataOffset (smb_vwv0 + 27)
545 #define smb_ntr_DataDisplacement (smb_vwv0 + 31)
547 /* these are for the NT create_and_X */
548 #define smb_ntcreate_NameLength (smb_vwv0 + 5)
549 #define smb_ntcreate_Flags (smb_vwv0 + 7)
550 #define smb_ntcreate_RootDirectoryFid (smb_vwv0 + 11)
551 #define smb_ntcreate_DesiredAccess (smb_vwv0 + 15)
552 #define smb_ntcreate_AllocationSize (smb_vwv0 + 19)
553 #define smb_ntcreate_FileAttributes (smb_vwv0 + 27)
554 #define smb_ntcreate_ShareAccess (smb_vwv0 + 31)
555 #define smb_ntcreate_CreateDisposition (smb_vwv0 + 35)
556 #define smb_ntcreate_CreateOptions (smb_vwv0 + 39)
557 #define smb_ntcreate_ImpersonationLevel (smb_vwv0 + 43)
558 #define smb_ntcreate_SecurityFlags (smb_vwv0 + 47)
560 /* this is used on a TConX. I'm not sure the name is very helpful though */
561 #define SMB_SUPPORT_SEARCH_BITS 0x0001
562 #define SMB_SHARE_IN_DFS 0x0002
564 /* Named pipe write mode flags. Used in writeX calls. */
565 #define PIPE_RAW_MODE 0x4
566 #define PIPE_START_MESSAGE 0x8
568 /* the desired access to use when opening a pipe */
569 #define DESIRED_ACCESS_PIPE 0x2019f
571 /* Mapping of access rights to UNIX perms. */
572 #define UNIX_ACCESS_RWX FILE_GENERIC_ALL
573 #define UNIX_ACCESS_R FILE_GENERIC_READ
574 #define UNIX_ACCESS_W FILE_GENERIC_WRITE
575 #define UNIX_ACCESS_X FILE_GENERIC_EXECUTE
577 /* Mapping of access rights to UNIX perms. for a UNIX directory. */
578 #define UNIX_DIRECTORY_ACCESS_RWX FILE_GENERIC_ALL
579 #define UNIX_DIRECTORY_ACCESS_R FILE_GENERIC_READ
580 #define UNIX_DIRECTORY_ACCESS_W (FILE_GENERIC_WRITE|FILE_DELETE_CHILD)
581 #define UNIX_DIRECTORY_ACCESS_X FILE_GENERIC_EXECUTE
585 * This is the old mapping we used to use. To get W2KSP2 profiles
586 * working we need to map to the canonical file perms.
588 #define UNIX_ACCESS_RWX (UNIX_ACCESS_R|UNIX_ACCESS_W|UNIX_ACCESS_X)
589 #define UNIX_ACCESS_R (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
590 FILE_READ_ATTRIBUTES|FILE_READ_EA|FILE_READ_DATA)
591 #define UNIX_ACCESS_W (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
592 FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|\
593 FILE_APPEND_DATA|FILE_WRITE_DATA)
594 #define UNIX_ACCESS_X (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
595 FILE_EXECUTE|FILE_READ_ATTRIBUTES)
598 #define UNIX_ACCESS_NONE (WRITE_OWNER_ACCESS)
601 #define REQUEST_OPLOCK 2
602 #define REQUEST_BATCH_OPLOCK 4
603 #define OPEN_DIRECTORY 8
604 #define EXTENDED_RESPONSE_REQUIRED 0x10
606 /* ShareAccess field. */
607 #define FILE_SHARE_NONE 0 /* Cannot be used in bitmask. */
608 #define FILE_SHARE_READ 1
609 #define FILE_SHARE_WRITE 2
610 #define FILE_SHARE_DELETE 4
612 /* Flags - combined with attributes. */
613 #define FILE_FLAG_WRITE_THROUGH 0x80000000L
614 #define FILE_FLAG_NO_BUFFERING 0x20000000L
615 #define FILE_FLAG_RANDOM_ACCESS 0x10000000L
616 #define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000L
617 #define FILE_FLAG_DELETE_ON_CLOSE 0x04000000L
618 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L
619 #define FILE_FLAG_POSIX_SEMANTICS 0x01000000L
621 /* CreateDisposition field. */
622 #define FILE_SUPERSEDE 0 /* File exists overwrite/supersede. File not exist create. */
623 #define FILE_OPEN 1 /* File exists open. File not exist fail. */
624 #define FILE_CREATE 2 /* File exists fail. File not exist create. */
625 #define FILE_OPEN_IF 3 /* File exists open. File not exist create. */
626 #define FILE_OVERWRITE 4 /* File exists overwrite. File not exist fail. */
627 #define FILE_OVERWRITE_IF 5 /* File exists overwrite. File not exist create. */
629 /* CreateOptions field. */
630 #define FILE_DIRECTORY_FILE 0x0001
631 #define FILE_WRITE_THROUGH 0x0002
632 #define FILE_SEQUENTIAL_ONLY 0x0004
633 #define FILE_NO_INTERMEDIATE_BUFFERING 0x0008
634 #define FILE_SYNCHRONOUS_IO_ALERT 0x0010 /* may be ignored */
635 #define FILE_SYNCHRONOUS_IO_NONALERT 0x0020 /* may be ignored */
636 #define FILE_NON_DIRECTORY_FILE 0x0040
637 #define FILE_CREATE_TREE_CONNECTION 0x0080 /* ignore, should be zero */
638 #define FILE_COMPLETE_IF_OPLOCKED 0x0100 /* ignore, should be zero */
639 #define FILE_NO_EA_KNOWLEDGE 0x0200
640 #define FILE_EIGHT_DOT_THREE_ONLY 0x0400 /* aka OPEN_FOR_RECOVERY: ignore, should be zero */
641 #define FILE_RANDOM_ACCESS 0x0800
642 #define FILE_DELETE_ON_CLOSE 0x1000
643 #define FILE_OPEN_BY_FILE_ID 0x2000
644 #define FILE_OPEN_FOR_BACKUP_INTENT 0x4000
645 #define FILE_NO_COMPRESSION 0x8000
646 #define FILE_RESERVER_OPFILTER 0x00100000 /* ignore, should be zero */
647 #define FILE_OPEN_REPARSE_POINT 0x00200000
648 #define FILE_OPEN_NO_RECALL 0x00400000
649 #define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000 /* ignore should be zero */
651 #define NTCREATEX_OPTIONS_MUST_IGNORE_MASK (0x008F0480)
653 #define NTCREATEX_OPTIONS_INVALID_PARAM_MASK (0xFF100030)
656 * Private create options used by the ntcreatex processing code. From Samba4.
657 * We reuse some ignored flags for private use. Passed in the private_flags
660 #define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS 0x0001
661 #define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB 0x0002
663 /* Private options for streams support */
664 #define NTCREATEX_OPTIONS_PRIVATE_STREAM_DELETE 0x0004
666 /* Private options for printer support */
667 #define NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE 0x0008
669 /* Responses when opening a file. */
670 #define FILE_WAS_SUPERSEDED 0
671 #define FILE_WAS_OPENED 1
672 #define FILE_WAS_CREATED 2
673 #define FILE_WAS_OVERWRITTEN 3
675 /* Flag for NT transact rename call. */
676 #define RENAME_REPLACE_IF_EXISTS 1
678 /* flags for SMBntrename call (from Samba4) */
679 #define RENAME_FLAG_MOVE_CLUSTER_INFORMATION 0x102 /* ???? */
680 #define RENAME_FLAG_HARD_LINK 0x103
681 #define RENAME_FLAG_RENAME 0x104
682 #define RENAME_FLAG_COPY 0x105
684 /* Filesystem Attributes. */
685 #define FILE_CASE_SENSITIVE_SEARCH 0x00000001
686 #define FILE_CASE_PRESERVED_NAMES 0x00000002
687 #define FILE_UNICODE_ON_DISK 0x00000004
688 /* According to cifs9f, this is 4, not 8 */
689 /* Acconding to testing, this actually sets the security attribute! */
690 #define FILE_PERSISTENT_ACLS 0x00000008
691 #define FILE_FILE_COMPRESSION 0x00000010
692 #define FILE_VOLUME_QUOTAS 0x00000020
693 #define FILE_SUPPORTS_SPARSE_FILES 0x00000040
694 #define FILE_SUPPORTS_REPARSE_POINTS 0x00000080
695 #define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100
696 #define FS_LFN_APIS 0x00004000
697 #define FILE_VOLUME_IS_COMPRESSED 0x00008000
698 #define FILE_SUPPORTS_OBJECT_IDS 0x00010000
699 #define FILE_SUPPORTS_ENCRYPTION 0x00020000
700 #define FILE_NAMED_STREAMS 0x00040000
701 #define FILE_READ_ONLY_VOLUME 0x00080000
703 /* ChangeNotify flags. */
704 #define FILE_NOTIFY_CHANGE_FILE_NAME 0x001
705 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x002
706 #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x004
707 #define FILE_NOTIFY_CHANGE_SIZE 0x008
708 #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x010
709 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x020
710 #define FILE_NOTIFY_CHANGE_CREATION 0x040
711 #define FILE_NOTIFY_CHANGE_EA 0x080
712 #define FILE_NOTIFY_CHANGE_SECURITY 0x100
713 #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
714 #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
715 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
717 #define FILE_NOTIFY_CHANGE_NAME \
718 (FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME)
720 #define FILE_NOTIFY_CHANGE_ALL \
721 (FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | \
722 FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE | \
723 FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_LAST_ACCESS | \
724 FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_EA | \
725 FILE_NOTIFY_CHANGE_SECURITY | FILE_NOTIFY_CHANGE_STREAM_NAME | \
726 FILE_NOTIFY_CHANGE_STREAM_SIZE | FILE_NOTIFY_CHANGE_STREAM_WRITE)
728 /* change notify action results */
729 #define NOTIFY_ACTION_ADDED 1
730 #define NOTIFY_ACTION_REMOVED 2
731 #define NOTIFY_ACTION_MODIFIED 3
732 #define NOTIFY_ACTION_OLD_NAME 4
733 #define NOTIFY_ACTION_NEW_NAME 5
734 #define NOTIFY_ACTION_ADDED_STREAM 6
735 #define NOTIFY_ACTION_REMOVED_STREAM 7
736 #define NOTIFY_ACTION_MODIFIED_STREAM 8
739 /* where to find the base of the SMB packet proper */
740 #define smb_base(buf) (((const char *)(buf))+4)
742 /* we don't allow server strings to be longer than 48 characters as
743 otherwise NT will not honour the announce packets */
744 #define MAX_SERVER_STRING_LENGTH 48
747 #define SMB_SUCCESS 0 /* The request was successful. */
750 void dfs_unlogin(void);
751 extern int dcelogin_atmost_once
;
755 char *strdup(char *s
);
762 /* This was set by JHT in liaison with Jeremy Allison early 1997
764 * Version 4.0 - never made public
765 * Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9
766 * - Reappeared in 1.9.16p11 with fixed smbd services
767 * Version 4.20 - To indicate that nmbd and browsing now works better
768 * Version 4.50 - Set at release of samba-2.2.0 by JHT
770 * Note: In the presence of NT4.X do not set above 4.9
771 * Setting this above 4.9 can have undesired side-effects.
772 * This may change again in Samba-3.0 after further testing. JHT
775 #define SAMBA_MAJOR_NBT_ANNOUNCE_VERSION 0x04
776 #define SAMBA_MINOR_NBT_ANNOUNCE_VERSION 0x09
778 /* Browser Election Values */
779 #define BROWSER_ELECTION_VERSION 0x010f
780 #define BROWSER_CONSTANT 0xaa55
782 /* TCONX Flag (smb_vwv2). */
783 #define TCONX_FLAG_EXTENDED_RESPONSE 0x8
785 /* File Status Flags. See:
787 http://msdn.microsoft.com/en-us/library/cc246334(PROT.13).aspx
791 #define NO_SUBSTREAMS 0x2
792 #define NO_REPARSETAG 0x4
795 enum printing_types
{PRINT_BSD
,PRINT_SYSV
,PRINT_AIX
,PRINT_HPUX
,
796 PRINT_QNX
,PRINT_PLP
,PRINT_LPRNG
,PRINT_SOFTQ
,
797 PRINT_CUPS
,PRINT_LPRNT
,PRINT_LPROS2
,PRINT_IPRINT
798 #if defined(DEVELOPER) || defined(ENABLE_BUILD_FARM_HACKS)
799 ,PRINT_TEST
,PRINT_VLP
800 #endif /* DEVELOPER */
803 /* LDAP SSL options */
804 enum ldap_ssl_types
{LDAP_SSL_OFF
, LDAP_SSL_START_TLS
};
806 /* LDAP PASSWD SYNC methods */
807 enum ldap_passwd_sync_types
{LDAP_PASSWD_SYNC_ON
, LDAP_PASSWD_SYNC_OFF
, LDAP_PASSWD_SYNC_ONLY
};
810 * This should be under the HAVE_KRB5 flag but since they're used
811 * in lp_kerberos_method(), they ned to be always available
812 * If you add any entries to KERBEROS_VERIFY defines, please modify USE.*KEYTAB macros
813 * so they remain accurate.
816 #define KERBEROS_VERIFY_SECRETS 0
817 #define KERBEROS_VERIFY_SYSTEM_KEYTAB 1
818 #define KERBEROS_VERIFY_DEDICATED_KEYTAB 2
819 #define KERBEROS_VERIFY_SECRETS_AND_KEYTAB 3
821 /* Remote architectures we know about. */
822 enum remote_arch_types
{RA_UNKNOWN
, RA_WFWG
, RA_OS2
, RA_WIN95
, RA_WINNT
,
823 RA_WIN2K
, RA_WINXP
, RA_WIN2K3
, RA_VISTA
,
824 RA_SAMBA
, RA_CIFSFS
, RA_WINXP64
, RA_OSX
};
827 enum case_handling
{CASE_LOWER
,CASE_UPPER
};
829 /* ACL compatibility */
830 enum acl_compatibility
{ACL_COMPAT_AUTO
, ACL_COMPAT_WINNT
, ACL_COMPAT_WIN2K
};
832 * Global value meaing that the smb_uid field should be
833 * ingored (in share level security and protocol level == CORE)
836 #define UID_FIELD_INVALID 0
837 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
840 * Size of buffer to use when moving files across filesystems.
842 #define COPYBUF_SIZE (8*1024)
845 * Map the Core and Extended Oplock requesst bits down
846 * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
852 #define CORE_OPLOCK_REQUEST(inbuf) \
853 ((CVAL(inbuf,smb_flg)&(FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK))>>5)
858 #define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
862 * Note these must fit into 16-bits.
865 #define NO_OPLOCK OPLOCK_NONE
866 #define EXCLUSIVE_OPLOCK OPLOCK_EXCLUSIVE
867 #define BATCH_OPLOCK OPLOCK_BATCH
868 #define LEVEL_II_OPLOCK OPLOCK_LEVEL_II
870 /* The following are Samba-private. */
871 #define INTERNAL_OPEN_ONLY 0x8
872 #define FAKE_LEVEL_II_OPLOCK 0x10 /* Client requested no_oplock, but we have to
873 * inform potential level2 holders on
875 #define DEFERRED_OPEN_ENTRY 0x20
876 /* #define UNUSED_SHARE_MODE_ENTRY 0x40 */ /* Not used anymore */
877 #define FORCE_OPLOCK_BREAK_TO_NONE 0x80
879 /* None of the following should ever appear in fsp->oplock_request. */
880 #define SAMBA_PRIVATE_OPLOCK_MASK (INTERNAL_OPEN_ONLY|DEFERRED_OPEN_ENTRY|FORCE_OPLOCK_BREAK_TO_NONE)
882 #define EXCLUSIVE_OPLOCK_TYPE(lck) ((lck) & ((unsigned int)EXCLUSIVE_OPLOCK|(unsigned int)BATCH_OPLOCK))
883 #define BATCH_OPLOCK_TYPE(lck) ((lck) & (unsigned int)BATCH_OPLOCK)
884 #define LEVEL_II_OPLOCK_TYPE(lck) ((lck) & ((unsigned int)LEVEL_II_OPLOCK|(unsigned int)FAKE_LEVEL_II_OPLOCK))
886 /* kernel_oplock_message definition.
888 struct kernel_oplock_message {
892 unsigned long file_id;
896 0 uint64_t dev 8 bytes
897 8 uint64_t inode 8 bytes
898 16 uint64_t extid 8 bytes
899 24 unsigned long file_id 4 bytes
903 #define MSG_SMB_KERNEL_BREAK_SIZE 28
905 /* file_renamed_message definition.
907 struct file_renamed_message {
910 char names[1]; A variable area containing sharepath and filename.
914 0 uint64_t dev 8 bytes
915 8 uint64_t inode 8 bytes
916 16 unit64_t extid 8 bytes
917 24 char [] name zero terminated namelen bytes
918 minimum length == 24.
922 #define MSG_FILE_RENAMED_MIN_SIZE 24
925 * On the wire return values for oplock types.
928 #define CORE_OPLOCK_GRANTED (1<<5)
929 #define EXTENDED_OPLOCK_GRANTED (1<<15)
931 #define NO_OPLOCK_RETURN 0
932 #define EXCLUSIVE_OPLOCK_RETURN 1
933 #define BATCH_OPLOCK_RETURN 2
934 #define LEVEL_II_OPLOCK_RETURN 3
937 #define OPLOCKLEVEL_NONE 0
938 #define OPLOCKLEVEL_II 1
941 * Capabilities abstracted for different systems.
944 enum smbd_capability
{
945 KERNEL_OPLOCK_CAPABILITY
,
946 DMAPI_ACCESS_CAPABILITY
,
951 * Kernel oplocks capability flags.
954 /* Level 2 oplocks are supported natively by kernel oplocks. */
955 #define KOPLOCKS_LEVEL2_SUPPORTED 0x1
957 /* The kernel notifies deferred openers when they can retry the open. */
958 #define KOPLOCKS_DEFERRED_OPEN_NOTIFICATION 0x2
960 /* The kernel notifies smbds when an oplock break times out. */
961 #define KOPLOCKS_TIMEOUT_NOTIFICATION 0x4
963 /* The kernel notifies smbds when an oplock is broken. */
964 #define KOPLOCKS_OPLOCK_BROKEN_NOTIFICATION 0x8
966 struct kernel_oplocks_ops
;
967 struct kernel_oplocks
{
968 const struct kernel_oplocks_ops
*ops
;
973 enum level2_contention_type
{
974 LEVEL2_CONTEND_ALLOC_SHRINK
,
975 LEVEL2_CONTEND_ALLOC_GROW
,
976 LEVEL2_CONTEND_SET_FILE_LEN
,
977 LEVEL2_CONTEND_FILL_SPARSE
,
978 LEVEL2_CONTEND_WRITE
,
979 LEVEL2_CONTEND_WINDOWS_BRL
,
980 LEVEL2_CONTEND_POSIX_BRL
983 /* if a kernel does support oplocks then a structure of the following
984 typee is used to describe how to interact with the kernel */
985 struct kernel_oplocks_ops
{
986 bool (*set_oplock
)(struct kernel_oplocks
*ctx
,
987 files_struct
*fsp
, int oplock_type
);
988 void (*release_oplock
)(struct kernel_oplocks
*ctx
,
989 files_struct
*fsp
, int oplock_type
);
990 void (*contend_level2_oplocks_begin
)(files_struct
*fsp
,
991 enum level2_contention_type type
);
992 void (*contend_level2_oplocks_end
)(files_struct
*fsp
,
993 enum level2_contention_type type
);
996 #include "smb_macros.h"
998 #define MAX_NETBIOSNAME_LEN 16
999 /* DOS character, NetBIOS namestring. Type used on the wire. */
1000 typedef char nstring
[MAX_NETBIOSNAME_LEN
];
1001 /* Unix character, NetBIOS namestring. Type used to manipulate name in nmbd. */
1002 typedef char unstring
[MAX_NETBIOSNAME_LEN
*4];
1004 /* A netbios name structure. */
1008 unsigned int name_type
;
1011 /* A netbios node status array element. */
1012 struct node_status
{
1015 unsigned char flags
;
1018 /* The extra info from a NetBIOS node status query */
1019 struct node_status_extra
{
1020 unsigned char mac_addr
[6];
1021 /* There really is more here ... */
1024 typedef struct user_struct
{
1025 struct user_struct
*next
, *prev
;
1026 uint16 vuid
; /* Tag for this entry. */
1028 char *session_keystr
; /* used by utmp and pam session code.
1032 struct auth_session_info
*session_info
;
1034 struct gensec_security
*gensec_security
;
1038 Do you want session setups at user level security with a invalid
1039 password to be rejected or allowed in as guest? WinNT rejects them
1040 but it can be a pain as it means "net view" needs to use a password
1042 You have 3 choices in the setting of map_to_guest:
1044 "NEVER_MAP_TO_GUEST" means session setups with an invalid password
1045 are rejected. This is the default.
1047 "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
1048 are rejected, unless the username does not exist, in which case it
1049 is treated as a guest login
1051 "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
1052 are treated as a guest login
1054 Note that map_to_guest only has an effect in user or server
1058 #define NEVER_MAP_TO_GUEST 0
1059 #define MAP_TO_GUEST_ON_BAD_USER 1
1060 #define MAP_TO_GUEST_ON_BAD_PASSWORD 2
1061 #define MAP_TO_GUEST_ON_BAD_UID 3
1063 #define SAFE_NETBIOS_CHARS ". -_"
1065 /* The maximum length of a trust account password.
1066 Used when we randomly create it, 15 char passwords
1067 exceed NT4's max password length */
1069 #define DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH 14
1073 #define LDAP_PORT 389
1075 #define LDAP_GC_PORT 3268
1077 /* used by the IP comparison function */
1079 struct sockaddr_storage ss
;
1090 struct ea_list
*next
, *prev
;
1091 struct ea_struct ea
;
1094 /* EA names used internally in Samba. KEEP UP TO DATE with prohibited_ea_names in trans2.c !. */
1095 #define SAMBA_POSIX_INHERITANCE_EA_NAME "user.SAMBA_PAI"
1096 /* EA to use for DOS attributes */
1097 #define SAMBA_XATTR_DOS_ATTRIB "user.DOSATTRIB"
1098 /* Prefix for DosStreams in the vfs_streams_xattr module */
1099 #define SAMBA_XATTR_DOSSTREAM_PREFIX "user.DosStream."
1100 /* Prefix for xattrs storing streams. */
1101 #define SAMBA_XATTR_MARKER "user.SAMBA_STREAMS"
1103 /* map readonly options */
1104 enum mapreadonly_options
{MAP_READONLY_NO
, MAP_READONLY_YES
, MAP_READONLY_PERMISSIONS
};
1106 /* usershare error codes. */
1107 enum usershare_err
{
1109 USERSHARE_MALFORMED_FILE
,
1110 USERSHARE_BAD_VERSION
,
1111 USERSHARE_MALFORMED_PATH
,
1112 USERSHARE_MALFORMED_COMMENT_DEF
,
1113 USERSHARE_MALFORMED_ACL_DEF
,
1115 USERSHARE_PATH_NOT_ABSOLUTE
,
1116 USERSHARE_PATH_IS_DENIED
,
1117 USERSHARE_PATH_NOT_ALLOWED
,
1118 USERSHARE_PATH_NOT_DIRECTORY
,
1119 USERSHARE_POSIX_ERR
,
1120 USERSHARE_MALFORMED_SHARENAME_DEF
,
1121 USERSHARE_BAD_SHARENAME
1124 /* Different reasons for closing a file. */
1125 enum file_close_type
{NORMAL_CLOSE
=0,SHUTDOWN_CLOSE
,ERROR_CLOSE
};
1127 /* Used in SMB_FS_OBJECTID_INFORMATION requests. Must be exactly 48 bytes. */
1128 #define SAMBA_EXTENDED_INFO_MAGIC 0x536d4261 /* "SmBa" */
1129 #define SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH 28
1130 struct smb_extended_info
{
1131 uint32 samba_magic
; /* Always SAMBA_EXTRA_INFO_MAGIC */
1132 uint32 samba_version
; /* Major/Minor/Release/Revision */
1133 uint32 samba_subversion
; /* Prerelease/RC/Vendor patch */
1134 NTTIME samba_gitcommitdate
;
1135 char samba_version_string
[SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH
];
1139 struct smb_file_time
{
1140 struct timespec mtime
;
1141 struct timespec atime
;
1142 struct timespec ctime
;
1143 struct timespec create_time
;
1147 * unix_convert_flags
1149 #define UCF_SAVE_LCOMP 0x00000001
1150 #define UCF_ALWAYS_ALLOW_WCARD_LCOMP 0x00000002
1151 #define UCF_COND_ALLOW_WCARD_LCOMP 0x00000004
1152 #define UCF_POSIX_PATHNAMES 0x00000008
1153 #define UCF_UNIX_NAME_LOOKUP 0x00000010
1158 struct smb_filename
{
1161 char *original_lcomp
;
1165 /* Used to keep track of deferred opens. */
1166 struct deferred_open_record
;
1168 /* Used inside aio code. */
1172 * Reasons for cache flush.
1175 enum flush_reason_enum
{
1180 OPLOCK_RELEASE_FLUSH
,
1184 /* NUM_FLUSH_REASONS must remain the last value in the enumeration. */