Remove reply_unixerror() - no longer needed. Should make Metze's refactoring a lot...
[samba.git] / source3 / smbd / trans2.c
index 2c74c8f49e3785cd746d1919a9d8244b8336a8b0..6a18f0f710260b3bdcd2642aa0497c2bba70829f 100644 (file)
@@ -964,7 +964,7 @@ static void call_trans2open(connection_struct *conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
                                &smb_fname,
-                               &fname);
+                               NULL);
        if (!NT_STATUS_IS_OK(status)) {
                if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
                        reply_botherror(req,
@@ -981,7 +981,8 @@ static void call_trans2open(connection_struct *conn,
                goto out;
        }
 
-       if (!map_open_params_to_ntcreate(fname, deny_mode, open_ofun,
+       if (!map_open_params_to_ntcreate(smb_fname->base_name, deny_mode,
+                               open_ofun,
                                &access_mask,
                                &share_mode,
                                &create_disposition,
@@ -1047,7 +1048,7 @@ static void call_trans2open(connection_struct *conn,
        }
 
        size = get_file_size_stat(&smb_fname->st);
-       fattr = dos_mode(conn, fsp->fsp_name, &smb_fname->st);
+       fattr = dos_mode(conn, smb_fname);
        mtime = convert_timespec_to_time_t(smb_fname->st.st_ex_mtime);
        inode = smb_fname->st.st_ex_ino;
        if (fattr & aDIR) {
@@ -1388,6 +1389,8 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
 
                if (got_match) {
                        bool isdots = (ISDOT(dname) || ISDOTDOT(dname));
+                       struct smb_filename *smb_fname = NULL;
+                       NTSTATUS status;
 
                        if (dont_descend && !isdots) {
                                TALLOC_FREE(fname);
@@ -1412,25 +1415,41 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                                return False;
                        }
 
+                       /* A dirent from dptr_ReadDirName isn't a stream. */
+                       status = create_synthetic_smb_fname(ctx, pathreal,
+                                                           NULL, &sbuf,
+                                                           &smb_fname);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               TALLOC_FREE(fname);
+                               return false;
+                       }
+
                        if (INFO_LEVEL_IS_UNIX(info_level)) {
-                               if (vfs_lstat_smb_fname(conn, pathreal,
-                                                       &sbuf) != 0) {
-                                       DEBUG(5,("get_lanman2_dir_entry:Couldn't lstat [%s] (%s)\n",
-                                               pathreal,strerror(errno)));
+                               if (SMB_VFS_LSTAT(conn, smb_fname) != 0) {
+                                       DEBUG(5,("get_lanman2_dir_entry: "
+                                                "Couldn't lstat [%s] (%s)\n",
+                                                smb_fname_str_dbg(smb_fname),
+                                                strerror(errno)));
+                                       TALLOC_FREE(smb_fname);
                                        TALLOC_FREE(pathreal);
                                        TALLOC_FREE(fname);
                                        continue;
                                }
-                       } else if (!VALID_STAT(sbuf) &&
-                                  vfs_stat_smb_fname(conn, pathreal,
-                                                     &sbuf) != 0) {
+                       } else if (!VALID_STAT(smb_fname->st) &&
+                                  SMB_VFS_STAT(conn, smb_fname) != 0) {
                                /* Needed to show the msdfs symlinks as
                                 * directories */
 
-                               ms_dfs_link = check_msdfs_link(conn, pathreal, &sbuf);
+                               ms_dfs_link =
+                                   check_msdfs_link(conn,
+                                                    smb_fname->base_name,
+                                                    &smb_fname->st);
                                if (!ms_dfs_link) {
-                                       DEBUG(5,("get_lanman2_dir_entry:Couldn't stat [%s] (%s)\n",
-                                               pathreal,strerror(errno)));
+                                       DEBUG(5,("get_lanman2_dir_entry: "
+                                                "Couldn't stat [%s] (%s)\n",
+                                                smb_fname_str_dbg(smb_fname),
+                                                strerror(errno)));
+                                       TALLOC_FREE(smb_fname);
                                        TALLOC_FREE(pathreal);
                                        TALLOC_FREE(fname);
                                        continue;
@@ -1438,38 +1457,43 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                        }
 
                        if (ms_dfs_link) {
-                               mode = dos_mode_msdfs(conn,pathreal,&sbuf);
+                               mode = dos_mode_msdfs(conn, smb_fname);
                        } else {
-                               mode = dos_mode(conn,pathreal,&sbuf);
+                               mode = dos_mode(conn, smb_fname);
                        }
 
                        if (!dir_check_ftype(conn,mode,dirtype)) {
                                DEBUG(5,("get_lanman2_dir_entry: [%s] attribs didn't match %x\n",fname,dirtype));
+                               TALLOC_FREE(smb_fname);
                                TALLOC_FREE(pathreal);
                                TALLOC_FREE(fname);
                                continue;
                        }
 
                        if (!(mode & aDIR)) {
-                               file_size = get_file_size_stat(&sbuf);
+                               file_size = get_file_size_stat(&smb_fname->st);
                        }
-                       allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn,NULL,&sbuf);
-
-                       mdate_ts = sbuf.st_ex_mtime;
-                       adate_ts = sbuf.st_ex_atime;
-                       create_date_ts = sbuf.st_ex_btime;
+                       allocation_size =
+                           SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st);
 
                        if (ask_sharemode) {
                                struct timespec write_time_ts;
                                struct file_id fileid;
 
-                               fileid = vfs_file_id_from_sbuf(conn, &sbuf);
+                               ZERO_STRUCT(write_time_ts);
+                               fileid = vfs_file_id_from_sbuf(conn,
+                                                              &smb_fname->st);
                                get_file_infos(fileid, NULL, &write_time_ts);
                                if (!null_timespec(write_time_ts)) {
-                                       mdate_ts = write_time_ts;
+                                       update_stat_ex_mtime(&smb_fname->st,
+                                                            write_time_ts);
                                }
                        }
 
+                       mdate_ts = smb_fname->st.st_ex_mtime;
+                       adate_ts = smb_fname->st.st_ex_atime;
+                       create_date_ts = smb_fname->st.st_ex_btime;
+
                        if (lp_dos_filetime_resolution(SNUM(conn))) {
                                dos_filetime_timespec(&create_date_ts);
                                dos_filetime_timespec(&mdate_ts);
@@ -1481,11 +1505,14 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                        adate = convert_timespec_to_time_t(adate_ts);
 
                        DEBUG(5,("get_lanman2_dir_entry: found %s fname=%s\n",
-                               pathreal,fname));
+                                smb_fname_str_dbg(smb_fname), fname));
 
                        found = True;
 
                        dptr_DirCacheAdd(conn->dirptr, dname, curr_dirpos);
+                       sbuf = smb_fname->st;
+
+                       TALLOC_FREE(smb_fname);
                }
 
                if (!found)
@@ -2670,7 +2697,7 @@ static void call_trans2qfsinfo(connection_struct *conn,
                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
                        data_len = 18;
                        if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
-                               reply_unixerror(req, ERRHRD, ERRgeneral);
+                               reply_nterror(req, map_nt_error_from_unix(errno));
                                return;
                        }
 
@@ -2791,7 +2818,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st.st_ex_dev, (u
                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
                        data_len = 24;
                        if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
-                               reply_unixerror(req, ERRHRD, ERRgeneral);
+                               reply_nterror(req, map_nt_error_from_unix(errno));
                                return;
                        }
                        block_size = lp_block_size(snum);
@@ -2824,7 +2851,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
                        data_len = 32;
                        if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
-                               reply_unixerror(req, ERRHRD, ERRgeneral);
+                               reply_nterror(req, map_nt_error_from_unix(errno));
                                return;
                        }
                        block_size = lp_block_size(snum);
@@ -3965,7 +3992,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                                                 "(%s)\n",
                                                 smb_fname_str_dbg(smb_fname),
                                                 strerror(errno)));
-                                       reply_unixerror(req,ERRDOS,ERRbadpath);
+                                       reply_nterror(req,map_nt_error_from_unix(errno));
                                        return;
                                }
                        } else if (SMB_VFS_STAT(conn, smb_fname)) {
@@ -3973,7 +4000,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                                         "SMB_VFS_STAT of %s failed (%s)\n",
                                         smb_fname_str_dbg(smb_fname),
                                         strerror(errno)));
