]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: factor out fsp_bind_smb()
authorRalph Boehme <slow@samba.org>
Fri, 19 Jun 2020 05:31:51 +0000 (07:31 +0200)
committerJeremy Allison <jra@samba.org>
Sat, 18 Jul 2020 05:58:41 +0000 (05:58 +0000)
Needed for path-ref fsps in the future.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/files.c
source3/smbd/proto.h

index 8bba6c550b37ce399b9b08b19b22a2e54a59ec2e..999100a9e6c3a14543b013e5809f3d6d22b729a0 100644 (file)
@@ -99,6 +99,39 @@ void fsp_set_gen_id(files_struct *fsp)
  Find first available file slot.
 ****************************************************************************/
 
+NTSTATUS fsp_bind_smb(struct files_struct *fsp, struct smb_request *req)
+{
+       struct smbXsrv_open *op = NULL;
+       NTTIME now;
+       NTSTATUS status;
+
+       if (req == NULL) {
+               DBG_DEBUG("INTERNAL_OPEN_ONLY, skipping smbXsrv_open\n");
+               return NT_STATUS_OK;
+       }
+
+       now = timeval_to_nttime(&fsp->open_time);
+
+       status = smbXsrv_open_create(req->xconn,
+                                    fsp->conn->session_info,
+                                    now,
+                                    &op);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+       fsp->op = op;
+       op->compat = fsp;
+       fsp->fnum = op->local_id;
+
+       fsp->mid = req->mid;
+       req->chain_fsp = fsp;
+
+       DBG_DEBUG("fsp [%s] mid [%" PRIu64"]\n",
+               fsp_str_dbg(fsp), fsp->mid);
+
+       return NT_STATUS_OK;
+}
+
 NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
                  files_struct **result)
 {
@@ -113,24 +146,10 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
 
        GetTimeOfDay(&fsp->open_time);
 
-       if (req) {
-               struct smbXsrv_connection *xconn = req->xconn;
-               struct smbXsrv_open *op = NULL;
-               NTTIME now = timeval_to_nttime(&fsp->open_time);
-
-               status = smbXsrv_open_create(xconn,
-                                            conn->session_info,
-                                            now, &op);
-               if (!NT_STATUS_IS_OK(status)) {
-                       file_free(NULL, fsp);
-                       return status;
-               }
-               fsp->op = op;
-               op->compat = fsp;
-               fsp->fnum = op->local_id;
-       } else {
-               DEBUG(10, ("%s: req==NULL, INTERNAL_OPEN_ONLY, smbXsrv_open "
-                          "allocated\n", __func__));
+       status = fsp_bind_smb(fsp, req);
+       if (!NT_STATUS_IS_OK(status)) {
+               file_free(NULL, fsp);
+               return status;
        }
 
        fsp_set_gen_id(fsp);
@@ -154,11 +173,6 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
        DEBUG(5,("allocated file structure %s (%u used)\n",
                 fsp_fnum_dbg(fsp), (unsigned int)sconn->num_files));
 
-       if (req != NULL) {
-               fsp->mid = req->mid;
-               req->chain_fsp = fsp;
-       }
-
        /* A new fsp invalidates the positive and
          negative fsp_fi_cache as the new fsp is pushed
          at the start of the list and we search from
index 7d59ca5242f7269652340431d6ce658d52c4d363..da85b5cb1a63c3153233c37b8c658be03157c8b4 100644 (file)
@@ -408,6 +408,7 @@ NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
 void fsp_set_gen_id(files_struct *fsp);
 NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
                  files_struct **result);
+NTSTATUS fsp_bind_smb(struct files_struct *fsp, struct smb_request *req);
 void file_close_conn(connection_struct *conn);
 bool file_init_global(void);
 bool file_init(struct smbd_server_connection *sconn);