s3:smbXsrv_session: add smbXsrv_session_global_traverse()
[kai/samba-autobuild/.git] / source3 / smbd / globals.h
index cf9d01b9f704aa3453fff248bb9ad98ff433eaec..6509dda37c9963efc7411d09c3316514382110b2 100644 (file)
@@ -202,6 +202,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);
 
@@ -219,7 +220,7 @@ bool smbd_is_smb2_header(const uint8_t *inbuf, size_t size);
 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 smbd_server_connection *sconn,
-                            const uint8_t *inbuf, size_t size);
+                            uint8_t *inbuf, size_t size);
 
 NTSTATUS smbd_smb2_request_error_ex(struct smbd_smb2_request *req,
                                    NTSTATUS status,
@@ -235,8 +236,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 +396,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,
@@ -440,6 +446,12 @@ 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 smbd_smb2_request {
        struct smbd_smb2_request *prev, *next;
@@ -456,57 +468,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 +562,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
                 * .
                 * .
                 * .