unix_msg: Use struct initializers
[kamenim/samba-autobuild/.git] / source3 / smbd / files.c
index ef229a4098a2f25a5c25f76afe0059db756678b9..2a0f6cebc0c560079888214bec1bc4460b2c7c76 100644 (file)
@@ -93,7 +93,7 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
 
        GetTimeOfDay(&fsp->open_time);
 
-       if (sconn->conn) {
+       if (req) {
                struct smbXsrv_open *op = NULL;
                NTTIME now = timeval_to_nttime(&fsp->open_time);
 
@@ -108,6 +108,9 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
                op->compat = fsp;
                fsp->fnum = op->local_id;
                fsp->fh->gen_id = smbXsrv_open_hash(op);
+       } else {
+               DEBUG(10, ("%s: req==NULL, INTERNAL_OPEN_ONLY, smbXsrv_open "
+                          "allocated\n", __func__));
        }
 
        /*
@@ -115,11 +118,10 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
         * few NULL checks, so make sure it's initialized with something. to
         * be safe until an audit can be done.
         */
-       status = create_synthetic_smb_fname(fsp, "", NULL, NULL,
-                                           &fsp->fsp_name);
-       if (!NT_STATUS_IS_OK(status)) {
+       fsp->fsp_name = synthetic_smb_fname(fsp, "", NULL, NULL);
+       if (fsp->fsp_name == NULL) {
                file_free(NULL, fsp);
-               return status;
+               return NT_STATUS_NO_MEMORY;
        }
 
        DEBUG(5,("allocated file structure %s (%u used)\n",
@@ -319,8 +321,7 @@ files_struct *file_find_dif(struct smbd_server_connection *sconn,
                        }
                        /* Paranoia check. */
                        if ((fsp->fh->fd == -1) &&
-                           (fsp->oplock_type != NO_OPLOCK) &&
-                           (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK)) {
+                           (fsp->oplock_type != NO_OPLOCK)) {
                                DEBUG(0,("file_find_dif: file %s file_id = "
                                         "%s, gen = %u oplock_type = %u is a "
                                         "stat open with oplock type !\n",
@@ -582,22 +583,15 @@ files_struct *file_fsp(struct smb_request *req, uint16 fid)
        return fsp;
 }
 
-struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
-                                  uint64_t persistent_id,
-                                  uint64_t volatile_id)
+struct files_struct *file_fsp_get(struct smbd_smb2_request *smb2req,
+                                 uint64_t persistent_id,
+                                 uint64_t volatile_id)
 {
        struct smbXsrv_open *op;
        NTSTATUS status;
        NTTIME now = 0;
        struct files_struct *fsp;
 
-       if (smb2req->compat_chain_fsp != NULL) {
-               if (smb2req->compat_chain_fsp->deferred_close) {
-                       return NULL;
-               }
-               return smb2req->compat_chain_fsp;
-       }
-
        now = timeval_to_nttime(&smb2req->request_time);
 
        status = smb2srv_open_lookup(smb2req->sconn->conn,
@@ -636,6 +630,27 @@ struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
                return NULL;
        }
 
+       return fsp;
+}
+
+struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
+                                  uint64_t persistent_id,
+                                  uint64_t volatile_id)
+{
+       struct files_struct *fsp;
+
+       if (smb2req->compat_chain_fsp != NULL) {
+               if (smb2req->compat_chain_fsp->deferred_close) {
+                       return NULL;
+               }
+               return smb2req->compat_chain_fsp;
+       }
+
+       fsp = file_fsp_get(smb2req, persistent_id, volatile_id);
+       if (fsp == NULL) {
+               return NULL;
+       }
+
        smb2req->compat_chain_fsp = fsp;
        return fsp;
 }
@@ -683,23 +698,24 @@ NTSTATUS dup_file_fsp(struct smb_request *req, files_struct *from,
 NTSTATUS file_name_hash(connection_struct *conn,
                        const char *name, uint32_t *p_name_hash)
 {
-       char *fullpath = NULL;
+       char tmpbuf[PATH_MAX];
+       char *fullpath, *to_free;
+       size_t len;
 
        /* Set the hash of the full pathname. */
-       fullpath = talloc_asprintf(talloc_tos(),
-                       "%s/%s",
-                       conn->connectpath,
-                       name);
-       if (!fullpath) {
+
+       len = full_path_tos(conn->connectpath, name, tmpbuf, sizeof(tmpbuf),
+                           &fullpath, &to_free);
+       if (len == -1) {
                return NT_STATUS_NO_MEMORY;
        }
-       *p_name_hash = hash(fullpath, talloc_get_size(fullpath), 0);
+       *p_name_hash = hash(fullpath, len+1, 0);
 
        DEBUG(10,("file_name_hash: %s hash 0x%x\n",
-               fullpath,
+                 fullpath,
                (unsigned int)*p_name_hash ));
 
-       TALLOC_FREE(fullpath);
+       TALLOC_FREE(to_free);
        return NT_STATUS_OK;
 }
 
@@ -709,12 +725,11 @@ NTSTATUS file_name_hash(connection_struct *conn,
 NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
                           const struct smb_filename *smb_fname_in)
 {
-       NTSTATUS status;
        struct smb_filename *smb_fname_new;
 
-       status = copy_smb_filename(fsp, smb_fname_in, &smb_fname_new);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
+       smb_fname_new = cp_smb_filename(fsp, smb_fname_in);
+       if (smb_fname_new == NULL) {
+               return NT_STATUS_NO_MEMORY;
        }
 
        TALLOC_FREE(fsp->fsp_name);