2009-01-08 14:03:45 +03:00
/*
Unix SMB / Netbios implementation .
smbd globals
Copyright ( C ) Stefan Metzmacher 2009
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/>.
*/
# if defined(WITH_AIO)
struct aio_extra ;
extern struct aio_extra * aio_list_head ;
2009-01-22 20:04:17 +03:00
extern struct tevent_signal * aio_signal_event ;
2009-01-08 14:03:45 +03:00
extern int aio_pending_size ;
extern int outstanding_aio_calls ;
# endif
/* dlink list we store pending lock records on. */
extern struct blocking_lock_record * blocking_lock_queue ;
/* dlink list we move cancelled lock records onto. */
extern struct blocking_lock_record * blocking_lock_cancelled_queue ;
/* The event that makes us process our blocking lock queue */
extern struct timed_event * brl_timeout ;
extern bool blocking_lock_unlock_state ;
extern bool blocking_lock_cancel_state ;
# ifdef USE_DMAPI
struct smbd_dmapi_context ;
extern struct smbd_dmapi_context * dmapi_ctx ;
# endif
extern bool dfree_broken ;
extern struct bitmap * dptr_bmap ;
//struct dptr_struct;
extern struct dptr_struct * dirptrs ;
extern int dirhandles_open ;
/* how many write cache buffers have been allocated */
extern unsigned int allocated_write_caches ;
extern int real_max_open_files ;
extern struct bitmap * file_bmap ;
extern files_struct * Files ;
extern int files_used ;
/* A singleton cache to speed up searching by dev/inode. */
struct fsp_singleton_cache {
files_struct * fsp ;
struct file_id id ;
} ;
extern struct fsp_singleton_cache fsp_fi_cache ;
extern unsigned long file_gen_counter ;
extern int first_file ;
extern const struct mangle_fns * mangle_fns ;
extern unsigned char * chartest ;
extern TDB_CONTEXT * tdb_mangled_cache ;
/* these tables are used to provide fast tests for characters */
extern unsigned char char_flags [ 256 ] ;
/*
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 ;
extern unsigned char base_reverse [ 256 ] ;
extern char * last_from ;
extern char * last_to ;
struct msg_state ;
extern struct msg_state * smbd_msg_state ;
extern bool logged_ioctl_message ;
extern int trans_num ;
extern pid_t mypid ;
extern time_t last_smb_conf_reload_time ;
extern time_t last_printer_reload_time ;
/****************************************************************************
structure to hold a linked list of queued messages .
for processing .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
struct pending_message_list ;
extern struct pending_message_list * deferred_open_queue ;
extern uint32_t common_flags2 ;
struct smb_srv_trans_enc_ctx ;
extern struct smb_srv_trans_enc_ctx * partial_srv_trans_enc_ctx ;
extern struct smb_srv_trans_enc_ctx * srv_trans_enc_ctx ;
struct sec_ctx {
UNIX_USER_TOKEN ut ;
NT_USER_TOKEN * token ;
} ;
/* 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 connection_struct * last_conn ;
extern uint16_t last_flags ;
extern struct db_context * session_db_ctx_ptr ;
extern uint32_t global_client_caps ;
extern uint16_t fnf_handle ;
struct conn_ctx {
connection_struct * conn ;
uint16 vuid ;
} ;
/* 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 ;
extern char * LastDir ;
/* Current number of oplocks we have outstanding. */
extern int32_t exclusive_oplocks_open ;
extern int32_t level_II_oplocks_open ;
extern bool global_client_failed_oplock_break ;
2009-01-09 16:02:18 +03:00
extern struct kernel_oplocks * koplocks ;
2009-01-08 14:03:45 +03:00
extern int am_parent ;
extern int server_fd ;
extern struct event_context * smbd_event_ctx ;
extern struct messaging_context * smbd_msg_ctx ;
extern struct memcache * smbd_memcache_ctx ;
extern bool exit_firsttime ;
struct child_pid ;
extern struct child_pid * children ;
extern int num_children ;
2009-05-14 16:17:28 +04:00
struct tstream_context ;
struct smbd_smb2_request ;
2009-05-20 22:51:10 +04:00
struct smbd_smb2_session ;
2009-05-15 13:50:20 +04:00
struct smbd_smb2_tcon ;
2009-05-14 16:17:28 +04:00
2009-05-19 12:46:35 +04:00
DATA_BLOB negprot_spnego ( void ) ;
2009-05-23 00:58:39 +04:00
NTSTATUS smb2_signing_sign_pdu ( DATA_BLOB session_key ,
struct iovec * vector ,
int count ) ;
NTSTATUS smb2_signing_check_pdu ( DATA_BLOB session_key ,
const struct iovec * vector ,
int count ) ;
2009-06-02 18:07:08 +04:00
void smbd_server_connection_terminate_ex ( struct smbd_server_connection * sconn ,
const char * reason ,
const char * location ) ;
# define smbd_server_connection_terminate(sconn, reason) \
smbd_server_connection_terminate_ex ( sconn , reason , __location__ )
2009-05-14 16:17:28 +04:00
bool smbd_is_smb2_header ( const uint8_t * inbuf , size_t size ) ;
2009-05-19 12:47:51 +04:00
void reply_smb2002 ( struct smb_request * req , uint16_t choice ) ;
2009-05-14 16:17:28 +04:00
void smbd_smb2_first_negprot ( struct smbd_server_connection * conn ,
const uint8_t * inbuf , size_t size ) ;
2009-06-05 13:05:03 +04:00
NTSTATUS smbd_smb2_request_error_ex ( struct smbd_smb2_request * req ,
NTSTATUS status ,
DATA_BLOB * info ,
const char * location ) ;
# define smbd_smb2_request_error(req, status) \
smbd_smb2_request_error_ex ( req , status , 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
2009-06-09 22:44:13 +04:00
NTSTATUS smbd_smb2_send_oplock_break ( struct smbd_server_connection * sconn ,
uint64_t file_id_persistent ,
uint64_t file_id_volatile ,
uint8_t oplock_level ) ;
2009-06-10 00:33:32 +04:00
NTSTATUS smbd_smb2_request_pending_queue ( struct smbd_smb2_request * req ) ;
2009-05-20 22:51:10 +04:00
NTSTATUS smbd_smb2_request_check_session ( struct smbd_smb2_request * req ) ;
2009-05-15 13:50:20 +04:00
NTSTATUS smbd_smb2_request_check_tcon ( struct smbd_smb2_request * req ) ;
2009-05-20 22:51:10 +04:00
2009-06-02 13:54:00 +04:00
struct smb_request * smbd_smb2_fake_smb_request ( struct smbd_smb2_request * req ) ;
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 ) ;
2009-05-28 03:28:34 +04:00
NTSTATUS smbd_smb2_request_process_write ( struct smbd_smb2_request * req ) ;
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 ) ;
2009-07-02 14:28:58 +04:00
NTSTATUS smbd_smb2_request_process_find ( 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 ) ;
2009-05-14 17:32:02 +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-05-14 16:17:28 +04:00
TALLOC_CTX * mem_pool ;
2009-06-09 23:29:40 +04:00
struct smbd_smb2_request * * parent ;
2009-05-14 16:17:28 +04:00
struct smbd_server_connection * conn ;
2009-05-20 22:51:10 +04:00
/* the session the request operates on, maybe NULL */
struct smbd_smb2_session * session ;
2009-05-15 13:50:20 +04:00
/* the tcon the request operates on, maybe NULL */
struct smbd_smb2_tcon * tcon ;
2009-05-14 16:17:28 +04:00
int current_idx ;
2009-05-23 00:58:39 +04:00
bool do_signing ;
2009-05-14 16:17:28 +04:00
2009-06-05 22:02:21 +04:00
struct files_struct * compat_chain_fsp ;
2009-06-08 15:30:32 +04:00
NTSTATUS next_status ;
2009-05-14 16:17:28 +04:00
struct {
/* the NBT header is not allocated */
uint8_t nbt_hdr [ 4 ] ;
/*
* vector [ 0 ] NBT
* .
* vector [ 1 ] SMB2
* vector [ 2 ] fixed body
* vector [ 3 ] dynamic body
* .
* .
* .
* vector [ 4 ] SMB2
* vector [ 5 ] fixed body
* vector [ 6 ] dynamic body
* .
* .
* .
*/
struct iovec * vector ;
int vector_count ;
} in ;
struct {
/* the NBT header is not allocated */
uint8_t nbt_hdr [ 4 ] ;
/*
* vector [ 0 ] NBT
* .
* vector [ 1 ] SMB2
* vector [ 2 ] fixed body
* vector [ 3 ] dynamic body
* .
* .
* .
* vector [ 4 ] SMB2
* vector [ 5 ] fixed body
* vector [ 6 ] dynamic body
* .
* .
* .
*/
struct iovec * vector ;
int vector_count ;
} out ;
} ;
2009-05-15 13:20:34 +04:00
struct smbd_server_connection ;
struct smbd_smb2_session {
struct smbd_smb2_session * prev , * next ;
struct smbd_server_connection * conn ;
NTSTATUS status ;
uint64_t vuid ;
AUTH_NTLMSSP_STATE * auth_ntlmssp_state ;
2009-05-23 00:58:39 +04:00
struct auth_serversupplied_info * server_info ;
DATA_BLOB session_key ;
bool do_signing ;
2009-05-15 13:50:20 +04:00
2009-05-27 20:33:45 +04:00
user_struct * compat_vuser ;
2009-05-15 13:50:20 +04:00
struct {
/* an id tree used to allocate tids */
struct idr_context * idtree ;
/* this is the limit of tid values for this connection */
uint32_t limit ;
struct smbd_smb2_tcon * list ;
} tcons ;
} ;
struct smbd_smb2_tcon {
struct smbd_smb2_tcon * prev , * next ;
struct smbd_smb2_session * session ;
uint32_t tid ;
int snum ;
2009-05-27 20:40:42 +04:00
connection_struct * compat_conn ;
2009-05-15 13:20:34 +04:00
} ;
2009-05-26 14:07:16 +04:00
struct pending_auth_data ;
2009-01-08 17:38:47 +03:00
struct smbd_server_connection {
2009-05-26 17:20:36 +04:00
struct {
bool got_session ;
} nbt ;
2009-05-14 16:17:28 +04:00
bool allow_smb2 ;
2009-05-26 12:48:12 +04:00
struct {
struct fd_event * fde ;
uint64_t num_requests ;
2009-05-26 14:48:58 +04:00
struct {
bool encrypted_passwords ;
bool spnego ;
struct auth_context * auth_context ;
bool done ;
2009-05-26 16:56:08 +04:00
/*
* Size of the data we can receive . Set by us .
* Can be modified by the max xmit parameter .
*/
int max_recv ;
2009-05-26 14:48:58 +04:00
} negprot ;
2009-05-26 17:21:16 +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 ;
uint16_t last_session_tag ;
2009-05-26 18:38:45 +04:00
/* users from session setup */
char * session_userlist ;
/* workgroup from session setup. */
char * session_workgroup ;
/*
* this holds info on user ids that are already
* validated for this VC
*/
user_struct * validated_users ;
uint16_t next_vuid ;
int num_validated_vuids ;
# ifdef HAVE_NETGROUP
char * my_yp_domain ;
# endif
2009-05-26 17:21:16 +04:00
} sessions ;
2009-05-27 13:15:44 +04:00
struct {
connection_struct * Connections ;
/* number of open connections */
struct bitmap * bmap ;
int num_open ;
} tcons ;
2009-05-26 12:48:12 +04:00
struct smb_signing_state * signing_state ;
2009-05-26 14:07:16 +04:00
/* List to store partial SPNEGO auth fragments. */
struct pending_auth_data * pd_list ;
2009-06-30 12:17:38 +04:00
struct notify_mid_map * notify_mid_maps ;
2009-05-26 12:48:12 +04:00
} smb1 ;
2009-05-14 16:17:28 +04:00
struct {
struct tevent_context * event_ctx ;
struct tevent_queue * recv_queue ;
struct tevent_queue * send_queue ;
struct tstream_context * stream ;
2009-05-15 13:20:34 +04:00
struct {
/* an id tree used to allocate vuids */
/* this holds info on session vuids that are already
* validated for this VC */
struct idr_context * idtree ;
/* this is the limit of vuid values for this connection */
uint64_t limit ;
struct smbd_smb2_session * list ;
} sessions ;
2009-06-09 23:29:40 +04:00
struct smbd_smb2_request * requests ;
2009-05-14 16:17:28 +04:00
} smb2 ;
2009-01-08 17:38:47 +03:00
} ;
2009-05-14 16:17:28 +04:00
2009-01-08 17:38:47 +03:00
extern struct smbd_server_connection * smbd_server_conn ;
2009-01-08 14:03:45 +03:00
void smbd_init_globals ( void ) ;