-                               reply_unixerror(req, ERRDOS, ERRbadpath);
+                               reply_nterror(req, map_nt_error_from_unix(errno));
                                return;
                        }
 
@@ -3990,7 +4017,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                        if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
                                DEBUG(3, ("fstat of fnum %d failed (%s)\n",
                                          fsp->fnum, strerror(errno)));
-                               reply_unixerror(req, ERRDOS, ERRbadfid);
+                               reply_nterror(req, map_nt_error_from_unix(errno));
                                return;
                        }
                        pos = fsp->fh->position_information;
@@ -4063,8 +4090,8 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                                                 "(%s)\n",
                                                 smb_fname_str_dbg(smb_fname_base),
                                                 strerror(errno)));
+                                       reply_nterror(req,map_nt_error_from_unix(errno));
                                        TALLOC_FREE(smb_fname_base);
-                                       reply_unixerror(req,ERRDOS,ERRbadpath);
                                        return;
                                }
                        } else {
@@ -4074,8 +4101,8 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                                                 "(%s)\n",
                                                 smb_fname_str_dbg(smb_fname_base),
                                                 strerror(errno)));
+                                       reply_nterror(req,map_nt_error_from_unix(errno));
                                        TALLOC_FREE(smb_fname_base);
-                                       reply_unixerror(req,ERRDOS,ERRbadpath);
                                        return;
                                }
                        }
