s3:smbd: split out smbd_do_qfilepathinfo() from call_trans2qfilepathinfo()
[samba.git] / source3 / smbd / trans2.c
index 52340d53703873135d462993bfa4b7d5c4a51eed..c9e7e4bbfbd74cb1b399c24b3049231197c15267 100644 (file)
 #include "includes.h"
 #include "version.h"
 #include "smbd/globals.h"
+#include "../libcli/auth/libcli_auth.h"
 
 extern enum protocol_types Protocol;
 
-#define get_file_size(sbuf) ((sbuf).st_size)
 #define DIR_ENTRY_SAFETY_MARGIN 4096
 
 static char *store_file_unix_basic(connection_struct *conn,
@@ -59,31 +59,6 @@ uint64_t smb_roundup(connection_struct *conn, uint64_t val)
        return val;
 }
 
-/********************************************************************
- Given a stat buffer return the allocated size on disk, taking into
- account sparse files.
-********************************************************************/
-
-uint64_t get_allocation_size(connection_struct *conn, files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
-{
-       uint64_t ret;
-
-       if(S_ISDIR(sbuf->st_mode)) {
-               return 0;
-       }
-
-#if defined(HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
-       ret = (uint64_t)STAT_ST_BLOCKSIZE * (uint64_t)sbuf->st_blocks;
-#else
-       ret = (uint64_t)get_file_size(*sbuf);
-#endif
-
-       if (fsp && fsp->initial_allocation_size)
-               ret = MAX(ret,fsp->initial_allocation_size);
-
-       return smb_roundup(conn, ret);
-}
-
 /****************************************************************************
  Utility functions for dealing with extended attributes.
 ****************************************************************************/
@@ -429,12 +404,22 @@ static void canonicalize_ea_name(connection_struct *conn, files_struct *fsp, con
  Set or delete an extended attribute.
 ****************************************************************************/
 
-NTSTATUS set_ea(connection_struct *conn, files_struct *fsp, const char *fname, struct ea_list *ea_list)
+NTSTATUS set_ea(connection_struct *conn, files_struct *fsp,
+               const struct smb_filename *smb_fname, struct ea_list *ea_list)
 {
+       char *fname = NULL;
+       NTSTATUS status;
+
        if (!lp_ea_support(SNUM(conn))) {
                return NT_STATUS_EAS_NOT_SUPPORTED;
        }
 
+       status = get_full_smb_filename(talloc_tos(), smb_fname,
+                                      &fname);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
        for (;ea_list; ea_list = ea_list->next) {
                int ret;
                fstring unix_ea_name;
@@ -707,6 +692,8 @@ void send_trans2_replies(connection_struct *conn,
        int alignment_offset = 1; /* JRA. This used to be 3. Set to 1 to make netmon parse ok. */
        int data_alignment_offset = 0;
        bool overflow = False;
+       struct smbd_server_connection *sconn = smbd_server_conn;
+       int max_send = sconn->smb1.sessions.max_send;
 
        /* Modify the data_to_send and datasize and set the error if
           we're trying to send more than max_data_bytes. We still send
@@ -725,6 +712,14 @@ void send_trans2_replies(connection_struct *conn,
        if(params_to_send == 0 && data_to_send == 0) {
                reply_outbuf(req, 10, 0);
                show_msg((char *)req->outbuf);
+               if (!srv_send_smb(smbd_server_fd(),
+                               (char *)req->outbuf,
+                               true, req->seqnum+1,
+                               IS_CONN_ENCRYPTED(conn),
+                               &req->pcd)) {
+                       exit_server_cleanly("send_trans2_replies: srv_send_smb failed.");
+               }
+               TALLOC_FREE(req->outbuf);
                return;
        }
 
@@ -858,7 +853,9 @@ void send_trans2_replies(connection_struct *conn,
                show_msg((char *)req->outbuf);
                if (!srv_send_smb(smbd_server_fd(),
                                (char *)req->outbuf,
-                               IS_CONN_ENCRYPTED(conn)))
+                               true, req->seqnum+1,
+                               IS_CONN_ENCRYPTED(conn),
+                               &req->pcd))
                        exit_server_cleanly("send_trans2_replies: srv_send_smb failed.");
 
                TALLOC_FREE(req->outbuf);
@@ -890,6 +887,7 @@ static void call_trans2open(connection_struct *conn,
                            char **ppdata, int total_data,
                            unsigned int max_data_bytes)
 {
+       struct smb_filename *smb_fname = NULL;
        char *params = *pparams;
        char *pdata = *ppdata;
        int deny_mode;
@@ -907,7 +905,6 @@ static void call_trans2open(connection_struct *conn,
        SMB_OFF_T size=0;
        int fattr=0,mtime=0;
        SMB_INO_T inode = 0;
-       SMB_STRUCT_STAT sbuf;
        int smb_action = 0;
        files_struct *fsp;
        struct ea_list *ea_list = NULL;
@@ -925,7 +922,7 @@ static void call_trans2open(connection_struct *conn,
 
        if (total_params < 29) {
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-               return;
+               goto out;
        }
 
        flags = SVAL(params, 0);
@@ -947,7 +944,7 @@ static void call_trans2open(connection_struct *conn,
 
        if (IS_IPC(conn)) {
                reply_doserror(req, ERRSRV, ERRaccess);
-               return;
+               goto out;
        }
 
        srvstr_get_path(ctx, params, req->flags2, &fname, pname,
@@ -955,63 +952,80 @@ static void call_trans2open(connection_struct *conn,
                        &status);
        if (!NT_STATUS_IS_OK(status)) {
                reply_nterror(req, status);
-               return;
+               goto out;
        }
 
        DEBUG(3,("call_trans2open %s deny_mode=0x%x attr=%d ofun=0x%x size=%d\n",
                fname, (unsigned int)deny_mode, (unsigned int)open_attr,
                (unsigned int)open_ofun, open_size));
 
+       status = filename_convert(ctx,
+                               conn,
+                               req->flags2 & FLAGS2_DFS_PATHNAMES,
+                               fname,
+                               &smb_fname,
+                               NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+                       reply_botherror(req,
+                               NT_STATUS_PATH_NOT_COVERED,
+                               ERRSRV, ERRbadpath);
+                       goto out;
+               }
+               reply_nterror(req, status);
+               goto out;
+       }
+
        if (open_ofun == 0) {
                reply_nterror(req, NT_STATUS_OBJECT_NAME_COLLISION);
-               return;
+               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,
                                &create_options)) {
                reply_doserror(req, ERRDOS, ERRbadaccess);
-               return;
+               goto out;
        }
 
        /* Any data in this call is an EA list. */
        if (total_data && (total_data != 4) && !lp_ea_support(SNUM(conn))) {
                reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
-               return;
+               goto out;
        }
 
        if (total_data != 4) {
                if (total_data < 10) {
                        reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-                       return;
+                       goto out;
                }
 
                if (IVAL(pdata,0) > total_data) {
                        DEBUG(10,("call_trans2open: bad total data size (%u) > %u\n",
                                IVAL(pdata,0), (unsigned int)total_data));
                        reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-                       return;
+                       goto out;
                }
 
                ea_list = read_ea_list(talloc_tos(), pdata + 4,
                                       total_data - 4);
                if (!ea_list) {
                        reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-                       return;
+                       goto out;
                }
        } else if (IVAL(pdata,0) != 4) {
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-               return;
+               goto out;
        }
 
        status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                req,                                    /* req */
                0,                                      /* root_dir_fid */
-               fname,                                  /* fname */
-               CFF_DOS_PATH,                           /* create_file_flags */
+               smb_fname,                              /* fname */
                access_mask,                            /* access_mask */
                share_mode,                             /* share_access */
                create_disposition,                     /* create_disposition*/
@@ -1022,33 +1036,32 @@ static void call_trans2open(connection_struct *conn,
                NULL,                                   /* sd */
                ea_list,                                /* ea_list */
                &fsp,                                   /* result */
-               &smb_action,                            /* pinfo */
-               &sbuf);                                 /* psbuf */
+               &smb_action);                           /* psbuf */
 
        if (!NT_STATUS_IS_OK(status)) {
                if (open_was_deferred(req->mid)) {
                        /* We have re-scheduled this call. */
-                       return;
+                       goto out;
                }
                reply_openerror(req, status);
-               return;
+               goto out;
        }
 
-       size = get_file_size(sbuf);
-       fattr = dos_mode(conn,fsp->fsp_name,&sbuf);
-       mtime = sbuf.st_mtime;
-       inode = sbuf.st_ino;
+       size = get_file_size_stat(&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) {
                close_file(req, fsp, ERROR_CLOSE);
                reply_doserror(req, ERRDOS,ERRnoaccess);
-               return;
+               goto out;
        }
 
        /* Realloc the size of parameters and data we will return */
        *pparams = (char *)SMB_REALLOC(*pparams, 30);
        if(*pparams == NULL ) {
                reply_nterror(req, NT_STATUS_NO_MEMORY);
-               return;
+               goto out;
        }
        params = *pparams;
 
@@ -1080,6 +1093,8 @@ static void call_trans2open(connection_struct *conn,
 
        /* Send the required number of replies */
        send_trans2_replies(conn, req, params, 30, *ppdata, 0, max_data_bytes);
+ out:
+       TALLOC_FREE(smb_fname);
 }
 
 /*********************************************************
@@ -1146,7 +1161,7 @@ static uint32 unix_filetype(mode_t mode)
 enum perm_type { PERM_NEW_FILE, PERM_NEW_DIR, PERM_EXISTING_FILE, PERM_EXISTING_DIR};
 
 static NTSTATUS unix_perms_from_wire( connection_struct *conn,
-                               SMB_STRUCT_STAT *psbuf,
+                               const SMB_STRUCT_STAT *psbuf,
                                uint32 perms,
                                enum perm_type ptype,
                                mode_t *ret_perms)
@@ -1157,7 +1172,7 @@ static NTSTATUS unix_perms_from_wire( connection_struct *conn,
                if (!VALID_STAT(*psbuf)) {
                        return NT_STATUS_INVALID_PARAMETER;
                } else {
-                       *ret_perms = psbuf->st_mode;
+                       *ret_perms = psbuf->st_ex_mode;
                        return NT_STATUS_OK;
                }
        }
@@ -1228,7 +1243,7 @@ static bool check_msdfs_link(connection_struct *conn,
                DEBUG(5,("check_msdfs_link: Masquerading msdfs link %s "
                        "as a directory\n",
                        pathname));
-               psbuf->st_mode = (psbuf->st_mode & 0xFFF) | S_IFDIR;
+               psbuf->st_ex_mode = (psbuf->st_ex_mode & 0xFFF) | S_IFDIR;
                errno = saved_errno;
                return true;
        }
@@ -1259,12 +1274,12 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                                int *last_entry_off,
                                struct ea_list *name_list)
 {
-       const char *dname;
+       char *dname;
        bool found = False;
        SMB_STRUCT_STAT sbuf;
        const char *mask = NULL;
        char *pathreal = NULL;
-       const char *fname = NULL;
+       char *fname = NULL;
        char *p, *q, *pdata = *ppdata;
        uint32 reskey=0;
        long prev_dirpos=0;
@@ -1340,9 +1355,13 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                /* Mangle fname if it's an illegal name. */
                if (mangle_must_mangle(dname,conn->params)) {
                        if (!name_to_8_3(dname,mangled_name,True,conn->params)) {
+                               TALLOC_FREE(fname);
                                continue; /* Error - couldn't mangle. */
                        }
-                       fname = mangled_name;
+                       fname = talloc_strdup(ctx, mangled_name);
+                       if (!fname) {
+                               return False;
+                       }
                }
 
                if(!(got_match = *got_exact_match = exact_match(conn, fname, mask))) {
@@ -1359,6 +1378,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                         */
                        /* Force the mangling into 8.3. */
                        if (!name_to_8_3( fname, mangled_name, False, conn->params)) {
+                               TALLOC_FREE(fname);
                                continue; /* Error - couldn't mangle. */
                        }
 
@@ -1369,8 +1389,11 @@ 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);
                                continue;
                        }
 
@@ -1388,61 +1411,89 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                        }
 
                        if (!pathreal) {
+                               TALLOC_FREE(fname);
                                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 (SMB_VFS_LSTAT(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) && SMB_VFS_STAT(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;
                                }
                        }
 
                        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(sbuf);
+                               file_size = get_file_size_stat(&smb_fname->st);
                        }
-                       allocation_size = get_allocation_size(conn,NULL,&sbuf);
-
-                       mdate_ts = get_mtimespec(&sbuf);
-                       adate_ts = get_atimespec(&sbuf);
-                       create_date_ts = get_create_timespec(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
+                       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);
@@ -1453,12 +1504,19 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                        mdate = convert_timespec_to_time_t(mdate_ts);
                        adate = convert_timespec_to_time_t(adate_ts);
 
-                       DEBUG(5,("get_lanman2_dir_entry: found %s fname=%s\n",pathreal,fname));
+                       DEBUG(5,("get_lanman2_dir_entry: found %s fname=%s\n",
+                                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)
+                       TALLOC_FREE(fname);
        }
 
        p = pdata;
@@ -1743,8 +1801,8 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                                p +=4;
                        }
                        SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */
-                       SIVAL(p,0,sbuf.st_ino); p += 4; /* FileIndexLow */
-                       SIVAL(p,0,sbuf.st_dev); p += 4; /* FileIndexHigh */
+                       SIVAL(p,0,sbuf.st_ex_ino); p += 4; /* FileIndexLow */
+                       SIVAL(p,0,sbuf.st_ex_dev); p += 4; /* FileIndexHigh */
                        len = srvstr_push(base_data, flags2, p,
                                          fname, PTR_DIFF(end_data, p),
                                          STR_TERMINATE_ASCII);
@@ -1799,8 +1857,8 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                        }
                        p += 26;
                        SSVAL(p,0,0); p += 2; /* Reserved ? */
-                       SIVAL(p,0,sbuf.st_ino); p += 4; /* FileIndexLow */
-                       SIVAL(p,0,sbuf.st_dev); p += 4; /* FileIndexHigh */
+                       SIVAL(p,0,sbuf.st_ex_ino); p += 4; /* FileIndexLow */
+                       SIVAL(p,0,sbuf.st_ex_dev); p += 4; /* FileIndexHigh */
                        len = srvstr_push(base_data, flags2, p,
                                          fname, PTR_DIFF(end_data, p),
                                          STR_TERMINATE_ASCII);
@@ -1852,10 +1910,11 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                        break;
 
                default:
+                       TALLOC_FREE(fname);
                        return(False);
        }
 
