]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: add smbXsrv_session to smbXsrv_open
authorRalph Boehme <slow@samba.org>
Sat, 28 Jun 2025 06:55:25 +0000 (08:55 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 5 Aug 2025 14:52:34 +0000 (14:52 +0000)
From "MS-SMB2 3.3.1.10 Per Open":

  Open.Session: A reference to the authenticated session, as specified in section
  3.3.1.8, over which this open was performed. If the open is not attached to a
  session at this time, this value MUST be NULL.

Needed to implement:

  3.3.5.9 Receiving an SMB2 CREATE Request

  If the server implements the SMB 3.x dialect family and all of the following
  conditions are TRUE, the server MUST look up an Open in GlobalOpenTable where
  Open.IsReplayEligible is TRUE and Open.CreateGuid matches the CreateGuid in
  the SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 create context and Open.ClientGuid
  matches the ClientGuid of the connection that received this request:

  ...

  If an Open is found, the server MUST perform the following:

  ..

  If Open.Session.SessionId is not equal to the current Session.SessionId, the
  server MUST fail the request with STATUS_DUPLICATE_OBJECTID.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/librpc/idl/smbXsrv.idl
source3/smbd/files.c
source3/smbd/smb2_create.c
source3/smbd/smbXsrv_open.c
source3/smbd/smbXsrv_open.h

index 12ae39e664519a4246804cd62838a61af3d4b95d..a6d7075663e4781ef2bf81fb0cc571d397abbbec 100644 (file)
@@ -474,6 +474,7 @@ interface smbXsrv
                [ignore] smbXsrv_open_table             *table;
                uint32                                  local_id;
                [ref] smbXsrv_open_global0              *global;
+               smbXsrv_session                         *session;
                NTSTATUS                                status;
                NTTIME                                  idle_time;
                [ignore] files_struct                   *compat;
index 73c20b680043478827152a3594a5efd82b1eb867..2c770e2a8b0d27af05a04a557d07af3bc75e060f 100644 (file)
@@ -120,7 +120,7 @@ NTSTATUS fsp_bind_smb(struct files_struct *fsp, struct smb_request *req)
        now = timeval_to_nttime(&fsp->open_time);
 
        status = smbXsrv_open_create(req->xconn,
-                                    fsp->conn->session_info,
+                                    req->session,
                                     now,
                                     &op);
        if (!NT_STATUS_IS_OK(status)) {
index 82b2b57299d062dd5ac9c7076622c14fae657786..0b516f9b3fb47e83be039bf30f4eb1e74bfd8b91 100644 (file)
@@ -1102,7 +1102,7 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
                        lease_key = &state->lease_ptr->lease_key;
                }
                status = smb2srv_open_recreate(smb2req->xconn,
-                                              smb1req->conn->session_info,
+                                              smb2req->session,
                                               state->persistent_id,
                                               state->create_guid,
                                               lease_key,
index 2564c2b6e8c28d71f6e4f7b5975749e81773ad7b..f7e55f8b78d3d7a6d23097fc91f5ffe8258d4a45 100644 (file)
@@ -565,11 +565,12 @@ static int smbXsrv_open_destructor(struct smbXsrv_open *op)
 }
 
 NTSTATUS smbXsrv_open_create(struct smbXsrv_connection *conn,
-                            struct auth_session_info *session_info,
+                            struct smbXsrv_session *session,
                             NTTIME now,
                             struct smbXsrv_open **_open)
 {
        struct smbXsrv_open_table *table = conn->client->open_table;
+       struct auth_session_info *session_info = NULL;
        struct smbXsrv_open *op = NULL;
        struct smbXsrv_open_global0 *global = NULL;
        NTSTATUS status;
@@ -577,6 +578,7 @@ NTSTATUS smbXsrv_open_create(struct smbXsrv_connection *conn,
        struct security_token *current_token = NULL;
        int local_id;
 
+       session_info = session->global->auth_session_info;
        if (session_info == NULL) {
                return NT_STATUS_INVALID_HANDLE;
        }
@@ -599,6 +601,7 @@ NTSTATUS smbXsrv_open_create(struct smbXsrv_connection *conn,
        op->table = table;
        op->status = NT_STATUS_OK; /* TODO: start with INTERNAL_ERROR */
        op->idle_time = now;
+       op->session = session;
 
        global = talloc_zero(op, struct smbXsrv_open_global0);
        if (global == NULL) {
@@ -1318,7 +1321,7 @@ not_found:
 }
 
 NTSTATUS smb2srv_open_recreate(struct smbXsrv_connection *conn,
-                              struct auth_session_info *session_info,
+                              struct smbXsrv_session *session,
                               uint64_t persistent_id,
                               const struct GUID *create_guid,
                               const struct smb2_lease_key *lease_key,
@@ -1332,6 +1335,8 @@ NTSTATUS smb2srv_open_recreate(struct smbXsrv_connection *conn,
                .lease_key = lease_key,
                .me = messaging_server_id(conn->client->msg_ctx),
        };
+       struct auth_session_info *session_info =
+               session->global->auth_session_info;
        struct smbXsrv_open_global_key_buf key_buf;
        TDB_DATA key = smbXsrv_open_global_id_to_key(
                persistent_id & UINT32_MAX, &key_buf);
@@ -1401,6 +1406,8 @@ NTSTATUS smb2srv_open_recreate(struct smbXsrv_connection *conn,
                goto fail;
        }
 
+       state.op->session = session;
+
        talloc_set_destructor(state.op, smbXsrv_open_destructor);
 
        if (CHECK_DEBUGLVL(10)) {
index 94672f2ada15736576d0cff1a07218d6510ee4b9..4f57363d6158f566899a027b376f3a41b1aa4e14 100644 (file)
@@ -35,7 +35,7 @@ struct smbXsrv_client;
 
 NTSTATUS smbXsrv_open_global_init(void);
 NTSTATUS smbXsrv_open_create(struct smbXsrv_connection *conn,
-                            struct auth_session_info *session_info,
+                            struct smbXsrv_session *session,
                             NTTIME now,
                             struct smbXsrv_open **_open);
 NTSTATUS smbXsrv_open_update(struct smbXsrv_open *_open);
@@ -59,7 +59,7 @@ NTSTATUS smb2srv_open_lookup_replay_cache(struct smbXsrv_connection *conn,
                                          struct smbXsrv_open **_open);
 struct smb2_lease_key;
 NTSTATUS smb2srv_open_recreate(struct smbXsrv_connection *conn,
-                              struct auth_session_info *session_info,
+                              struct smbXsrv_session *session,
                               uint64_t persistent_id,
                               const struct GUID *create_guid,
                               const struct smb2_lease_key *lease_key,