@@ -4097,7 +4124,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                                         "SMB_VFS_LSTAT of %s failed (%s)\n",
                                         smb_fname_str_dbg(smb_fname),
                                         strerror(errno)));
-                               reply_unixerror(req, ERRDOS, ERRbadpath);
+                               reply_nterror(req,map_nt_error_from_unix(errno));
                                return;
                        }
 
@@ -4112,7 +4139,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                                         "SMB_VFS_STAT of %s failed (%s)\n",
                                         smb_fname_str_dbg(smb_fname),
                                         strerror(errno)));
-                               reply_unixerror(req, ERRDOS, ERRbadpath);
+                               reply_nterror(req,map_nt_error_from_unix(errno));
                                return;
                        }
                }
@@ -4136,16 +4163,16 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
        DEBUG(3,("call_trans2qfilepathinfo %s (fnum = %d) level=%d call=%d total_data=%d\n",
                fname,fsp ? fsp->fnum : -1, info_level,tran_call,total_data));
 
-       p = strrchr_m(fname,'/');
+       p = strrchr_m(smb_fname->base_name,'/');
        if (!p)
-               base_name = fname;
+               base_name = smb_fname->base_name;
        else
                base_name = p+1;
 
        if (ms_dfs_link) {
-               mode = dos_mode_msdfs(conn,fname,&sbuf);
+               mode = dos_mode_msdfs(conn, smb_fname);
        } else {
-               mode = dos_mode(conn,fname,&sbuf);
+               mode = dos_mode(conn, smb_fname);
        }
        if (!mode)
                mode = FILE_ATTRIBUTE_NORMAL;
@@ -4244,10 +4271,6 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        dstart = pdata;
        dend = dstart + data_size - 1;
 
-       create_time_ts = sbuf.st_ex_btime;
-       mtime_ts = sbuf.st_ex_mtime;
-       atime_ts = sbuf.st_ex_atime;
-
        allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&sbuf);
 
        if (!fsp) {
@@ -4261,9 +4284,13 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        }
 
        if (!null_timespec(write_time_ts) && !INFO_LEVEL_IS_UNIX(info_level)) {
-               mtime_ts = write_time_ts;
+               update_stat_ex_mtime(&sbuf, write_time_ts);
        }
 