-
+       TALLOC_FREE(fname);
        if (PTR_DIFF(p,pdata) > space_remaining) {
                /* Move the dirptr back to prev_dirpos */
                dptr_SeekDir(conn->dirptr, prev_dirpos);
@@ -1887,6 +1946,7 @@ static void call_trans2findfirst(connection_struct *conn,
                maxentries then so be it. We assume that the redirector has
                enough room for the fixed number of parameter bytes it has
                requested. */
+       struct smb_filename *smb_dname = NULL;
        char *params = *pparams;
        char *pdata = *ppdata;
        char *data_end;
@@ -1909,7 +1969,6 @@ static void call_trans2findfirst(connection_struct *conn,
        bool out_of_space = False;
        int space_remaining;
        bool mask_contains_wcard = False;
-       SMB_STRUCT_STAT sbuf;
        struct ea_list *ea_list = NULL;
        NTSTATUS ntstatus = NT_STATUS_OK;
        bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
@@ -1937,7 +1996,7 @@ close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
                /* W2K3 seems to treat zero as 1. */
                maxentries = 1;
        }
+
        switch (info_level) {
                case SMB_FIND_INFO_STANDARD:
                case SMB_FIND_EA_SIZE:
@@ -1986,7 +2045,17 @@ close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
                return;
        }
 
-       ntstatus = unix_convert(ctx, conn, directory, True, &directory, &mask, &sbuf);
+       ntstatus = unix_convert(ctx, conn, directory, &smb_dname,
+                               (UCF_SAVE_LCOMP | UCF_ALLOW_WCARD_LCOMP));
+       if (!NT_STATUS_IS_OK(ntstatus)) {
+               reply_nterror(req, ntstatus);
+               return;
+       }
+
+       mask = smb_dname->original_lcomp;
+
+       ntstatus = get_full_smb_filename(ctx, smb_dname, &directory);
+       TALLOC_FREE(smb_dname);
        if (!NT_STATUS_IS_OK(ntstatus)) {
                reply_nterror(req, ntstatus);
                return;
@@ -2066,7 +2135,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        }
        params = *pparams;
 
-       /* Save the wildcard match and attribs we are using on this directory - 
+       /* Save the wildcard match and attribs we are using on this directory -
                needed as lanman2 assumes these are being saved between calls */
 
        ntstatus = dptr_create(conn,
@@ -2087,6 +2156,9 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        dptr_num = dptr_dnum(conn->dirptr);
        DEBUG(4,("dptr_num is %d, wcard = %s, attr = %d\n", dptr_num, mask, dirtype));
 
+       /* Initialize per TRANS2_FIND_FIRST operation data */
+       dptr_init_search_op(conn->dirptr);
+
        /* We don't need to check for VOL here as this is returned by
                a different TRANS2 call. */
 
@@ -2101,7 +2173,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        for (i=0;(i<maxentries) && !finished && !out_of_space;i++) {
                bool got_exact_match = False;
 
-               /* this is a heuristic to avoid seeking the dirptr except when 
+               /* this is a heuristic to avoid seeking the dirptr except when
                        absolutely necessary. It allows for a filename of about 40 chars */
                if (space_remaining < DIRLEN_GUESS && numentries > 0) {
                        out_of_space = True;
@@ -2397,6 +2469,9 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                (long)conn->dirptr,
                dptr_TellDir(conn->dirptr)));
 
+       /* Initialize per TRANS2_FIND_NEXT operation data */
+       dptr_init_search_op(conn->dirptr);
+
        /* We don't need to check for VOL here as this is returned by
                a different TRANS2 call. */
 
@@ -2568,7 +2643,7 @@ static void call_trans2qfsinfo(connection_struct *conn,
        int snum = SNUM(conn);
        char *fstype = lp_fstype(SNUM(conn));
        uint32 additional_flags = 0;
-       
+
        if (total_params < 2) {
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                return;
@@ -2599,7 +2674,7 @@ static void call_trans2qfsinfo(connection_struct *conn,
 
        DEBUG(3,("call_trans2qfsinfo: level = %d\n", info_level));
 
-       if(SMB_VFS_STAT(conn,".",&st)!=0) {
+       if(vfs_stat_smb_fname(conn,".",&st)!=0) {
                DEBUG(2,("call_trans2qfsinfo: stat of . failed (%s)\n", strerror(errno)));
                reply_doserror(req, ERRSRV, ERRinvdevice);
                return;
@@ -2622,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;
                        }
 
@@ -2643,10 +2718,10 @@ static void call_trans2qfsinfo(connection_struct *conn,
                        sectors_per_unit = bsize/bytes_per_sector;
 
                        DEBUG(5,("call_trans2qfsinfo : SMB_INFO_ALLOCATION id=%x, bsize=%u, cSectorUnit=%u, \
-cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st.st_dev, (unsigned int)bsize, (unsigned int)sectors_per_unit,
+cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st.st_ex_dev, (unsigned int)bsize, (unsigned int)sectors_per_unit,
                                (unsigned int)bytes_per_sector, (unsigned int)dsize, (unsigned int)dfree));
 
-                       SIVAL(pdata,l1_idFileSystem,st.st_dev);
+                       SIVAL(pdata,l1_idFileSystem,st.st_ex_dev);
                        SIVAL(pdata,l1_cSectorUnit,sectors_per_unit);
                        SIVAL(pdata,l1_cUnit,dsize);
                        SIVAL(pdata,l1_cUnitAvail,dfree);
@@ -2675,7 +2750,8 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st.st_dev, (unsi
                        SCVAL(pdata,l2_vol_cch,len);
                        data_len = l2_vol_szVolLabel + len;
                        DEBUG(5,("call_trans2qfsinfo : time = %x, namelen = %d, name = %s\n",
-                               (unsigned)st.st_ctime, len, vname));
+                                (unsigned)convert_timespec_to_time_t(st.st_ex_ctime),
+                                len, vname));
                        break;
 
                case SMB_QUERY_FS_ATTRIBUTE_INFO:
@@ -2742,7 +2818,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st.st_dev, (unsi
                        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);
@@ -2775,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);
@@ -2838,13 +2914,13 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                         */
                        files_struct fsp;
                        SMB_NTQUOTA_STRUCT quotas;
-                       
+
                        ZERO_STRUCT(fsp);
                        ZERO_STRUCT(quotas);
-                       
+
                        fsp.conn = conn;
                        fsp.fnum = -1;
-                       
+
                        /* access check */
                        if (conn->server_info->utok.uid != 0) {
                                DEBUG(0,("set_user_quota: access_denied "
@@ -2854,7 +2930,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                                reply_doserror(req, ERRDOS, ERRnoaccess);
                                return;
                        }
-                       
+
                        if (vfs_get_ntquota(&fsp, SMB_USER_FS_QUOTA_TYPE, NULL, &quotas)!=0) {
                                DEBUG(0,("vfs_get_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
                                reply_doserror(req, ERRSRV, ERRerror);
@@ -2864,25 +2940,25 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                        data_len = 48;
 
                        DEBUG(10,("SMB_FS_QUOTA_INFORMATION: for service [%s]\n",lp_servicename(SNUM(conn))));          
-               
+
                        /* Unknown1 24 NULL bytes*/
                        SBIG_UINT(pdata,0,(uint64_t)0);
                        SBIG_UINT(pdata,8,(uint64_t)0);
                        SBIG_UINT(pdata,16,(uint64_t)0);
-               
+
                        /* Default Soft Quota 8 bytes */
                        SBIG_UINT(pdata,24,quotas.softlim);
 
                        /* Default Hard Quota 8 bytes */
                        SBIG_UINT(pdata,32,quotas.hardlim);
-       
+
                        /* Quota flag 2 bytes */
                        SSVAL(pdata,40,quotas.qflags);
-               
+
                        /* Unknown3 6 NULL bytes */
                        SSVAL(pdata,42,0);
                        SIVAL(pdata,44,0);
-                       
+
                        break;
                }
 #endif /* HAVE_SYS_QUOTAS */
@@ -2909,8 +2985,8 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                case SMB_QUERY_CIFS_UNIX_INFO:
                {
                        bool large_write = lp_min_receive_file_size() &&
-                                               !srv_is_signing_active();
-                       bool large_read = !srv_is_signing_active();
+                                       !srv_is_signing_active(smbd_server_conn);
+                       bool large_read = !srv_is_signing_active(smbd_server_conn);
                        int encrypt_caps = 0;
 
                        if (!lp_unix_extensions()) {
@@ -3289,7 +3365,7 @@ cap_low = 0x%x, cap_high = 0x%x\n",
                        {
                                files_struct *fsp = NULL;
                                SMB_NTQUOTA_STRUCT quotas;
-       
+
                                ZERO_STRUCT(quotas);
 
                                /* access check */
@@ -3324,9 +3400,9 @@ cap_low = 0x%x, cap_high = 0x%x\n",
                                                NT_STATUS_INVALID_PARAMETER);
                                        return;
                                }
-                       
+
                                /* unknown_1 24 NULL bytes in pdata*/
-               
+
                                /* the soft quotas 8 bytes (uint64_t)*/
                                quotas.softlim = (uint64_t)IVAL(pdata,24);
 #ifdef LARGE_SMB_OFF_T
@@ -3342,7 +3418,7 @@ cap_low = 0x%x, cap_high = 0x%x\n",
                                        return;
                                }
 #endif /* LARGE_SMB_OFF_T */
-               
+
                                /* the hard quotas 8 bytes (uint64_t)*/
                                quotas.hardlim = (uint64_t)IVAL(pdata,32);
 #ifdef LARGE_SMB_OFF_T
@@ -3358,19 +3434,19 @@ cap_low = 0x%x, cap_high = 0x%x\n",
                                        return;
                                }
 #endif /* LARGE_SMB_OFF_T */
-               
+
                                /* quota_flags 2 bytes **/
                                quotas.qflags = SVAL(pdata,40);
-               
+
                                /* unknown_2 6 NULL bytes follow*/
-               
+
                                /* now set the quotas */
                                if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, &quotas)!=0) {
                                        DEBUG(0,("vfs_set_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
                                        reply_doserror(req, ERRSRV, ERRerror);
                                        return;
                                }
-                       
+
                                break;
                        }
                default:
@@ -3450,7 +3526,7 @@ static bool marshall_posix_acl(connection_struct *conn, char *pdata, SMB_STRUCT_
                switch (tagtype) {
                        case SMB_ACL_USER_OBJ:
                                SCVAL(pdata,0,SMB_POSIX_ACL_USER_OBJ);
-                               own_grp = (unsigned int)pst->st_uid;
+                               own_grp = (unsigned int)pst->st_ex_uid;
                                SIVAL(pdata,2,own_grp);
                                SIVAL(pdata,6,0);
                                break;
@@ -3470,7 +3546,7 @@ static bool marshall_posix_acl(connection_struct *conn, char *pdata, SMB_STRUCT_
                                }
                        case SMB_ACL_GROUP_OBJ:
                                SCVAL(pdata,0,SMB_POSIX_ACL_GROUP_OBJ);
-                               own_grp = (unsigned int)pst->st_gid;
+                               own_grp = (unsigned int)pst->st_ex_gid;
                                SIVAL(pdata,2,own_grp);
                                SIVAL(pdata,6,0);
                                break;
@@ -3519,46 +3595,46 @@ static char *store_file_unix_basic(connection_struct *conn,
                                const SMB_STRUCT_STAT *psbuf)
 {
        DEBUG(10,("store_file_unix_basic: SMB_QUERY_FILE_UNIX_BASIC\n"));
-       DEBUG(4,("store_file_unix_basic: st_mode=%o\n",(int)psbuf->st_mode));
+       DEBUG(4,("store_file_unix_basic: st_mode=%o\n",(int)psbuf->st_ex_mode));
 
-       SOFF_T(pdata,0,get_file_size(*psbuf));             /* File size 64 Bit */
+       SOFF_T(pdata,0,get_file_size_stat(psbuf));             /* File size 64 Bit */
        pdata += 8;
 
-       SOFF_T(pdata,0,get_allocation_size(conn,fsp,psbuf)); /* Number of bytes used on disk - 64 Bit */
+       SOFF_T(pdata,0,SMB_VFS_GET_ALLOC_SIZE(conn,fsp,psbuf)); /* Number of bytes used on disk - 64 Bit */
        pdata += 8;
 
-       put_long_date_timespec(pdata,get_ctimespec(psbuf));       /* Change Time 64 Bit */
-       put_long_date_timespec(pdata+8,get_atimespec(psbuf));     /* Last access time 64 Bit */
-       put_long_date_timespec(pdata+16,get_mtimespec(psbuf));    /* Last modification time 64 Bit */
+       put_long_date_timespec(pdata, psbuf->st_ex_ctime);       /* Change Time 64 Bit */
+       put_long_date_timespec(pdata+8, psbuf->st_ex_atime);     /* Last access time 64 Bit */
+       put_long_date_timespec(pdata+16, psbuf->st_ex_mtime);    /* Last modification time 64 Bit */
        pdata += 24;
 
-       SIVAL(pdata,0,psbuf->st_uid);               /* user id for the owner */
+       SIVAL(pdata,0,psbuf->st_ex_uid);               /* user id for the owner */
        SIVAL(pdata,4,0);
        pdata += 8;
 
-       SIVAL(pdata,0,psbuf->st_gid);               /* group id of owner */
+       SIVAL(pdata,0,psbuf->st_ex_gid);               /* group id of owner */
        SIVAL(pdata,4,0);
        pdata += 8;
 
-       SIVAL(pdata,0,unix_filetype(psbuf->st_mode));
+       SIVAL(pdata,0,unix_filetype(psbuf->st_ex_mode));
        pdata += 4;
 
-       SIVAL(pdata,0,unix_dev_major(psbuf->st_rdev));   /* Major device number if type is device */
+       SIVAL(pdata,0,unix_dev_major(psbuf->st_ex_rdev));   /* Major device number if type is device */
        SIVAL(pdata,4,0);
        pdata += 8;
 
-       SIVAL(pdata,0,unix_dev_minor(psbuf->st_rdev));   /* Minor device number if type is device */
+       SIVAL(pdata,0,unix_dev_minor(psbuf->st_ex_rdev));   /* Minor device number if type is device */
        SIVAL(pdata,4,0);
        pdata += 8;
 
-       SINO_T_VAL(pdata,0,(SMB_INO_T)psbuf->st_ino);   /* inode number */
+       SINO_T_VAL(pdata,0,(SMB_INO_T)psbuf->st_ex_ino);   /* inode number */
        pdata += 8;
-                               
-       SIVAL(pdata,0, unix_perms_to_wire(psbuf->st_mode));     /* Standard UNIX file permissions */
+
+       SIVAL(pdata,0, unix_perms_to_wire(psbuf->st_ex_mode));     /* Standard UNIX file permissions */
        SIVAL(pdata,4,0);
        pdata += 8;
 
-       SIVAL(pdata,0,psbuf->st_nlink);             /* number of hard links */
+       SIVAL(pdata,0,psbuf->st_ex_nlink);             /* number of hard links */
        SIVAL(pdata,4,0);
        pdata += 8;
 
@@ -3602,16 +3678,14 @@ static const struct {unsigned stat_fflag; unsigned smb_fflag;}
 static void map_info2_flags_from_sbuf(const SMB_STRUCT_STAT *psbuf,
                                uint32 *smb_fflags, uint32 *smb_fmask)
 {
-#ifdef HAVE_STAT_ST_FLAGS
        int i;
 
        for (i = 0; i < ARRAY_SIZE(info2_flags_map); ++i) {
            *smb_fmask |= info2_flags_map[i].smb_fflag;
-           if (psbuf->st_flags & info2_flags_map[i].stat_fflag) {
+           if (psbuf->st_ex_flags & info2_flags_map[i].stat_fflag) {
                    *smb_fflags |= info2_flags_map[i].smb_fflag;
            }
        }
-#endif /* HAVE_STAT_ST_FLAGS */
 }
 
 static bool map_info2_flags_to_sbuf(const SMB_STRUCT_STAT *psbuf,
@@ -3619,11 +3693,10 @@ static bool map_info2_flags_to_sbuf(const SMB_STRUCT_STAT *psbuf,
                                const uint32 smb_fmask,
                                int *stat_fflags)
 {
-#ifdef HAVE_STAT_ST_FLAGS
        uint32 max_fmask = 0;
        int i;
 
-       *stat_fflags = psbuf->st_flags;
+       *stat_fflags = psbuf->st_ex_flags;
 
        /* For each flags requested in smb_fmask, check the state of the
         * corresponding flag in smb_fflags and set or clear the matching
@@ -3649,9 +3722,6 @@ static bool map_info2_flags_to_sbuf(const SMB_STRUCT_STAT *psbuf,
        }
 
        return True;
-#else
-       return False;
-#endif /* HAVE_STAT_ST_FLAGS */
 }
 
 
@@ -3669,7 +3739,7 @@ static char *store_file_unix_basic_info2(connection_struct *conn,
        pdata = store_file_unix_basic(conn, pdata, fsp, psbuf);
 
        /* Create (birth) time 64 bit */
-       put_long_date_timespec(pdata, get_create_timespec(psbuf, False));
+       put_long_date_timespec(pdata, psbuf->st_ex_btime);
        pdata += 8;
 
        map_info2_flags_from_sbuf(psbuf, &file_flags, &flags_mask);
@@ -3808,424 +3878,144 @@ static void call_trans2qpipeinfo(connection_struct *conn,
        return;
 }
 
-/****************************************************************************
- Reply to a TRANS2_QFILEPATHINFO or TRANSACT2_QFILEINFO (query file info by
- file name or file id).
-****************************************************************************/
-
-static void call_trans2qfilepathinfo(connection_struct *conn,
-                                    struct smb_request *req,
-                                    unsigned int tran_call,
-                                    char **pparams, int total_params,
-                                    char **ppdata, int total_data,
-                                    unsigned int max_data_bytes)
+static NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
+                                     TALLOC_CTX *mem_ctx,
+                                     uint16_t info_level,
+                                     files_struct *fsp,
+                                     const struct smb_filename *smb_fname,
+                                     bool delete_pending,
+                                     struct timespec write_time_ts,
+                                     bool ms_dfs_link,
+                                     struct ea_list *ea_list,
+                                     int lock_data_count,
+                                     char *lock_data,
+                                     uint16_t flags2,
+                                     unsigned int max_data_bytes,
+                                     char **ppdata,
+                                     unsigned int *pdata_size)
 {
-       char *params = *pparams;
        char *pdata = *ppdata;
        char *dstart, *dend;
-       uint16 info_level;
-       int mode=0;
-       int nlink;
-       SMB_OFF_T file_size=0;
-       uint64_t allocation_size=0;
-       unsigned int data_size = 0;
-       unsigned int param_size = 2;
+       unsigned int data_size;
+       struct timespec create_time_ts, mtime_ts, atime_ts;
+       time_t create_time, mtime, atime;
        SMB_STRUCT_STAT sbuf;
-       char *dos_fname = NULL;
-       char *fname = NULL;
-       char *fullpathname;
-       char *base_name;
        char *p;
-       SMB_OFF_T pos = 0;
-       bool delete_pending = False;
-       int len;
-       time_t create_time, mtime, atime;
-       struct timespec create_time_ts, mtime_ts, atime_ts;
-       struct timespec write_time_ts;
-       files_struct *fsp = NULL;
-       struct file_id fileid;
-       struct ea_list *ea_list = NULL;
-       char *lock_data = NULL;
-       bool ms_dfs_link = false;
-       TALLOC_CTX *ctx = talloc_tos();
+       char *fname;
+       char *base_name;
+       char *dos_fname;
+       int mode;
+       int nlink;
+       NTSTATUS status;
+       uint64_t file_size = 0;
+       uint64_t pos = 0;
+       uint64_t allocation_size = 0;
 
-       if (!params) {
-               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-               return;
-       }
+       sbuf = smb_fname->st;
 
-       ZERO_STRUCT(sbuf);
-       ZERO_STRUCT(write_time_ts);
+       if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
+               return NT_STATUS_INVALID_LEVEL;
+       }
 
-       if (tran_call == TRANSACT2_QFILEINFO) {
-               if (total_params < 4) {
-                       reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-                       return;
-               }
+       status = get_full_smb_filename(mem_ctx, smb_fname, &fname);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
 
-               if (IS_IPC(conn)) {
-                       call_trans2qpipeinfo(conn, req, tran_call,
-                                            pparams, total_params,
-                                            ppdata, total_data,
-                                            max_data_bytes);
-                       return;
-               }
+       DEBUG(5,("smbd_do_qfilepathinfo: %s (fnum = %d) level=%d max_data=%u\n",
+               fname, fsp ? fsp->fnum : -1, info_level, max_data_bytes));
 
-               fsp = file_fsp(req, SVAL(params,0));
-               info_level = SVAL(params,2);
+       if (ms_dfs_link) {
+               mode = dos_mode_msdfs(conn, smb_fname);
+       } else {
+               mode = dos_mode(conn, smb_fname);
+       }
+       if (!mode)
+               mode = FILE_ATTRIBUTE_NORMAL;
 
-               DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QFILEINFO: level = %d\n", info_level));
+       nlink = sbuf.st_ex_nlink;
 
-               if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
-                       reply_nterror(req, NT_STATUS_INVALID_LEVEL);
-                       return;
-               }
+       if (nlink && (mode&aDIR)) {
+               nlink = 1;
+       }
 
-               /* Initial check for valid fsp ptr. */
-               if (!check_fsp_open(conn, req, fsp)) {
-                       return;
-               }
+       if ((nlink > 0) && delete_pending) {
+               nlink -= 1;
+       }
 
-               fname = talloc_strdup(talloc_tos(),fsp->fsp_name);
-               if (!fname) {
-                       reply_nterror(req, NT_STATUS_NO_MEMORY);
-                       return;
-               }
+       data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
+       *ppdata = (char *)SMB_REALLOC(*ppdata, data_size); 
+       if (*ppdata == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       pdata = *ppdata;
+       dstart = pdata;
+       dend = dstart + data_size - 1;
 
-               if(fsp->fake_file_handle) {
-                       /*
-                        * This is actually for the QUOTA_FAKE_FILE --metze
-                        */
+       if (!null_timespec(write_time_ts) && !INFO_LEVEL_IS_UNIX(info_level)) {
+               update_stat_ex_mtime(&sbuf, write_time_ts);
+       }
 
-                       /* We know this name is ok, it's already passed the checks. */
+       create_time_ts = sbuf.st_ex_btime;
+       mtime_ts = sbuf.st_ex_mtime;
+       atime_ts = sbuf.st_ex_atime;
 
-               } else if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
-                       /*
-                        * This is actually a QFILEINFO on a directory
-                        * handle (returned from an NT SMB). NT5.0 seems
-                        * to do this call. JRA.
-                        */
+       if (lp_dos_filetime_resolution(SNUM(conn))) {
+               dos_filetime_timespec(&create_time_ts);
+               dos_filetime_timespec(&mtime_ts);
+               dos_filetime_timespec(&atime_ts);
+       }
 
-                       if (INFO_LEVEL_IS_UNIX(info_level)) {
-                               /* Always do lstat for UNIX calls. */
-                               if (SMB_VFS_LSTAT(conn,fname,&sbuf)) {
-                                       DEBUG(3,("call_trans2qfilepathinfo: SMB_VFS_LSTAT of %s failed (%s)\n",fname,strerror(errno)));
-                                       reply_unixerror(req,ERRDOS,ERRbadpath);
-                                       return;
-                               }
-                       } else if (SMB_VFS_STAT(conn,fname,&sbuf)) {
-                               DEBUG(3,("call_trans2qfilepathinfo: SMB_VFS_STAT of %s failed (%s)\n",fname,strerror(errno)));
-                               reply_unixerror(req, ERRDOS, ERRbadpath);
-                               return;
-                       }
+       create_time = convert_timespec_to_time_t(create_time_ts);
+       mtime = convert_timespec_to_time_t(mtime_ts);
+       atime = convert_timespec_to_time_t(atime_ts);
 
-                       fileid = vfs_file_id_from_sbuf(conn, &sbuf);
-                       get_file_infos(fileid, &delete_pending, &write_time_ts);
-               } else {
-                       /*
-                        * Original code - this is an open file.
-                        */
-                       if (!check_fsp(conn, req, fsp)) {
-                               return;
-                       }
+       p = strrchr_m(smb_fname->base_name,'/');
+       if (!p)
+               base_name = smb_fname->base_name;
+       else
+               base_name = p+1;
 
-                       if (SMB_VFS_FSTAT(fsp, &sbuf) != 0) {
-                               DEBUG(3,("fstat of fnum %d failed (%s)\n", fsp->fnum, strerror(errno)));
-                               reply_unixerror(req, ERRDOS, ERRbadfid);
-                               return;
-                       }
-                       pos = fsp->fh->position_information;
-                       fileid = vfs_file_id_from_sbuf(conn, &sbuf);
-                       get_file_infos(fileid, &delete_pending, &write_time_ts);
+       /* NT expects the name to be in an exact form of the *full*
+          filename. See the trans2 torture test */
+       if (ISDOT(base_name)) {
+               dos_fname = talloc_strdup(mem_ctx, "\\");
+               if (!dos_fname) {
+                       return NT_STATUS_NO_MEMORY;
                }
-
        } else {
-               NTSTATUS status = NT_STATUS_OK;
-
-               /* qpathinfo */
-               if (total_params < 7) {
-                       reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-                       return;
+               dos_fname = talloc_asprintf(mem_ctx,
+                               "\\%s",
+                               fname);
+               if (!dos_fname) {
+                       return NT_STATUS_NO_MEMORY;
                }
+               string_replace(dos_fname, '/', '\\');
+       }
 
-               info_level = SVAL(params,0);
-
-               DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QPATHINFO: level = %d\n", info_level));
+       allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &sbuf);
 
-               if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
-                       reply_nterror(req, NT_STATUS_INVALID_LEVEL);
-                       return;
+       if (!fsp) {
+               /* Do we have this path open ? */
+               files_struct *fsp1;
+               struct file_id fileid = vfs_file_id_from_sbuf(conn, &sbuf);
+               fsp1 = file_find_di_first(fileid);
+               if (fsp1 && fsp1->initial_allocation_size) {
+                       allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, fsp1, &sbuf);
                }
+       }
 
-               srvstr_get_path(ctx, params, req->flags2, &fname, &params[6],
-                               total_params - 6,
-                               STR_TERMINATE, &status);
-               if (!NT_STATUS_IS_OK(status)) {
-                       reply_nterror(req, status);
-                       return;
-               }
-
-               status = resolve_dfspath(ctx,
-                                       conn,
-                                       req->flags2 & FLAGS2_DFS_PATHNAMES,
-                                       fname,
-                                       &fname);
-               if (!NT_STATUS_IS_OK(status)) {
-                       if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
-                               reply_botherror(req,
-                                               NT_STATUS_PATH_NOT_COVERED,
-                                               ERRSRV, ERRbadpath);
-                       }
-                       reply_nterror(req, status);
-                       return;
-               }
-
-               status = unix_convert(ctx, conn, fname, False, &fname, NULL, &sbuf);
-               if (!NT_STATUS_IS_OK(status)) {
-                       reply_nterror(req, status);
-                       return;
-               }
-               status = check_name(conn, fname);
-               if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(3,("call_trans2qfilepathinfo: fileinfo of %s failed (%s)\n",fname,nt_errstr(status)));
-                       reply_nterror(req, status);
-                       return;
-               }
-
-               if ((conn->fs_capabilities & FILE_NAMED_STREAMS)
-                   && is_ntfs_stream_name(fname)) {
-                       char *base;
-                       SMB_STRUCT_STAT bsbuf;
-
-                       status = split_ntfs_stream_name(talloc_tos(), fname,
-                                                       &base, NULL);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               DEBUG(10, ("create_file_unixpath: "
-                                       "split_ntfs_stream_name failed: %s\n",
-                                       nt_errstr(status)));
-                               reply_nterror(req, status);
-                               return;
-                       }
-
-                       SMB_ASSERT(!is_ntfs_stream_name(base)); /* paranoia.. */
-
-                       if (INFO_LEVEL_IS_UNIX(info_level)) {
-                               /* Always do lstat for UNIX calls. */
-                               if (SMB_VFS_LSTAT(conn,base,&bsbuf)) {
-                                       DEBUG(3,("call_trans2qfilepathinfo: SMB_VFS_LSTAT of %s failed (%s)\n",base,strerror(errno)));
-                                       reply_unixerror(req,ERRDOS,ERRbadpath);
-                                       return;
-                               }
-                       } else {
-                               if (SMB_VFS_STAT(conn,base,&bsbuf) != 0) {
-                                       DEBUG(3,("call_trans2qfilepathinfo: fileinfo of %s failed (%s)\n",base,strerror(errno)));
-                                       reply_unixerror(req,ERRDOS,ERRbadpath);
-                                       return;
-                               }
-                       }
-
-                       fileid = vfs_file_id_from_sbuf(conn, &bsbuf);
-                       get_file_infos(fileid, &delete_pending, NULL);
-                       if (delete_pending) {
-                               reply_nterror(req, NT_STATUS_DELETE_PENDING);
-                               return;
-                       }
-               }
-
-               if (INFO_LEVEL_IS_UNIX(info_level)) {
-                       /* Always do lstat for UNIX calls. */
-                       if (SMB_VFS_LSTAT(conn,fname,&sbuf)) {
-                               DEBUG(3,("call_trans2qfilepathinfo: SMB_VFS_LSTAT of %s failed (%s)\n",fname,strerror(errno)));
-                               reply_unixerror(req, ERRDOS, ERRbadpath);
-                               return;
-                       }
-
-               } else if (!VALID_STAT(sbuf) && SMB_VFS_STAT(conn,fname,&sbuf) && (info_level != SMB_INFO_IS_NAME_VALID)) {
-                       ms_dfs_link = check_msdfs_link(conn,fname,&sbuf);
-
-                       if (!ms_dfs_link) {
-                               DEBUG(3,("call_trans2qfilepathinfo: SMB_VFS_STAT of %s failed (%s)\n",fname,strerror(errno)));
-                               reply_unixerror(req, ERRDOS, ERRbadpath);
-                               return;
-                       }
-               }
-
-               fileid = vfs_file_id_from_sbuf(conn, &sbuf);
-               get_file_infos(fileid, &delete_pending, &write_time_ts);
-               if (delete_pending) {
-                       reply_nterror(req, NT_STATUS_DELETE_PENDING);
-                       return;
-               }
-       }
-
-       if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
-               reply_nterror(req, NT_STATUS_INVALID_LEVEL);
-               return;
-       }
-
-       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,'/');
-       if (!p)
-               base_name = fname;
-       else
-               base_name = p+1;
-
-       if (ms_dfs_link) {
-               mode = dos_mode_msdfs(conn,fname,&sbuf);
-       } else {
-               mode = dos_mode(conn,fname,&sbuf);
-       }
-       if (!mode)
-               mode = FILE_ATTRIBUTE_NORMAL;
-
-       nlink = sbuf.st_nlink;
-
-       if (nlink && (mode&aDIR)) {
-               nlink = 1;
-       }
-
-       if ((nlink > 0) && delete_pending) {
-               nlink -= 1;
-       }
-
-       fullpathname = fname;
-       if (!(mode & aDIR))
-               file_size = get_file_size(sbuf);
-
-       /* Pull out any data sent here before we realloc. */
-       switch (info_level) {
-               case SMB_INFO_QUERY_EAS_FROM_LIST:
-               {
-                       /* Pull any EA list from the data portion. */
-                       uint32 ea_size;
-
-                       if (total_data < 4) {
-                               reply_nterror(
-                                       req, NT_STATUS_INVALID_PARAMETER);
-                               return;
-                       }
-                       ea_size = IVAL(pdata,0);
-
-                       if (total_data > 0 && ea_size != total_data) {
-                               DEBUG(4,("call_trans2qfilepathinfo: Rejecting EA request with incorrect \
-total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pdata,0) ));
-                               reply_nterror(
-                                       req, NT_STATUS_INVALID_PARAMETER);
-                               return;
-                       }
-
-                       if (!lp_ea_support(SNUM(conn))) {
-                               reply_doserror(req, ERRDOS,
-                                              ERReasnotsupported);
-                               return;
-                       }
-
-                       /* Pull out the list of names. */
-                       ea_list = read_ea_name_list(ctx, pdata + 4, ea_size - 4);
-                       if (!ea_list) {
-                               reply_nterror(
-                                       req, NT_STATUS_INVALID_PARAMETER);
-                               return;
-                       }
-                       break;
-               }
-
-               case SMB_QUERY_POSIX_LOCK:
-               {
-                       if (fsp == NULL || fsp->fh->fd == -1) {
-                               reply_nterror(req, NT_STATUS_INVALID_HANDLE);
-                               return;
-                       }
-
-                       if (total_data != POSIX_LOCK_DATA_SIZE) {
-                               reply_nterror(
-                                       req, NT_STATUS_INVALID_PARAMETER);
-                               return;
-                       }
-
-                       /* Copy the lock range data. */
-                       lock_data = (char *)TALLOC_MEMDUP(
-                               ctx, pdata, total_data);
-                       if (!lock_data) {
-                               reply_nterror(req, NT_STATUS_NO_MEMORY);
-                               return;
-                       }
-               }
-               default:
-                       break;
+       if (!(mode & aDIR)) {
+               file_size = get_file_size_stat(&sbuf);
        }
 
-       *pparams = (char *)SMB_REALLOC(*pparams,2);
-       if (*pparams == NULL) {
-               reply_nterror(req, NT_STATUS_NO_MEMORY);
-               return;
-       }
-       params = *pparams;
-       SSVAL(params,0,0);
-       data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
-       *ppdata = (char *)SMB_REALLOC(*ppdata, data_size); 
-       if (*ppdata == NULL ) {
-               reply_nterror(req, NT_STATUS_NO_MEMORY);
-               return;
-       }
-       pdata = *ppdata;
-       dstart = pdata;
-       dend = dstart + data_size - 1;
-
-       create_time_ts = get_create_timespec(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
-       mtime_ts = get_mtimespec(&sbuf);
-       atime_ts = get_atimespec(&sbuf);
-
-       allocation_size = get_allocation_size(conn,fsp,&sbuf);
-
-       if (!fsp) {
-               /* Do we have this path open ? */
-               files_struct *fsp1;
-               fileid = vfs_file_id_from_sbuf(conn, &sbuf);
-               fsp1 = file_find_di_first(fileid);
-               if (fsp1 && fsp1->initial_allocation_size) {
-                       allocation_size = get_allocation_size(conn, fsp1, &sbuf);
-               }
-       }
-
-       if (!null_timespec(write_time_ts) && !INFO_LEVEL_IS_UNIX(info_level)) {
-               mtime_ts = write_time_ts;
-       }
-
-       if (lp_dos_filetime_resolution(SNUM(conn))) {
-               dos_filetime_timespec(&create_time_ts);
-               dos_filetime_timespec(&mtime_ts);
-               dos_filetime_timespec(&atime_ts);
-       }
-
-       create_time = convert_timespec_to_time_t(create_time_ts);
-       mtime = convert_timespec_to_time_t(mtime_ts);
-       atime = convert_timespec_to_time_t(atime_ts);
-
-       /* NT expects the name to be in an exact form of the *full*
-          filename. See the trans2 torture test */
-       if (ISDOT(base_name)) {
-               dos_fname = talloc_strdup(ctx, "\\");
-               if (!dos_fname) {
-                       reply_nterror(req, NT_STATUS_NO_MEMORY);
-                       return;
-               }
-       } else {
-               dos_fname = talloc_asprintf(ctx,
-                               "\\%s",
-                               fname);
-               if (!dos_fname) {
-                       reply_nterror(req, NT_STATUS_NO_MEMORY);
-                       return;
-               }
-               string_replace(dos_fname, '/', '\\');
+       if (fsp && fsp->fh) {
+               pos = fsp->fh->position_information;
        }
 
        switch (info_level) {
                case SMB_INFO_STANDARD:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_STANDARD\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_STANDARD\n"));
                        data_size = 22;
                        srv_put_dos_date2(pdata,l1_fdateCreation,create_time);
                        srv_put_dos_date2(pdata,l1_fdateLastAccess,atime);
@@ -4238,7 +4028,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                case SMB_INFO_QUERY_EA_SIZE:
                {
                        unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n"));
                        data_size = 26;
                        srv_put_dos_date2(pdata,0,create_time);
                        srv_put_dos_date2(pdata,4,atime);
@@ -4251,14 +4041,13 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                }
 
                case SMB_INFO_IS_NAME_VALID:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_IS_NAME_VALID\n"));
-                       if (tran_call == TRANSACT2_QFILEINFO) {
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_IS_NAME_VALID\n"));
+                       if (fsp) {
                                /* os/2 needs this ? really ?*/
-                               reply_doserror(req, ERRDOS, ERRbadfunc);
-                               return;
+                               return NT_STATUS_DOS(ERRDOS, ERRbadfunc);
                        }
+                       /* This is only reached for qpathinfo */
                        data_size = 0;
-                       param_size = 0;
                        break;
 
                case SMB_INFO_QUERY_EAS_FROM_LIST:
@@ -4266,9 +4055,9 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        size_t total_ea_len = 0;
                        struct ea_list *ea_file_list = NULL;
 
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_QUERY_EAS_FROM_LIST\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EAS_FROM_LIST\n"));
 
-                       ea_file_list = get_ea_list_from_file(ctx, conn, fsp, fname, &total_ea_len);
+                       ea_file_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
                        ea_list = ea_list_union(ea_list, ea_file_list, &total_ea_len);
 
                        if (!ea_list || (total_ea_len > data_size)) {
@@ -4277,7 +4066,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                break;
                        }
 
-                       data_size = fill_ea_buffer(ctx, pdata, data_size, conn, ea_list);
+                       data_size = fill_ea_buffer(mem_ctx, pdata, data_size, conn, ea_list);
                        break;
                }
 
@@ -4286,16 +4075,16 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        /* We have data_size bytes to put EA's into. */
                        size_t total_ea_len = 0;
 
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_QUERY_ALL_EAS\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_ALL_EAS\n"));
 
-                       ea_list = get_ea_list_from_file(ctx, conn, fsp, fname, &total_ea_len);
+                       ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
                        if (!ea_list || (total_ea_len > data_size)) {
                                data_size = 4;
                                SIVAL(pdata,0,4);   /* EA List Length must be set to 4 if no EA's. */
                                break;
                        }
 
-                       data_size = fill_ea_buffer(ctx, pdata, data_size, conn, ea_list);
+                       data_size = fill_ea_buffer(mem_ctx, pdata, data_size, conn, ea_list);
                        break;
                }
 
@@ -4303,10 +4092,10 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                case SMB_QUERY_FILE_BASIC_INFO:
 
                        if (info_level == SMB_QUERY_FILE_BASIC_INFO) {
-                               DEBUG(10,("call_trans2qfilepathinfo: SMB_QUERY_FILE_BASIC_INFO\n"));
+                               DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_BASIC_INFO\n"));
                                data_size = 36; /* w95 returns 40 bytes not 36 - why ?. */
                        } else {
-                               DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_BASIC_INFORMATION\n"));
+                               DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_BASIC_INFORMATION\n"));
                                data_size = 40;
                                SIVAL(pdata,36,0);
                        }
@@ -4327,7 +4116,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                case SMB_FILE_STANDARD_INFORMATION:
                case SMB_QUERY_FILE_STANDARD_INFO:
 
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_STANDARD_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_STANDARD_INFORMATION\n"));
                        data_size = 24;
                        SOFF_T(pdata,0,allocation_size);
                        SOFF_T(pdata,8,file_size);
@@ -4341,7 +4130,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                case SMB_QUERY_FILE_EA_INFO:
                {
                        unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_EA_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_EA_INFORMATION\n"));
                        data_size = 4;
                        SIVAL(pdata,0,ea_size);
                        break;
@@ -4351,15 +4140,14 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                case SMB_QUERY_FILE_ALT_NAME_INFO:
                case SMB_FILE_ALTERNATE_NAME_INFORMATION:
                {
+                       int len;
                        char mangled_name[13];
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ALTERNATE_NAME_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALTERNATE_NAME_INFORMATION\n"));
                        if (!name_to_8_3(base_name,mangled_name,
                                                True,conn->params)) {
-                               reply_nterror(
-                                       req,
-                                       NT_STATUS_NO_MEMORY);
+                               return NT_STATUS_NO_MEMORY;
                        }
-                       len = srvstr_push(dstart, req->flags2,
+                       len = srvstr_push(dstart, flags2,
                                          pdata+4, mangled_name,
                                          PTR_DIFF(dend, pdata+4),
                                          STR_UNICODE);
@@ -4369,28 +4157,31 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                }
 
                case SMB_QUERY_FILE_NAME_INFO:
+               {
+                       int len;
                        /*
                          this must be *exactly* right for ACLs on mapped drives to work
                         */
-                       len = srvstr_push(dstart, req->flags2,
+                       len = srvstr_push(dstart, flags2,
                                          pdata+4, dos_fname,
                                          PTR_DIFF(dend, pdata+4),
                                          STR_UNICODE);
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_QUERY_FILE_NAME_INFO\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_NAME_INFO\n"));
                        data_size = 4 + len;
                        SIVAL(pdata,0,len);
                        break;
+               }
 
                case SMB_FILE_ALLOCATION_INFORMATION:
                case SMB_QUERY_FILE_ALLOCATION_INFO:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ALLOCATION_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALLOCATION_INFORMATION\n"));
                        data_size = 8;
                        SOFF_T(pdata,0,allocation_size);
                        break;
 
                case SMB_FILE_END_OF_FILE_INFORMATION:
                case SMB_QUERY_FILE_END_OF_FILEINFO:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_END_OF_FILE_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_END_OF_FILE_INFORMATION\n"));
                        data_size = 8;
                        SOFF_T(pdata,0,file_size);
                        break;
@@ -4398,8 +4189,9 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                case SMB_QUERY_FILE_ALL_INFO:
                case SMB_FILE_ALL_INFORMATION:
                {
+                       int len;
                        unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ALL_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALL_INFORMATION\n"));
                        put_long_date_timespec(pdata,create_time_ts);
                        put_long_date_timespec(pdata+8,atime_ts);
                        put_long_date_timespec(pdata+16,mtime_ts); /* write time */
@@ -4416,7 +4208,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        pdata += 24;
                        SIVAL(pdata,0,ea_size);
                        pdata += 4; /* EA info */
-                       len = srvstr_push(dstart, req->flags2,
+                       len = srvstr_push(dstart, flags2,
                                          pdata+4, dos_fname,
                                          PTR_DIFF(dend, pdata+4),
                                          STR_UNICODE);
@@ -4432,14 +4224,14 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                           I think this causes us to fail the IFSKIT
                           BasicFileInformationTest. -tpot */
 
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_INTERNAL_INFORMATION\n"));
-                       SIVAL(pdata,0,sbuf.st_ino); /* FileIndexLow */
-                       SIVAL(pdata,4,sbuf.st_dev); /* FileIndexHigh */
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_INTERNAL_INFORMATION\n"));
+                       SIVAL(pdata,0,sbuf.st_ex_ino); /* FileIndexLow */
+                       SIVAL(pdata,4,sbuf.st_ex_dev); /* FileIndexHigh */
                        data_size = 8;
                        break;
 
                case SMB_FILE_ACCESS_INFORMATION:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ACCESS_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ACCESS_INFORMATION\n"));
                        if (fsp) {
                                SIVAL(pdata,0,fsp->access_mask);
                        } else {
@@ -4454,32 +4246,32 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        {
                                size_t byte_len;
                                byte_len = dos_PutUniCode(pdata+4,dos_fname,(size_t)max_data_bytes,False);
-                               DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_NAME_INFORMATION\n"));
+                               DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_NAME_INFORMATION\n"));
                                SIVAL(pdata,0,byte_len);
                                data_size = 4 + byte_len;
                                break;
                        }
 
                case SMB_FILE_DISPOSITION_INFORMATION:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_DISPOSITION_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_DISPOSITION_INFORMATION\n"));
                        data_size = 1;
                        SCVAL(pdata,0,delete_pending);
                        break;
 
                case SMB_FILE_POSITION_INFORMATION:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_POSITION_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_POSITION_INFORMATION\n"));
                        data_size = 8;
                        SOFF_T(pdata,0,pos);
                        break;
 
                case SMB_FILE_MODE_INFORMATION:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_MODE_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_MODE_INFORMATION\n"));
                        SIVAL(pdata,0,mode);
                        data_size = 4;
                        break;
 
                case SMB_FILE_ALIGNMENT_INFORMATION:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ALIGNMENT_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALIGNMENT_INFORMATION\n"));
                        SIVAL(pdata,0,0); /* No alignment needed. */
                        data_size = 4;
                        break;
@@ -4496,9 +4288,8 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                case SMB_FILE_STREAM_INFORMATION: {
                        unsigned int num_streams;
                        struct stream_struct *streams;
-                       NTSTATUS status;
 
-                       DEBUG(10,("call_trans2qfilepathinfo: "
+                       DEBUG(10,("smbd_do_qfilepathinfo: "
                                  "SMB_FILE_STREAM_INFORMATION\n"));
 
                        status = SMB_VFS_STREAMINFO(
@@ -4508,8 +4299,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        if (!NT_STATUS_IS_OK(status)) {
                                DEBUG(10, ("could not get stream info: %s\n",
                                           nt_errstr(status)));
-                               reply_nterror(req, status);
-                               return;
+                               return status;
                        }
 
                        status = marshall_stream_info(num_streams, streams,
@@ -4519,8 +4309,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        if (!NT_STATUS_IS_OK(status)) {
                                DEBUG(10, ("marshall_stream_info failed: %s\n",
                                           nt_errstr(status)));
-                               reply_nterror(req, status);
-                               return;
+                               return status;
                        }
 
                        TALLOC_FREE(streams);
@@ -4529,7 +4318,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                }
                case SMB_QUERY_COMPRESSION_INFO:
                case SMB_FILE_COMPRESSION_INFORMATION:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_COMPRESSION_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_COMPRESSION_INFORMATION\n"));
                        SOFF_T(pdata,0,file_size);
                        SIVAL(pdata,8,0); /* ??? */
                        SIVAL(pdata,12,0); /* ??? */
@@ -4537,7 +4326,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        break;
 
                case SMB_FILE_NETWORK_OPEN_INFORMATION:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_NETWORK_OPEN_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_NETWORK_OPEN_INFORMATION\n"));
                        put_long_date_timespec(pdata,create_time_ts);
                        put_long_date_timespec(pdata+8,atime_ts);
                        put_long_date_timespec(pdata+16,mtime_ts); /* write time */
@@ -4550,7 +4339,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        break;
 
                case SMB_FILE_ATTRIBUTE_TAG_INFORMATION:
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ATTRIBUTE_TAG_INFORMATION\n"));
+                       DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ATTRIBUTE_TAG_INFORMATION\n"));
                        SIVAL(pdata,0,mode);
                        SIVAL(pdata,4,0);
                        data_size = 8;
@@ -4567,7 +4356,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
 
                        {
                                int i;
-                               DEBUG(4,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_BASIC "));
+                               DEBUG(4,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_BASIC "));
 
                                for (i=0; i<100; i++)
                                        DEBUG(4,("%d=%x, ",i, (*ppdata)[i]));
@@ -4583,7 +4372,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
 
                        {
                                int i;
-                               DEBUG(4,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_INFO2 "));
+                               DEBUG(4,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_INFO2 "));
 
                                for (i=0; i<100; i++)
                                        DEBUG(4,("%d=%x, ",i, (*ppdata)[i]));
@@ -4594,33 +4383,28 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
 
                case SMB_QUERY_FILE_UNIX_LINK:
                        {
-                               char *buffer = TALLOC_ARRAY(ctx, char, PATH_MAX+1);
+                               int len;
+                               char *buffer = TALLOC_ARRAY(mem_ctx, char, PATH_MAX+1);
 
                                if (!buffer) {
-                                       reply_nterror(req, NT_STATUS_NO_MEMORY);
-                                       return;
+                                       return NT_STATUS_NO_MEMORY;
                                }
 
-                               DEBUG(10,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_LINK\n"));
+                               DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_LINK\n"));
 #ifdef S_ISLNK
-                               if(!S_ISLNK(sbuf.st_mode)) {
-                                       reply_unixerror(req, ERRSRV,
-                                                       ERRbadlink);
-                                       return;
+                               if(!S_ISLNK(sbuf.st_ex_mode)) {
+                                       return NT_STATUS_DOS(ERRSRV, ERRbadlink);
                                }
 #else
-                               reply_unixerror(req, ERRDOS, ERRbadlink);
-                               return;
+                               return NT_STATUS_DOS(ERRDOS, ERRbadlink);
 #endif
-                               len = SMB_VFS_READLINK(conn,fullpathname,
+                               len = SMB_VFS_READLINK(conn,fname,
                                                buffer, PATH_MAX);
                                if (len == -1) {
-                                       reply_unixerror(req, ERRDOS,
-                                                       ERRnoaccess);
-                                       return;
+                                       return map_nt_error_from_unix(errno);
                                }
                                buffer[len] = 0;
-                               len = srvstr_push(dstart, req->flags2,
+                               len = srvstr_push(dstart, flags2,
                                                  pdata, buffer,
                                                  PTR_DIFF(dend, pdata),
                                                  STR_TERMINATE);
@@ -4645,15 +4429,12 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                }
 
                                if (file_acl == NULL && no_acl_syscall_error(errno)) {
-                                       DEBUG(5,("call_trans2qfilepathinfo: ACLs not implemented on filesystem containing %s\n",
+                                       DEBUG(5,("smbd_do_qfilepathinfo: ACLs not implemented on filesystem containing %s\n",
                                                fname ));
-                                       reply_nterror(
-                                               req,
-                                               NT_STATUS_NOT_IMPLEMENTED);
-                                       return;
+                                       return NT_STATUS_NOT_IMPLEMENTED;
                                }
 
-                               if (S_ISDIR(sbuf.st_mode)) {
+                               if (S_ISDIR(sbuf.st_ex_mode)) {
                                        if (fsp && fsp->is_directory) {
                                                def_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fsp->fsp_name, SMB_ACL_TYPE_DEFAULT);
                                        } else {
@@ -4666,7 +4447,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                num_def_acls = count_acl_entries(conn, def_acl);
 
                                if ( data_size < (num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE + SMB_POSIX_ACL_HEADER_SIZE) {
-                                       DEBUG(5,("call_trans2qfilepathinfo: data_size too small (%u) need %u\n",
+                                       DEBUG(5,("smbd_do_qfilepathinfo: data_size too small (%u) need %u\n",
                                                data_size,
                                                (unsigned int)((num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE +
                                                        SMB_POSIX_ACL_HEADER_SIZE) ));
@@ -4676,10 +4457,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                        if (def_acl) {
                                                SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
                                        }
-                                       reply_nterror(
-                                               req,
-                                               NT_STATUS_BUFFER_TOO_SMALL);
-                                       return;
+                                       return NT_STATUS_BUFFER_TOO_SMALL;
                                }
 
                                SSVAL(pdata,0,SMB_POSIX_ACL_VERSION);
@@ -4692,9 +4470,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                        if (def_acl) {
                                                SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
                                        }
-                                       reply_nterror(
-                                               req, NT_STATUS_INTERNAL_ERROR);
-                                       return;
+                                       return NT_STATUS_INTERNAL_ERROR;
                                }
                                if (!marshall_posix_acl(conn, pdata + SMB_POSIX_ACL_HEADER_SIZE + (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE), &sbuf, def_acl)) {
                                        if (file_acl) {
@@ -4703,10 +4479,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                        if (def_acl) {
                                                SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
                                        }
-                                       reply_nterror(
-                                               req,
-                                               NT_STATUS_INTERNAL_ERROR);
-                                       return;
+                                       return NT_STATUS_INTERNAL_ERROR;
                                }
 
                                if (file_acl) {
@@ -4723,16 +4496,13 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
 
                case SMB_QUERY_POSIX_LOCK:
                {
-                       NTSTATUS status = NT_STATUS_INVALID_LEVEL;
                        uint64_t count;
                        uint64_t offset;
                        uint32 lock_pid;
                        enum brl_type lock_type;
 
-                       if (total_data != POSIX_LOCK_DATA_SIZE) {
-                               reply_nterror(
-                                       req, NT_STATUS_INVALID_PARAMETER);
-                               return;
+                       if (lock_data_count != POSIX_LOCK_DATA_SIZE) {
+                               return NT_STATUS_INVALID_PARAMETER;
                        }
 
                        switch (SVAL(pdata, POSIX_LOCK_TYPE_OFFSET)) {
@@ -4745,10 +4515,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                case POSIX_LOCK_TYPE_UNLOCK:
                                default:
                                        /* There's no point in asking for an unlock... */
-                                       reply_nterror(
-                                               req,
-                                               NT_STATUS_INVALID_PARAMETER);
-                                       return;
+                                       return NT_STATUS_INVALID_PARAMETER;
                        }
 
                        lock_pid = IVAL(pdata, POSIX_LOCK_PID_OFFSET);
@@ -4793,15 +4560,388 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                memcpy(pdata, lock_data, POSIX_LOCK_DATA_SIZE);
                                SSVAL(pdata, POSIX_LOCK_TYPE_OFFSET, POSIX_LOCK_TYPE_UNLOCK);
                        } else {
+                               return status;
+                       }
+                       break;
+               }
+
+               default:
+                       return NT_STATUS_INVALID_LEVEL;
+       }
+
+       *pdata_size = data_size;
+       return NT_STATUS_OK;
+}
+
+/****************************************************************************
+ Reply to a TRANS2_QFILEPATHINFO or TRANSACT2_QFILEINFO (query file info by
+ file name or file id).
+****************************************************************************/
+
+static void call_trans2qfilepathinfo(connection_struct *conn,
+                                    struct smb_request *req,
+                                    unsigned int tran_call,
+                                    char **pparams, int total_params,
+                                    char **ppdata, int total_data,
+                                    unsigned int max_data_bytes)
+{
+       char *params = *pparams;
+       char *pdata = *ppdata;
+       uint16 info_level;
+       unsigned int data_size = 0;
+       unsigned int param_size = 2;
+       char *fname = NULL;
+       struct smb_filename *smb_fname = NULL;
+       bool delete_pending = False;
+       struct timespec write_time_ts;
+       files_struct *fsp = NULL;
+       struct file_id fileid;
+       struct ea_list *ea_list = NULL;
+       int lock_data_count = 0;
+       char *lock_data = NULL;
+       bool ms_dfs_link = false;
+       NTSTATUS status = NT_STATUS_OK;
+
+       if (!params) {
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               return;
+       }
+
+       ZERO_STRUCT(write_time_ts);
+
+       if (tran_call == TRANSACT2_QFILEINFO) {
+               if (total_params < 4) {
+                       reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+                       return;
+               }
+
+               if (IS_IPC(conn)) {
+                       call_trans2qpipeinfo(conn, req, tran_call,
+                                            pparams, total_params,
+                                            ppdata, total_data,
+                                            max_data_bytes);
+                       return;
+               }
+
+               fsp = file_fsp(req, SVAL(params,0));
+               info_level = SVAL(params,2);
+
+               DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QFILEINFO: level = %d\n", info_level));
+
+               if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
+                       reply_nterror(req, NT_STATUS_INVALID_LEVEL);
+                       return;
+               }
+
+               /* Initial check for valid fsp ptr. */
+               if (!check_fsp_open(conn, req, fsp)) {
+                       return;
+               }
+
+               fname = talloc_strdup(talloc_tos(),fsp->fsp_name);
+               if (!fname) {
+                       reply_nterror(req, NT_STATUS_NO_MEMORY);
+                       return;
+               }
+
+               status = create_synthetic_smb_fname_split(talloc_tos(), fname,
+                                                         NULL, &smb_fname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       reply_nterror(req, status);
+                       return;
+               }
+
+               if(fsp->fake_file_handle) {
+                       /*
+                        * This is actually for the QUOTA_FAKE_FILE --metze
+                        */
+
+                       /* We know this name is ok, it's already passed the checks. */
+
+               } else if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
+                       /*
+                        * This is actually a QFILEINFO on a directory
+                        * handle (returned from an NT SMB). NT5.0 seems
+                        * to do this call. JRA.
+                        */
+
+                       if (INFO_LEVEL_IS_UNIX(info_level)) {
+                               /* Always do lstat for UNIX calls. */
+                               if (SMB_VFS_LSTAT(conn, smb_fname)) {
+                                       DEBUG(3,("call_trans2qfilepathinfo: "
+                                                "SMB_VFS_LSTAT of %s failed "
+                                                "(%s)\n",
+                                                smb_fname_str_dbg(smb_fname),
+                                                strerror(errno)));
+                                       reply_nterror(req,
+                                               map_nt_error_from_unix(errno));
+                                       return;
+                               }
+                       } else if (SMB_VFS_STAT(conn, smb_fname)) {
+                               DEBUG(3,("call_trans2qfilepathinfo: "
+                                        "SMB_VFS_STAT of %s failed (%s)\n",
+                                        smb_fname_str_dbg(smb_fname),
+                                        strerror(errno)));
+                               reply_nterror(req,
+                                       map_nt_error_from_unix(errno));
+                               return;
+                       }
+
+                       fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
+                       get_file_infos(fileid, &delete_pending, &write_time_ts);
+               } else {
+                       /*
+                        * Original code - this is an open file.
+                        */
+                       if (!check_fsp(conn, req, fsp)) {
+                               return;
+                       }
+
+                       if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
+                               DEBUG(3, ("fstat of fnum %d failed (%s)\n",
+                                         fsp->fnum, strerror(errno)));
+                               reply_nterror(req,
+                                       map_nt_error_from_unix(errno));
+                               return;
+                       }
+                       fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
+                       get_file_infos(fileid, &delete_pending, &write_time_ts);
+               }
+
+       } else {
+               /* qpathinfo */
+               if (total_params < 7) {
+                       reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+                       return;
+               }
+
+               info_level = SVAL(params,0);
+
+               DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QPATHINFO: level = %d\n", info_level));
+
+               if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
+                       reply_nterror(req, NT_STATUS_INVALID_LEVEL);
+                       return;
+               }
+
+               srvstr_get_path(req, params, req->flags2, &fname, &params[6],
+                               total_params - 6,
+                               STR_TERMINATE, &status);
+               if (!NT_STATUS_IS_OK(status)) {
+                       reply_nterror(req, status);
+                       return;
+               }
+
+               status = filename_convert(req,
+                                       conn,
+                                       req->flags2 & FLAGS2_DFS_PATHNAMES,
+                                       fname,
+                                       &smb_fname,
+                                       &fname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+                               reply_botherror(req,
+                                               NT_STATUS_PATH_NOT_COVERED,
+                                               ERRSRV, ERRbadpath);
+                               return;
+                       }
+                       reply_nterror(req, status);
+                       return;
+               }
+
+               /* If this is a stream, check if there is a delete_pending. */
+               if ((conn->fs_capabilities & FILE_NAMED_STREAMS)
+                   && is_ntfs_stream_smb_fname(smb_fname)) {
+                       struct smb_filename *smb_fname_base = NULL;
+
+                       /* Create an smb_filename with stream_name == NULL. */
+                       status =
+                           create_synthetic_smb_fname(talloc_tos(),
+                                                      smb_fname->base_name,
+                                                      NULL, NULL,
+                                                      &smb_fname_base);
+                       if (!NT_STATUS_IS_OK(status)) {
                                reply_nterror(req, status);
                                return;
                        }
+
+                       if (INFO_LEVEL_IS_UNIX(info_level)) {
+                               /* Always do lstat for UNIX calls. */
+                               if (SMB_VFS_LSTAT(conn, smb_fname_base) != 0) {
+                                       DEBUG(3,("call_trans2qfilepathinfo: "
+                                                "SMB_VFS_LSTAT of %s failed "
+                                                "(%s)\n",
+                                                smb_fname_str_dbg(smb_fname_base),
+                                                strerror(errno)));
+                                       TALLOC_FREE(smb_fname_base);
+                                       reply_nterror(req,
+                                               map_nt_error_from_unix(errno));
+                                       return;
+                               }
+                       } else {
+                               if (SMB_VFS_STAT(conn, smb_fname_base) != 0) {
+                                       DEBUG(3,("call_trans2qfilepathinfo: "
+                                                "fileinfo of %s failed "
+                                                "(%s)\n",
+                                                smb_fname_str_dbg(smb_fname_base),
+                                                strerror(errno)));
+                                       TALLOC_FREE(smb_fname_base);
+                                       reply_nterror(req,
+                                               map_nt_error_from_unix(errno));
+                                       return;
+                               }
+                       }
+
+                       fileid = vfs_file_id_from_sbuf(conn,
+                                                      &smb_fname_base->st);
+                       TALLOC_FREE(smb_fname_base);
+                       get_file_infos(fileid, &delete_pending, NULL);
+                       if (delete_pending) {
+                               reply_nterror(req, NT_STATUS_DELETE_PENDING);
+                               return;
+                       }
+               }
+
+               if (INFO_LEVEL_IS_UNIX(info_level)) {
+                       /* Always do lstat for UNIX calls. */
+                       if (SMB_VFS_LSTAT(conn, smb_fname)) {
+                               DEBUG(3,("call_trans2qfilepathinfo: "
+                                        "SMB_VFS_LSTAT of %s failed (%s)\n",
+                                        smb_fname_str_dbg(smb_fname),
+                                        strerror(errno)));
+                               reply_nterror(req,
+                                       map_nt_error_from_unix(errno));
+                               return;
+                       }
+
+               } else if (!VALID_STAT(smb_fname->st) &&
+                          SMB_VFS_STAT(conn, smb_fname) &&
+                          (info_level != SMB_INFO_IS_NAME_VALID)) {
+                       ms_dfs_link = check_msdfs_link(conn, fname,
+                                                      &smb_fname->st);
+
+                       if (!ms_dfs_link) {
+                               DEBUG(3,("call_trans2qfilepathinfo: "
+                                        "SMB_VFS_STAT of %s failed (%s)\n",
+                                        smb_fname_str_dbg(smb_fname),
+                                        strerror(errno)));
+                               reply_nterror(req,
+                                       map_nt_error_from_unix(errno));
+                               return;
+                       }
+               }
+
+               fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
+               get_file_infos(fileid, &delete_pending, &write_time_ts);
+               if (delete_pending) {
+                       reply_nterror(req, NT_STATUS_DELETE_PENDING);
+                       return;
+               }
+       }
+
+       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));
+
+       /* Pull out any data sent here before we realloc. */
+       switch (info_level) {
+               case SMB_INFO_QUERY_EAS_FROM_LIST:
+               {
+                       /* Pull any EA list from the data portion. */
+                       uint32 ea_size;
+
+                       if (total_data < 4) {
+                               reply_nterror(
+                                       req, NT_STATUS_INVALID_PARAMETER);
+                               return;
+                       }
+                       ea_size = IVAL(pdata,0);
+
+                       if (total_data > 0 && ea_size != total_data) {
+                               DEBUG(4,("call_trans2qfilepathinfo: Rejecting EA request with incorrect \
+total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pdata,0) ));
+                               reply_nterror(
+                                       req, NT_STATUS_INVALID_PARAMETER);
+                               return;
+                       }
+
+                       if (!lp_ea_support(SNUM(conn))) {
+                               reply_doserror(req, ERRDOS,
+                                              ERReasnotsupported);
+                               return;
+                       }
+
+                       /* Pull out the list of names. */
+                       ea_list = read_ea_name_list(req, pdata + 4, ea_size - 4);
+                       if (!ea_list) {
+                               reply_nterror(
+                                       req, NT_STATUS_INVALID_PARAMETER);
+                               return;
+                       }
                        break;
                }
 
+               case SMB_QUERY_POSIX_LOCK:
+               {
+                       if (fsp == NULL || fsp->fh->fd == -1) {
+                               reply_nterror(req, NT_STATUS_INVALID_HANDLE);
+                               return;
+                       }
+
+                       if (total_data != POSIX_LOCK_DATA_SIZE) {
+                               reply_nterror(
+                                       req, NT_STATUS_INVALID_PARAMETER);
+                               return;
+                       }
+
+                       /* Copy the lock range data. */
+                       lock_data = (char *)TALLOC_MEMDUP(
+                               req, pdata, total_data);
+                       if (!lock_data) {
+                               reply_nterror(req, NT_STATUS_NO_MEMORY);
+                               return;
+                       }
+                       lock_data_count = total_data;
+               }
                default:
-                       reply_nterror(req, NT_STATUS_INVALID_LEVEL);
-                       return;
+                       break;
+       }
+
+       *pparams = (char *)SMB_REALLOC(*pparams,2);
+       if (*pparams == NULL) {
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
+               return;
+       }
+       params = *pparams;
+       SSVAL(params,0,0);
+
+       /*
+        * draft-leach-cifs-v1-spec-02.txt
+        * 4.2.14 TRANS2_QUERY_PATH_INFORMATION: Get File Attributes given Path
+        * says:
+        *
+        *  The requested information is placed in the Data portion of the
+        *  transaction response. For the information levels greater than 0x100,
+        *  the transaction response has 1 parameter word which should be
+        *  ignored by the client.
+        *
+        * However Windows only follows this rule for the IS_NAME_VALID call.
+        */
+       switch (info_level) {
+       case SMB_INFO_IS_NAME_VALID:
+               param_size = 0;
+               break;
+       }
+
+       status = smbd_do_qfilepathinfo(conn, req, info_level,
+                                      fsp, smb_fname,
+                                      delete_pending, write_time_ts,
+                                      ms_dfs_link, ea_list,
+                                      lock_data_count, lock_data,
+                                      req->flags2, max_data_bytes,
+                                      ppdata, &data_size);
+       if (!NT_STATUS_IS_OK(status)) {
+               reply_nterror(req, status);
+               return;
        }
 
        send_trans2_replies(conn, req, params, param_size, *ppdata, data_size,
@@ -4817,60 +4957,35 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
 
 NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
                connection_struct *conn,
-               const char *oldname_in,
-               const char *newname_in)
+               const struct smb_filename *smb_fname_old,
+               const struct smb_filename *smb_fname_new)
 {
-       SMB_STRUCT_STAT sbuf1, sbuf2;
-       char *last_component_oldname = NULL;
-       char *last_component_newname = NULL;
        char *oldname = NULL;
        char *newname = NULL;
        NTSTATUS status = NT_STATUS_OK;
 
-       ZERO_STRUCT(sbuf1);
-       ZERO_STRUCT(sbuf2);
-
-       status = unix_convert(ctx, conn, oldname_in, False, &oldname,
-                       &last_component_oldname, &sbuf1);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-       status = check_name(conn, oldname);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
        /* source must already exist. */
-       if (!VALID_STAT(sbuf1)) {
+       if (!VALID_STAT(smb_fname_old->st)) {
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
-       status = unix_convert(ctx, conn, newname_in, False, &newname,
-                       &last_component_newname, &sbuf2);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-       status = check_name(conn, newname);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
        /* Disallow if newname already exists. */
-       if (VALID_STAT(sbuf2)) {
+       if (VALID_STAT(smb_fname_new->st)) {
                return NT_STATUS_OBJECT_NAME_COLLISION;
        }
 
        /* No links from a directory. */
-       if (S_ISDIR(sbuf1.st_mode)) {
+       if (S_ISDIR(smb_fname_old->st.st_ex_mode)) {
                return NT_STATUS_FILE_IS_A_DIRECTORY;
        }
 
-       /* Ensure this is within the share. */
-       status = check_reduced_name(conn, oldname);
+       status = get_full_smb_filename(ctx, smb_fname_new, &newname);
        if (!NT_STATUS_IS_OK(status)) {
-               return status;
+               goto out;
+       }
+       status = get_full_smb_filename(ctx, smb_fname_old, &oldname);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto out;
        }
 
        DEBUG(10,("hardlink_internals: doing hard link %s -> %s\n", newname, oldname ));
@@ -4878,9 +4993,11 @@ NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
        if (SMB_VFS_LINK(conn,oldname,newname) != 0) {
                status = map_nt_error_from_unix(errno);
                DEBUG(3,("hardlink_internals: Error %s hard link %s -> %s\n",
-                                nt_errstr(status), newname, oldname));
+                                nt_errstr(status), newname, oldname));
        }
-
+ out:
+       TALLOC_FREE(newname);
+       TALLOC_FREE(oldname);
        return status;
 }
 
@@ -4890,37 +5007,44 @@ 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,
-                          struct timespec ts[2],
+                          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(ts[0])) {
-               ts[0] = get_atimespec(psbuf);
+       if (null_timespec(ft->atime)) {
+               ft->atime= smb_fname->st.st_ex_atime;
                action &= ~FILE_NOTIFY_CHANGE_LAST_ACCESS;
        }
 
-       if (null_timespec(ts[1])) {
-               ts[1] = get_mtimespec(psbuf);
+       if (null_timespec(ft->mtime)) {
+               ft->mtime = smb_fname->st.st_ex_mtime;
                action &= ~FILE_NOTIFY_CHANGE_LAST_WRITE;
        }
 
        if (!setting_write_time) {
-               /* ts[1] comes from change time, not write time. */
+               /* ft->mtime comes from change time, not write time. */
                action &= ~FILE_NOTIFY_CHANGE_LAST_WRITE;
        }
 
-       DEBUG(6,("smb_set_file_time: actime: %s " , time_to_asc(convert_timespec_to_time_t(ts[0])) ));
-       DEBUG(6,("smb_set_file_time: modtime: %s ", time_to_asc(convert_timespec_to_time_t(ts[1])) ));
+       DEBUG(5,("smb_set_filetime: actime: %s\n ",
+               time_to_asc(convert_timespec_to_time_t(ft->atime))));
+       DEBUG(5,("smb_set_filetime: modtime: %s\n ",
+               time_to_asc(convert_timespec_to_time_t(ft->mtime))));
+       if (!null_timespec(ft->create_time)) {
+               DEBUG(5,("smb_set_file_time: createtime: %s\n ",
+                  time_to_asc(convert_timespec_to_time_t(ft->create_time))));
+       }
 
        /*
         * Try and set the times of this file if
@@ -4928,16 +5052,17 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
         */
 
        {
-               struct timespec mts = get_mtimespec(psbuf);
-               struct timespec ats = get_atimespec(psbuf);
-               if ((timespec_compare(&ts[0], &ats) == 0) && (timespec_compare(&ts[1], &mts) == 0)) {
+               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;
                }
        }
 
        if (setting_write_time) {
                /*
-                * This was a setfileinfo on an open file.
+                * This was a Windows setfileinfo on an open file.
                 * NT does this a lot. We also need to 
                 * set the time here, as it can be read by 
                 * FindFirst/FindNext and with the patch for bug #2045
@@ -4947,32 +5072,40 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
                 */
 
                DEBUG(10,("smb_set_file_time: setting pending modtime to %s\n",
-                         time_to_asc(convert_timespec_to_time_t(ts[1])) ));
+                         time_to_asc(convert_timespec_to_time_t(ft->mtime))));
 
                if (fsp != NULL) {
                        if (fsp->base_fsp) {
-                               set_sticky_write_time_fsp(fsp->base_fsp, ts[1]);
+                               set_sticky_write_time_fsp(fsp->base_fsp,
+                                                         ft->mtime);
                        } else {
-                               set_sticky_write_time_fsp(fsp, ts[1]);
+                               set_sticky_write_time_fsp(fsp, ft->mtime);
                        }
                } else {
-                       set_sticky_write_time_path(conn, fname,
-                                           vfs_file_id_from_sbuf(conn, psbuf),
-                                           ts[1]);
+                       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, ts)!=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;
 }
 
@@ -4981,16 +5114,26 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
-                               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;
        }
 
+       /* 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_mode)) {
+               if (S_ISDIR(smb_fname_base->st.st_ex_mode)) {
                        dosmode |= aDIR;
                } else {
                        dosmode &= ~aDIR;
@@ -5000,18 +5143,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))) {
-
-               DEBUG(10,("smb_set_file_dosmode: file %s : setting dos mode 0x%x\n",
-                                       fname, (unsigned int)dosmode ));
-
-               if(file_set_dosmode(conn, fname, dosmode, psbuf, NULL, false)) {
-                       DEBUG(2,("smb_set_file_dosmode: file_set_dosmode of %s failed (%s)\n",
-                                               fname, strerror(errno)));
-                       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;
                }
        }
-       return NT_STATUS_OK;
+       status = NT_STATUS_OK;
+ out:
+       TALLOC_FREE(smb_fname_base);
+       return status;
 }
 
 /****************************************************************************
@@ -5020,12 +5170,13 @@ static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
 
 static NTSTATUS smb_set_file_size(connection_struct *conn,
                                  struct smb_request *req,
-                               files_struct *fsp,
-                               const char *fname,
-                               SMB_STRUCT_STAT *psbuf,
-                               SMB_OFF_T size)
+                                 files_struct *fsp,
+                                 const struct smb_filename *smb_fname,
+                                 const SMB_STRUCT_STAT *psbuf,
+                                 SMB_OFF_T size)
 {
        NTSTATUS status = NT_STATUS_OK;
+       struct smb_filename *smb_fname_tmp = NULL;
        files_struct *new_fsp = NULL;
 
        if (!VALID_STAT(*psbuf)) {
@@ -5034,12 +5185,12 @@ static NTSTATUS smb_set_file_size(connection_struct *conn,
 
        DEBUG(6,("smb_set_file_size: size: %.0f ", (double)size));
 
-       if (size == get_file_size(*psbuf)) {
+       if (size == get_file_size_stat(psbuf)) {
                return NT_STATUS_OK;
        }
 
        DEBUG(10,("smb_set_file_size: file %s : setting new size to %.0f\n",
-               fname, (double)size ));
+                 smb_fname_str_dbg(smb_fname), (double)size));
 
        if (fsp && fsp->fh->fd != -1) {
                /* Handle based call. */
@@ -5050,12 +5201,18 @@ static NTSTATUS smb_set_file_size(connection_struct *conn,
                return NT_STATUS_OK;
        }
 
+       status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       smb_fname_tmp->st = *psbuf;
+
         status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                req,                                    /* req */
                0,                                      /* root_dir_fid */
-               fname,                                  /* fname */
-               0,                                      /* create_file_flags */
+               smb_fname_tmp,                          /* fname */
                FILE_WRITE_ATTRIBUTES,                  /* access_mask */
                (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
                    FILE_SHARE_DELETE),
@@ -5067,8 +5224,9 @@ static NTSTATUS smb_set_file_size(connection_struct *conn,
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
                &new_fsp,                               /* result */
-               NULL,                                   /* pinfo */
-               psbuf);                                 /* psbuf */
+               NULL);                                  /* pinfo */
+
+       TALLOC_FREE(smb_fname_tmp);
 
        if (!NT_STATUS_IS_OK(status)) {
                /* NB. We check for open_was_deferred in the caller. */
@@ -5094,7 +5252,7 @@ static NTSTATUS smb_info_set_ea(connection_struct *conn,
                                const char *pdata,
                                int total_data,
                                files_struct *fsp,
-                               const char *fname)
+                               const struct smb_filename *smb_fname)
 {
        struct ea_list *ea_list = NULL;
        TALLOC_CTX *ctx = NULL;
@@ -5124,7 +5282,7 @@ static NTSTATUS smb_info_set_ea(connection_struct *conn,
        if (!ea_list) {
                return NT_STATUS_INVALID_PARAMETER;
        }
-       status = set_ea(conn, fsp, fname, ea_list);
+       status = set_ea(conn, fsp, smb_fname, ea_list);
 
        return status;
 }
@@ -5137,8 +5295,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;
@@ -5153,11 +5310,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 ));
 
@@ -5317,9 +5474,10 @@ static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
 static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
                                        struct smb_request *req,
                                        const char *pdata, int total_data,
-                                       const char *fname)
+                                       const struct smb_filename *smb_fname_new)
 {
        char *oldname = NULL;
+       struct smb_filename *smb_fname_old = NULL;
        TALLOC_CTX *ctx = talloc_tos();
        NTSTATUS status = NT_STATUS_OK;
 
@@ -5334,18 +5492,20 @@ static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
                return status;
        }
 
-       status = resolve_dfspath(ctx, conn,
+       DEBUG(10,("smb_set_file_unix_hlink: SMB_SET_FILE_UNIX_LINK doing hard link %s -> %s\n",
+               smb_fname_str_dbg(smb_fname_new), oldname));
+
+       status = filename_convert(ctx,
+                               conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                oldname,
-                               &oldname);
+                               &smb_fname_old,
+                               NULL);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
-       DEBUG(10,("smb_set_file_unix_hlink: SMB_SET_FILE_UNIX_LINK doing hard link %s -> %s\n",
-               fname, oldname));
-
-       return hardlink_internals(ctx, conn, oldname, fname);
+       return hardlink_internals(ctx, conn, smb_fname_old, smb_fname_new);
 }
 
 /****************************************************************************
@@ -5364,9 +5524,8 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
        uint32 len;
        char *newname = NULL;
        char *base_name = NULL;
+       struct smb_filename *smb_fname = NULL;
        bool dest_has_wcard = False;
-       SMB_STRUCT_STAT sbuf;
-       char *newname_last_component = NULL;
        NTSTATUS status = NT_STATUS_OK;
        char *p;
        TALLOC_CTX *ctx = talloc_tos();
@@ -5375,8 +5534,6 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       ZERO_STRUCT(sbuf);
-
        overwrite = (CVAL(pdata,0) ? True : False);
        root_fid = IVAL(pdata,4);
        len = IVAL(pdata,8);
@@ -5414,15 +5571,36 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                if (newname[0] != ':') {
                        return NT_STATUS_NOT_SUPPORTED;
                }
+
+               /* Create an smb_fname to call rename_internals_fsp() with. */
+               status = create_synthetic_smb_fname(talloc_tos(),
+                                                   fsp->base_fsp->fsp_name,
+                                                   newname, NULL, &smb_fname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto out;
+               }
+
+               /*
+                * Set the original last component, since
+                * rename_internals_fsp() requires it.
+                */
+               smb_fname->original_lcomp = talloc_strdup(smb_fname, newname);
+               if (smb_fname->original_lcomp == NULL) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto out;
+               }
+
+               /* Create a char * to call rename_internals() with. */
                base_name = talloc_asprintf(ctx, "%s%s",
                                           fsp->base_fsp->fsp_name,
                                           newname);
                if (!base_name) {
-                       return NT_STATUS_NO_MEMORY;
+                       status = NT_STATUS_NO_MEMORY;
+                       goto out;
                }
        } else {
                /* newname must *not* be a stream name. */
-               if (is_ntfs_stream_name(newname)) {
+               if (newname[0] == ':') {
                        return NT_STATUS_NOT_SUPPORTED;
                }
 
@@ -5448,26 +5626,32 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                        return NT_STATUS_NO_MEMORY;
                }
 
-               status = unix_convert(ctx, conn, newname, False,
-                               &newname,
-                               &newname_last_component,
-                               &sbuf);
+               status = unix_convert(ctx, conn, base_name, &smb_fname,
+                                     UCF_SAVE_LCOMP);
 
                /* If an error we expect this to be
                 * NT_STATUS_OBJECT_PATH_NOT_FOUND */
 
-               if (!NT_STATUS_IS_OK(status)
-                   && !NT_STATUS_EQUAL(NT_STATUS_OBJECT_PATH_NOT_FOUND,
-                                       status)) {
-                       return status;
+               if (!NT_STATUS_IS_OK(status)) {
+                       if(!NT_STATUS_EQUAL(NT_STATUS_OBJECT_PATH_NOT_FOUND,
+                                           status)) {
+                               goto out;
+                       }
+                       /* Create an smb_fname to call rename_internals_fsp() */
+                       status = create_synthetic_smb_fname(talloc_tos(),
+                                                           base_name, NULL,
+                                                           NULL, &smb_fname);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               goto out;
+                       }
                }
+
        }
 
        if (fsp) {
                DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
                        fsp->fnum, fsp->fsp_name, base_name ));
-               status = rename_internals_fsp(conn, fsp, base_name,
-                                             newname_last_component, 0,
+               status = rename_internals_fsp(conn, fsp, smb_fname, 0,
                                              overwrite);
        } else {
                DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
@@ -5476,7 +5660,8 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                                        overwrite, False, dest_has_wcard,
                                        FILE_WRITE_ATTRIBUTES);
        }
-
+ out:
+       TALLOC_FREE(smb_fname);
        return status;
 }
 
@@ -5637,7 +5822,8 @@ static NTSTATUS smb_set_posix_lock(connection_struct *conn,
                                                        POSIX_LOCK,
                                                        blocking_lock,
                                                        &status,
-                                                       &block_smbpid);
+                                                       &block_smbpid,
+                                                       NULL);
 
                if (br_lck && blocking_lock && ERROR_WAS_LOCK_DENIED(status)) {
                        /*
@@ -5674,29 +5860,28 @@ 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 timespec ts[2];
+       struct smb_file_time ft;
+       ZERO_STRUCT(ft);
 
        if (total_data < 12) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
+       /* create time */
+       ft.create_time = interpret_long_date(pdata);
+
        /* access time */
-       ts[0] = convert_time_t_to_timespec(srv_make_unix_date2(pdata+l1_fdateLastAccess));
+       ft.atime = interpret_long_date(pdata + 8);
+
        /* write time */
-       ts[1] = convert_time_t_to_timespec(srv_make_unix_date2(pdata+l1_fdateLastWrite));
+       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,
-                               ts,
-                               true);
+       return smb_set_file_time(conn, fsp, smb_fname, &ft, true);
 }
 
 /****************************************************************************
@@ -5707,65 +5892,61 @@ 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;
        struct timespec changed_time;
+       struct smb_file_time ft;
        uint32 dosmode = 0;
-       struct timespec ts[2];
        NTSTATUS status = NT_STATUS_OK;
        bool setting_write_time = true;
 
+       ZERO_STRUCT(ft);
+
        if (total_data < 36) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
        /* Set the attributes */
        dosmode = IVAL(pdata,32);
-       status = smb_set_file_dosmode(conn,
-                                       fname,
-                                       psbuf,
-                                       dosmode);
+       status = smb_set_file_dosmode(conn, smb_fname, dosmode);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
-       /* Ignore create time at offset pdata. */
-
        /* access time */
-       ts[0] = interpret_long_date(pdata+8);
+       ft.atime = interpret_long_date(pdata+8);
 
        write_time = interpret_long_date(pdata+16);
        changed_time = interpret_long_date(pdata+24);
 
        /* mtime */
-       ts[1] = timespec_min(&write_time, &changed_time);
+       ft.mtime = timespec_min(&write_time, &changed_time);
 
-       if ((timespec_compare(&write_time, &ts[1]) == 1) && !null_timespec(write_time)) {
-               ts[1] = write_time;
+       /* create time */
+       ft.create_time = interpret_long_date(pdata);
+
+       if ((timespec_compare(&write_time, &ft.mtime) == 1) &&
+           !null_timespec(write_time)) {
+               ft.mtime = write_time;
        }
 
        /* Prefer a defined time to an undefined one. */
-       if (null_timespec(ts[1])) {
+       if (null_timespec(ft.mtime)) {
                if (null_timespec(write_time)) {
-                       ts[1] = changed_time;
+                       ft.mtime = changed_time;
                        setting_write_time = false;
                } else {
-                       ts[1] = write_time;
+                       ft.mtime = write_time;
                }
        }
 
-       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,
-                               ts,
-                               setting_write_time);
+       return smb_set_file_time(conn, fsp, smb_fname, &ft,
+                                setting_write_time);
 }
 
 /****************************************************************************
@@ -5777,14 +5958,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)
 {
        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;
        }
 
@@ -5802,20 +5982,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(*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);
                        }
@@ -5830,13 +6012,11 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
        }
 
        /* Pathname or stat or directory file. */
-
        status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                req,                                    /* req */
                0,                                      /* root_dir_fid */
-               fname,                                  /* fname */
-               0,                                      /* create_file_flags */
+               smb_fname,                              /* fname */
                FILE_WRITE_DATA,                        /* access_mask */
                (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
                    FILE_SHARE_DELETE),
@@ -5848,8 +6028,7 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
                &new_fsp,                               /* result */
-               NULL,                                   /* pinfo */
-               psbuf);                                 /* psbuf */
+               NULL);                                  /* pinfo */
 
        if (!NT_STATUS_IS_OK(status)) {
                /* NB. We check for open_was_deferred in the caller. */
@@ -5857,7 +6036,7 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
        }
 
        /* Only change if needed. */
-       if (allocation_size != get_file_size(*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);
@@ -5885,8 +6064,7 @@ static NTSTATUS smb_set_file_end_of_file_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)
 {
        SMB_OFF_T size;
 
@@ -5904,12 +6082,13 @@ static NTSTATUS smb_set_file_end_of_file_info(connection_struct *conn,
        }
 #endif /* LARGE_SMB_OFF_T */
        DEBUG(10,("smb_set_file_end_of_file_info: Set end of file info for "
-               "file %s to %.0f\n", fname, (double)size ));
+                 "file %s to %.0f\n", smb_fname_str_dbg(smb_fname),
+                 (double)size));
 
        return smb_set_file_size(conn, req,
                                fsp,
-                               fname,
-                               psbuf,
+                               smb_fname,
+                               &smb_fname->st,
                                size);
 }
 
@@ -5920,8 +6099,7 @@ static NTSTATUS smb_set_file_end_of_file_info(connection_struct *conn,
 static NTSTATUS smb_unix_mknod(connection_struct *conn,
                                        const char *pdata,
                                        int total_data,
-                                       const char *fname,
-                                       SMB_STRUCT_STAT *psbuf)
+                                       const struct smb_filename *smb_fname)
 {
        uint32 file_type = IVAL(pdata,56);
 #if defined(HAVE_MAKEDEV)
@@ -5937,7 +6115,8 @@ static NTSTATUS smb_unix_mknod(connection_struct *conn,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       status = unix_perms_from_wire(conn, psbuf, raw_unixmode, PERM_NEW_FILE, &unixmode);
+       status = unix_perms_from_wire(conn, &smb_fname->st, raw_unixmode,
+                                     PERM_NEW_FILE, &unixmode);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -5971,11 +6150,12 @@ static NTSTATUS smb_unix_mknod(connection_struct *conn,
                        return NT_STATUS_INVALID_PARAMETER;
        }
 
-       DEBUG(10,("smb_unix_mknod: SMB_SET_FILE_UNIX_BASIC doing mknod dev %.0f mode \
-0%o for file %s\n", (double)dev, (unsigned int)unixmode, fname ));
+       DEBUG(10,("smb_unix_mknod: SMB_SET_FILE_UNIX_BASIC doing mknod dev "
+                 "%.0f mode 0%o for file %s\n", (double)dev,
+                 (unsigned int)unixmode, smb_fname_str_dbg(smb_fname)));
 
        /* Ok - do the mknod. */
-       if (SMB_VFS_MKNOD(conn, fname, unixmode, dev) != 0) {
+       if (SMB_VFS_MKNOD(conn, smb_fname->base_name, unixmode, dev) != 0) {
                return map_nt_error_from_unix(errno);
        }
 
@@ -5985,18 +6165,15 @@ static NTSTATUS smb_unix_mknod(connection_struct *conn,
 
        if (lp_inherit_perms(SNUM(conn))) {
                char *parent;
-               if (!parent_dirname(talloc_tos(), fname, &parent, NULL)) {
+               if (!parent_dirname(talloc_tos(), smb_fname->base_name,
+                                   &parent, NULL)) {
                        return NT_STATUS_NO_MEMORY;
                }
-               inherit_access_posix_acl(conn, parent, fname, unixmode);
+               inherit_access_posix_acl(conn, parent, smb_fname->base_name,
+                                        unixmode);
                TALLOC_FREE(parent);
        }
 
-       if (SMB_VFS_STAT(conn, fname, psbuf) != 0) {
-               status = map_nt_error_from_unix(errno);
-               SMB_VFS_UNLINK(conn,fname);
-               return status;
-       }
        return NT_STATUS_OK;
 }
 
@@ -6009,10 +6186,9 @@ static NTSTATUS smb_set_file_unix_basic(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)
 {
-       struct timespec ts[2];
+       struct smb_file_time ft;
        uint32 raw_unixmode;
        mode_t unixmode;
        SMB_OFF_T size = 0;
@@ -6021,6 +6197,12 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
        NTSTATUS status = NT_STATUS_OK;
        bool delete_on_fail = False;
        enum perm_type ptype;
+       files_struct *all_fsps = NULL;
+       bool modify_mtime = true;
+       struct file_id id;
+       SMB_STRUCT_STAT sbuf;
+
+       ZERO_STRUCT(ft);
 
        if (total_data < 100) {
                return NT_STATUS_INVALID_PARAMETER;
@@ -6039,14 +6221,14 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
 #endif /* LARGE_SMB_OFF_T */
        }
 
-       ts[0] = interpret_long_date(pdata+24); /* access_time */
-       ts[1] = interpret_long_date(pdata+32); /* modification_time */
+       ft.atime = interpret_long_date(pdata+24); /* access_time */
+       ft.mtime = interpret_long_date(pdata+32); /* modification_time */
        set_owner = (uid_t)IVAL(pdata,40);
        set_grp = (gid_t)IVAL(pdata,48);
        raw_unixmode = IVAL(pdata,84);
 
-       if (VALID_STAT(*psbuf)) {
-               if (S_ISDIR(psbuf->st_mode)) {
+       if (VALID_STAT(smb_fname->st)) {
+               if (S_ISDIR(smb_fname->st.st_ex_mode)) {
                        ptype = PERM_EXISTING_DIR;
                } else {
                        ptype = PERM_EXISTING_FILE;
@@ -6055,16 +6237,22 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
                ptype = PERM_NEW_FILE;
        }
 
-       status = unix_perms_from_wire(conn, psbuf, raw_unixmode, ptype, &unixmode);
+       status = unix_perms_from_wire(conn, &smb_fname->st, raw_unixmode,
+                                     ptype, &unixmode);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
-       DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC: name = %s \
-size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
-               fname, (double)size, (unsigned int)set_owner, (unsigned int)set_grp, (int)raw_unixmode));
+       DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC: name = "
+                 "%s size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
+                 smb_fname_str_dbg(smb_fname), (double)size,
+                 (unsigned int)set_owner, (unsigned int)set_grp,
+                 (int)raw_unixmode));
 
-       if (!VALID_STAT(*psbuf)) {
+       sbuf = smb_fname->st;
+
+       if (!VALID_STAT(sbuf)) {
+               struct smb_filename *smb_fname_tmp = NULL;
                /*
                 * The only valid use of this is to create character and block
                 * devices, and named pipes. This is deprecated (IMHO) and 
@@ -6074,17 +6262,32 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
                status = smb_unix_mknod(conn,
                                        pdata,
                                        total_data,
-                                       fname,
-                                       psbuf);
+                                       smb_fname);
                if (!NT_STATUS_IS_OK(status)) {
                        return status;
                }
 
+               status = copy_smb_filename(talloc_tos(), smb_fname,
+                                          &smb_fname_tmp);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+
+               if (SMB_VFS_STAT(conn, smb_fname_tmp) != 0) {
+                       status = map_nt_error_from_unix(errno);
+                       TALLOC_FREE(smb_fname_tmp);
+                       SMB_VFS_UNLINK(conn, smb_fname);
+                       return status;
+               }
+
+               sbuf = smb_fname_tmp->st;
+               TALLOC_FREE(smb_fname_tmp);
+
                /* Ensure we don't try and change anything else. */
                raw_unixmode = SMB_MODE_NO_CHANGE;
-               size = get_file_size(*psbuf);
-               ts[0] = get_atimespec(psbuf);
-               ts[1] = get_mtimespec(psbuf);
+               size = get_file_size_stat(&sbuf);
+               ft.atime = sbuf.st_ex_atime;
+               ft.mtime = sbuf.st_ex_mtime;
                /* 
                 * We continue here as we might want to change the 
                 * owner uid/gid.
@@ -6098,7 +6301,7 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
         * */
 
        if (!size) {
-               size = get_file_size(*psbuf);
+               size = get_file_size_stat(&sbuf);
        }
 #endif
 
@@ -6107,9 +6310,11 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
         */
 
        if (raw_unixmode != SMB_MODE_NO_CHANGE) {
-               DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC setting mode 0%o for file %s\n",
-                       (unsigned int)unixmode, fname ));
-               if (SMB_VFS_CHMOD(conn, fname, unixmode) != 0) {
+               DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
+                         "setting mode 0%o for file %s\n",
+                         (unsigned int)unixmode,
+                         smb_fname_str_dbg(smb_fname)));
+               if (SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode) != 0) {
                        return map_nt_error_from_unix(errno);
                }
        }
@@ -6118,22 +6323,27 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
         * Deal with the UNIX specific uid set.
         */
 
-       if ((set_owner != (uid_t)SMB_UID_NO_CHANGE) && (psbuf->st_uid != set_owner)) {
+       if ((set_owner != (uid_t)SMB_UID_NO_CHANGE) &&
+           (sbuf.st_ex_uid != set_owner)) {
                int ret;
 
-               DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC changing owner %u for path %s\n",
-                       (unsigned int)set_owner, fname ));
+               DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
+                         "changing owner %u for path %s\n",
+                         (unsigned int)set_owner,
+                         smb_fname_str_dbg(smb_fname)));
 
-               if (S_ISLNK(psbuf->st_mode)) {
-                       ret = SMB_VFS_LCHOWN(conn, fname, set_owner, (gid_t)-1);
+               if (S_ISLNK(sbuf.st_ex_mode)) {
+                       ret = SMB_VFS_LCHOWN(conn, smb_fname->base_name,
+                                            set_owner, (gid_t)-1);
                } else {
-                       ret = SMB_VFS_CHOWN(conn, fname, set_owner, (gid_t)-1);
+                       ret = SMB_VFS_CHOWN(conn, smb_fname->base_name,
+                                           set_owner, (gid_t)-1);
                }
 
                if (ret != 0) {
                        status = map_nt_error_from_unix(errno);
                        if (delete_on_fail) {
-                               SMB_VFS_UNLINK(conn,fname);
+                               SMB_VFS_UNLINK(conn, smb_fname);
                        }
                        return status;
                }
@@ -6143,13 +6353,17 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
         * Deal with the UNIX specific gid set.
         */
 
-       if ((set_grp != (uid_t)SMB_GID_NO_CHANGE) && (psbuf->st_gid != set_grp)) {
-               DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC changing group %u for file %s\n",
-                       (unsigned int)set_owner, fname ));
-               if (SMB_VFS_CHOWN(conn, fname, (uid_t)-1, set_grp) != 0) {
+       if ((set_grp != (uid_t)SMB_GID_NO_CHANGE) &&
+           (sbuf.st_ex_gid != set_grp)) {
+               DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
+                         "changing group %u for file %s\n",
+                         (unsigned int)set_owner,
+                         smb_fname_str_dbg(smb_fname)));
+               if (SMB_VFS_CHOWN(conn, smb_fname->base_name, (uid_t)-1,
+                                 set_grp) != 0) {
                        status = map_nt_error_from_unix(errno);
                        if (delete_on_fail) {
-                               SMB_VFS_UNLINK(conn,fname);
+                               SMB_VFS_UNLINK(conn, smb_fname);
                        }
                        return status;
                }
@@ -6158,22 +6372,51 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
        /* Deal with any size changes. */
 
        status = smb_set_file_size(conn, req,
-                               fsp,
-                               fname,
-                               psbuf,
-                               size);
+                                  fsp,
+                                  smb_fname,
+                                  &sbuf,
+                                  size);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
        /* Deal with any time changes. */
+       if (null_timespec(ft.mtime) && null_timespec(ft.atime)) {
+               /* No change, don't cancel anything. */
+               return status;
+       }
+
+       id = vfs_file_id_from_sbuf(conn, &sbuf);
+       for(all_fsps = file_find_di_first(id); all_fsps;
+                       all_fsps = file_find_di_next(all_fsps)) {
+               /*
+                * We're setting the time explicitly for UNIX.
+                * Cancel any pending changes over all handles.
+                */
+               all_fsps->update_write_time_on_close = false;
+               TALLOC_FREE(all_fsps->update_write_time_event);
+       }
+
+       /*
+        * Override the "setting_write_time"
+        * parameter here as it almost does what
+        * we need. Just remember if we modified
+        * mtime and send the notify ourselves.
+        */
+       if (null_timespec(ft.mtime)) {
+               modify_mtime = false;
+       }
 
-       return smb_set_file_time(conn,
+       status = smb_set_file_time(conn,
                                fsp,
-                               fname,
-                               psbuf,
-                               ts,
-                               true);
+                               smb_fname,
+                               &ft,
+                               false);
+       if (modify_mtime) {
+               notify_fname(conn, NOTIFY_ACTION_MODIFIED,
+                       FILE_NOTIFY_CHANGE_LAST_WRITE, smb_fname->base_name);
+       }
+       return status;
 }
 
 /****************************************************************************
@@ -6185,8 +6428,7 @@ static NTSTATUS smb_set_file_unix_info2(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;
        uint32 smb_fflags;
@@ -6200,7 +6442,7 @@ static NTSTATUS smb_set_file_unix_info2(connection_struct *conn,
         * and UNIX_INFO2.
         */
        status = smb_set_file_unix_basic(conn, req, pdata, total_data,
-                               fsp, fname, psbuf);
+                                        fsp, smb_fname);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -6214,8 +6456,8 @@ static NTSTATUS smb_set_file_unix_info2(connection_struct *conn,
        if (smb_fmask != 0) {
                int stat_fflags = 0;
 
-               if (!map_info2_flags_to_sbuf(psbuf, smb_fflags, smb_fmask,
-                           &stat_fflags)) {
+               if (!map_info2_flags_to_sbuf(&smb_fname->st, smb_fflags,
+                                            smb_fmask, &stat_fflags)) {
                        /* Client asked to alter a flag we don't understand. */
                        return NT_STATUS_INVALID_PARAMETER;
                }
@@ -6224,7 +6466,8 @@ static NTSTATUS smb_set_file_unix_info2(connection_struct *conn,
                        /* XXX: we should be  using SMB_VFS_FCHFLAGS here. */
                        return NT_STATUS_NOT_SUPPORTED;
                } else {
-                       if (SMB_VFS_CHFLAGS(conn, fname, stat_fflags) != 0) {
+                       if (SMB_VFS_CHFLAGS(conn, smb_fname->base_name,
+                                           stat_fflags) != 0) {
                                return map_nt_error_from_unix(errno);
                        }
                }
@@ -6250,6 +6493,7 @@ static NTSTATUS smb_posix_mkdir(connection_struct *conn,
                                SMB_STRUCT_STAT *psbuf,
                                int *pdata_return_size)
 {
+       struct smb_filename *smb_fname;
        NTSTATUS status = NT_STATUS_OK;
        uint32 raw_unixmode = 0;
        uint32 mod_unixmode = 0;
@@ -6276,12 +6520,17 @@ static NTSTATUS smb_posix_mkdir(connection_struct *conn,
        DEBUG(10,("smb_posix_mkdir: file %s, mode 0%o\n",
                fname, (unsigned int)unixmode ));
 
-       status = SMB_VFS_CREATE_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 */
                0,                                      /* root_dir_fid */
-               fname,                                  /* fname */
-               0,                                      /* create_file_flags */
+               smb_fname,                              /* fname */
                FILE_READ_ATTRIBUTES,                   /* access_mask */
                FILE_SHARE_NONE,                        /* share_access */
                FILE_CREATE,                            /* create_disposition*/
@@ -6292,8 +6541,10 @@ static NTSTATUS smb_posix_mkdir(connection_struct *conn,
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
                &fsp,                                   /* result */
-               &info,                                  /* pinfo */
-               psbuf);                                 /* psbuf */
+               &info);                                 /* pinfo */
+
+       *psbuf = smb_fname->st;
+       TALLOC_FREE(smb_fname);
 
         if (NT_STATUS_IS_OK(status)) {
                 close_file(req, fsp, NORMAL_CLOSE);
@@ -6353,6 +6604,7 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
                                SMB_STRUCT_STAT *psbuf,
                                int *pdata_return_size)
 {
+       struct smb_filename *smb_fname = NULL;
        bool extended_oplock_granted = False;
        char *pdata = *ppdata;
        uint32 flags = 0;
@@ -6414,6 +6666,8 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
                create_disp = FILE_OVERWRITE_IF;
        } else if((wire_open_mode & SMB_O_CREAT) == SMB_O_CREAT) {
                create_disp = FILE_OPEN_IF;
+       } else if ((wire_open_mode & (SMB_O_CREAT | SMB_O_EXCL | SMB_O_TRUNC)) == 0) {
+               create_disp = FILE_OPEN;
        } else {
                DEBUG(5,("smb_posix_open: invalid create mode 0x%x\n",
                        (unsigned int)wire_open_mode ));
@@ -6450,25 +6704,32 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
                (unsigned int)wire_open_mode,
                (unsigned int)unixmode ));
 
+       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 */
                0,                                      /* root_dir_fid */
-               fname,                                  /* fname */
-               0,                                      /* create_file_flags */
+               smb_fname,                              /* fname */
                access_mask,                            /* access_mask */
                (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
                    FILE_SHARE_DELETE),
                create_disp,                            /* create_disposition*/
-               0,                                      /* create_options */
+               FILE_NON_DIRECTORY_FILE,                /* create_options */
                mod_unixmode,                           /* file_attributes */
                oplock_request,                         /* oplock_request */
                0,                                      /* allocation_size */
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
                &fsp,                                   /* result */
-               &info,                                  /* pinfo */
-               psbuf);                                 /* psbuf */
+               &info);                                 /* pinfo */
+
+       *psbuf = smb_fname->st;
+       TALLOC_FREE(smb_fname);
 
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -6545,8 +6806,7 @@ 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)
 {
        NTSTATUS status = NT_STATUS_OK;
        files_struct *fsp = NULL;
@@ -6563,20 +6823,20 @@ 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;
        }
 
@@ -6584,8 +6844,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
                conn,                                   /* conn */
                req,                                    /* req */
                0,                                      /* root_dir_fid */
-               fname,                                  /* fname */
-               0,                                      /* create_file_flags */
+               smb_fname,                              /* fname */
                DELETE_ACCESS,                          /* access_mask */
                (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
                    FILE_SHARE_DELETE),
@@ -6597,8 +6856,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
                &fsp,                                   /* result */
-               &info,                                  /* pinfo */
-               psbuf);                                 /* psbuf */
+               &info);                                 /* pinfo */
 
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -6643,8 +6901,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);
@@ -6671,6 +6928,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
        uint16 info_level;
        SMB_STRUCT_STAT sbuf;
        char *fname = NULL;
+       struct smb_filename *smb_fname = NULL;
        files_struct *fsp = NULL;
        NTSTATUS status = NT_STATUS_OK;
        int data_return_size = 0;
@@ -6681,8 +6939,6 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                return;
        }
 
-       ZERO_STRUCT(sbuf);
-
        if (tran_call == TRANSACT2_SETFILEINFO) {
                if (total_params < 4) {
                        reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
@@ -6702,6 +6958,13 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                        return;
                }
 
+               status = create_synthetic_smb_fname_split(talloc_tos(), fname,
+                                                         NULL, &smb_fname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       reply_nterror(req, status);
+                       return;
+               }
+
                if(fsp->is_directory || fsp->fh->fd == -1) {
                        /*
                         * This is actually a SETFILEINFO on a directory
@@ -6710,15 +6973,22 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                         */
                        if (INFO_LEVEL_IS_UNIX(info_level)) {
                                /* Always do lstat for UNIX calls. */
-                               if (SMB_VFS_LSTAT(conn,fname,&sbuf)) {
-                                       DEBUG(3,("call_trans2setfilepathinfo: SMB_VFS_LSTAT of %s failed (%s)\n",fname,strerror(errno)));
-                                       reply_unixerror(req,ERRDOS,ERRbadpath);
+                               if (SMB_VFS_LSTAT(conn, smb_fname)) {
+                                       DEBUG(3,("call_trans2setfilepathinfo: "
+                                                "SMB_VFS_LSTAT of %s failed "
+                                                "(%s)\n",
+                                                smb_fname_str_dbg(smb_fname),
+                                                strerror(errno)));
+                                       reply_nterror(req, map_nt_error_from_unix(errno));
                                        return;
                                }
                        } else {
-                               if (SMB_VFS_STAT(conn,fname,&sbuf) != 0) {
-                                       DEBUG(3,("call_trans2setfilepathinfo: fileinfo of %s failed (%s)\n",fname,strerror(errno)));
-                                       reply_unixerror(req,ERRDOS,ERRbadpath);
+                               if (SMB_VFS_STAT(conn, smb_fname) != 0) {
+                                       DEBUG(3,("call_trans2setfilepathinfo: "
+                                                "fileinfo of %s failed (%s)\n",
+                                                smb_fname_str_dbg(smb_fname),
+                                                strerror(errno)));
+                                       reply_nterror(req, map_nt_error_from_unix(errno));
                                        return;
                                }
                        }
@@ -6737,7 +7007,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 {
@@ -6748,9 +7018,11 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                return;
                        }
 
-                       if (SMB_VFS_FSTAT(fsp, &sbuf) != 0) {
-                               DEBUG(3,("call_trans2setfilepathinfo: fstat of fnum %d failed (%s)\n",fsp->fnum, strerror(errno)));
-                               reply_unixerror(req, ERRDOS, ERRbadfid);
+                       if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
+                               DEBUG(3,("call_trans2setfilepathinfo: fstat "
+                                        "of fnum %d failed (%s)\n", fsp->fnum,
+                                        strerror(errno)));
+                               reply_nterror(req, map_nt_error_from_unix(errno));
                                return;
                        }
                }
@@ -6770,9 +7042,10 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                        return;
                }
 
-               status = resolve_dfspath(ctx, conn,
+               status = filename_convert(ctx, conn,
                                         req->flags2 & FLAGS2_DFS_PATHNAMES,
                                         fname,
+                                        &smb_fname,
                                         &fname);
                if (!NT_STATUS_IS_OK(status)) {
                        if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
@@ -6785,44 +7058,42 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                        return;
                }
 
-               status = unix_convert(ctx, conn, fname, False,
-                               &fname, NULL, &sbuf);
-               if (!NT_STATUS_IS_OK(status)) {
-                       reply_nterror(req, status);
-                       return;
-               }
-
-               status = check_name(conn, fname);
-               if (!NT_STATUS_IS_OK(status)) {
-                       reply_nterror(req, status);
-                       return;
-               }
-
                if (INFO_LEVEL_IS_UNIX(info_level)) {
                        /*
                         * For CIFS UNIX extensions the target name may not exist.
                         */
 
                        /* Always do lstat for UNIX calls. */
-                       SMB_VFS_LSTAT(conn,fname,&sbuf);
-
-               } else if (!VALID_STAT(sbuf) && SMB_VFS_STAT(conn,fname,&sbuf)) {
-                       DEBUG(3,("call_trans2setfilepathinfo: SMB_VFS_STAT of %s failed (%s)\n",fname,strerror(errno)));
-                       reply_unixerror(req, ERRDOS, ERRbadpath);
+                       SMB_VFS_LSTAT(conn, smb_fname);
+
+               } else if (!VALID_STAT(smb_fname->st) &&
+                          SMB_VFS_STAT(conn, smb_fname)) {
+                       DEBUG(3,("call_trans2setfilepathinfo: SMB_VFS_STAT of "
+                                "%s failed (%s)\n",
+                                smb_fname_str_dbg(smb_fname),
+                                strerror(errno)));
+                       reply_nterror(req, map_nt_error_from_unix(errno));
                        return;
                }
        }
 
-       if (!CAN_WRITE(conn)) {
-               reply_doserror(req, ERRSRV, ERRaccess);
-               return;
-       }
+       /* Set sbuf for use below. */
+       sbuf = smb_fname->st;
 
        if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
                reply_nterror(req, NT_STATUS_INVALID_LEVEL);
                return;
        }
 
+       if (!CAN_WRITE(conn)) {
+               /* Allow POSIX opens. The open path will deny
+                * any non-readonly opens. */
+               if (info_level != SMB_POSIX_PATH_OPEN) {
+                       reply_doserror(req, ERRSRV, ERRaccess);
+                       return;
+               }
+       }
+
        DEBUG(3,("call_trans2setfilepathinfo(%d) %s (fnum %d) info_level=%d totdata=%d\n",
                tran_call,fname, fsp ? fsp->fnum : -1, info_level,total_data));
 
@@ -6844,8 +7115,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                        pdata,
                                        total_data,
                                        fsp,
-                                       fname,
-                                       &sbuf);
+                                       smb_fname);
                        break;
                }
 
@@ -6855,7 +7125,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                pdata,
                                                total_data,
                                                fsp,
-                                               fname);
+                                               smb_fname);
                        break;
                }
 
@@ -6866,8 +7136,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                        pdata,
                                                        total_data,
                                                        fsp,
-                                                       fname,
-                                                       &sbuf);
+                                                       smb_fname);
                        break;
                }
 
@@ -6878,8 +7147,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                                pdata,
                                                                total_data,
                                                                fsp,
-                                                               fname,
-                                                               &sbuf);
+                                                               smb_fname);
                        break;
                }
 
