s3 file_access: Convert some more functions over to use smb_filneame
[ira/wip.git] / source3 / smbd / nttrans.c
index d2a052dd559f5dda1ddf463de93711067c915daa..04767bf5590d8c5ca574b053a06812beb39cf284 100644 (file)
@@ -317,6 +317,18 @@ bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname)
        return smb_fname->stream_name;
 }
 
+/****************************************************************************
+ Returns true if the filename's stream == "::$DATA"
+ ***************************************************************************/
+bool is_ntfs_default_stream_smb_fname(const struct smb_filename *smb_fname)
+{
+       if (!is_ntfs_stream_smb_fname(smb_fname)) {
+               return false;
+       }
+
+       return StrCaseCmp(smb_fname->stream_name, "::$DATA") == 0;
+}
+
 /****************************************************************************
  Reply to an NT create and X call on a pipe
 ****************************************************************************/
@@ -519,10 +531,11 @@ void reply_ntcreate_and_X(struct smb_request *req)
                        ? BATCH_OPLOCK : 0;
        }
 
-       status = resolve_dfspath(ctx,
+       status = filename_convert(ctx,
                                conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
+                               &smb_fname,
                                &fname);
 
        if (!NT_STATUS_IS_OK(status)) {
@@ -536,12 +549,6 @@ void reply_ntcreate_and_X(struct smb_request *req)
                goto out;
        }
 
-       status = unix_convert(ctx, conn, fname, &smb_fname, 0);
-       if (!NT_STATUS_IS_OK(status)) {
-               reply_nterror(req, status);
-               goto out;
-       }
-
        status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                req,                                    /* req */
@@ -666,7 +673,7 @@ void reply_ntcreate_and_X(struct smb_request *req)
                uint32 perms = 0;
                p += 25;
                if (fsp->is_directory ||
-                   can_write_to_file(conn, fsp->fsp_name, &smb_fname->st)) {
+                   can_write_to_file(conn, smb_fname)) {
                        perms = FILE_GENERIC_ALL;
                } else {
                        perms = FILE_GENERIC_READ|FILE_EXECUTE;
@@ -1005,10 +1012,11 @@ static void call_nt_transact_create(connection_struct *conn,
                goto out;
        }
 
-       status = resolve_dfspath(ctx,
+       status = filename_convert(ctx,
                                conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
+                               &smb_fname,
                                &fname);
 
        if (!NT_STATUS_IS_OK(status)) {
@@ -1022,12 +1030,6 @@ static void call_nt_transact_create(connection_struct *conn,
                goto out;
        }
 
-       status = unix_convert(ctx, conn, fname, &smb_fname, 0);
-       if (!NT_STATUS_IS_OK(status)) {
-               reply_nterror(req, status);
-               goto out;
-       }
-
        oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
        if (oplock_request) {
                oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
@@ -1153,7 +1155,7 @@ static void call_nt_transact_create(connection_struct *conn,
                uint32 perms = 0;
                p += 25;
                if (fsp->is_directory ||
-                   can_write_to_file(conn, fsp->fsp_name, &smb_fname->st)) {
+                   can_write_to_file(conn, smb_fname)) {
                        perms = FILE_GENERIC_ALL;
                } else {
                        perms = FILE_GENERIC_READ|FILE_EXECUTE;
@@ -1199,12 +1201,10 @@ void reply_ntcancel(struct smb_request *req)
 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
                                connection_struct *conn,
                                struct smb_request *req,
-                               const char *oldname_in,
-                               const char *newname_in,
+                               struct smb_filename *smb_fname_src,
+                               struct smb_filename *smb_fname_dst,
                                uint32 attrs)
 {
-       struct smb_filename *smb_fname_src = NULL;
-       struct smb_filename *smb_fname_dst = NULL;
        char *oldname = NULL;
        char *newname = NULL;
        files_struct *fsp1,*fsp2;
@@ -1219,16 +1219,6 @@ static NTSTATUS copy_internals(TALLOC_CTX *ctx,
                goto out;
        }
 
-       status = unix_convert(ctx, conn, oldname_in, &smb_fname_src, 0);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto out;
-       }
-
-       status = check_name(conn, smb_fname_src->base_name);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto out;
-       }
-
         /* Source must already exist. */
        if (!VALID_STAT(smb_fname_src->st)) {
                status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
@@ -1247,16 +1237,6 @@ static NTSTATUS copy_internals(TALLOC_CTX *ctx,
                goto out;
        }
 
-       status = unix_convert(ctx, conn, newname_in, &smb_fname_dst, 0);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto out;
-       }
-
-       status = check_name(conn, smb_fname_dst->base_name);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto out;
-       }
-
        /* Disallow if dst file already exists. */
        if (VALID_STAT(smb_fname_dst->st)) {
                status = NT_STATUS_OBJECT_NAME_COLLISION;
@@ -1269,12 +1249,6 @@ static NTSTATUS copy_internals(TALLOC_CTX *ctx,
                goto out;
        }
 
-       /* Ensure this is within the share. */
-       status = check_reduced_name(conn, smb_fname_src->base_name);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto out;
-       }
-
        DEBUG(10,("copy_internals: doing file copy %s to %s\n",
                  smb_fname_str_dbg(smb_fname_src),
                  smb_fname_str_dbg(smb_fname_dst)));
@@ -1368,8 +1342,6 @@ static NTSTATUS copy_internals(TALLOC_CTX *ctx,
                        smb_fname_str_dbg(smb_fname_dst)));
        }
 
-       TALLOC_FREE(smb_fname_src);
-       TALLOC_FREE(smb_fname_dst);
        TALLOC_FREE(oldname);
        TALLOC_FREE(newname);
 
@@ -1383,6 +1355,8 @@ static NTSTATUS copy_internals(TALLOC_CTX *ctx,
 void reply_ntrename(struct smb_request *req)
 {
        connection_struct *conn = req->conn;
+       struct smb_filename *smb_fname_old = NULL;
+       struct smb_filename *smb_fname_new = NULL;
        char *oldname = NULL;
        char *newname = NULL;
        const char *p;
@@ -1428,9 +1402,10 @@ void reply_ntrename(struct smb_request *req)
                return;
        }
 
-       status = resolve_dfspath(ctx, conn,
+       status = filename_convert(ctx, conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                oldname,
+                               &smb_fname_old,
                                &oldname);
        if (!NT_STATUS_IS_OK(status)) {
                if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
@@ -1444,9 +1419,10 @@ void reply_ntrename(struct smb_request *req)
                return;
        }
 
-       status = resolve_dfspath(ctx, conn,
+       status = filename_convert(ctx, conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                newname,
+                               &smb_fname_new,
                                &newname);
        if (!NT_STATUS_IS_OK(status)) {
                if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
@@ -1482,8 +1458,8 @@ void reply_ntrename(struct smb_request *req)
                        } else {
                                status = hardlink_internals(ctx,
                                                conn,
-                                               oldname,
-                                               newname);
+                                               smb_fname_old,
+                                               smb_fname_new);
                        }
                        break;
                case RENAME_FLAG_COPY:
@@ -1491,8 +1467,10 @@ void reply_ntrename(struct smb_request *req)
                                /* No wildcards. */
                                status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
                        } else {
-                               status = copy_internals(ctx, conn, req, oldname,
-                                                       newname, attrs);
+                               status = copy_internals(ctx, conn, req,
+                                                       smb_fname_old,
+                                                       smb_fname_new,
+                                                       attrs);
                        }
                        break;
                case RENAME_FLAG_MOVE_CLUSTER_INFORMATION: