Revert "smbd: remove unused smbd_server_connection->ev_ctx"
[garming/samba-autobuild/.git] / source3 / smbd / globals.h
index dbdc9e8d8e2b69dbe3730caa2cf62f08c9d9b852..a13916e230ab3a0f100acc4a5d87d6aa67f5eec7 100644 (file)
@@ -22,9 +22,6 @@
 #include "librpc/gen_ndr/smbXsrv.h"
 #include "smbprofile.h"
 
-extern int aio_pending_size;
-extern int outstanding_aio_calls;
-
 #ifdef USE_DMAPI
 struct smbd_dmapi_context;
 extern struct smbd_dmapi_context *dmapi_ctx;
@@ -92,6 +89,9 @@ extern uint16_t fnf_handle;
 struct conn_ctx {
        connection_struct *conn;
        uint64_t vuid;
+       bool need_chdir;
+       bool done_chdir;
+       userdom_struct user_info;
 };
 /* A stack of current_user connection contexts. */
 extern struct conn_ctx conn_ctx_stack[MAX_SEC_CTX_DEPTH];
@@ -143,6 +143,13 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
                               char **ppdata,
                               unsigned int *pdata_size);
 
+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);
+
 NTSTATUS smbd_do_setfilepathinfo(connection_struct *conn,
                                struct smb_request *req,
                                TALLOC_CTX *mem_ctx,
@@ -169,6 +176,7 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
                           uint32_t dirtype,
                           bool dont_descend,
                           bool ask_sharemode,
+                          bool get_dosmode,
                           bool (*match_fn)(TALLOC_CTX *ctx,
                                            void *private_data,
                                            const char *dname,
@@ -177,6 +185,7 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
                           bool (*mode_fn)(TALLOC_CTX *ctx,
                                           void *private_data,
                                           struct smb_filename *smb_fname,
+                                          bool get_dosmode,
                                           uint32_t *_mode),
                           void *private_data,
                           char **_fname,
@@ -194,15 +203,18 @@ NTSTATUS smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,
                               int requires_resume_key,
                               bool dont_descend,
                               bool ask_sharemode,
+                              bool get_dosmode,
                               uint8_t align,
                               bool do_pad,
                               char **ppdata,
                               char *base_data,
                               char *end_data,
                               int space_remaining,
+                              struct smb_filename **smb_fname,
                               bool *got_exact_match,
                               int *_last_entry_off,
-                              struct ea_list *name_list);
+                              struct ea_list *name_list,
+                              struct file_id *file_id);
 
 NTSTATUS smbd_calculate_access_mask(connection_struct *conn,
                                    const struct smb_filename *smb_fname,
@@ -220,14 +232,16 @@ void smbd_server_connection_terminate_ex(struct smbXsrv_connection *xconn,
 
 const char *smb2_opcode_name(uint16_t opcode);
 bool smbd_is_smb2_header(const uint8_t *inbuf, size_t size);
+bool smbd_smb2_is_compound(const struct smbd_smb2_request *req);
 
 NTSTATUS smbd_add_connection(struct smbXsrv_client *client, int sock_fd,
                             struct smbXsrv_connection **_xconn);
 
 void reply_smb2002(struct smb_request *req, uint16_t choice);
 void reply_smb20ff(struct smb_request *req, uint16_t choice);
-void smbd_smb2_first_negprot(struct smbXsrv_connection *xconn,
-                            const uint8_t *inpdu, size_t size);
+void smbd_smb2_process_negprot(struct smbXsrv_connection *xconn,
+                              uint64_t expected_seq_low,
+                              const uint8_t *inpdu, size_t size);
 
 DATA_BLOB smbd_smb2_generate_outbody(struct smbd_smb2_request *req, size_t size);
 
@@ -270,6 +284,9 @@ NTSTATUS smbd_smb2_request_verify_creditcharge(struct smbd_smb2_request *req,
 NTSTATUS smbd_smb2_request_verify_sizes(struct smbd_smb2_request *req,
                                        size_t expected_body_size);
 
+void smb2_request_set_async_internal(struct smbd_smb2_request *req,
+                                    bool async_internal);
+
 enum protocol_types smbd_smb2_protocol_dialect_match(const uint8_t *indyn,
                                                     const int dialect_count,
                                                     uint16_t *dialect);
@@ -351,14 +368,10 @@ struct smbXsrv_connection {
 
        struct smbXsrv_client *client;
 
-
        const struct tsocket_address *local_address;
        const struct tsocket_address *remote_address;
        const char *remote_hostname;
 
-       struct tevent_context *ev_ctx;
-       struct messaging_context *msg_ctx;
-
        enum protocol_types protocol;
 
        struct {
@@ -503,6 +516,7 @@ struct smbXsrv_connection {
                struct {
                        uint32_t capabilities;
                        struct GUID guid;
+                       bool guid_verified;
                        uint16_t security_mode;
                        uint16_t num_dialects;
                        uint16_t *dialects;
@@ -529,25 +543,54 @@ const char *smbXsrv_connection_dbg(const struct smbXsrv_connection *xconn);
 NTSTATUS smbXsrv_version_global_init(const struct server_id *server_id);
 uint32_t smbXsrv_version_global_current(void);
 
+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_update(struct smbXsrv_client *client);
+NTSTATUS smbXsrv_client_remove(struct smbXsrv_client *client);
+NTSTATUS smb2srv_client_lookup_global(struct smbXsrv_client *client,
+                                     struct GUID client_guid,
+                                     TALLOC_CTX *mem_ctx,
+                                     struct smbXsrv_client_global0 **_pass);
+NTSTATUS smb2srv_client_connection_pass(struct smbd_smb2_request *smb2req,
+                                       struct smbXsrv_client_global0 *global);
+
 NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn,
                                        enum protocol_types protocol);
 
-NTSTATUS smbXsrv_session_global_init(void);
+NTSTATUS smbXsrv_session_global_init(struct messaging_context *msg_ctx);
 NTSTATUS smbXsrv_session_create(struct smbXsrv_connection *conn,
                                NTTIME now,
                                struct smbXsrv_session **_session);
+NTSTATUS smbXsrv_session_add_channel(struct smbXsrv_session *session,
+                                    struct smbXsrv_connection *conn,
+                                    struct smbXsrv_channel_global0 **_c);
 NTSTATUS smbXsrv_session_update(struct smbXsrv_session *session);
 struct smbXsrv_channel_global0;
 NTSTATUS smbXsrv_session_find_channel(const struct smbXsrv_session *session,
                                      const struct smbXsrv_connection *conn,
                                      struct smbXsrv_channel_global0 **_c);
+NTSTATUS smbXsrv_session_find_auth(const struct smbXsrv_session *session,
+                                  const struct smbXsrv_connection *conn,
+                                  NTTIME now,
+                                  struct smbXsrv_session_auth0 **_a);
+NTSTATUS smbXsrv_session_create_auth(struct smbXsrv_session *session,
+                                    struct smbXsrv_connection *conn,
+                                    NTTIME now,
+                                    uint8_t in_flags,
+                                    uint8_t in_security_mode,
+                                    struct smbXsrv_session_auth0 **_a);
 struct tevent_req *smb2srv_session_shutdown_send(TALLOC_CTX *mem_ctx,
                                        struct tevent_context *ev,
                                        struct smbXsrv_session *session,
                                        struct smbd_smb2_request *current_req);
 NTSTATUS smb2srv_session_shutdown_recv(struct tevent_req *req);
 NTSTATUS smbXsrv_session_logoff(struct smbXsrv_session *session);
-NTSTATUS smbXsrv_session_logoff_all(struct smbXsrv_connection *conn);
+NTSTATUS smbXsrv_session_logoff_all(struct smbXsrv_client *client);
 NTSTATUS smb1srv_session_table_init(struct smbXsrv_connection *conn);
 NTSTATUS smb1srv_session_lookup(struct smbXsrv_connection *conn,
                                uint16_t vuid, NTTIME now,
@@ -556,6 +599,9 @@ NTSTATUS smb2srv_session_table_init(struct smbXsrv_connection *conn);
 NTSTATUS smb2srv_session_lookup_conn(struct smbXsrv_connection *conn,
                                     uint64_t session_id, NTTIME now,
                                     struct smbXsrv_session **session);
+NTSTATUS smb2srv_session_lookup_client(struct smbXsrv_client *client,
+                                      uint64_t session_id, NTTIME now,
+                                      struct smbXsrv_session **session);
 struct smbXsrv_session_global0;
 NTSTATUS smbXsrv_session_global_traverse(
                        int (*fn)(struct smbXsrv_session_global0 *, void *),
@@ -578,7 +624,7 @@ NTSTATUS smb1srv_tcon_create(struct smbXsrv_connection *conn,
 NTSTATUS smb1srv_tcon_lookup(struct smbXsrv_connection *conn,
                             uint16_t tree_id, NTTIME now,
                             struct smbXsrv_tcon **tcon);
-NTSTATUS smb1srv_tcon_disconnect_all(struct smbXsrv_connection *conn);
+NTSTATUS smb1srv_tcon_disconnect_all(struct smbXsrv_client *client);
 NTSTATUS smb2srv_tcon_table_init(struct smbXsrv_session *session);
 NTSTATUS smb2srv_tcon_create(struct smbXsrv_session *session,
                             NTTIME now,
@@ -610,6 +656,10 @@ NTSTATUS smb2srv_open_lookup(struct smbXsrv_connection *conn,
                             uint64_t volatile_id,
                             NTTIME now,
                             struct smbXsrv_open **_open);
+NTSTATUS smb2srv_open_lookup_replay_cache(struct smbXsrv_connection *conn,
+                                         const struct GUID *create_guid,
+                                         NTTIME now,
+                                         struct smbXsrv_open **_open);
 NTSTATUS smb2srv_open_recreate(struct smbXsrv_connection *conn,
                               struct auth_session_info *session_info,
                               uint64_t persistent_id,
@@ -622,6 +672,11 @@ NTSTATUS smbXsrv_open_global_traverse(
        void *private_data);
 
 NTSTATUS smbXsrv_open_cleanup(uint64_t persistent_id);
+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);
+bool smbXsrv_is_signed(uint8_t signing_flags);
+bool smbXsrv_is_partially_signed(uint8_t signing_flags);
 
 struct smbd_smb2_send_queue {
        struct smbd_smb2_send_queue *prev, *next;
@@ -650,6 +705,9 @@ struct smbd_smb2_request {
        struct smbXsrv_tcon *tcon;
        uint32_t last_tid;
 
+       /* the tevent_context (wrapper) the request operates on */
+       struct tevent_context *ev_ctx;
+
        int current_idx;
        bool do_signing;
        /* Was the request encrypted? */
@@ -659,6 +717,13 @@ struct smbd_smb2_request {
        struct tevent_timer *async_te;
        bool compound_related;
 
+       /*
+        * 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;
+
        /*
         * the encryption key for the whole
         * compound chain
@@ -679,6 +744,14 @@ struct smbd_smb2_request {
        struct smb_request *smb1req;
        struct files_struct *compat_chain_fsp;
 
+       /*
+        * 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;
+       uint64_t channel_generation;
+
        /*
         * The sub request for async backend calls.
         * This is used for SMB2 Cancel.
@@ -800,15 +873,20 @@ struct user_struct {
        struct smbXsrv_session *session;
 };
 
+struct pthreadpool_tevent;
+
 struct smbd_server_connection {
        const struct tsocket_address *local_address;
        const struct tsocket_address *remote_address;
        const char *remote_hostname;
        struct tevent_context *ev_ctx;
+       struct tevent_context *raw_ev_ctx;
+       struct tevent_context *root_ev_ctx;
+       struct tevent_context *guest_ev_ctx;
        struct messaging_context *msg_ctx;
-       struct sys_notify_context *sys_notify_ctx;
        struct notify_context *notify_ctx;
        bool using_smb2;
+       bool aapl_zero_file_id; /* Apple-specific */
        int trans_num;
 
        size_t num_users;
@@ -866,11 +944,7 @@ struct smbd_server_connection {
                } locks;
        } smb2;
 
-       /*
-        * Link into libasys for asynchronous operations
-        */
-       struct asys_context *asys_ctx;
-       struct tevent_fd *asys_fde;
+       struct pthreadpool_tevent *pool;
 
        struct smbXsrv_client *client;
 };