@@ -6890,8 +7158,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                                pdata,
                                                                total_data,
                                                                fsp,
-                                                               fname,
-                                                               &sbuf);
+                                                               smb_fname);
                        break;
                }
 
@@ -6911,8 +7178,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                pdata,
                                                total_data,
                                                fsp,
-                                               fname,
-                                               &sbuf);
+                                               smb_fname);
                        break;
                }
 
@@ -6949,8 +7215,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                        pdata,
                                                        total_data,
                                                        fsp,
-                                                       fname,
-                                                       &sbuf);
+                                                       smb_fname);
                        break;
                }
 
@@ -6960,8 +7225,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                        pdata,
                                                        total_data,
                                                        fsp,
-                                                       fname,
-                                                       &sbuf);
+                                                       smb_fname);
                        break;
                }
 
@@ -6979,14 +7243,14 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
 
                case SMB_SET_FILE_UNIX_HLINK:
                {
-                       if (tran_call != TRANSACT2_SETPATHINFO) {
+                       if (tran_call != TRANSACT2_SETPATHINFO || smb_fname == NULL) {
                                /* We must have a pathname for this. */
                                reply_nterror(req, NT_STATUS_INVALID_LEVEL);
                                return;
                        }
                        status = smb_set_file_unix_hlink(conn, req,
                                                         pdata, total_data,
-                                                        fname);
+                                                        smb_fname);
                        break;
                }
 