+       create_time_ts = sbuf.st_ex_btime;
+       mtime_ts = sbuf.st_ex_mtime;
+       atime_ts = sbuf.st_ex_atime;
+
        if (lp_dos_filetime_resolution(SNUM(conn))) {
                dos_filetime_timespec(&create_time_ts);
                dos_filetime_timespec(&mtime_ts);
@@ -4673,19 +4700,18 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                DEBUG(10,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_LINK\n"));
 #ifdef S_ISLNK
                                if(!S_ISLNK(sbuf.st_ex_mode)) {
-                                       reply_unixerror(req, ERRSRV,
+                                       reply_doserror(req, ERRSRV,
                                                        ERRbadlink);
                                        return;
                                }
 #else
-                               reply_unixerror(req, ERRDOS, ERRbadlink);
+                               reply_doserror(req, ERRDOS, ERRbadlink);
                                return;
 #endif
                                len = SMB_VFS_READLINK(conn,fullpathname,
                                                buffer, PATH_MAX);
                                if (len == -1) {
-                                       reply_unixerror(req, ERRDOS,
-                                                       ERRnoaccess);
+                                       reply_nterror(req, map_nt_error_from_unix(errno));
                                        return;
                                }
                                buffer[len] = 0;
@@ -4935,27 +4961,28 @@ NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
 
 NTSTATUS smb_set_file_time(connection_struct *conn,
                           files_struct *fsp,
-                          const char *fname,
-                          const SMB_STRUCT_STAT *psbuf,
+                          const struct smb_filename *smb_fname,
                           struct smb_file_time *ft,
                           bool setting_write_time)
 {
+       struct smb_filename *smb_fname_base = NULL;
        uint32 action =
                FILE_NOTIFY_CHANGE_LAST_ACCESS
                |FILE_NOTIFY_CHANGE_LAST_WRITE;
+       NTSTATUS status;
 
-       if (!VALID_STAT(*psbuf)) {
+       if (!VALID_STAT(smb_fname->st)) {
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
        /* get some defaults (no modifications) if any info is zero or -1. */
        if (null_timespec(ft->atime)) {
-               ft->atime= psbuf->st_ex_atime;
+               ft->atime= smb_fname->st.st_ex_atime;
                action &= ~FILE_NOTIFY_CHANGE_LAST_ACCESS;
        }
 
        if (null_timespec(ft->mtime)) {
-               ft->mtime = psbuf->st_ex_mtime;
+               ft->mtime = smb_fname->st.st_ex_mtime;
                action &= ~FILE_NOTIFY_CHANGE_LAST_WRITE;
        }
 
@@ -4979,8 +5006,8 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
         */
 
        {
-               struct timespec mts = psbuf->st_ex_mtime;
-               struct timespec ats = psbuf->st_ex_atime;
+               struct timespec mts = smb_fname->st.st_ex_mtime;
+               struct timespec ats = smb_fname->st.st_ex_atime;
                if ((timespec_compare(&ft->atime, &ats) == 0) &&
                    (timespec_compare(&ft->mtime, &mts) == 0)) {
                        return NT_STATUS_OK;
@@ -5009,23 +5036,30 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
                                set_sticky_write_time_fsp(fsp, ft->mtime);
                        }
                } else {
-                       set_sticky_write_time_path(conn, fname,
-                                           vfs_file_id_from_sbuf(conn, psbuf),
-                                           ft->mtime);
+                       set_sticky_write_time_path(
+                               vfs_file_id_from_sbuf(conn, &smb_fname->st),
+                               ft->mtime);
                }
        }
 
        DEBUG(10,("smb_set_file_time: setting utimes to modified values.\n"));
 
-       if (fsp && fsp->base_fsp) {
-               fname = fsp->base_fsp->fsp_name;
+       /* Always call ntimes on the base, even if a stream was passed in. */
+       status = create_synthetic_smb_fname(talloc_tos(), smb_fname->base_name,
+                                           NULL, &smb_fname->st,
+                                           &smb_fname_base);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
        }
 
-       if(file_ntimes(conn, fname, ft, psbuf)!=0) {
+       if(file_ntimes(conn, smb_fname_base, ft)!=0) {
+               TALLOC_FREE(smb_fname_base);
                return map_nt_error_from_unix(errno);
        }
-       notify_fname(conn, NOTIFY_ACTION_MODIFIED, action, fname);
+       TALLOC_FREE(smb_fname_base);
 
+       notify_fname(conn, NOTIFY_ACTION_MODIFIED, action,
+                    smb_fname->base_name);
        return NT_STATUS_OK;
 }
 
@@ -5034,25 +5068,26 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
-                               files_struct *fsp,
-                               const char *fname,
-                               SMB_STRUCT_STAT *psbuf,
-                               uint32 dosmode)
+                                    const struct smb_filename *smb_fname,
+                                    uint32 dosmode)
 {
-       if (!VALID_STAT(*psbuf)) {
+       struct smb_filename *smb_fname_base = NULL;
+       NTSTATUS status;
+
+       if (!VALID_STAT(smb_fname->st)) {
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
-       if (fsp) {
-               if (fsp->base_fsp) {
-                       fname = fsp->base_fsp->fsp_name;
-               } else {
-                       fname = fsp->fsp_name;
-               }
+       /* Always operate on the base_name, even if a stream was passed in. */
+       status = create_synthetic_smb_fname(talloc_tos(), smb_fname->base_name,
+                                           NULL, &smb_fname->st,
+                                           &smb_fname_base);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
        }
 
        if (dosmode) {
-               if (S_ISDIR(psbuf->st_ex_mode)) {
+               if (S_ISDIR(smb_fname_base->st.st_ex_mode)) {
                        dosmode |= aDIR;
                } else {
                        dosmode &= ~aDIR;
@@ -5062,29 +5097,25 @@ static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
        DEBUG(6,("smb_set_file_dosmode: dosmode: 0x%x\n", (unsigned int)dosmode));
 
        /* check the mode isn't different, before changing it */
-       if ((dosmode != 0) && (dosmode != dos_mode(conn, fname, psbuf))) {
-               struct smb_filename *smb_fname = NULL;
-               NTSTATUS status;
-
-               status = create_synthetic_smb_fname_split(talloc_tos(), fname,
-                                                         psbuf, &smb_fname);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return status;
-               }
-
-               DEBUG(10,("smb_set_file_dosmode: file %s : setting dos mode 0x%x\n",
-                                       fname, (unsigned int)dosmode ));
-
-               if(file_set_dosmode(conn, smb_fname, dosmode, NULL, false)) {
-                       DEBUG(2,("smb_set_file_dosmode: file_set_dosmode of %s failed (%s)\n",
-                                               fname, strerror(errno)));
-                       TALLOC_FREE(smb_fname);
-                       return map_nt_error_from_unix(errno);
+       if ((dosmode != 0) && (dosmode != dos_mode(conn, smb_fname_base))) {
+               DEBUG(10,("smb_set_file_dosmode: file %s : setting dos mode "
+                         "0x%x\n", smb_fname_str_dbg(smb_fname_base),
+                         (unsigned int)dosmode));
+
+               if(file_set_dosmode(conn, smb_fname_base, dosmode, NULL,
+                                   false)) {
+                       DEBUG(2,("smb_set_file_dosmode: file_set_dosmode of "
+                                "%s failed (%s)\n",
+                                smb_fname_str_dbg(smb_fname_base),
+                                strerror(errno)));
+                       status = map_nt_error_from_unix(errno);
+                       goto out;
                }
-               *psbuf = smb_fname->st;
-               TALLOC_FREE(smb_fname);
        }
-       return NT_STATUS_OK;
+       status = NT_STATUS_OK;
+ out:
+       TALLOC_FREE(smb_fname_base);
+       return status;
 }
 
 /****************************************************************************
@@ -5218,8 +5249,7 @@ static NTSTATUS smb_set_file_disposition_info(connection_struct *conn,
                                const char *pdata,
                                int total_data,
                                files_struct *fsp,
-                               const char *fname,
-                               SMB_STRUCT_STAT *psbuf)
+                               const struct smb_filename *smb_fname)
 {
        NTSTATUS status = NT_STATUS_OK;
        bool delete_on_close;
@@ -5234,11 +5264,11 @@ static NTSTATUS smb_set_file_disposition_info(connection_struct *conn,
        }
 
        delete_on_close = (CVAL(pdata,0) ? True : False);
-       dosmode = dos_mode(conn, fname, psbuf);
+       dosmode = dos_mode(conn, smb_fname);
 
        DEBUG(10,("smb_set_file_disposition_info: file %s, dosmode = %u, "
                "delete_on_close = %u\n",
-               fsp->fsp_name,
+               smb_fname_str_dbg(smb_fname),
                (unsigned int)dosmode,
                (unsigned int)delete_on_close ));
 
@@ -5524,7 +5554,7 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                }
        } else {
                /* newname must *not* be a stream name. */
-               if (is_ntfs_stream_name(newname)) {
+               if (newname[0] == ':') {
                        return NT_STATUS_NOT_SUPPORTED;
                }
 
@@ -5784,8 +5814,7 @@ static NTSTATUS smb_set_info_standard(connection_struct *conn,
                                        const char *pdata,
                                        int total_data,
                                        files_struct *fsp,
-                                       const char *fname,
-                                       const SMB_STRUCT_STAT *psbuf)
+                                       const struct smb_filename *smb_fname)
 {
        struct smb_file_time ft;
        ZERO_STRUCT(ft);
@@ -5804,14 +5833,9 @@ static NTSTATUS smb_set_info_standard(connection_struct *conn,
        ft.mtime = interpret_long_date(pdata + 16);
 
        DEBUG(10,("smb_set_info_standard: file %s\n",
-               fname ? fname : fsp->fsp_name ));
+                 smb_fname_str_dbg(smb_fname)));
 
-       return smb_set_file_time(conn,
-                               fsp,
-                               fname,
-                               psbuf,
-                               &ft,
-                               true);
+       return smb_set_file_time(conn, fsp, smb_fname, &ft, true);
 }
 
 /****************************************************************************
@@ -5822,8 +5846,7 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
                                        const char *pdata,
                                        int total_data,
                                        files_struct *fsp,
-                                       const char *fname,
-                                       SMB_STRUCT_STAT *psbuf)
+                                       const struct smb_filename *smb_fname)
 {
        /* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
        struct timespec write_time;
@@ -5841,7 +5864,7 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
 
        /* Set the attributes */
        dosmode = IVAL(pdata,32);
-       status = smb_set_file_dosmode(conn, fsp, fname, psbuf, dosmode);
+       status = smb_set_file_dosmode(conn, smb_fname, dosmode);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -5873,15 +5896,11 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
                }
        }
 
-       DEBUG(10,("smb_set_file_basic_info: file %s\n",
-               fname ? fname : fsp->fsp_name ));
+       DEBUG(10, ("smb_set_file_basic_info: file %s\n",
+                  smb_fname_str_dbg(smb_fname)));
 
-       return smb_set_file_time(conn,
-                               fsp,
-                               fname,
-                               psbuf,
-                               &ft,
-                               setting_write_time);
+       return smb_set_file_time(conn, fsp, smb_fname, &ft,
+                                setting_write_time);
 }
 
 /****************************************************************************
@@ -5893,15 +5912,13 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
                                        const char *pdata,
                                        int total_data,
                                        files_struct *fsp,
-                                       const char *fname,
-                                       SMB_STRUCT_STAT *psbuf)
+                                       struct smb_filename *smb_fname)
 {
-       struct smb_filename *smb_fname = NULL;
        uint64_t allocation_size = 0;
        NTSTATUS status = NT_STATUS_OK;
        files_struct *new_fsp = NULL;
 
-       if (!VALID_STAT(*psbuf)) {
+       if (!VALID_STAT(smb_fname->st)) {
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
@@ -5919,20 +5936,22 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
        }
 #endif /* LARGE_SMB_OFF_T */
 
-       DEBUG(10,("smb_set_file_allocation_info: Set file allocation info for file %s to %.0f\n",
-                       fname, (double)allocation_size ));
+       DEBUG(10,("smb_set_file_allocation_info: Set file allocation info for "
+                 "file %s to %.0f\n", smb_fname_str_dbg(smb_fname),
+                 (double)allocation_size));
 
        if (allocation_size) {
                allocation_size = smb_roundup(conn, allocation_size);
        }
 
-       DEBUG(10,("smb_set_file_allocation_info: file %s : setting new allocation size to %.0f\n",
-                       fname, (double)allocation_size ));
+       DEBUG(10,("smb_set_file_allocation_info: file %s : setting new "
+                 "allocation size to %.0f\n", smb_fname_str_dbg(smb_fname),
+                 (double)allocation_size));
 
        if (fsp && fsp->fh->fd != -1) {
                /* Open file handle. */
                /* Only change if needed. */
-               if (allocation_size != get_file_size_stat(psbuf)) {
+               if (allocation_size != get_file_size_stat(&smb_fname->st)) {
                        if (vfs_allocate_file_space(fsp, allocation_size) == -1) {
                                return map_nt_error_from_unix(errno);
                        }
@@ -5947,14 +5966,7 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
        }
 
        /* Pathname or stat or directory file. */
-
-       status = create_synthetic_smb_fname_split(talloc_tos(), fname, psbuf,
-                                                 &smb_fname);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-        status = SMB_VFS_CREATE_FILE(
+       status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                req,                                    /* req */
                0,                                      /* root_dir_fid */
@@ -5972,16 +5984,13 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
                &new_fsp,                               /* result */
                NULL);                                  /* pinfo */
 
-       *psbuf = smb_fname->st;
-       TALLOC_FREE(smb_fname);
-
        if (!NT_STATUS_IS_OK(status)) {
                /* NB. We check for open_was_deferred in the caller. */
                return status;
        }
 
        /* Only change if needed. */
-       if (allocation_size != get_file_size_stat(psbuf)) {
+       if (allocation_size != get_file_size_stat(&smb_fname->st)) {
                if (vfs_allocate_file_space(new_fsp, allocation_size) == -1) {
                        status = map_nt_error_from_unix(errno);
                        close_file(req, new_fsp, NORMAL_CLOSE);
@@ -6354,8 +6363,7 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
 
        status = smb_set_file_time(conn,
                                fsp,
-                               smb_fname->base_name,
-                               &sbuf,
+                               smb_fname,
                                &ft,
                                false);
        if (modify_mtime) {
@@ -6752,10 +6760,8 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
                                 struct smb_request *req,
                                const char *pdata,
                                int total_data,
-                               const char *fname,
-                               SMB_STRUCT_STAT *psbuf)
+                               struct smb_filename *smb_fname)
 {
-       struct smb_filename *smb_fname = NULL;
        NTSTATUS status = NT_STATUS_OK;
        files_struct *fsp = NULL;
        uint16 flags = 0;
@@ -6771,29 +6777,23 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
 
        flags = SVAL(pdata,0);
 
-       if (!VALID_STAT(*psbuf)) {
+       if (!VALID_STAT(smb_fname->st)) {
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
        if ((flags == SMB_POSIX_UNLINK_DIRECTORY_TARGET) &&
-                       !VALID_STAT_OF_DIR(*psbuf)) {
+                       !VALID_STAT_OF_DIR(smb_fname->st)) {
                return NT_STATUS_NOT_A_DIRECTORY;
        }
 
        DEBUG(10,("smb_posix_unlink: %s %s\n",
                (flags == SMB_POSIX_UNLINK_DIRECTORY_TARGET) ? "directory" : "file",
-               fname));
+               smb_fname_str_dbg(smb_fname)));
 
-       if (VALID_STAT_OF_DIR(*psbuf)) {
+       if (VALID_STAT_OF_DIR(smb_fname->st)) {
                create_options |= FILE_DIRECTORY_FILE;
        }
 
-       status = create_synthetic_smb_fname_split(talloc_tos(), fname, psbuf,
-                                                 &smb_fname);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
         status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                req,                                    /* req */
@@ -6812,9 +6812,6 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
                &fsp,                                   /* result */
                &info);                                 /* pinfo */
 
-       *psbuf = smb_fname->st;
-       TALLOC_FREE(smb_fname);
-
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -6858,8 +6855,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
                                                &del,
                                                1,
                                                fsp,
-                                               fname,
-                                               psbuf);
+                                               smb_fname);
 
        if (!NT_STATUS_IS_OK(status)) {
                close_file(req, fsp, NORMAL_CLOSE);
@@ -6937,7 +6933,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                 "(%s)\n",
                                                 smb_fname_str_dbg(smb_fname),
                                                 strerror(errno)));
-                                       reply_unixerror(req,ERRDOS,ERRbadpath);
+                                       reply_nterror(req, map_nt_error_from_unix(errno));
                                        return;
                                }
                        } else {
@@ -6946,7 +6942,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                 "fileinfo of %s failed (%s)\n",
                                                 smb_fname_str_dbg(smb_fname),
                                                 strerror(errno)));
-                                       reply_unixerror(req,ERRDOS,ERRbadpath);
+                                       reply_nterror(req, map_nt_error_from_unix(errno));
                                        return;
                                }
                        }
@@ -6965,7 +6961,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                    max_data_bytes);
                                return;
                        } else {
-                               reply_unixerror(req, ERRDOS, ERRbadpath);
+                               reply_doserror(req, ERRDOS, ERRbadpath);
                                return;
                        }
                } else {
@@ -6980,7 +6976,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                DEBUG(3,("call_trans2setfilepathinfo: fstat "
                                         "of fnum %d failed (%s)\n", fsp->fnum,
                                         strerror(errno)));
-                               reply_unixerror(req, ERRDOS, ERRbadfid);
+                               reply_nterror(req, map_nt_error_from_unix(errno));
                                return;
                        }
                }
