2 Unix SMB/Netbios implementation.
4 Copyright (C) Stefan Metzmacher 2009
5 Copyright (C) Jeremy Allison 2010
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef _SOURCE3_SMBD_GLOBALS_H_
22 #define _SOURCE3_SMBD_GLOBALS_H_
24 #include "system/select.h"
25 #include "librpc/gen_ndr/smbXsrv.h"
26 #include "smbprofile.h"
29 struct smbd_dmapi_context
;
30 extern struct smbd_dmapi_context
*dmapi_ctx
;
33 /* A singleton cache to speed up searching by dev/inode. */
34 struct fsp_singleton_cache
{
39 extern const struct mangle_fns
*mangle_fns
;
41 extern unsigned char *chartest
;
43 extern struct tdb_context
*tdb_mangled_cache
;
46 this determines how many characters are used from the original filename
47 in the 8.3 mangled name. A larger value leads to a weaker hash and more collisions.
48 The largest possible value is 6.
50 extern unsigned mangle_prefix
;
54 extern bool logged_ioctl_message
;
58 extern time_t last_smb_conf_reload_time
;
59 extern time_t last_printer_reload_time
;
60 extern pid_t background_lpq_updater_pid
;
62 /****************************************************************************
63 structure to hold a linked list of queued messages.
65 ****************************************************************************/
66 extern uint32_t common_flags2
;
68 extern struct smb_trans_enc_state
*partial_srv_trans_enc_ctx
;
69 extern struct smb_trans_enc_state
*srv_trans_enc_ctx
;
72 struct security_unix_token ut
;
73 struct security_token
*token
;
75 /* A stack of security contexts. We include the current context as being
76 the first one, so there is room for another MAX_SEC_CTX_DEPTH more. */
77 extern struct sec_ctx sec_ctx_stack
[MAX_SEC_CTX_DEPTH
+ 1];
78 extern int sec_ctx_stack_ndx
;
79 extern bool become_uid_done
;
80 extern bool become_gid_done
;
82 extern uint32_t global_client_caps
;
84 extern uint16_t fnf_handle
;
87 connection_struct
*conn
;
89 userdom_struct user_info
;
91 /* A stack of current_user connection contexts. */
92 extern struct conn_ctx conn_ctx_stack
[MAX_SEC_CTX_DEPTH
];
93 extern int conn_ctx_stack_ndx
;
95 struct vfs_init_function_entry
;
96 extern struct vfs_init_function_entry
*backends
;
97 extern char *sparse_buf
;
100 struct smbd_parent_context
;
101 extern struct smbd_parent_context
*am_parent
;
102 extern struct memcache
*smbd_memcache_ctx
;
103 extern bool exit_firsttime
;
105 struct tstream_context
;
106 struct smbd_smb2_request
;
108 DATA_BLOB
negprot_spnego(TALLOC_CTX
*ctx
, struct smbXsrv_connection
*xconn
);
110 void smbd_lock_socket(struct smbXsrv_connection
*xconn
);
111 void smbd_unlock_socket(struct smbXsrv_connection
*xconn
);
113 struct GUID
smbd_request_guid(struct smb_request
*smb1req
, uint16_t idx
);
115 NTSTATUS
smbd_do_unlocking(struct smb_request
*req
,
118 struct smbd_lock_element
*ulocks
);
120 NTSTATUS
smbd_do_qfilepathinfo(connection_struct
*conn
,
122 struct smb_request
*req
,
125 struct smb_filename
*smb_fname
,
127 struct timespec write_time_ts
,
128 struct ea_list
*ea_list
,
130 unsigned int max_data_bytes
,
131 size_t *fixed_portion
,
133 unsigned int *pdata_size
);
135 NTSTATUS
smbd_do_setfsinfo(connection_struct
*conn
,
136 struct smb_request
*req
,
140 const DATA_BLOB
*pdata
);
142 NTSTATUS
smbd_do_setfilepathinfo(connection_struct
*conn
,
143 struct smb_request
*req
,
147 struct smb_filename
*smb_fname
,
148 char **ppdata
, int total_data
,
151 NTSTATUS
smbd_do_qfsinfo(struct smbXsrv_connection
*xconn
,
152 connection_struct
*conn
,
156 unsigned int max_data_bytes
,
157 size_t *fixed_portion
,
158 struct smb_filename
*smb_fname
,
162 bool smbd_dirptr_get_entry(TALLOC_CTX
*ctx
,
163 struct dptr_struct
*dirptr
,
169 bool (*match_fn
)(TALLOC_CTX
*ctx
,
174 bool (*mode_fn
)(TALLOC_CTX
*ctx
,
176 struct files_struct
*dirfsp
,
177 struct smb_filename
*atname
,
178 struct smb_filename
*smb_fname
,
183 struct smb_filename
**_smb_fname
,
187 NTSTATUS
smbd_dirptr_lanman2_entry(TALLOC_CTX
*ctx
,
188 connection_struct
*conn
,
189 struct dptr_struct
*dirptr
,
191 const char *path_mask
,
194 int requires_resume_key
,
204 struct smb_filename
**smb_fname
,
205 bool *got_exact_match
,
206 int *_last_entry_off
,
207 struct ea_list
*name_list
,
208 struct file_id
*file_id
);
210 NTSTATUS
smbd_calculate_access_mask_fsp(struct files_struct
*dirsfp
,
211 struct files_struct
*fsp
,
213 uint32_t access_mask
,
214 uint32_t *access_mask_out
);
216 void smbd_notify_cancel_by_smbreq(const struct smb_request
*smbreq
);
218 void smbXsrv_connection_disconnect_transport(struct smbXsrv_connection
*xconn
,
220 size_t smbXsrv_client_valid_connections(struct smbXsrv_client
*client
);
221 void smbd_server_connection_terminate_ex(struct smbXsrv_connection
*xconn
,
223 const char *location
);
224 #define smbd_server_connection_terminate(xconn, reason) \
225 smbd_server_connection_terminate_ex(xconn, reason, __location__)
227 void smbd_server_disconnect_client_ex(struct smbXsrv_client
*client
,
229 const char *location
);
230 #define smbd_server_disconnect_client(__client, __reason) \
231 smbd_server_disconnect_client_ex(__client, __reason, __location__)
233 const char *smb2_opcode_name(uint16_t opcode
);
234 bool smbd_is_smb2_header(const uint8_t *inbuf
, size_t size
);
235 bool smbd_smb2_is_compound(const struct smbd_smb2_request
*req
);
236 bool smbd_smb2_is_last_in_compound(const struct smbd_smb2_request
*req
);
238 NTSTATUS
smbd_add_connection(struct smbXsrv_client
*client
, int sock_fd
,
239 NTTIME now
, struct smbXsrv_connection
**_xconn
);
241 NTSTATUS
reply_smb2002(struct smb_request
*req
, uint16_t choice
);
242 NTSTATUS
reply_smb20ff(struct smb_request
*req
, uint16_t choice
);
243 NTSTATUS
smbd_smb2_process_negprot(struct smbXsrv_connection
*xconn
,
244 uint64_t expected_seq_low
,
245 const uint8_t *inpdu
, size_t size
);
246 NTSTATUS
smb2_multi_protocol_reply_negprot(struct smb_request
*req
);
248 DATA_BLOB
smbd_smb2_generate_outbody(struct smbd_smb2_request
*req
, size_t size
);
250 bool smbXsrv_server_multi_channel_enabled(void);
252 NTSTATUS
smbd_smb2_request_error_ex(struct smbd_smb2_request
*req
,
254 uint8_t error_context_count
,
256 const char *location
);
257 #define smbd_smb2_request_error(req, status) \
258 smbd_smb2_request_error_ex(req, status, 0, NULL, __location__)
259 NTSTATUS
smbd_smb2_request_done_ex(struct smbd_smb2_request
*req
,
261 DATA_BLOB body
, DATA_BLOB
*dyn
,
262 const char *location
);
263 #define smbd_smb2_request_done(req, body, dyn) \
264 smbd_smb2_request_done_ex(req, NT_STATUS_OK, body, dyn, __location__)
266 NTSTATUS
smbd_smb2_send_oplock_break(struct smbXsrv_client
*client
,
267 struct smbXsrv_open
*op
,
268 uint8_t oplock_level
);
269 NTSTATUS
smbd_smb2_send_lease_break(struct smbXsrv_client
*client
,
271 uint32_t lease_flags
,
272 struct smb2_lease_key
*lease_key
,
273 uint32_t current_lease_state
,
274 uint32_t new_lease_state
);
276 NTSTATUS
smbd_smb2_request_pending_queue(struct smbd_smb2_request
*req
,
277 struct tevent_req
*subreq
,
278 uint32_t defer_time
);
280 struct smb_request
*smbd_smb2_fake_smb_request(struct smbd_smb2_request
*req
,
281 struct files_struct
*fsp
);
282 size_t smbd_smb2_unread_bytes(struct smbd_smb2_request
*req
);
283 void remove_smb2_chained_fsp(files_struct
*fsp
);
285 NTSTATUS
smbd_smb2_request_verify_creditcharge(struct smbd_smb2_request
*req
,
286 uint32_t data_length
);
288 NTSTATUS
smbd_smb2_request_verify_sizes(struct smbd_smb2_request
*req
,
289 size_t expected_body_size
);
291 void smb2_request_set_async_internal(struct smbd_smb2_request
*req
,
292 bool async_internal
);
294 enum protocol_types
smbd_smb2_protocol_dialect_match(const uint8_t *indyn
,
295 const int dialect_count
,
297 NTSTATUS
smbd_smb2_request_process_negprot(struct smbd_smb2_request
*req
);
298 NTSTATUS
smbd_smb2_request_process_sesssetup(struct smbd_smb2_request
*req
);
299 NTSTATUS
smbd_smb2_request_process_logoff(struct smbd_smb2_request
*req
);
300 NTSTATUS
smbd_smb2_request_process_tcon(struct smbd_smb2_request
*req
);
301 NTSTATUS
smbd_smb2_request_process_tdis(struct smbd_smb2_request
*req
);
302 NTSTATUS
smbd_smb2_request_process_create(struct smbd_smb2_request
*req
);
303 NTSTATUS
smbd_smb2_request_process_close(struct smbd_smb2_request
*req
);
304 NTSTATUS
smbd_smb2_request_process_flush(struct smbd_smb2_request
*req
);
305 NTSTATUS
smbd_smb2_request_process_read(struct smbd_smb2_request
*req
);
306 NTSTATUS
smb2_read_complete(struct tevent_req
*req
, ssize_t nread
, int err
);
307 NTSTATUS
smbd_smb2_request_process_write(struct smbd_smb2_request
*req
);
308 NTSTATUS
smb2_write_complete(struct tevent_req
*req
, ssize_t nwritten
, int err
);
309 NTSTATUS
smb2_write_complete_nosync(struct tevent_req
*req
, ssize_t nwritten
,
311 NTSTATUS
smbd_smb2_request_process_lock(struct smbd_smb2_request
*req
);
312 NTSTATUS
smbd_smb2_request_process_ioctl(struct smbd_smb2_request
*req
);
313 NTSTATUS
smbd_smb2_request_process_keepalive(struct smbd_smb2_request
*req
);
314 NTSTATUS
smbd_smb2_request_process_query_directory(struct smbd_smb2_request
*req
);
315 NTSTATUS
smbd_smb2_request_process_notify(struct smbd_smb2_request
*req
);
316 NTSTATUS
smbd_smb2_request_process_getinfo(struct smbd_smb2_request
*req
);
317 NTSTATUS
smbd_smb2_request_process_setinfo(struct smbd_smb2_request
*req
);
318 NTSTATUS
smbd_smb2_request_process_break(struct smbd_smb2_request
*req
);
319 NTSTATUS
smbd_smb2_request_dispatch(struct smbd_smb2_request
*req
);
320 void smbd_smb2_request_dispatch_immediate(struct tevent_context
*ctx
,
321 struct tevent_immediate
*im
,
324 struct deferred_open_record
;
326 /* SMB1 -> SMB2 glue. */
327 void send_break_message_smb2(files_struct
*fsp
,
330 /* From smbd/smb2_create.c */
331 int map_smb2_oplock_levels_to_samba(uint8_t in_oplock_level
);
332 bool get_deferred_open_message_state_smb2(struct smbd_smb2_request
*smb2req
,
333 struct timeval
*p_request_time
,
334 struct deferred_open_record
**open_rec
);
335 bool open_was_deferred_smb2(
336 struct smbXsrv_connection
*xconn
, uint64_t mid
);
337 void remove_deferred_open_message_smb2(
338 struct smbXsrv_connection
*xconn
, uint64_t mid
);
339 bool schedule_deferred_open_message_smb2(
340 struct smbXsrv_connection
*xconn
, uint64_t mid
);
341 bool push_deferred_open_message_smb2(struct smbd_smb2_request
*smb2req
,
342 struct timeval request_time
,
343 struct timeval timeout
,
345 struct deferred_open_record
*open_rec
);
347 struct smbXsrv_client
;
349 struct smbXsrv_preauth
{
350 uint8_t sha512_value
[64];
353 struct smbXsrv_connection
{
354 struct smbXsrv_connection
*prev
, *next
;
356 struct smbXsrv_client
*client
;
360 const struct tsocket_address
*local_address
;
361 const struct tsocket_address
*remote_address
;
362 const char *remote_hostname
;
363 bool has_cluster_movable_ip
;
365 enum protocol_types protocol
;
370 struct tevent_queue
*shutdown_wait_queue
;
372 struct tevent_fd
*fde
;
380 bool force_unacked_timeout
;
381 uint64_t unacked_bytes
;
383 struct tevent_req
*checker_subreq
;
384 struct smbd_smb2_send_queue
*queue
;
387 #if defined(WITH_SMB1SERVER)
391 * fd for the fcntl lock and process shared
392 * robust mutex to coordinate access to the
393 * client socket. When the system supports
394 * process shared robust mutexes, those are
395 * used. If not, then the fcntl lock will be
399 #ifdef HAVE_ROBUST_MUTEXES
400 pthread_mutex_t
*socket_mutex
;
404 * fd for the trusted pipe from
410 * fde for the trusted_fd
412 struct tevent_fd
*trusted_fde
;
415 * Reference count for the fcntl lock to
416 * allow recursive locks.
422 bool encrypted_passwords
;
424 struct auth4_context
*auth_context
;
427 * Size of the data we can receive. Set by us.
428 * Can be modified by the max xmit parameter.
436 * Size of data we can send to client. Set
437 * by the client for all protocols above CORE.
438 * Set by us for CORE protocol.
442 struct smb1_signing_state
*signing_state
;
445 uint16_t client_major
;
446 uint16_t client_minor
;
447 uint32_t client_cap_low
;
448 uint32_t client_cap_high
;
451 struct msg_state
*msg_state
;
455 struct smbd_smb2_request_read_state
{
456 struct smbd_smb2_request
*req
;
458 uint8_t nbt
[NBT_HDR_SIZE
];
462 bool doing_receivefile
;
463 size_t min_recv_size
;
467 } request_read_state
;
468 struct smbd_smb2_send_queue
*send_queue
;
469 size_t send_queue_len
;
473 * seq_low is the lowest sequence number
478 * seq_range is the range of credits we have
479 * granted from the sequence windows starting
482 * This gets incremented when new credits are
483 * granted and gets decremented when the
484 * lowest sequence number is consumed
485 * (when seq_low gets incremented).
489 * The number of credits we have currently granted
492 * This gets incremented when new credits are
493 * granted and gets decremented when any credit
496 * Note: the decrementing is different compared
501 * The maximum number of credits we will ever
502 * grant to the client.
504 * Typically we will only grant 1/16th of
507 * This is the "server max credits" parameter.
511 * a bitmap of size max_credits
513 struct bitmap
*bitmap
;
519 uint32_t capabilities
;
522 uint16_t security_mode
;
523 uint16_t num_dialects
;
527 uint32_t capabilities
;
529 uint16_t security_mode
;
536 bool posix_extensions_negotiated
;
539 struct smbXsrv_preauth preauth
;
541 struct smbd_smb2_request
*requests
;
544 uint8_t read_body_padding
;
547 bool signing_mandatory
;
551 const char *smbXsrv_connection_dbg(const struct smbXsrv_connection
*xconn
);
553 NTSTATUS
smbXsrv_version_global_init(const struct server_id
*server_id
);
554 uint32_t smbXsrv_version_global_current(void);
556 struct smbXsrv_client_table
;
557 NTSTATUS
smbXsrv_client_global_init(void);
558 NTSTATUS
smbXsrv_client_create(TALLOC_CTX
*mem_ctx
,
559 struct tevent_context
*ev_ctx
,
560 struct messaging_context
*msg_ctx
,
562 struct smbXsrv_client
**_client
);
563 NTSTATUS
smbXsrv_client_remove(struct smbXsrv_client
*client
);
564 struct tevent_req
*smb2srv_client_mc_negprot_send(TALLOC_CTX
*mem_ctx
,
565 struct tevent_context
*ev
,
566 struct smbd_smb2_request
*smb2req
);
567 NTSTATUS
smb2srv_client_mc_negprot_recv(struct tevent_req
*req
);
569 NTSTATUS
smbXsrv_connection_init_tables(struct smbXsrv_connection
*conn
,
570 enum protocol_types protocol
);
572 NTSTATUS
smbXsrv_session_global_init(struct messaging_context
*msg_ctx
);
573 NTSTATUS
smbXsrv_session_create(struct smbXsrv_connection
*conn
,
575 struct smbXsrv_session
**_session
);
576 NTSTATUS
smbXsrv_session_add_channel(struct smbXsrv_session
*session
,
577 struct smbXsrv_connection
*conn
,
579 struct smbXsrv_channel_global0
**_c
);
580 NTSTATUS
smbXsrv_session_remove_channel(struct smbXsrv_session
*session
,
581 struct smbXsrv_connection
*xconn
);
582 NTSTATUS
smbXsrv_session_disconnect_xconn(struct smbXsrv_connection
*xconn
);
583 NTSTATUS
smbXsrv_session_update(struct smbXsrv_session
*session
);
584 struct smbXsrv_channel_global0
;
585 NTSTATUS
smbXsrv_session_find_channel(const struct smbXsrv_session
*session
,
586 const struct smbXsrv_connection
*conn
,
587 struct smbXsrv_channel_global0
**_c
);
588 NTSTATUS
smbXsrv_session_find_auth(const struct smbXsrv_session
*session
,
589 const struct smbXsrv_connection
*conn
,
591 struct smbXsrv_session_auth0
**_a
);
592 NTSTATUS
smbXsrv_session_create_auth(struct smbXsrv_session
*session
,
593 struct smbXsrv_connection
*conn
,
596 uint8_t in_security_mode
,
597 struct smbXsrv_session_auth0
**_a
);
598 struct tevent_req
*smb2srv_session_shutdown_send(TALLOC_CTX
*mem_ctx
,
599 struct tevent_context
*ev
,
600 struct smbXsrv_session
*session
,
601 struct smbd_smb2_request
*current_req
);
602 NTSTATUS
smb2srv_session_shutdown_recv(struct tevent_req
*req
);
603 NTSTATUS
smbXsrv_session_logoff(struct smbXsrv_session
*session
);
604 NTSTATUS
smbXsrv_session_logoff_all(struct smbXsrv_client
*client
);
605 NTSTATUS
smb1srv_session_table_init(struct smbXsrv_connection
*conn
);
606 NTSTATUS
smb1srv_session_lookup(struct smbXsrv_connection
*conn
,
607 uint16_t vuid
, NTTIME now
,
608 struct smbXsrv_session
**session
);
609 NTSTATUS
smbXsrv_session_info_lookup(struct smbXsrv_client
*client
,
610 uint64_t session_wire_id
,
611 struct auth_session_info
**si
);
612 NTSTATUS
smb2srv_session_table_init(struct smbXsrv_connection
*conn
);
613 NTSTATUS
smb2srv_session_lookup_conn(struct smbXsrv_connection
*conn
,
614 uint64_t session_id
, NTTIME now
,
615 struct smbXsrv_session
**session
);
616 NTSTATUS
smb2srv_session_lookup_client(struct smbXsrv_client
*client
,
617 uint64_t session_id
, NTTIME now
,
618 struct smbXsrv_session
**session
);
619 NTSTATUS
smb2srv_session_lookup_global(struct smbXsrv_client
*client
,
620 uint64_t session_wire_id
,
622 struct smbXsrv_session
**session
);
623 NTSTATUS
get_valid_smbXsrv_session(struct smbXsrv_client
*client
,
624 uint64_t session_wire_id
,
625 struct smbXsrv_session
**session
);
626 NTSTATUS
smbXsrv_session_local_traverse(
627 struct smbXsrv_client
*client
,
628 int (*caller_cb
)(struct smbXsrv_session
*session
,
631 struct smbXsrv_session_global0
;
632 NTSTATUS
smbXsrv_session_global_traverse(
633 int (*fn
)(struct smbXsrv_session_global0
*, void *),
635 struct tevent_req
*smb2srv_session_close_previous_send(TALLOC_CTX
*mem_ctx
,
636 struct tevent_context
*ev
,
637 struct smbXsrv_connection
*conn
,
638 struct auth_session_info
*session_info
,
639 uint64_t previous_session_id
,
640 uint64_t current_session_id
);
641 NTSTATUS
smb2srv_session_close_previous_recv(struct tevent_req
*req
);
643 NTSTATUS
smbXsrv_tcon_global_init(void);
644 NTSTATUS
smbXsrv_tcon_update(struct smbXsrv_tcon
*tcon
);
645 NTSTATUS
smbXsrv_tcon_disconnect(struct smbXsrv_tcon
*tcon
, uint64_t vuid
);
646 NTSTATUS
smb1srv_tcon_table_init(struct smbXsrv_connection
*conn
);
647 NTSTATUS
smb1srv_tcon_create(struct smbXsrv_connection
*conn
,
649 struct smbXsrv_tcon
**_tcon
);
650 NTSTATUS
smb1srv_tcon_lookup(struct smbXsrv_connection
*conn
,
651 uint16_t tree_id
, NTTIME now
,
652 struct smbXsrv_tcon
**tcon
);
653 NTSTATUS
smb1srv_tcon_disconnect_all(struct smbXsrv_client
*client
);
654 NTSTATUS
smb2srv_tcon_table_init(struct smbXsrv_session
*session
);
655 NTSTATUS
smb2srv_tcon_create(struct smbXsrv_session
*session
,
657 struct smbXsrv_tcon
**_tcon
);
658 NTSTATUS
smb2srv_tcon_lookup(struct smbXsrv_session
*session
,
659 uint32_t tree_id
, NTTIME now
,
660 struct smbXsrv_tcon
**tcon
);
661 NTSTATUS
smb2srv_tcon_disconnect_all(struct smbXsrv_session
*session
);
662 struct smbXsrv_tcon_global0
;
663 NTSTATUS
smbXsrv_tcon_global_traverse(
664 int (*fn
)(struct smbXsrv_tcon_global0
*, void *),
668 bool smbXsrv_is_encrypted(uint8_t encryption_flags
);
669 bool smbXsrv_is_partially_encrypted(uint8_t encryption_flags
);
670 bool smbXsrv_set_crypto_flag(uint8_t *flags
, uint8_t flag
);
671 bool smbXsrv_is_signed(uint8_t signing_flags
);
672 bool smbXsrv_is_partially_signed(uint8_t signing_flags
);
674 struct smbd_smb2_send_queue
{
675 struct smbd_smb2_send_queue
*prev
, *next
;
677 DATA_BLOB
*sendfile_header
;
678 uint32_t sendfile_body_size
;
679 NTSTATUS
*sendfile_status
;
680 struct iovec
*vector
;
684 struct tevent_req
*req
;
685 struct timeval timeout
;
686 uint64_t required_acked_bytes
;
692 struct smbd_smb2_request
{
693 struct smbd_smb2_request
*prev
, *next
;
695 struct smbd_server_connection
*sconn
;
696 struct smbXsrv_connection
*xconn
;
698 struct smbd_smb2_send_queue queue_entry
;
700 /* the session the request operates on, maybe NULL */
701 struct smbXsrv_session
*session
;
702 uint64_t last_session_id
;
704 /* the tcon the request operates on, maybe NULL */
705 struct smbXsrv_tcon
*tcon
;
710 /* Was the request encrypted? */
712 /* Should we encrypt? */
714 struct tevent_timer
*async_te
;
715 bool compound_related
;
716 NTSTATUS compound_create_err
;
719 * Give the implementation of an SMB2 req a way to tell the SMB2 request
720 * processing engine that the internal request is going async, while
721 * preserving synchronous SMB2 behaviour.
726 * the encryption key for the whole
729 struct smb2_signing_key
*first_enc_key
;
731 * the signing key for the last
732 * request/response of a compound chain
734 struct smb2_signing_key
*last_sign_key
;
735 struct smbXsrv_preauth
*preauth
;
737 struct timeval request_time
;
739 SMBPROFILE_IOBYTES_ASYNC_STATE(profile
);
741 /* fake smb1 request. */
742 struct smb_request
*smb1req
;
743 struct files_struct
*compat_chain_fsp
;
746 * Keep track of whether the outstanding request counters
747 * had been updated in dispatch, so that they need to be
748 * adapted again in reply.
750 bool request_counters_updated
;
751 uint64_t channel_generation
;
754 * The sub request for async backend calls.
755 * This is used for SMB2 Cancel.
757 struct tevent_req
*subreq
;
759 #define SMBD_SMB2_TF_IOV_OFS 0
760 #define SMBD_SMB2_HDR_IOV_OFS 1
761 #define SMBD_SMB2_BODY_IOV_OFS 2
762 #define SMBD_SMB2_DYN_IOV_OFS 3
764 #define SMBD_SMB2_NUM_IOV_PER_REQ 4
766 #define SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,ofs) \
767 (&req->dir.vector[(idx)+(ofs)])
769 #define SMBD_SMB2_IDX_TF_IOV(req,dir,idx) \
770 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_TF_IOV_OFS)
771 #define SMBD_SMB2_IDX_HDR_IOV(req,dir,idx) \
772 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_HDR_IOV_OFS)
773 #define SMBD_SMB2_IDX_BODY_IOV(req,dir,idx) \
774 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_BODY_IOV_OFS)
775 #define SMBD_SMB2_IDX_DYN_IOV(req,dir,idx) \
776 SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_DYN_IOV_OFS)
778 #define SMBD_SMB2_IN_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,in,req->current_idx)
779 #define SMBD_SMB2_IN_TF_PTR(req) (uint8_t *)(SMBD_SMB2_IN_TF_IOV(req)->iov_base)
780 #define SMBD_SMB2_IN_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,in,req->current_idx)
781 #define SMBD_SMB2_IN_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_IN_HDR_IOV(req)->iov_base)
782 #define SMBD_SMB2_IN_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,in,req->current_idx)
783 #define SMBD_SMB2_IN_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_IN_BODY_IOV(req)->iov_base)
784 #define SMBD_SMB2_IN_BODY_LEN(req) (SMBD_SMB2_IN_BODY_IOV(req)->iov_len)
785 #define SMBD_SMB2_IN_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,in,req->current_idx)
786 #define SMBD_SMB2_IN_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_IN_DYN_IOV(req)->iov_base)
787 #define SMBD_SMB2_IN_DYN_LEN(req) (SMBD_SMB2_IN_DYN_IOV(req)->iov_len)
789 #define SMBD_SMB2_OUT_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,out,req->current_idx)
790 #define SMBD_SMB2_OUT_TF_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_TF_IOV(req)->iov_base)
791 #define SMBD_SMB2_OUT_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,out,req->current_idx)
792 #define SMBD_SMB2_OUT_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_HDR_IOV(req)->iov_base)
793 #define SMBD_SMB2_OUT_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,out,req->current_idx)
794 #define SMBD_SMB2_OUT_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_BODY_IOV(req)->iov_base)
795 #define SMBD_SMB2_OUT_BODY_LEN(req) (SMBD_SMB2_OUT_BODY_IOV(req)->iov_len)
796 #define SMBD_SMB2_OUT_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,out,req->current_idx)
797 #define SMBD_SMB2_OUT_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_DYN_IOV(req)->iov_base)
798 #define SMBD_SMB2_OUT_DYN_LEN(req) (SMBD_SMB2_OUT_DYN_IOV(req)->iov_len)
800 #define SMBD_SMB2_SHORT_RECEIVEFILE_WRITE_LEN (SMB2_HDR_BODY + 0x30)
804 * vector[0] TRANSPORT HEADER (empty)
806 * vector[1] SMB2_TRANSFORM (optional)
808 * vector[3] fixed body
809 * vector[4] dynamic body
813 * vector[5] SMB2_TRANSFORM (optional)
815 * vector[7] fixed body
816 * vector[8] dynamic body
821 struct iovec
*vector
;
823 struct iovec _vector
[1 + SMBD_SMB2_NUM_IOV_PER_REQ
];
826 /* the NBT header is not allocated */
829 * vector[0] TRANSPORT HEADER
831 * vector[1] SMB2_TRANSFORM (optional)
833 * vector[3] fixed body
834 * vector[4] dynamic body
838 * vector[5] SMB2_TRANSFORM (empty)
840 * vector[7] fixed body
841 * vector[8] dynamic body
846 struct iovec
*vector
;
848 struct iovec _vector
[1 + SMBD_SMB2_NUM_IOV_PER_REQ
];
849 #define OUTVEC_ALLOC_SIZE (SMB2_HDR_BODY + 9)
850 uint8_t _hdr
[OUTVEC_ALLOC_SIZE
];
855 struct smbd_server_connection
;
857 struct pending_message_list
;
858 struct pending_auth_data
;
860 struct pthreadpool_tevent
;
861 struct dcesrv_context
;
863 struct smbd_server_connection
{
864 const struct tsocket_address
*local_address
;
865 const struct tsocket_address
*remote_address
;
866 const char *remote_hostname
;
867 struct tevent_context
*ev_ctx
;
868 struct messaging_context
*msg_ctx
;
869 struct dcesrv_context
*dce_ctx
;
870 struct notify_context
*notify_ctx
;
876 size_t num_connections
;
877 struct connection_struct
*connections
;
880 struct files_struct
*files
;
882 int real_max_open_files
;
883 struct fsp_singleton_cache fsp_fi_cache
;
885 struct pending_message_list
*deferred_open_queue
;
888 /* open directory handles. */
890 struct bitmap
*dptr_bmap
;
891 struct dptr_struct
*dirptrs
;
894 uint64_t num_requests
;
896 /* Current number of oplocks we have outstanding. */
898 int32_t exclusive_open
;
899 int32_t level_II_open
;
900 struct kernel_oplocks
*kernel_ops
;
903 struct notify_mid_map
*notify_mid_maps
;
905 struct pthreadpool_tevent
*pool
;
907 struct smbXsrv_client
*client
;
910 extern struct smbXsrv_client
*global_smbXsrv_client
;
912 void smbd_init_globals(void);
914 /****************************************************************************
915 The buffer we keep around whilst an aio request is in process.
916 *****************************************************************************/
920 struct smb_request
*smbreq
;
922 struct lock_struct lock
;
928 #endif /* _SOURCE3_SMBD_GLOBALS_H_ */