@@ -7050,8 +7314,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                        status = smb_posix_unlink(conn, req,
                                                pdata,
                                                total_data,
-                                               fname,
-                                               &sbuf);
+                                               smb_fname);
                        break;
                }
 
@@ -7060,7 +7323,6 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                        return;
        }
 
-       
        if (!NT_STATUS_IS_OK(status)) {
                if (open_was_deferred(req->mid)) {
                        /* We have re-scheduled this call. */
@@ -7087,7 +7349,7 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
        SSVAL(params,0,0);
        send_trans2_replies(conn, req, params, 2, *ppdata, data_return_size,
                            max_data_bytes);
-  
+
        return;
 }
 
@@ -7100,10 +7362,10 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
                             char **ppdata, int total_data,
                             unsigned int max_data_bytes)
 {
+       struct smb_filename *smb_dname = NULL;
        char *params = *pparams;
        char *pdata = *ppdata;
        char *directory = NULL;
-       SMB_STRUCT_STAT sbuf;
        NTSTATUS status = NT_STATUS_OK;
        struct ea_list *ea_list = NULL;
        TALLOC_CTX *ctx = talloc_tos();
@@ -7128,23 +7390,28 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
 
        DEBUG(3,("call_trans2mkdir : name = %s\n", directory));
 
-       status = unix_convert(ctx, conn, directory, False, &directory, NULL, &sbuf);
-       if (!NT_STATUS_IS_OK(status)) {
-               reply_nterror(req, status);
-               return;
-       }
+       status = filename_convert(ctx,
+                               conn,
+                               req->flags2 & FLAGS2_DFS_PATHNAMES,
+                               directory,
+                               &smb_dname,
+                               NULL);
 
-       status = check_name(conn, directory);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(5,("call_trans2mkdir error (%s)\n", nt_errstr(status)));
+               if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+                       reply_botherror(req,
+                               NT_STATUS_PATH_NOT_COVERED,
+                               ERRSRV, ERRbadpath);
+                       return;
+               }
                reply_nterror(req, status);
                return;
