s3:smbXsrv_open: add function smbXsrv_open_cleanup()
[bbaumbach/samba-autobuild/.git] / source3 / smbd / globals.h
index 9a8910cdfd0b74279da9b10fcb6357c27a7a53a7..150275894b62d13719b7363f92f58867ce2cdf8d 100644 (file)
@@ -155,6 +155,7 @@ NTSTATUS smbd_do_qfsinfo(connection_struct *conn,
                         uint16_t info_level,
                         uint16_t flags2,
                         unsigned int max_data_bytes,
+                        struct smb_filename *smb_fname,
                         char **ppdata,
                         int *ret_data_len);
 
@@ -202,6 +203,7 @@ bool smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,
 
 NTSTATUS smbd_calculate_access_mask(connection_struct *conn,
                                    const struct smb_filename *smb_fname,
+                                   bool use_privs,
                                    uint32_t access_mask,
                                    uint32_t *access_mask_out);
 
@@ -235,8 +237,9 @@ NTSTATUS smbd_smb2_request_done_ex(struct smbd_smb2_request *req,
        smbd_smb2_request_done_ex(req, NT_STATUS_OK, body, dyn, __location__)
 
 NTSTATUS smbd_smb2_send_oplock_break(struct smbd_server_connection *sconn,
-                                    uint64_t file_id_persistent,
-                                    uint64_t file_id_volatile,
+                                    struct smbXsrv_session *session,
+                                    struct smbXsrv_tcon *tcon,
+                                    struct smbXsrv_open *op,
                                     uint8_t oplock_level);
 
 NTSTATUS smbd_smb2_request_pending_queue(struct smbd_smb2_request *req,
@@ -394,6 +397,10 @@ NTSTATUS smb2srv_session_table_init(struct smbXsrv_connection *conn);
 NTSTATUS smb2srv_session_lookup(struct smbXsrv_connection *conn,
                                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 *),
+                       void *private_data);
 struct tevent_req *smb2srv_session_close_previous_send(TALLOC_CTX *mem_ctx,
                                        struct tevent_context *ev,
                                        struct smbXsrv_connection *conn,
@@ -421,6 +428,10 @@ 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);
+struct smbXsrv_tcon_global0;
+NTSTATUS smbXsrv_tcon_global_traverse(
+                       int (*fn)(struct smbXsrv_tcon_global0 *, void *),
+                       void *private_data);
 
 NTSTATUS smbXsrv_open_global_init(void);
 NTSTATUS smbXsrv_open_create(struct smbXsrv_connection *conn,
@@ -440,6 +451,19 @@ NTSTATUS smb2srv_open_lookup(struct smbXsrv_connection *conn,
                             uint64_t volatile_id,
                             NTTIME now,
                             struct smbXsrv_open **_open);
+NTSTATUS smb2srv_open_recreate(struct smbXsrv_connection *conn,
+                              struct auth_session_info *session_info,
+                              uint64_t persistent_id,
+                              struct GUID create_guid,
+                              NTTIME now,
+                              struct smbXsrv_open **_open);
+struct smbXsrv_open_global0;
+NTSTATUS smbXsrv_open_global_traverse(
+       int (*fn)(struct smbXsrv_open_global0 *, void *),
+       void *private_data);
+
+NTSTATUS smbXsrv_open_cleanup(uint64_t persistent_id);
+
 
 struct smbd_smb2_request {
        struct smbd_smb2_request *prev, *next;
@@ -456,57 +480,89 @@ struct smbd_smb2_request {
 
        int current_idx;
        bool do_signing;
+       bool do_encryption;
        struct tevent_timer *async_te;
-       bool cancelled;
        bool compound_related;
 
+       /*
+        * the encryption key for the whole
+        * compound chain
+        */
+       DATA_BLOB first_key;
+       /*
+        * the signing key for the last
+        * request/response of a compound chain
+        */
+       DATA_BLOB last_key;
+
        struct timeval request_time;
 
        /* fake smb1 request. */
        struct smb_request *smb1req;
        struct files_struct *compat_chain_fsp;
 
-       NTSTATUS next_status;
-
        /*
         * The sub request for async backend calls.
         * This is used for SMB2 Cancel.
         */
        struct tevent_req *subreq;
 
-#define SMBD_SMB2_IN_HDR_IOV(req)    (&req->in.vector[req->current_idx+0])
+#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
+
+#define SMBD_SMB2_NUM_IOV_PER_REQ 4
+
+#define SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,ofs) \
+       (&req->dir.vector[(idx)+(ofs)])
+
+#define SMBD_SMB2_IDX_TF_IOV(req,dir,idx) \
+       SMBD_SMB2_IOV_IDX_OFS(req,dir,idx,SMBD_SMB2_TF_IOV_OFS)
+#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)
+
+#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)
+#define SMBD_SMB2_IN_HDR_IOV(req)    SMBD_SMB2_IDX_HDR_IOV(req,in,req->current_idx)
 #define SMBD_SMB2_IN_HDR_PTR(req)    (uint8_t *)(SMBD_SMB2_IN_HDR_IOV(req)->iov_base)
-#define SMBD_SMB2_IN_BODY_IOV(req)   (&req->in.vector[req->current_idx+1])
+#define SMBD_SMB2_IN_BODY_IOV(req)   SMBD_SMB2_IDX_BODY_IOV(req,in,req->current_idx)
 #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)
-#define SMBD_SMB2_IN_DYN_IOV(req)    (&req->in.vector[req->current_idx+2])
+#define SMBD_SMB2_IN_DYN_IOV(req)    SMBD_SMB2_IDX_DYN_IOV(req,in,req->current_idx)
 #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)
 
-#define SMBD_SMB2_OUT_HDR_IOV(req)   (&req->out.vector[req->current_idx+0])
+#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)
+#define SMBD_SMB2_OUT_HDR_IOV(req)   SMBD_SMB2_IDX_HDR_IOV(req,out,req->current_idx)
 #define SMBD_SMB2_OUT_HDR_PTR(req)   (uint8_t *)(SMBD_SMB2_OUT_HDR_IOV(req)->iov_base)
-#define SMBD_SMB2_OUT_BODY_IOV(req)  (&req->out.vector[req->current_idx+1])
+#define SMBD_SMB2_OUT_BODY_IOV(req)  SMBD_SMB2_IDX_BODY_IOV(req,out,req->current_idx)
 #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)
-#define SMBD_SMB2_OUT_DYN_IOV(req)   (&req->out.vector[req->current_idx+2])
+#define SMBD_SMB2_OUT_DYN_IOV(req)   SMBD_SMB2_IDX_DYN_IOV(req,out,req->current_idx)
 #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)
 
        struct {
-               /* the NBT header is not allocated */
-               uint8_t nbt_hdr[4];
                /*
-                * vector[0] NBT
+                * vector[0] TRANSPORT HEADER (empty)
                 * .
-                * vector[1] SMB2
-                * vector[2] fixed body
-                * vector[3] dynamic body
+                * vector[1] SMB2_TRANSFORM (optional)
+                * vector[2] SMB2
+                * vector[3] fixed body
+                * vector[4] dynamic body
                 * .
                 * .
                 * .
-                * vector[4] SMB2
-                * vector[5] fixed body
-                * vector[6] dynamic body
+                * vector[5] SMB2_TRANSFORM (optional)
+                * vector[6] SMB2
+                * vector[7] fixed body
+                * vector[8] dynamic body
                 * .
                 * .
                 * .
@@ -518,17 +574,19 @@ struct smbd_smb2_request {
                /* the NBT header is not allocated */
                uint8_t nbt_hdr[4];
                /*
-                * vector[0] NBT
+                * vector[0] TRANSPORT HEADER
                 * .
-                * vector[1] SMB2
-                * vector[2] fixed body
-                * vector[3] dynamic body
+                * vector[1] SMB2_TRANSFORM (optional)
+                * vector[2] SMB2
+                * vector[3] fixed body
+                * vector[4] dynamic body
                 * .
                 * .
                 * .
-                * vector[4] SMB2
-                * vector[5] fixed body
-                * vector[6] dynamic body
+                * vector[5] SMB2_TRANSFORM (empty)
+                * vector[6] SMB2
+                * vector[7] fixed body
+                * vector[8] dynamic body
                 * .
                 * .
                 * .
@@ -604,7 +662,7 @@ struct smbd_server_connection {
        } oplocks;
 
        struct {
-               struct fd_event *fde;
+               struct tevent_fd *fde;
 
                struct {
                        /*
@@ -621,7 +679,7 @@ struct smbd_server_connection {
                        /*
                         * fde for the trusted_fd
                         */
-                       struct fd_event *trusted_fde;
+                       struct tevent_fd *trusted_fde;
 
                        /*
                         * Reference count for the fcntl lock to
@@ -670,7 +728,7 @@ struct smbd_server_connection {
                        struct blocking_lock_record *blocking_lock_cancelled_queue;
 
                        /* The event that makes us process our blocking lock queue */
-                       struct timed_event *brl_timeout;
+                       struct tevent_timer *brl_timeout;
 
                        bool blocking_lock_unlock_state;
                        bool blocking_lock_cancel_state;
@@ -683,7 +741,7 @@ struct smbd_server_connection {
                bool negprot_2ff;
                struct {
                        /* The event that makes us process our blocking lock queue */
-                       struct timed_event *brl_timeout;
+                       struct tevent_timer *brl_timeout;
                        bool blocking_lock_unlock_state;
                } locks;
                struct smbd_smb2_request *requests;