2009-01-08 14:03:45 +03:00
/*
Unix SMB / Netbios implementation .
smbd globals
Copyright ( C ) Stefan Metzmacher 2009
2010-04-29 01:56:12 +04:00
Copyright ( C ) Jeremy Allison 2010
2009-01-08 14:03:45 +03:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2019-09-12 20:05:57 +03:00
# ifndef _SOURCE3_SMBD_GLOBALS_H_
# define _SOURCE3_SMBD_GLOBALS_H_
2011-02-03 23:55:02 +03:00
# include "system/select.h"
2011-12-15 17:45:56 +04:00
# include "librpc/gen_ndr/smbXsrv.h"
2014-10-31 13:15:50 +03:00
# include "smbprofile.h"
2011-02-03 23:55:02 +03:00
2009-01-08 14:03:45 +03:00
# ifdef USE_DMAPI
struct smbd_dmapi_context ;
extern struct smbd_dmapi_context * dmapi_ctx ;
# endif
/* A singleton cache to speed up searching by dev/inode. */
struct fsp_singleton_cache {
files_struct * fsp ;
struct file_id id ;
} ;
extern const struct mangle_fns * mangle_fns ;
extern unsigned char * chartest ;
2011-05-05 13:25:29 +04:00
struct tdb_context ;
extern struct tdb_context * tdb_mangled_cache ;
2009-01-08 14:03:45 +03:00
/*
this determines how many characters are used from the original filename
in the 8.3 mangled name . A larger value leads to a weaker hash and more collisions .
The largest possible value is 6.
*/
extern unsigned mangle_prefix ;
struct msg_state ;
extern bool logged_ioctl_message ;
extern int trans_num ;
extern time_t last_smb_conf_reload_time ;
extern time_t last_printer_reload_time ;
2011-08-04 01:04:50 +04:00
extern pid_t background_lpq_updater_pid ;
2009-01-08 14:03:45 +03:00
/****************************************************************************
structure to hold a linked list of queued messages .
for processing .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
extern uint32_t common_flags2 ;
2011-10-19 09:33:04 +04:00
extern struct smb_trans_enc_state * partial_srv_trans_enc_ctx ;
extern struct smb_trans_enc_state * srv_trans_enc_ctx ;
2009-01-08 14:03:45 +03:00
struct sec_ctx {
2011-02-11 10:49:15 +03:00
struct security_unix_token ut ;
2010-08-26 16:08:22 +04:00
struct security_token * token ;
2009-01-08 14:03:45 +03:00
} ;
/* A stack of security contexts. We include the current context as being
the first one , so there is room for another MAX_SEC_CTX_DEPTH more . */
extern struct sec_ctx sec_ctx_stack [ MAX_SEC_CTX_DEPTH + 1 ] ;
extern int sec_ctx_stack_ndx ;
extern bool become_uid_done ;
extern bool become_gid_done ;
extern uint32_t global_client_caps ;
extern uint16_t fnf_handle ;
struct conn_ctx {
connection_struct * conn ;
2012-06-05 17:27:38 +04:00
uint64_t vuid ;
2018-05-25 15:22:43 +03:00
userdom_struct user_info ;
2009-01-08 14:03:45 +03:00
} ;
/* A stack of current_user connection contexts. */
extern struct conn_ctx conn_ctx_stack [ MAX_SEC_CTX_DEPTH ] ;
extern int conn_ctx_stack_ndx ;
struct vfs_init_function_entry ;
extern struct vfs_init_function_entry * backends ;
extern char * sparse_buf ;
2012-09-13 21:13:21 +04:00
extern char * LastDir ;
2009-01-08 14:03:45 +03:00
2011-12-13 17:58:50 +04:00
struct smbd_parent_context ;
extern struct smbd_parent_context * am_parent ;
2009-01-08 14:03:45 +03:00
extern struct memcache * smbd_memcache_ctx ;
extern bool exit_firsttime ;
2009-05-14 16:17:28 +04:00
struct tstream_context ;
struct smbd_smb2_request ;
2014-06-11 14:41:26 +04:00
DATA_BLOB negprot_spnego ( TALLOC_CTX * ctx , struct smbXsrv_connection * xconn ) ;
2009-05-19 12:46:35 +04:00
2014-06-12 10:43:26 +04:00
void smbd_lock_socket ( struct smbXsrv_connection * xconn ) ;
void smbd_unlock_socket ( struct smbXsrv_connection * xconn ) ;
2010-03-18 11:17:43 +03:00
2019-08-08 20:26:28 +03:00
struct GUID smbd_request_guid ( struct smb_request * smb1req , uint16_t idx ) ;
2014-07-03 14:06:56 +04:00
NTSTATUS smbd_do_unlocking ( struct smb_request * req ,
files_struct * fsp ,
uint16_t num_ulocks ,
2021-11-17 04:04:02 +03:00
struct smbd_lock_element * ulocks ) ;
2009-07-07 20:09:16 +04:00
2009-07-10 22:02:44 +04:00
NTSTATUS smbd_do_qfilepathinfo ( connection_struct * conn ,
TALLOC_CTX * mem_ctx ,
2019-06-18 23:11:51 +03:00
struct smb_request * req ,
2009-07-10 22:02:44 +04:00
uint16_t info_level ,
files_struct * fsp ,
2009-08-13 02:08:23 +04:00
struct smb_filename * smb_fname ,
2009-07-10 22:02:44 +04:00
bool delete_pending ,
struct timespec write_time_ts ,
struct ea_list * ea_list ,
uint16_t flags2 ,
unsigned int max_data_bytes ,
2013-08-27 13:06:27 +04:00
size_t * fixed_portion ,
2009-07-10 22:02:44 +04:00
char * * ppdata ,
unsigned int * pdata_size ) ;
2016-04-14 15:39:05 +03:00
NTSTATUS smbd_do_setfsinfo ( connection_struct * conn ,
struct smb_request * req ,
TALLOC_CTX * mem_ctx ,
uint16_t info_level ,
files_struct * fsp ,
const DATA_BLOB * pdata ) ;
2009-07-13 11:01:56 +04:00
NTSTATUS smbd_do_setfilepathinfo ( connection_struct * conn ,
struct smb_request * req ,
TALLOC_CTX * mem_ctx ,
uint16_t info_level ,
files_struct * fsp ,
struct smb_filename * smb_fname ,
char * * ppdata , int total_data ,
int * ret_data_size ) ;
2014-06-11 15:36:34 +04:00
NTSTATUS smbd_do_qfsinfo ( struct smbXsrv_connection * xconn ,
connection_struct * conn ,
2009-07-13 14:05:34 +04:00
TALLOC_CTX * mem_ctx ,
uint16_t info_level ,
uint16_t flags2 ,
unsigned int max_data_bytes ,
2013-08-27 13:06:27 +04:00
size_t * fixed_portion ,
2023-11-13 09:43:11 +03:00
struct files_struct * fsp ,
2013-02-06 17:35:25 +04:00
struct smb_filename * smb_fname ,
2009-07-13 14:05:34 +04:00
char * * ppdata ,
int * ret_data_len ) ;
2014-08-27 01:49:37 +04:00
NTSTATUS smbd_dirptr_lanman2_entry ( TALLOC_CTX * ctx ,
2009-08-14 15:23:19 +04:00
connection_struct * conn ,
struct dptr_struct * dirptr ,
2015-05-03 07:01:14 +03:00
uint16_t flags2 ,
2009-08-14 15:23:19 +04:00
const char * path_mask ,
2015-05-03 07:01:14 +03:00
uint32_t dirtype ,
2009-08-14 15:23:19 +04:00
int info_level ,
int requires_resume_key ,
bool dont_descend ,
bool ask_sharemode ,
2018-03-15 17:50:41 +03:00
bool get_dosmode ,
2009-08-14 15:23:19 +04:00
uint8_t align ,
bool do_pad ,
char * * ppdata ,
char * base_data ,
char * end_data ,
int space_remaining ,
2018-03-15 21:03:59 +03:00
struct smb_filename * * smb_fname ,
2009-08-14 15:23:19 +04:00
int * _last_entry_off ,
2016-12-22 16:53:17 +03:00
struct ea_list * name_list ,
struct file_id * file_id ) ;
2009-08-14 15:23:19 +04:00
2021-06-08 21:56:25 +03:00
NTSTATUS smbd_calculate_access_mask_fsp ( struct files_struct * dirsfp ,
struct files_struct * fsp ,
2021-06-08 03:02:06 +03:00
bool use_privs ,
uint32_t access_mask ,
uint32_t * access_mask_out ) ;
2010-06-12 15:08:31 +04:00
void smbd_notify_cancel_by_smbreq ( const struct smb_request * smbreq ) ;
2009-08-15 12:07:00 +04:00
2019-10-04 15:26:20 +03:00
void smbXsrv_connection_disconnect_transport ( struct smbXsrv_connection * xconn ,
NTSTATUS status ) ;
2020-06-17 00:58:54 +03:00
size_t smbXsrv_client_valid_connections ( struct smbXsrv_client * client ) ;
2014-06-11 14:15:48 +04:00
void smbd_server_connection_terminate_ex ( struct smbXsrv_connection * xconn ,
2009-06-02 18:07:08 +04:00
const char * reason ,
const char * location ) ;
2014-06-11 14:15:48 +04:00
# define smbd_server_connection_terminate(xconn, reason) \
smbd_server_connection_terminate_ex ( xconn , reason , __location__ )
2009-06-02 18:07:08 +04:00
2020-06-02 17:43:43 +03:00
void smbd_server_disconnect_client_ex ( struct smbXsrv_client * client ,
const char * reason ,
const char * location ) ;
# define smbd_server_disconnect_client(__client, __reason) \
smbd_server_disconnect_client_ex ( __client , __reason , __location__ )
2010-07-04 20:02:19 +04:00
const char * smb2_opcode_name ( uint16_t opcode ) ;
2009-05-14 16:17:28 +04:00
bool smbd_is_smb2_header ( const uint8_t * inbuf , size_t size ) ;
2017-09-22 03:41:25 +03:00
bool smbd_smb2_is_compound ( const struct smbd_smb2_request * req ) ;
2022-10-21 01:08:14 +03:00
bool smbd_smb2_is_last_in_compound ( const struct smbd_smb2_request * req ) ;
2009-05-14 16:17:28 +04:00
2014-06-20 02:31:31 +04:00
NTSTATUS smbd_add_connection ( struct smbXsrv_client * client , int sock_fd ,
2019-10-04 11:02:56 +03:00
NTTIME now , struct smbXsrv_connection * * _xconn ) ;
2014-06-20 02:31:31 +04:00
2019-11-26 23:43:25 +03:00
NTSTATUS reply_smb2002 ( struct smb_request * req , uint16_t choice ) ;
NTSTATUS reply_smb20ff ( struct smb_request * req , uint16_t choice ) ;
2019-11-26 23:14:29 +03:00
NTSTATUS smbd_smb2_process_negprot ( struct smbXsrv_connection * xconn ,
2015-09-27 03:01:47 +03:00
uint64_t expected_seq_low ,
const uint8_t * inpdu , size_t size ) ;
2022-03-30 11:57:21 +03:00
NTSTATUS smb2_multi_protocol_reply_negprot ( struct smb_request * req ) ;
2009-05-14 16:17:28 +04:00
2013-12-04 15:52:21 +04:00
DATA_BLOB smbd_smb2_generate_outbody ( struct smbd_smb2_request * req , size_t size ) ;
2020-06-08 13:23:47 +03:00
bool smbXsrv_server_multi_channel_enabled ( void ) ;
2009-06-05 13:05:03 +04:00
NTSTATUS smbd_smb2_request_error_ex ( struct smbd_smb2_request * req ,
NTSTATUS status ,
2022-10-14 17:23:30 +03:00
uint8_t error_context_count ,
2009-06-05 13:05:03 +04:00
DATA_BLOB * info ,
const char * location ) ;
# define smbd_smb2_request_error(req, status) \
2022-10-14 17:23:30 +03:00
smbd_smb2_request_error_ex ( req , status , 0 , NULL , __location__ )
2009-05-20 21:35:39 +04:00
NTSTATUS smbd_smb2_request_done_ex ( struct smbd_smb2_request * req ,
NTSTATUS status ,
2009-06-05 13:05:03 +04:00
DATA_BLOB body , DATA_BLOB * dyn ,
const char * location ) ;
# define smbd_smb2_request_done(req, body, dyn) \
smbd_smb2_request_done_ex ( req , NT_STATUS_OK , body , dyn , __location__ )
2009-05-14 16:17:28 +04:00
2020-06-02 17:50:22 +03:00
NTSTATUS smbd_smb2_send_oplock_break ( struct smbXsrv_client * client ,
2012-08-22 12:33:07 +04:00
struct smbXsrv_open * op ,
2009-06-09 22:44:13 +04:00
uint8_t oplock_level ) ;
2020-06-02 17:50:22 +03:00
NTSTATUS smbd_smb2_send_lease_break ( struct smbXsrv_client * client ,
2014-10-29 01:31:46 +03:00
uint16_t new_epoch ,
uint32_t lease_flags ,
struct smb2_lease_key * lease_key ,
uint32_t current_lease_state ,
uint32_t new_lease_state ) ;
2009-06-09 22:44:13 +04:00
2009-08-15 12:01:38 +04:00
NTSTATUS smbd_smb2_request_pending_queue ( struct smbd_smb2_request * req ,
2011-11-14 18:42:55 +04:00
struct tevent_req * subreq ,
uint32_t defer_time ) ;
2009-06-10 00:33:32 +04:00
2023-03-28 23:53:20 +03:00
struct smb_request * smbd_smb2_fake_smb_request ( struct smbd_smb2_request * req ,
struct files_struct * fsp ) ;
2013-03-19 23:24:17 +04:00
size_t smbd_smb2_unread_bytes ( struct smbd_smb2_request * req ) ;
2010-06-09 08:20:07 +04:00
void remove_smb2_chained_fsp ( files_struct * fsp ) ;
2009-06-02 13:54:00 +04:00
2012-02-28 05:49:12 +04:00
NTSTATUS smbd_smb2_request_verify_creditcharge ( struct smbd_smb2_request * req ,
uint32_t data_length ) ;
2011-09-06 16:00:04 +04:00
NTSTATUS smbd_smb2_request_verify_sizes ( struct smbd_smb2_request * req ,
size_t expected_body_size ) ;
2017-01-11 17:00:24 +03:00
void smb2_request_set_async_internal ( struct smbd_smb2_request * req ,
bool async_internal ) ;
2014-06-21 08:29:26 +04:00
enum protocol_types smbd_smb2_protocol_dialect_match ( const uint8_t * indyn ,
const int dialect_count ,
uint16_t * dialect ) ;
2009-05-14 17:32:02 +04:00
NTSTATUS smbd_smb2_request_process_negprot ( struct smbd_smb2_request * req ) ;
2009-05-15 13:20:34 +04:00
NTSTATUS smbd_smb2_request_process_sesssetup ( struct smbd_smb2_request * req ) ;
2009-05-15 13:40:19 +04:00
NTSTATUS smbd_smb2_request_process_logoff ( struct smbd_smb2_request * req ) ;
2009-05-15 13:50:20 +04:00
NTSTATUS smbd_smb2_request_process_tcon ( struct smbd_smb2_request * req ) ;
2009-05-22 14:42:24 +04:00
NTSTATUS smbd_smb2_request_process_tdis ( struct smbd_smb2_request * req ) ;
2009-05-28 02:07:26 +04:00
NTSTATUS smbd_smb2_request_process_create ( struct smbd_smb2_request * req ) ;
2009-06-02 15:42:28 +04:00
NTSTATUS smbd_smb2_request_process_close ( struct smbd_smb2_request * req ) ;
2009-06-02 14:06:34 +04:00
NTSTATUS smbd_smb2_request_process_flush ( struct smbd_smb2_request * req ) ;
2009-06-02 14:38:37 +04:00
NTSTATUS smbd_smb2_request_process_read ( struct smbd_smb2_request * req ) ;
2010-06-11 00:20:37 +04:00
NTSTATUS smb2_read_complete ( struct tevent_req * req , ssize_t nread , int err ) ;
2009-05-28 03:28:34 +04:00
NTSTATUS smbd_smb2_request_process_write ( struct smbd_smb2_request * req ) ;
2010-06-11 00:20:37 +04:00
NTSTATUS smb2_write_complete ( struct tevent_req * req , ssize_t nwritten , int err ) ;
2012-07-13 15:39:52 +04:00
NTSTATUS smb2_write_complete_nosync ( struct tevent_req * req , ssize_t nwritten ,
int err ) ;
2009-07-02 21:26:05 +04:00
NTSTATUS smbd_smb2_request_process_lock ( struct smbd_smb2_request * req ) ;
2009-06-05 19:32:58 +04:00
NTSTATUS smbd_smb2_request_process_ioctl ( struct smbd_smb2_request * req ) ;
2009-05-15 14:07:28 +04:00
NTSTATUS smbd_smb2_request_process_keepalive ( struct smbd_smb2_request * req ) ;
2015-03-24 17:16:26 +03:00
NTSTATUS smbd_smb2_request_process_query_directory ( struct smbd_smb2_request * req ) ;
2009-06-30 00:31:13 +04:00
NTSTATUS smbd_smb2_request_process_notify ( struct smbd_smb2_request * req ) ;
2009-07-02 12:17:30 +04:00
NTSTATUS smbd_smb2_request_process_getinfo ( struct smbd_smb2_request * req ) ;
2009-07-02 13:40:07 +04:00
NTSTATUS smbd_smb2_request_process_setinfo ( struct smbd_smb2_request * req ) ;
2009-07-02 13:56:23 +04:00
NTSTATUS smbd_smb2_request_process_break ( struct smbd_smb2_request * req ) ;
2010-04-23 10:52:19 +04:00
NTSTATUS smbd_smb2_request_dispatch ( struct smbd_smb2_request * req ) ;
void smbd_smb2_request_dispatch_immediate ( struct tevent_context * ctx ,
struct tevent_immediate * im ,
void * private_data ) ;
2009-05-14 17:32:02 +04:00
2014-06-20 18:12:14 +04:00
struct deferred_open_record ;
2010-04-10 06:26:34 +04:00
/* SMB1 -> SMB2 glue. */
2014-10-29 01:31:46 +03:00
void send_break_message_smb2 ( files_struct * fsp ,
uint32_t break_from ,
uint32_t break_to ) ;
2010-04-23 10:52:19 +04:00
/* From smbd/smb2_create.c */
2010-04-24 11:29:41 +04:00
int map_smb2_oplock_levels_to_samba ( uint8_t in_oplock_level ) ;
2010-04-23 10:52:19 +04:00
bool get_deferred_open_message_state_smb2 ( struct smbd_smb2_request * smb2req ,
2010-04-10 06:26:34 +04:00
struct timeval * p_request_time ,
2014-06-20 18:12:14 +04:00
struct deferred_open_record * * open_rec ) ;
2014-09-16 09:49:44 +04:00
bool open_was_deferred_smb2 (
struct smbXsrv_connection * xconn , uint64_t mid ) ;
2010-06-12 16:48:42 +04:00
void remove_deferred_open_message_smb2 (
2014-09-16 09:49:44 +04:00
struct smbXsrv_connection * xconn , uint64_t mid ) ;
2012-06-30 00:53:31 +04:00
bool schedule_deferred_open_message_smb2 (
2014-09-16 09:49:44 +04:00
struct smbXsrv_connection * xconn , uint64_t mid ) ;
2010-04-23 10:52:19 +04:00
bool push_deferred_open_message_smb2 ( struct smbd_smb2_request * smb2req ,
2014-06-20 18:12:14 +04:00
struct timeval request_time ,
struct timeval timeout ,
struct file_id id ,
struct deferred_open_record * open_rec ) ;
2010-04-08 06:00:44 +04:00
2014-05-20 21:47:13 +04:00
struct smbXsrv_client ;
2014-10-08 21:25:15 +04:00
struct smbXsrv_preauth {
uint8_t sha512_value [ 64 ] ;
} ;
2011-12-15 17:45:56 +04:00
struct smbXsrv_connection {
2014-05-20 21:47:13 +04:00
struct smbXsrv_connection * prev , * next ;
struct smbXsrv_client * client ;
2019-10-04 11:02:56 +03:00
NTTIME connect_time ;
uint64_t channel_id ;
2011-12-15 17:45:56 +04:00
const struct tsocket_address * local_address ;
const struct tsocket_address * remote_address ;
const char * remote_hostname ;
2020-09-06 23:59:20 +03:00
bool has_cluster_movable_ip ;
2011-12-15 17:45:56 +04:00
enum protocol_types protocol ;
2014-05-20 21:59:12 +04:00
struct {
2014-05-23 11:07:47 +04:00
NTSTATUS status ;
2020-09-23 14:07:20 +03:00
bool terminating ;
2021-02-24 19:44:12 +03:00
struct tevent_queue * shutdown_wait_queue ;
2014-05-22 01:23:34 +04:00
int sock ;
2014-05-23 10:45:01 +04:00
struct tevent_fd * fde ;
2014-05-22 01:23:34 +04:00
2014-05-20 21:59:12 +04:00
struct {
bool got_session ;
} nbt ;
} transport ;
2020-06-03 11:57:59 +03:00
struct {
2020-06-08 17:33:45 +03:00
bool force_unacked_timeout ;
2020-06-03 11:57:59 +03:00
uint64_t unacked_bytes ;
uint32_t rto_usecs ;
struct tevent_req * checker_subreq ;
struct smbd_smb2_send_queue * queue ;
} ack ;
2022-03-11 00:22:39 +03:00
# if defined(WITH_SMB1SERVER)
2014-05-21 12:27:50 +04:00
struct {
2014-05-23 11:26:26 +04:00
struct {
/*
* fd for the fcntl lock and process shared
* robust mutex to coordinate access to the
* client socket . When the system supports
* process shared robust mutexes , those are
* used . If not , then the fcntl lock will be
* used .
*/
int socket_lock_fd ;
# ifdef HAVE_ROBUST_MUTEXES
pthread_mutex_t * socket_mutex ;
# endif
/*
* fd for the trusted pipe from
* echo handler child
*/
int trusted_fd ;
/*
* fde for the trusted_fd
*/
struct tevent_fd * trusted_fde ;
/*
* Reference count for the fcntl lock to
* allow recursive locks .
*/
int ref_count ;
} echo_handler ;
2014-05-21 12:27:50 +04:00
struct {
bool encrypted_passwords ;
bool spnego ;
struct auth4_context * auth_context ;
bool done ;
/*
* Size of the data we can receive . Set by us .
* Can be modified by the max xmit parameter .
*/
int max_recv ;
} negprot ;
2014-05-21 12:56:26 +04:00
struct {
bool done_sesssetup ;
/*
* Size of data we can send to client . Set
* by the client for all protocols above CORE .
* Set by us for CORE protocol .
*/
int max_send ;
} sessions ;
2022-03-08 05:05:41 +03:00
struct smb1_signing_state * signing_state ;
2014-06-10 14:57:38 +04:00
struct {
uint16_t client_major ;
uint16_t client_minor ;
uint32_t client_cap_low ;
uint32_t client_cap_high ;
} unix_info ;
2014-06-11 14:36:14 +04:00
struct msg_state * msg_state ;
2014-05-21 12:27:50 +04:00
} smb1 ;
2022-03-11 00:22:39 +03:00
# endif
2011-12-15 17:45:56 +04:00
struct {
2014-05-23 11:41:57 +04:00
struct smbd_smb2_request_read_state {
struct smbd_smb2_request * req ;
struct {
uint8_t nbt [ NBT_HDR_SIZE ] ;
} hdr ;
2021-04-15 22:56:59 +03:00
struct iovec _vector [ 1 ] ;
struct iovec * vector ;
int count ;
2021-04-15 10:53:03 +03:00
struct msghdr msg ;
2014-05-23 11:41:57 +04:00
bool doing_receivefile ;
size_t min_recv_size ;
size_t pktfull ;
size_t pktlen ;
uint8_t * pktbuf ;
} request_read_state ;
2014-05-23 11:53:21 +04:00
struct smbd_smb2_send_queue * send_queue ;
size_t send_queue_len ;
2014-05-23 11:41:57 +04:00
2014-05-23 14:10:23 +04:00
struct {
/*
* seq_low is the lowest sequence number
* we will accept .
*/
uint64_t seq_low ;
/*
* seq_range is the range of credits we have
* granted from the sequence windows starting
* at seq_low .
*
* This gets incremented when new credits are
* granted and gets decremented when the
* lowest sequence number is consumed
* ( when seq_low gets incremented ) .
*/
uint16_t seq_range ;
/*
* The number of credits we have currently granted
* to the client .
*
* This gets incremented when new credits are
* granted and gets decremented when any credit
2023-07-18 12:30:18 +03:00
* is consumed .
2014-05-23 14:10:23 +04:00
*
* Note : the decrementing is different compared
* to seq_range .
*/
uint16_t granted ;
/*
* The maximum number of credits we will ever
* grant to the client .
*
* Typically we will only grant 1 / 16 th of
* max_credits .
*
* This is the " server max credits " parameter .
*/
uint16_t max ;
/*
* a bitmap of size max_credits
*/
struct bitmap * bitmap ;
bool multicredit ;
} credits ;
2014-05-23 12:07:21 +04:00
bool allow_2ff ;
2011-12-15 17:45:56 +04:00
struct {
uint32_t capabilities ;
struct GUID guid ;
2016-01-26 00:50:28 +03:00
bool guid_verified ;
2011-12-15 17:45:56 +04:00
uint16_t security_mode ;
uint16_t num_dialects ;
uint16_t * dialects ;
} client ;
struct {
uint32_t capabilities ;
struct GUID guid ;
uint16_t security_mode ;
uint16_t dialect ;
uint32_t max_trans ;
uint32_t max_read ;
uint32_t max_write ;
2020-11-11 15:18:24 +03:00
uint16_t sign_algo ;
2014-10-13 13:07:01 +04:00
uint16_t cipher ;
2022-01-27 21:55:18 +03:00
bool posix_extensions_negotiated ;
2011-12-15 17:45:56 +04:00
} server ;
2014-06-10 15:24:50 +04:00
2014-10-08 21:25:15 +04:00
struct smbXsrv_preauth preauth ;
2014-06-10 15:24:50 +04:00
struct smbd_smb2_request * requests ;
2021-07-05 18:49:00 +03:00
struct {
uint8_t read_body_padding ;
} smbtorture ;
2022-03-08 05:09:40 +03:00
bool signing_mandatory ;
2011-12-15 17:45:56 +04:00
} smb2 ;
} ;
2014-07-21 20:58:52 +04:00
const char * smbXsrv_connection_dbg ( const struct smbXsrv_connection * xconn ) ;
2012-05-08 18:01:21 +04:00
NTSTATUS smbXsrv_version_global_init ( const struct server_id * server_id ) ;
uint32_t smbXsrv_version_global_current ( void ) ;
2016-01-26 03:10:25 +03:00
struct smbXsrv_client_table ;
NTSTATUS smbXsrv_client_global_init ( void ) ;
NTSTATUS smbXsrv_client_create ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx ,
NTTIME now ,
struct smbXsrv_client * * _client ) ;
NTSTATUS smbXsrv_client_remove ( struct smbXsrv_client * client ) ;
2020-07-06 18:27:05 +03:00
struct tevent_req * smb2srv_client_mc_negprot_send ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
struct smbd_smb2_request * smb2req ) ;
NTSTATUS smb2srv_client_mc_negprot_recv ( struct tevent_req * req ) ;
2016-01-26 03:10:25 +03:00
2011-12-15 17:45:56 +04:00
NTSTATUS smbXsrv_connection_init_tables ( struct smbXsrv_connection * conn ,
enum protocol_types protocol ) ;
2012-03-16 19:32:28 +04:00
NTSTATUS smbXsrv_tcon_global_init ( void ) ;
NTSTATUS smbXsrv_tcon_update ( struct smbXsrv_tcon * tcon ) ;
NTSTATUS smbXsrv_tcon_disconnect ( struct smbXsrv_tcon * tcon , uint64_t vuid ) ;
NTSTATUS smb1srv_tcon_table_init ( struct smbXsrv_connection * conn ) ;
NTSTATUS smb1srv_tcon_create ( struct smbXsrv_connection * conn ,
2023-04-05 17:59:44 +03:00
uint32_t session_global_id ,
const char * share_name ,
2012-03-16 19:32:28 +04:00
NTTIME now ,
struct smbXsrv_tcon * * _tcon ) ;
NTSTATUS smb1srv_tcon_lookup ( struct smbXsrv_connection * conn ,
uint16_t tree_id , NTTIME now ,
struct smbXsrv_tcon * * tcon ) ;
2018-07-24 18:13:39 +03:00
NTSTATUS smb1srv_tcon_disconnect_all ( struct smbXsrv_client * client ) ;
2012-03-16 19:32:28 +04:00
NTSTATUS smb2srv_tcon_table_init ( struct smbXsrv_session * session ) ;
NTSTATUS smb2srv_tcon_create ( struct smbXsrv_session * session ,
2023-04-05 17:59:44 +03:00
uint32_t session_global_id ,
uint8_t encryption_flags ,
const char * share_name ,
2012-03-16 19:32:28 +04:00
NTTIME now ,
struct smbXsrv_tcon * * _tcon ) ;
NTSTATUS smb2srv_tcon_lookup ( struct smbXsrv_session * session ,
uint32_t tree_id , NTTIME now ,
struct smbXsrv_tcon * * tcon ) ;
NTSTATUS smb2srv_tcon_disconnect_all ( struct smbXsrv_session * session ) ;
2012-08-28 17:35:58 +04:00
struct smbXsrv_tcon_global0 ;
NTSTATUS smbXsrv_tcon_global_traverse (
int ( * fn ) ( struct smbXsrv_tcon_global0 * , void * ) ,
void * private_data ) ;
2012-03-16 19:32:28 +04:00
2012-02-07 02:06:41 +04:00
2015-11-13 12:30:50 +03:00
bool smbXsrv_is_encrypted ( uint8_t encryption_flags ) ;
bool smbXsrv_is_partially_encrypted ( uint8_t encryption_flags ) ;
bool smbXsrv_set_crypto_flag ( uint8_t * flags , uint8_t flag ) ;
2015-11-15 13:12:34 +03:00
bool smbXsrv_is_signed ( uint8_t signing_flags ) ;
bool smbXsrv_is_partially_signed ( uint8_t signing_flags ) ;
2013-03-12 17:36:32 +04:00
2013-10-14 12:33:57 +04:00
struct smbd_smb2_send_queue {
struct smbd_smb2_send_queue * prev , * next ;
2013-10-14 16:18:26 +04:00
DATA_BLOB * sendfile_header ;
2020-06-05 21:14:10 +03:00
uint32_t sendfile_body_size ;
2014-07-11 04:25:00 +04:00
NTSTATUS * sendfile_status ;
2020-10-01 00:42:48 +03:00
struct msghdr msg ;
2013-10-14 12:33:57 +04:00
struct iovec * vector ;
int count ;
2020-06-03 11:57:59 +03:00
struct {
struct tevent_req * req ;
struct timeval timeout ;
uint64_t required_acked_bytes ;
} ack ;
2013-10-14 12:33:57 +04:00
TALLOC_CTX * mem_ctx ;
} ;
2013-03-12 17:36:32 +04:00
2009-05-14 16:17:28 +04:00
struct smbd_smb2_request {
2009-06-09 23:29:40 +04:00
struct smbd_smb2_request * prev , * next ;
2009-08-07 17:21:07 +04:00
struct smbd_server_connection * sconn ;
2014-06-10 15:34:55 +04:00
struct smbXsrv_connection * xconn ;
2009-05-14 16:17:28 +04:00
2013-10-14 12:33:57 +04:00
struct smbd_smb2_send_queue queue_entry ;
2009-05-20 22:51:10 +04:00
/* the session the request operates on, maybe NULL */
2012-03-27 13:09:05 +04:00
struct smbXsrv_session * session ;
2011-10-27 18:35:28 +04:00
uint64_t last_session_id ;
2009-05-20 22:51:10 +04:00
2009-05-15 13:50:20 +04:00
/* the tcon the request operates on, maybe NULL */
2012-03-27 13:09:05 +04:00
struct smbXsrv_tcon * tcon ;
2011-10-27 18:35:28 +04:00
uint32_t last_tid ;
2009-05-15 13:50:20 +04:00
2009-05-14 16:17:28 +04:00
int current_idx ;
2009-05-23 00:58:39 +04:00
bool do_signing ;
2015-07-01 18:42:58 +03:00
/* Was the request encrypted? */
bool was_encrypted ;
/* Should we encrypt? */
2012-08-08 08:35:03 +04:00
bool do_encryption ;
2011-11-09 14:47:33 +04:00
struct tevent_timer * async_te ;
2011-08-26 01:33:41 +04:00
bool compound_related ;
2021-04-08 13:17:22 +03:00
NTSTATUS compound_create_err ;
2009-05-14 16:17:28 +04:00
2017-01-11 17:00:24 +03:00
/*
* Give the implementation of an SMB2 req a way to tell the SMB2 request
* processing engine that the internal request is going async , while
* preserving synchronous SMB2 behaviour .
*/
bool async_internal ;
2012-08-07 16:24:28 +04:00
/*
2012-08-08 09:07:03 +04:00
* the encryption key for the whole
* compound chain
*/
2021-03-06 01:14:21 +03:00
struct smb2_signing_key * first_enc_key ;
2012-08-08 09:07:03 +04:00
/*
* the signing key for the last
2012-08-07 16:24:28 +04:00
* request / response of a compound chain
*/
2021-03-06 01:14:21 +03:00
struct smb2_signing_key * last_sign_key ;
2014-10-08 21:25:15 +04:00
struct smbXsrv_preauth * preauth ;
2012-08-07 16:24:28 +04:00
2012-04-11 18:54:17 +04:00
struct timeval request_time ;
2014-10-31 13:15:50 +03:00
SMBPROFILE_IOBYTES_ASYNC_STATE ( profile ) ;
2010-06-09 08:20:07 +04:00
/* fake smb1 request. */
struct smb_request * smb1req ;
2009-06-05 22:02:21 +04:00
struct files_struct * compat_chain_fsp ;
2016-03-15 14:36:59 +03:00
/*
* Keep track of whether the outstanding request counters
* had been updated in dispatch , so that they need to be
* adapted again in reply .
*/
bool request_counters_updated ;
2018-01-11 17:34:45 +03:00
uint64_t channel_generation ;
2016-03-15 14:36:59 +03:00
2009-08-15 12:01:38 +04:00
/*
* The sub request for async backend calls .
* This is used for SMB2 Cancel .
*/
struct tevent_req * subreq ;
2012-08-08 09:07:03 +04:00
# define SMBD_SMB2_TF_IOV_OFS 0
# define SMBD_SMB2_HDR_IOV_OFS 1
# define SMBD_SMB2_BODY_IOV_OFS 2
# define SMBD_SMB2_DYN_IOV_OFS 3
2012-08-07 14:22:06 +04:00
2012-08-08 09:07:03 +04:00
# define SMBD_SMB2_NUM_IOV_PER_REQ 4
2012-08-07 14:22:06 +04:00
# define SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,ofs) \
( & req - > dir . vector [ ( idx ) + ( ofs ) ] )
2012-08-08 09:07:03 +04:00
# define SMBD_SMB2_IDX_TF_IOV(req,dir,idx) \
SMBD_SMB2_IOV_IDX_OFS ( req , dir , idx , SMBD_SMB2_TF_IOV_OFS )
2012-08-07 14:22:06 +04:00
# define SMBD_SMB2_IDX_HDR_IOV(req,dir,idx) \
SMBD_SMB2_IOV_IDX_OFS ( req , dir , idx , SMBD_SMB2_HDR_IOV_OFS )
# define SMBD_SMB2_IDX_BODY_IOV(req,dir,idx) \
SMBD_SMB2_IOV_IDX_OFS ( req , dir , idx , SMBD_SMB2_BODY_IOV_OFS )
# define SMBD_SMB2_IDX_DYN_IOV(req,dir,idx) \
SMBD_SMB2_IOV_IDX_OFS ( req , dir , idx , SMBD_SMB2_DYN_IOV_OFS )
2012-08-08 09:07:03 +04:00
# define SMBD_SMB2_IN_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,in,req->current_idx)
# define SMBD_SMB2_IN_TF_PTR(req) (uint8_t *)(SMBD_SMB2_IN_TF_IOV(req)->iov_base)
2012-08-07 14:22:06 +04:00
# define SMBD_SMB2_IN_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,in,req->current_idx)
2012-08-05 16:53:15 +04:00
# define SMBD_SMB2_IN_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_IN_HDR_IOV(req)->iov_base)
2012-08-07 14:22:06 +04:00
# define SMBD_SMB2_IN_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,in,req->current_idx)
2012-08-05 16:53:15 +04:00
# define SMBD_SMB2_IN_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_IN_BODY_IOV(req)->iov_base)
# define SMBD_SMB2_IN_BODY_LEN(req) (SMBD_SMB2_IN_BODY_IOV(req)->iov_len)
2012-08-07 14:22:06 +04:00
# define SMBD_SMB2_IN_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,in,req->current_idx)
2012-08-05 16:53:15 +04:00
# define SMBD_SMB2_IN_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_IN_DYN_IOV(req)->iov_base)
# define SMBD_SMB2_IN_DYN_LEN(req) (SMBD_SMB2_IN_DYN_IOV(req)->iov_len)
2012-08-08 09:07:03 +04:00
# define SMBD_SMB2_OUT_TF_IOV(req) SMBD_SMB2_IDX_TF_IOV(req,out,req->current_idx)
# define SMBD_SMB2_OUT_TF_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_TF_IOV(req)->iov_base)
2012-08-07 14:22:06 +04:00
# define SMBD_SMB2_OUT_HDR_IOV(req) SMBD_SMB2_IDX_HDR_IOV(req,out,req->current_idx)
2012-08-05 16:53:15 +04:00
# define SMBD_SMB2_OUT_HDR_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_HDR_IOV(req)->iov_base)
2012-08-07 14:22:06 +04:00
# define SMBD_SMB2_OUT_BODY_IOV(req) SMBD_SMB2_IDX_BODY_IOV(req,out,req->current_idx)
2012-08-05 16:53:15 +04:00
# define SMBD_SMB2_OUT_BODY_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_BODY_IOV(req)->iov_base)
# define SMBD_SMB2_OUT_BODY_LEN(req) (SMBD_SMB2_OUT_BODY_IOV(req)->iov_len)
2012-08-07 14:22:06 +04:00
# define SMBD_SMB2_OUT_DYN_IOV(req) SMBD_SMB2_IDX_DYN_IOV(req,out,req->current_idx)
2012-08-05 16:53:15 +04:00
# define SMBD_SMB2_OUT_DYN_PTR(req) (uint8_t *)(SMBD_SMB2_OUT_DYN_IOV(req)->iov_base)
# define SMBD_SMB2_OUT_DYN_LEN(req) (SMBD_SMB2_OUT_DYN_IOV(req)->iov_len)
2013-04-02 00:14:13 +04:00
# define SMBD_SMB2_SHORT_RECEIVEFILE_WRITE_LEN (SMB2_HDR_BODY + 0x30)
2009-05-14 16:17:28 +04:00
struct {
/*
2012-08-08 09:07:03 +04:00
* vector [ 0 ] TRANSPORT HEADER ( empty )
2009-05-14 16:17:28 +04:00
* .
2012-08-08 09:07:03 +04:00
* vector [ 1 ] SMB2_TRANSFORM ( optional )
* vector [ 2 ] SMB2
* vector [ 3 ] fixed body
* vector [ 4 ] dynamic body
2009-05-14 16:17:28 +04:00
* .
* .
* .
2012-08-08 09:07:03 +04:00
* vector [ 5 ] SMB2_TRANSFORM ( optional )
* vector [ 6 ] SMB2
* vector [ 7 ] fixed body
* vector [ 8 ] dynamic body
2009-05-14 16:17:28 +04:00
* .
* .
* .
*/
struct iovec * vector ;
int vector_count ;
2013-11-19 10:42:57 +04:00
struct iovec _vector [ 1 + SMBD_SMB2_NUM_IOV_PER_REQ ] ;
2009-05-14 16:17:28 +04:00
} in ;
struct {
/* the NBT header is not allocated */
uint8_t nbt_hdr [ 4 ] ;
/*
2012-08-05 22:52:55 +04:00
* vector [ 0 ] TRANSPORT HEADER
2009-05-14 16:17:28 +04:00
* .
2012-08-08 09:07:03 +04:00
* vector [ 1 ] SMB2_TRANSFORM ( optional )
* vector [ 2 ] SMB2
* vector [ 3 ] fixed body
* vector [ 4 ] dynamic body
2009-05-14 16:17:28 +04:00
* .
* .
* .
2012-08-08 09:07:03 +04:00
* vector [ 5 ] SMB2_TRANSFORM ( empty )
* vector [ 6 ] SMB2
* vector [ 7 ] fixed body
* vector [ 8 ] dynamic body
2009-05-14 16:17:28 +04:00
* .
* .
* .
*/
struct iovec * vector ;
int vector_count ;
2013-12-04 18:32:45 +04:00
struct iovec _vector [ 1 + SMBD_SMB2_NUM_IOV_PER_REQ ] ;
2013-11-20 12:56:19 +04:00
# define OUTVEC_ALLOC_SIZE (SMB2_HDR_BODY + 9)
uint8_t _hdr [ OUTVEC_ALLOC_SIZE ] ;
2013-12-04 18:05:34 +04:00
uint8_t _body [ 0x58 ] ;
2009-05-14 16:17:28 +04:00
} out ;
} ;
2009-05-15 13:20:34 +04:00
struct smbd_server_connection ;
2011-08-02 19:13:23 +04:00
struct pending_message_list ;
2009-05-26 14:07:16 +04:00
struct pending_auth_data ;
2016-08-08 16:07:30 +03:00
struct pthreadpool_tevent ;
2019-02-26 15:58:43 +03:00
struct dcesrv_context ;
2016-08-08 16:07:30 +03:00
2009-01-08 17:38:47 +03:00
struct smbd_server_connection {
2010-04-27 15:36:21 +04:00
const struct tsocket_address * local_address ;
const struct tsocket_address * remote_address ;
2011-06-16 17:39:25 +04:00
const char * remote_hostname ;
2018-12-27 17:17:22 +03:00
struct tevent_context * ev_ctx ;
2010-07-04 19:50:04 +04:00
struct messaging_context * msg_ctx ;
2019-02-26 15:58:43 +03:00
struct dcesrv_context * dce_ctx ;
2012-03-21 15:18:09 +04:00
struct notify_context * notify_ctx ;
2010-08-24 22:47:29 +04:00
int trans_num ;
2010-09-27 08:06:02 +04:00
2012-03-03 08:41:43 +04:00
size_t num_users ;
2012-03-03 08:43:31 +04:00
size_t num_connections ;
struct connection_struct * connections ;
2012-03-03 08:44:16 +04:00
size_t num_files ;
2010-09-27 04:29:36 +04:00
struct files_struct * files ;
2012-03-03 08:44:16 +04:00
2010-09-27 08:06:02 +04:00
int real_max_open_files ;
struct fsp_singleton_cache fsp_fi_cache ;
2011-08-02 19:13:23 +04:00
struct pending_message_list * deferred_open_queue ;
2011-03-18 02:16:54 +03:00
/* open directory handles. */
struct {
struct bitmap * dptr_bmap ;
struct dptr_struct * dirptrs ;
} searches ;
2011-07-08 01:59:41 +04:00
uint64_t num_requests ;
2012-05-25 01:15:08 +04:00
/* Current number of oplocks we have outstanding. */
struct {
int32_t exclusive_open ;
int32_t level_II_open ;
2012-05-25 01:33:32 +04:00
struct kernel_oplocks * kernel_ops ;
2012-05-25 01:15:08 +04:00
} oplocks ;
2021-09-09 01:06:11 +03:00
struct notify_mid_map * notify_mid_maps ;
2011-12-15 17:45:56 +04:00
2018-12-23 11:34:20 +03:00
struct pthreadpool_tevent * pool ;
2016-08-08 16:07:30 +03:00
2014-05-20 21:47:13 +04:00
struct smbXsrv_client * client ;
2009-01-08 17:38:47 +03:00
} ;
2009-05-14 16:17:28 +04:00
2014-05-20 21:47:13 +04:00
extern struct smbXsrv_client * global_smbXsrv_client ;
2009-01-08 17:38:47 +03:00
2009-01-08 14:03:45 +03:00
void smbd_init_globals ( void ) ;
2019-09-12 20:05:57 +03:00
2022-03-11 19:17:59 +03:00
/****************************************************************************
The buffer we keep around whilst an aio request is in process .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
struct aio_extra {
files_struct * fsp ;
struct smb_request * smbreq ;
DATA_BLOB outbuf ;
struct lock_struct lock ;
size_t nbyte ;
off_t offset ;
bool write_through ;
} ;
2019-09-12 20:05:57 +03:00
# endif /* _SOURCE3_SMBD_GLOBALS_H_ */