-       }
+        }
 
        /* Any data in this call is an EA list. */
        if (total_data && (total_data != 4) && !lp_ea_support(SNUM(conn))) {
                reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
-               return;
+               goto out;
        }
 
        /*
@@ -7156,21 +7423,21 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
        if (total_data != 4) {
                if (total_data < 10) {
                        reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-                       return;
+                       goto out;
                }
 
                if (IVAL(pdata,0) > total_data) {
                        DEBUG(10,("call_trans2mkdir: bad total data size (%u) > %u\n",
                                IVAL(pdata,0), (unsigned int)total_data));
                        reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-                       return;
+                       goto out;
                }
 
                ea_list = read_ea_list(talloc_tos(), pdata + 4,
                                       total_data - 4);
                if (!ea_list) {
                        reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-                       return;
+                       goto out;
                }
        }
        /* If total_data == 4 Windows doesn't care what values
@@ -7178,19 +7445,19 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
         * The System i QNTC IBM SMB client puts bad values here,
         * so ignore them. */
 
-       status = create_directory(conn, req, directory);
+       status = create_directory(conn, req, smb_dname);
 
        if (!NT_STATUS_IS_OK(status)) {
                reply_nterror(req, status);
-               return;
+               goto out;
        }
-  
+
        /* Try and set any given EA. */
        if (ea_list) {
-               status = set_ea(conn, NULL, directory, ea_list);
+               status = set_ea(conn, NULL, smb_dname, ea_list);
                if (!NT_STATUS_IS_OK(status)) {
                        reply_nterror(req, status);
-                       return;
+                       goto out;
                }
        }
 