@@ -7030,7 +7026,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                 "%s failed (%s)\n",
                                 smb_fname_str_dbg(smb_fname),
                                 strerror(errno)));
-                       reply_unixerror(req, ERRDOS, ERRbadpath);
+                       reply_nterror(req, map_nt_error_from_unix(errno));
                        return;
                }
        }
@@ -7073,8 +7069,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                        pdata,
                                        total_data,
                                        fsp,
-                                       fname,
-                                       &sbuf);
+                                       smb_fname);
                        break;
                }
 
@@ -7095,8 +7090,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                        pdata,
                                                        total_data,
                                                        fsp,
-                                                       fname,
-                                                       &sbuf);
+                                                       smb_fname);
                        break;
                }
 
@@ -7107,8 +7101,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                                pdata,
                                                                total_data,
                                                                fsp,
-                                                               fname,
-                                                               &sbuf);
+                                                               smb_fname);
                        break;
                }
 
@@ -7139,8 +7132,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                pdata,
                                                total_data,
                                                fsp,
-                                               fname,
-                                               &sbuf);
+                                               smb_fname);
                        break;
                }
 
@@ -7276,8 +7268,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                        status = smb_posix_unlink(conn, req,
                                                pdata,
                                                total_data,
-                                               fname,
-                                               &sbuf);
+                                               smb_fname);
                        break;
                }