@@ -7198,14 +7465,16 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
        *pparams = (char *)SMB_REALLOC(*pparams,2);
        if(*pparams == NULL) {
                reply_nterror(req, NT_STATUS_NO_MEMORY);
-               return;
+               goto out;
        }
        params = *pparams;
 
        SSVAL(params,0,0);
 
        send_trans2_replies(conn, req, params, 2, *ppdata, 0, max_data_bytes);
-  
+
+ out:
+       TALLOC_FREE(smb_dname);
        return;
 }
 
@@ -7258,7 +7527,7 @@ static void call_trans2findnotifyfirst(connection_struct *conn,
                fnf_handle = 257;
 
        send_trans2_replies(conn, req, params, 6, *ppdata, 0, max_data_bytes);
-  
+
        return;
 }
 
@@ -7289,7 +7558,7 @@ static void call_trans2findnotifynext(connection_struct *conn,
        SSVAL(params,2,0); /* No EA errors */
 
        send_trans2_replies(conn, req, params, 4, *ppdata, 0, max_data_bytes);
-  
+
        return;
 }
 
@@ -7439,7 +7708,7 @@ void reply_findnclose(struct smb_request *req)
                END_PROFILE(SMBfindnclose);
                return;
        }
-       
+
        dptr_num = SVAL(req->vwv+0, 0);
 
        DEBUG(3,("reply_findnclose, dptr_num = %d\n", dptr_num));
@@ -7475,6 +7744,8 @@ static void handle_trans2(connection_struct *conn, struct smb_request *req,
                }
        }
 
+       SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
+
        /* Now we must call the relevant TRANS2 function */
        switch(state->call)  {
        case TRANSACT2_OPEN:
@@ -7857,7 +8128,7 @@ void reply_transs2(struct smb_request *req)
 
        state->received_param += pcnt;
        state->received_data += dcnt;
-               
+
        if ((state->received_data > state->total_data) ||
            (state->received_param > state->total_param))
                goto bad_param;