Attempt to fix the build on NetBSD
[ira/wip.git] / source3 / smbd / trans2.c
index df8b272c793d4c9b1a6323ae5072ce6626edaaba..1d95c207bafc9c8c6a4b488457841c69bf4e6a50 100644 (file)
 */
 
 #include "includes.h"
+#include "version.h"
+#include "smbd/globals.h"
+#include "../libcli/auth/libcli_auth.h"
 
-extern int max_send;
 extern enum protocol_types Protocol;
-extern uint32 global_client_caps;
 
-#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.
 ****************************************************************************/
@@ -94,7 +69,7 @@ uint64_t get_allocation_size(connection_struct *conn, files_struct *fsp, const S
 
 static bool samba_private_attr_name(const char *unix_ea_name)
 {
-       static const char *prohibited_ea_names[] = {
+       static const char * const prohibited_ea_names[] = {
                SAMBA_POSIX_INHERITANCE_EA_NAME,
                SAMBA_XATTR_DOS_ATTRIB,
                NULL
@@ -768,6 +743,12 @@ void send_trans2_replies(connection_struct *conn,
                reply_outbuf(req, 10, total_sent_thistime + alignment_offset
                             + data_alignment_offset);
 
+               /*
+                * We might have SMBtrans2s in req which was transferred to
+                * the outbuf, fix that.
+                */
+               SCVAL(req->outbuf, smb_com, SMBtrans2);
+
                /* Set total params and data to be sent */
                SSVAL(req->outbuf,smb_tprcnt,paramsize);
                SSVAL(req->outbuf,smb_tdrcnt,datasize);
@@ -852,7 +833,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);
@@ -913,6 +896,8 @@ static void call_trans2open(connection_struct *conn,
        uint32 create_options = 0;
        TALLOC_CTX *ctx = talloc_tos();
 
+       SET_STAT_INVALID(sbuf);
+
        /*
         * Ensure we have enough parameters to perform the operation.
         */
@@ -1000,22 +985,24 @@ static void call_trans2open(connection_struct *conn,
                return;
        }
 
-       status = create_file(conn,                      /* conn */
-                            req,                       /* req */
-                            0,                         /* root_dir_fid */
-                            fname,                     /* fname */
-                            access_mask,               /* access_mask */
-                            share_mode,                /* share_access */
-                            create_disposition,        /* create_disposition*/
-                            create_options,            /* create_options */
-                            open_attr,                 /* file_attributes */
-                            oplock_request,            /* oplock_request */
-                            open_size,                 /* allocation_size */
-                            NULL,                      /* sd */
-                            ea_list,                   /* ea_list */
-                            &fsp,                      /* result */
-                            &smb_action,               /* pinfo */
-                            &sbuf);                    /* psbuf */
+       status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               0,                                      /* root_dir_fid */
+               fname,                                  /* fname */
+               CFF_DOS_PATH,                           /* create_file_flags */
+               access_mask,                            /* access_mask */
+               share_mode,                             /* share_access */
+               create_disposition,                     /* create_disposition*/
+               create_options,                         /* create_options */
+               open_attr,                              /* file_attributes */
+               oplock_request,                         /* oplock_request */
+               open_size,                              /* allocation_size */
+               NULL,                                   /* sd */
+               ea_list,                                /* ea_list */
+               &fsp,                                   /* result */
+               &smb_action,                            /* pinfo */
+               &sbuf);                                 /* psbuf */
 
        if (!NT_STATUS_IS_OK(status)) {
                if (open_was_deferred(req->mid)) {
@@ -1026,10 +1013,10 @@ static void call_trans2open(connection_struct *conn,
                return;
        }
 
-       size = get_file_size(sbuf);
+       size = get_file_size_stat(&sbuf);
        fattr = dos_mode(conn,fsp->fsp_name,&sbuf);
-       mtime = sbuf.st_mtime;
-       inode = sbuf.st_ino;
+       mtime = convert_timespec_to_time_t(sbuf.st_ex_mtime);
+       inode = sbuf.st_ex_ino;
        if (fattr & aDIR) {
                close_file(req, fsp, ERROR_CLOSE);
                reply_doserror(req, ERRDOS,ERRnoaccess);
@@ -1087,15 +1074,13 @@ static bool exact_match(connection_struct *conn,
 {
        if (mask[0] == '.' && mask[1] == 0)
                return False;
-       if (conn->case_sensitive)
-               return strcmp(str,mask)==0;
-       if (StrCaseCmp(str,mask) != 0) {
-               return False;
-       }
        if (dptr_has_wild(conn->dirptr)) {
                return False;
        }
-       return True;
+       if (conn->case_sensitive)
+               return strcmp(str,mask)==0;
+       else
+               return StrCaseCmp(str,mask) == 0;
 }
 
 /****************************************************************************
@@ -1129,7 +1114,7 @@ static uint32 unix_filetype(mode_t mode)
                return UNIX_TYPE_SOCKET;
 #endif
 
-       DEBUG(0,("unix_filetype: unknown filetype %u", (unsigned)mode));
+       DEBUG(0,("unix_filetype: unknown filetype %u\n", (unsigned)mode));
        return UNIX_TYPE_UNKNOWN;
 }
 
@@ -1151,7 +1136,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;
                }
        }
@@ -1222,7 +1207,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;
        }
@@ -1253,12 +1238,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;
@@ -1334,9 +1319,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))) {
@@ -1353,6 +1342,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. */
                        }
 
@@ -1365,6 +1355,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                        bool isdots = (ISDOT(dname) || ISDOTDOT(dname));
 
                        if (dont_descend && !isdots) {
+                               TALLOC_FREE(fname);
                                continue;
                        }
 
@@ -1382,6 +1373,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                        }
 
                        if (!pathreal) {
+                               TALLOC_FREE(fname);
                                return False;
                        }
 
@@ -1390,6 +1382,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                                        DEBUG(5,("get_lanman2_dir_entry:Couldn't lstat [%s] (%s)\n",
                                                pathreal,strerror(errno)));
                                        TALLOC_FREE(pathreal);
+                                       TALLOC_FREE(fname);
                                        continue;
                                }
                        } else if (!VALID_STAT(sbuf) && SMB_VFS_STAT(conn,pathreal,&sbuf) != 0) {
@@ -1401,6 +1394,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                                        DEBUG(5,("get_lanman2_dir_entry:Couldn't stat [%s] (%s)\n",
                                                pathreal,strerror(errno)));
                                        TALLOC_FREE(pathreal);
+                                       TALLOC_FREE(fname);
                                        continue;
                                }
                        }
@@ -1414,17 +1408,18 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                        if (!dir_check_ftype(conn,mode,dirtype)) {
                                DEBUG(5,("get_lanman2_dir_entry: [%s] attribs didn't match %x\n",fname,dirtype));
                                TALLOC_FREE(pathreal);
+                               TALLOC_FREE(fname);
                                continue;
                        }
 
                        if (!(mode & aDIR)) {
-                               file_size = get_file_size(sbuf);
+                               file_size = get_file_size_stat(&sbuf);
                        }
-                       allocation_size = get_allocation_size(conn,NULL,&sbuf);
+                       allocation_size = SMB_VFS_GET_ALLOC_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)));
+                       mdate_ts = sbuf.st_ex_mtime;
+                       adate_ts = sbuf.st_ex_atime;
+                       create_date_ts = sbuf.st_ex_btime;
 
                        if (ask_sharemode) {
                                struct timespec write_time_ts;
@@ -1447,12 +1442,16 @@ 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",
+                               pathreal,fname));
 
                        found = True;
 
                        dptr_DirCacheAdd(conn->dirptr, dname, curr_dirpos);
                }
+
+               if (!found)
+                       TALLOC_FREE(fname);
        }
 
        p = pdata;
@@ -1737,8 +1736,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);
@@ -1793,8 +1792,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);
@@ -1846,10 +1845,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);
@@ -1881,6 +1881,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;
@@ -1903,7 +1904,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);
@@ -1931,7 +1931,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:
@@ -1980,7 +1980,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;
@@ -2060,7 +2070,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,
@@ -2081,6 +2091,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. */
 
@@ -2095,7 +2108,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;
@@ -2183,7 +2196,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        }
 
        DEBUG( 4, ( "%s mask=%s directory=%s dirtype=%d numentries=%d\n",
-               smb_fn_name(CVAL(req->inbuf,smb_com)),
+               smb_fn_name(req->cmd),
                mask, directory, dirtype, numentries ) );
 
        /*
@@ -2391,6 +2404,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. */
 
@@ -2481,7 +2497,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        }
 
        DEBUG( 3, ( "%s mask=%s directory=%s dirtype=%d numentries=%d\n",
-               smb_fn_name(CVAL(req->inbuf,smb_com)),
+               smb_fn_name(req->cmd),
                mask, directory, dirtype, numentries ) );
 
        /* Check if we can close the dirptr */
@@ -2562,7 +2578,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;
@@ -2637,10 +2653,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);
@@ -2669,7 +2685,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:
@@ -2832,13 +2849,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 "
@@ -2848,7 +2865,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);
@@ -2858,25 +2875,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 */
@@ -2903,8 +2920,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()) {
@@ -3065,6 +3082,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                             i < conn->server_info->ptok->num_sids; ++i) {
                                sid_bytes += ndr_size_dom_sid(
                                        &conn->server_info->ptok->user_sids[i],
+                                       NULL, 
                                        0);
                        }
 
@@ -3087,6 +3105,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                            i < conn->server_info->ptok->num_sids; ++i) {
                                int sid_len = ndr_size_dom_sid(
                                        &conn->server_info->ptok->user_sids[i],
+                                       NULL,
                                        0);
 
                                sid_linearize(pdata + data_len, sid_len,
@@ -3118,7 +3137,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                            max_data_bytes);
 
        DEBUG( 4, ( "%s info_level = %d\n",
-                   smb_fn_name(CVAL(req->inbuf,smb_com)), info_level) );
+                   smb_fn_name(req->cmd), info_level) );
 
        return;
 }
@@ -3281,7 +3300,7 @@ cap_low = 0x%x, cap_high = 0x%x\n",
                        {
                                files_struct *fsp = NULL;
                                SMB_NTQUOTA_STRUCT quotas;
-       
+
                                ZERO_STRUCT(quotas);
 
                                /* access check */
@@ -3316,9 +3335,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
@@ -3334,7 +3353,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
@@ -3350,19 +3369,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:
@@ -3442,7 +3461,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;
@@ -3462,7 +3481,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;
@@ -3511,46 +3530,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;
 
@@ -3594,16 +3613,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,
@@ -3611,11 +3628,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
@@ -3641,9 +3657,6 @@ static bool map_info2_flags_to_sbuf(const SMB_STRUCT_STAT *psbuf,
        }
 
        return True;
-#else
-       return False;
-#endif /* HAVE_STAT_ST_FLAGS */
 }
 
 
@@ -3661,7 +3674,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);
@@ -3681,7 +3694,7 @@ static NTSTATUS marshall_stream_info(unsigned int num_streams,
        unsigned int i;
        unsigned int ofs = 0;
 
-       for (i=0; i<num_streams; i++) {
+       for (i = 0; i < num_streams && ofs <= max_data_bytes; i++) {
                unsigned int next_offset;
                size_t namelen;
                smb_ucs2_t *namebuf;
@@ -3700,11 +3713,6 @@ static NTSTATUS marshall_stream_info(unsigned int num_streams,
 
                namelen -= 2;
 
-               if (ofs + 24 + namelen > max_data_bytes) {
-                       TALLOC_FREE(namebuf);
-                       return NT_STATUS_BUFFER_TOO_SMALL;
-               }
-
                SIVAL(data, ofs+4, namelen);
                SOFF_T(data, ofs+8, streams[i].size);
                SOFF_T(data, ofs+16, streams[i].alloc_size);
@@ -3719,10 +3727,6 @@ static NTSTATUS marshall_stream_info(unsigned int num_streams,
                else {
                        unsigned int align = ndr_align_size(next_offset, 8);
 
-                       if (next_offset + align > max_data_bytes) {
-                               return NT_STATUS_BUFFER_TOO_SMALL;
-                       }
-
                        memset(data+next_offset, 0, align);
                        next_offset += align;
 
@@ -3834,6 +3838,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
        SMB_STRUCT_STAT sbuf;
        char *dos_fname = NULL;
        char *fname = NULL;
+       struct smb_filename *smb_fname = NULL;
        char *fullpathname;
        char *base_name;
        char *p;
@@ -3981,11 +3986,20 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                        return;
                }
 
-               status = unix_convert(ctx, conn, fname, False, &fname, NULL, &sbuf);
+               status = unix_convert(ctx, conn, fname, &smb_fname, 0);
+               if (!NT_STATUS_IS_OK(status)) {
+                       reply_nterror(req, status);
+                       return;
+               }
+               sbuf = smb_fname->st;
+
+               status = get_full_smb_filename(ctx, smb_fname, &fname);
+               TALLOC_FREE(smb_fname);
                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)));
@@ -3993,6 +4007,46 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                        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)) {
@@ -4041,7 +4095,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
        if (!mode)
                mode = FILE_ATTRIBUTE_NORMAL;
 
-       nlink = sbuf.st_nlink;
+       nlink = sbuf.st_ex_nlink;
 
        if (nlink && (mode&aDIR)) {
                nlink = 1;
@@ -4053,7 +4107,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
 
        fullpathname = fname;
        if (!(mode & aDIR))
-               file_size = get_file_size(sbuf);
+               file_size = get_file_size_stat(&sbuf);
 
        /* Pull out any data sent here before we realloc. */
        switch (info_level) {
@@ -4135,11 +4189,11 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        dstart = pdata;
        dend = dstart + data_size - 1;
 
-       create_time_ts = get_create_timespec(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
-       mtime_ts = get_mtimespec(&sbuf);
-       atime_ts = get_atimespec(&sbuf);
+       create_time_ts = sbuf.st_ex_btime;
+       mtime_ts = sbuf.st_ex_mtime;
+       atime_ts = sbuf.st_ex_atime;
 
-       allocation_size = get_allocation_size(conn,fsp,&sbuf);
+       allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&sbuf);
 
        if (!fsp) {
                /* Do we have this path open ? */
@@ -4147,7 +4201,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                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);
+                       allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, fsp1, &sbuf);
                }
        }
 
@@ -4394,8 +4448,8 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                           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 */
+                       SIVAL(pdata,0,sbuf.st_ex_ino); /* FileIndexLow */
+                       SIVAL(pdata,4,sbuf.st_ex_dev); /* FileIndexHigh */
                        data_size = 8;
                        break;
 
@@ -4564,7 +4618,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
 
                                DEBUG(10,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_LINK\n"));
 #ifdef S_ISLNK
-                               if(!S_ISLNK(sbuf.st_mode)) {
+                               if(!S_ISLNK(sbuf.st_ex_mode)) {
                                        reply_unixerror(req, ERRSRV,
                                                        ERRbadlink);
                                        return;
@@ -4614,7 +4668,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                        return;
                                }
 
-                               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 {
@@ -4781,57 +4835,64 @@ NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
                const char *oldname_in,
                const char *newname_in)
 {
-       SMB_STRUCT_STAT sbuf1, sbuf2;
-       char *last_component_oldname = NULL;
-       char *last_component_newname = NULL;
+       struct smb_filename *smb_fname = NULL;
+       struct smb_filename *smb_fname_new = 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, &smb_fname, 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto out;
+       }
 
-       status = unix_convert(ctx, conn, oldname_in, False, &oldname,
-                       &last_component_oldname, &sbuf1);
+       status = get_full_smb_filename(ctx, smb_fname, &oldname);
        if (!NT_STATUS_IS_OK(status)) {
-               return status;
+               goto out;
        }
 
        status = check_name(conn, oldname);
        if (!NT_STATUS_IS_OK(status)) {
-               return status;
+               goto out;
        }
 
        /* source must already exist. */
-       if (!VALID_STAT(sbuf1)) {
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+       if (!VALID_STAT(smb_fname->st)) {
+               status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+               goto out;
        }
 
-       status = unix_convert(ctx, conn, newname_in, False, &newname,
-                       &last_component_newname, &sbuf2);
+       status = unix_convert(ctx, conn, newname_in, &smb_fname_new, 0);
        if (!NT_STATUS_IS_OK(status)) {
-               return status;
+               goto out;
+       }
+
+       status = get_full_smb_filename(ctx, smb_fname_new, &newname);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto out;
        }
 
        status = check_name(conn, newname);
        if (!NT_STATUS_IS_OK(status)) {
-               return status;
+               goto out;
        }
 
        /* Disallow if newname already exists. */
-       if (VALID_STAT(sbuf2)) {
-               return NT_STATUS_OBJECT_NAME_COLLISION;
+       if (VALID_STAT(smb_fname_new->st)) {
+               status = NT_STATUS_OBJECT_NAME_COLLISION;
+               goto out;
        }
 
        /* No links from a directory. */
-       if (S_ISDIR(sbuf1.st_mode)) {
-               return NT_STATUS_FILE_IS_A_DIRECTORY;
+       if (S_ISDIR(smb_fname->st.st_ex_mode)) {
+               status = NT_STATUS_FILE_IS_A_DIRECTORY;
+               goto out;
        }
 
        /* Ensure this is within the share. */
        status = check_reduced_name(conn, oldname);
        if (!NT_STATUS_IS_OK(status)) {
-               return status;
+               goto out;
        }
 
        DEBUG(10,("hardlink_internals: doing hard link %s -> %s\n", newname, oldname ));
@@ -4839,9 +4900,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(smb_fname);
+       TALLOC_FREE(smb_fname_new);
        return status;
 }
 
@@ -4853,7 +4916,7 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
                           files_struct *fsp,
                           const char *fname,
                           const SMB_STRUCT_STAT *psbuf,
-                          struct timespec ts[2],
+                          struct smb_file_time *ft,
                           bool setting_write_time)
 {
        uint32 action =
@@ -4865,23 +4928,29 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
        }
 
        /* 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= psbuf->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 = psbuf->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
@@ -4889,9 +4958,10 @@ 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 = psbuf->st_ex_mtime;
+               struct timespec ats = psbuf->st_ex_atime;
+               if ((timespec_compare(&ft->atime, &ats) == 0) &&
+                   (timespec_compare(&ft->mtime, &mts) == 0)) {
                        return NT_STATUS_OK;
                }
        }
@@ -4908,20 +4978,29 @@ 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) {
-                       set_sticky_write_time_fsp(fsp, ts[1]);
+                       if (fsp->base_fsp) {
+                               set_sticky_write_time_fsp(fsp->base_fsp,
+                                                         ft->mtime);
+                       } else {
+                               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]);
+                                           ft->mtime);
                }
        }
 
        DEBUG(10,("smb_set_file_time: setting utimes to modified values.\n"));
 
-       if(file_ntimes(conn, fname, ts)!=0) {
+       if (fsp && fsp->base_fsp) {
+               fname = fsp->base_fsp->fsp_name;
+       }
+
+       if(file_ntimes(conn, fname, ft)!=0) {
                return map_nt_error_from_unix(errno);
        }
        notify_fname(conn, NOTIFY_ACTION_MODIFIED, action, fname);
@@ -4934,6 +5013,7 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
+                               files_struct *fsp,
                                const char *fname,
                                SMB_STRUCT_STAT *psbuf,
                                uint32 dosmode)
@@ -4942,8 +5022,16 @@ static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
+       if (fsp) {
+               if (fsp->base_fsp) {
+                       fname = fsp->base_fsp->fsp_name;
+               } else {
+                       fname = fsp->fsp_name;
+               }
+       }
+
        if (dosmode) {
-               if (S_ISDIR(psbuf->st_mode)) {
+               if (S_ISDIR(psbuf->st_ex_mode)) {
                        dosmode |= aDIR;
                } else {
                        dosmode &= ~aDIR;
@@ -4987,7 +5075,7 @@ 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;
        }
 
@@ -5003,15 +5091,26 @@ static NTSTATUS smb_set_file_size(connection_struct *conn,
                return NT_STATUS_OK;
        }
 
-       status = open_file_ntcreate(conn, req, fname, psbuf,
-                               FILE_WRITE_ATTRIBUTES,
-                               FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
-                               FILE_OPEN,
-                               0,
-                               FILE_ATTRIBUTE_NORMAL,
-                               FORCE_OPLOCK_BREAK_TO_NONE,
-                               NULL, &new_fsp);
-       
+        status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               0,                                      /* root_dir_fid */
+               fname,                                  /* fname */
+               0,                                      /* create_file_flags */
+               FILE_WRITE_ATTRIBUTES,                  /* access_mask */
+               (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
+                   FILE_SHARE_DELETE),
+               FILE_OPEN,                              /* create_disposition*/
+               0,                                      /* create_options */
+               FILE_ATTRIBUTE_NORMAL,                  /* file_attributes */
+               FORCE_OPLOCK_BREAK_TO_NONE,             /* oplock_request */
+               0,                                      /* allocation_size */
+               NULL,                                   /* sd */
+               NULL,                                   /* ea_list */
+               &new_fsp,                               /* result */
+               NULL,                                   /* pinfo */
+               psbuf);                                 /* psbuf */
+
        if (!NT_STATUS_IS_OK(status)) {
                /* NB. We check for open_was_deferred in the caller. */
                return status;
@@ -5306,6 +5405,7 @@ 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;
        NTSTATUS status = NT_STATUS_OK;
        char *p;
@@ -5347,38 +5447,47 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                return NT_STATUS_NOT_SUPPORTED;
        }
 
-       /* Create the base directory. */
-       base_name = talloc_strdup(ctx, fname);
-       if (!base_name) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       p = strrchr_m(base_name, '/');
-       if (p) {
-               p[1] = '\0';
-       } else {
-               base_name = talloc_strdup(ctx, "./");
+       if (fsp && fsp->base_fsp) {
+               /* newname must be a stream name. */
+               if (newname[0] != ':') {
+                       return NT_STATUS_NOT_SUPPORTED;
+               }
+               base_name = talloc_asprintf(ctx, "%s%s",
+                                          fsp->base_fsp->fsp_name,
+                                          newname);
                if (!base_name) {
                        return NT_STATUS_NO_MEMORY;
                }
-       }
-       /* Append the new name. */
-       base_name = talloc_asprintf_append(base_name,
-                       "%s",
-                       newname);
-       if (!base_name) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       if (fsp) {
-               SMB_STRUCT_STAT sbuf;
-               char *newname_last_component = NULL;
+       } else {
+               /* newname must *not* be a stream name. */
+               if (is_ntfs_stream_name(newname)) {
+                       return NT_STATUS_NOT_SUPPORTED;
+               }
 
-               ZERO_STRUCT(sbuf);
+               /* Create the base directory. */
+               base_name = talloc_strdup(ctx, fname);
+               if (!base_name) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+               p = strrchr_m(base_name, '/');
+               if (p) {
+                       p[1] = '\0';
+               } else {
+                       base_name = talloc_strdup(ctx, "./");
+                       if (!base_name) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
+               }
+               /* Append the new name. */
+               base_name = talloc_asprintf_append(base_name,
+                               "%s",
+                               newname);
+               if (!base_name) {
+                       return NT_STATUS_NO_MEMORY;
+               }
 
-               status = unix_convert(ctx, conn, newname, False,
-                                       &newname,
-                                       &newname_last_component,
-                                       &sbuf);
+               status = unix_convert(ctx, conn, newname, &smb_fname,
+                                     UCF_SAVE_LCOMP);
 
                /* If an error we expect this to be
                 * NT_STATUS_OBJECT_PATH_NOT_FOUND */
@@ -5386,14 +5495,17 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                if (!NT_STATUS_IS_OK(status)
                    && !NT_STATUS_EQUAL(NT_STATUS_OBJECT_PATH_NOT_FOUND,
                                        status)) {
-                       return 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,
-                                             overwrite);
+                                             smb_fname ?
+                                             smb_fname->original_lcomp : NULL,
+                                             0, overwrite);
        } else {
                DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
                        fname, base_name ));
@@ -5401,7 +5513,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;
 }
 
@@ -5473,7 +5586,7 @@ static NTSTATUS smb_set_posix_acl(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_set_posix_lock(connection_struct *conn,
-                               const struct smb_request *req,
+                               struct smb_request *req,
                                const char *pdata,
                                int total_data,
                                files_struct *fsp)
@@ -5562,7 +5675,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)) {
                        /*
@@ -5602,16 +5716,21 @@ static NTSTATUS smb_set_info_standard(connection_struct *conn,
                                        const char *fname,
                                        const SMB_STRUCT_STAT *psbuf)
 {
-       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 ));
@@ -5620,7 +5739,7 @@ static NTSTATUS smb_set_info_standard(connection_struct *conn,
                                fsp,
                                fname,
                                psbuf,
-                               ts,
+                               &ft,
                                true);
 }
 
@@ -5638,47 +5757,48 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
        /* 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, fsp, fname, psbuf, 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;
                }
        }
 
@@ -5689,7 +5809,7 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
                                fsp,
                                fname,
                                psbuf,
-                               ts,
+                               &ft,
                                setting_write_time);
 }
 
@@ -5740,7 +5860,7 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
        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(psbuf)) {
                        if (vfs_allocate_file_space(fsp, allocation_size) == -1) {
                                return map_nt_error_from_unix(errno);
                        }
@@ -5756,14 +5876,25 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
 
        /* Pathname or stat or directory file. */
 
-       status = open_file_ntcreate(conn, req, fname, psbuf,
-                               FILE_WRITE_DATA,
-                               FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
-                               FILE_OPEN,
-                               0,
-                               FILE_ATTRIBUTE_NORMAL,
-                               FORCE_OPLOCK_BREAK_TO_NONE,
-                               NULL, &new_fsp);
+       status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               0,                                      /* root_dir_fid */
+               fname,                                  /* fname */
+               0,                                      /* create_file_flags */
+               FILE_WRITE_DATA,                        /* access_mask */
+               (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
+                   FILE_SHARE_DELETE),
+               FILE_OPEN,                              /* create_disposition*/
+               0,                                      /* create_options */
+               FILE_ATTRIBUTE_NORMAL,                  /* file_attributes */
+               FORCE_OPLOCK_BREAK_TO_NONE,             /* oplock_request */
+               0,                                      /* allocation_size */
+               NULL,                                   /* sd */
+               NULL,                                   /* ea_list */
+               &new_fsp,                               /* result */
+               NULL,                                   /* pinfo */
+               psbuf);                                 /* psbuf */
 
        if (!NT_STATUS_IS_OK(status)) {
                /* NB. We check for open_was_deferred in the caller. */
@@ -5771,7 +5902,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(psbuf)) {
                if (vfs_allocate_file_space(new_fsp, allocation_size) == -1) {
                        status = map_nt_error_from_unix(errno);
                        close_file(req, new_fsp, NORMAL_CLOSE);
@@ -5898,9 +6029,12 @@ static NTSTATUS smb_unix_mknod(connection_struct *conn,
         */
 
        if (lp_inherit_perms(SNUM(conn))) {
-               inherit_access_posix_acl(
-                       conn, parent_dirname(fname),
-                       fname, unixmode);
+               char *parent;
+               if (!parent_dirname(talloc_tos(), fname, &parent, NULL)) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+               inherit_access_posix_acl(conn, parent, fname, unixmode);
+               TALLOC_FREE(parent);
        }
 
        if (SMB_VFS_STAT(conn, fname, psbuf) != 0) {
@@ -5923,7 +6057,7 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
                                        const char *fname,
                                        SMB_STRUCT_STAT *psbuf)
 {
-       struct timespec ts[2];
+       struct smb_file_time ft;
        uint32 raw_unixmode;
        mode_t unixmode;
        SMB_OFF_T size = 0;
@@ -5933,6 +6067,8 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
        bool delete_on_fail = False;
        enum perm_type ptype;
 
+       ZERO_STRUCT(ft);
+
        if (total_data < 100) {
                return NT_STATUS_INVALID_PARAMETER;
        }
@@ -5950,14 +6086,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 (S_ISDIR(psbuf->st_ex_mode)) {
                        ptype = PERM_EXISTING_DIR;
                } else {
                        ptype = PERM_EXISTING_FILE;
@@ -5993,9 +6129,9 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
 
                /* 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(psbuf);
+               ft.atime = psbuf->st_ex_atime;
+               ft.mtime = psbuf->st_ex_mtime;
                /* 
                 * We continue here as we might want to change the 
                 * owner uid/gid.
@@ -6009,7 +6145,7 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
         * */
 
        if (!size) {
-               size = get_file_size(*psbuf);
+               size = get_file_size_stat(psbuf);
        }
 #endif
 
@@ -6029,13 +6165,13 @@ 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) && (psbuf->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 ));
 
-               if (S_ISLNK(psbuf->st_mode)) {
+               if (S_ISLNK(psbuf->st_ex_mode)) {
                        ret = SMB_VFS_LCHOWN(conn, fname, set_owner, (gid_t)-1);
                } else {
                        ret = SMB_VFS_CHOWN(conn, fname, set_owner, (gid_t)-1);
@@ -6054,7 +6190,7 @@ 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)) {
+       if ((set_grp != (uid_t)SMB_GID_NO_CHANGE) && (psbuf->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, fname ));
                if (SMB_VFS_CHOWN(conn, fname, (uid_t)-1, set_grp) != 0) {
@@ -6083,7 +6219,7 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
                                fsp,
                                fname,
                                psbuf,
-                               ts,
+                               &ft,
                                true);
 }
 
@@ -6187,16 +6323,24 @@ static NTSTATUS smb_posix_mkdir(connection_struct *conn,
        DEBUG(10,("smb_posix_mkdir: file %s, mode 0%o\n",
                fname, (unsigned int)unixmode ));
 
-       status = open_directory(conn, req,
-                               fname,
-                               psbuf,
-                               FILE_READ_ATTRIBUTES, /* Just a stat open */
-                               FILE_SHARE_NONE, /* Ignored for stat opens */
-                               FILE_CREATE,
-                               0,
-                               mod_unixmode,
-                               &info,
-                               &fsp);
+       status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               0,                                      /* root_dir_fid */
+               fname,                                  /* fname */
+               0,                                      /* create_file_flags */
+               FILE_READ_ATTRIBUTES,                   /* access_mask */
+               FILE_SHARE_NONE,                        /* share_access */
+               FILE_CREATE,                            /* create_disposition*/
+               FILE_DIRECTORY_FILE,                    /* create_options */
+               mod_unixmode,                           /* file_attributes */
+               0,                                      /* oplock_request */
+               0,                                      /* allocation_size */
+               NULL,                                   /* sd */
+               NULL,                                   /* ea_list */
+               &fsp,                                   /* result */
+               &info,                                  /* pinfo */
+               psbuf);                                 /* psbuf */
 
         if (NT_STATUS_IS_OK(status)) {
                 close_file(req, fsp, NORMAL_CLOSE);
@@ -6317,6 +6461,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 ));
@@ -6353,17 +6499,25 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
                (unsigned int)wire_open_mode,
                (unsigned int)unixmode ));
 
-       status = open_file_ntcreate(conn, req,
-                               fname,
-                               psbuf,
-                               access_mask,
-                               FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
-                               create_disp,
-                               0,              /* no create options yet. */
-                               mod_unixmode,
-                               oplock_request,
-                               &info,
-                               &fsp);
+        status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               0,                                      /* root_dir_fid */
+               fname,                                  /* fname */
+               0,                                      /* create_file_flags */
+               access_mask,                            /* access_mask */
+               (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
+                   FILE_SHARE_DELETE),
+               create_disp,                            /* create_disposition*/
+               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 */
 
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -6448,6 +6602,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
        uint16 flags = 0;
        char del = 1;
        int info = 0;
+       int create_options = 0;
        int i;
        struct share_mode_lock *lck = NULL;
 
@@ -6471,30 +6626,28 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
                fname));
 
        if (VALID_STAT_OF_DIR(*psbuf)) {
-               status = open_directory(conn, req,
-                                       fname,
-                                       psbuf,
-                                       DELETE_ACCESS,
-                                       FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
-                                       FILE_OPEN,
-                                       0,
-                                       FILE_FLAG_POSIX_SEMANTICS|0777,
-                                       &info,
-                                       &fsp);
-       } else {
-
-               status = open_file_ntcreate(conn, req,
-                               fname,
-                               psbuf,
-                               DELETE_ACCESS,
-                               FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
-                               FILE_OPEN,
-                               0,
-                               FILE_FLAG_POSIX_SEMANTICS|0777,
-                               0, /* No oplock, but break existing ones. */
-                               &info,
-                               &fsp);
-       }
+               create_options |= FILE_DIRECTORY_FILE;
+       }
+
+        status = SMB_VFS_CREATE_FILE(
+               conn,                                   /* conn */
+               req,                                    /* req */
+               0,                                      /* root_dir_fid */
+               fname,                                  /* fname */
+               0,                                      /* create_file_flags */
+               DELETE_ACCESS,                          /* access_mask */
+               (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
+                   FILE_SHARE_DELETE),
+               FILE_OPEN,                              /* create_disposition*/
+               create_options,                         /* create_options */
+               FILE_FLAG_POSIX_SEMANTICS|0777,         /* file_attributes */
+               0,                                      /* oplock_request */
+               0,                                      /* allocation_size */
+               NULL,                                   /* sd */
+               NULL,                                   /* ea_list */
+               &fsp,                                   /* result */
+               &info,                                  /* pinfo */
+               psbuf);                                 /* psbuf */
 
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -6567,6 +6720,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 +6835,15 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                        return;
                }
 
-               status = unix_convert(ctx, conn, fname, False,
-                               &fname, NULL, &sbuf);
+               status = unix_convert(ctx, conn, fname, &smb_fname, 0);
+               if (!NT_STATUS_IS_OK(status)) {
+                       reply_nterror(req, status);
+                       return;
+               }
+               sbuf = smb_fname->st;
+
+               status = get_full_smb_filename(ctx, smb_fname, &fname);
+               TALLOC_FREE(smb_fname);
                if (!NT_STATUS_IS_OK(status)) {
                        reply_nterror(req, status);
                        return;
@@ -6956,7 +7117,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. */
@@ -6983,7 +7143,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;
 }
 
@@ -6996,10 +7156,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();
@@ -7024,7 +7184,13 @@ 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);
+       status = unix_convert(ctx, conn, directory, &smb_dname, 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               reply_nterror(req, status);
+               return;
+       }
+
+       status = get_full_smb_filename(ctx, smb_dname, &directory);
        if (!NT_STATUS_IS_OK(status)) {
                reply_nterror(req, status);
                return;
@@ -7080,7 +7246,7 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
                reply_nterror(req, status);
                return;
        }
-  
+
        /* Try and set any given EA. */
        if (ea_list) {
                status = set_ea(conn, NULL, directory, ea_list);
@@ -7101,7 +7267,7 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
        SSVAL(params,0,0);
 
        send_trans2_replies(conn, req, params, 2, *ppdata, 0, max_data_bytes);
-  
+
        return;
 }
 
@@ -7116,7 +7282,6 @@ static void call_trans2findnotifyfirst(connection_struct *conn,
                                       char **ppdata, int total_data,
                                       unsigned int max_data_bytes)
 {
-       static uint16 fnf_handle = 257;
        char *params = *pparams;
        uint16 info_level;
 
@@ -7155,7 +7320,7 @@ static void call_trans2findnotifyfirst(connection_struct *conn,
                fnf_handle = 257;
 
        send_trans2_replies(conn, req, params, 6, *ppdata, 0, max_data_bytes);
-  
+
        return;
 }
 
@@ -7186,7 +7351,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;
 }
 
@@ -7263,8 +7428,8 @@ static void call_trans2ioctl(connection_struct *conn,
                return;
        }
 
-       if ((SVAL(req->inbuf,(smb_setup+4)) == LMCAT_SPL)
-           && (SVAL(req->inbuf,(smb_setup+6)) == LMFUNC_GETJOBID)) {
+       if ((SVAL(req->vwv+16, 0) == LMCAT_SPL)
+           && (SVAL(req->vwv+17, 0) == LMFUNC_GETJOBID)) {
                *ppdata = (char *)SMB_REALLOC(*ppdata, 32);
                if (*ppdata == NULL) {
                        reply_nterror(req, NT_STATUS_NO_MEMORY);
@@ -7336,7 +7501,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));
@@ -7372,6 +7537,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:
@@ -7527,8 +7694,6 @@ void reply_trans2(struct smb_request *req)
        unsigned int psoff;
        unsigned int pscnt;
        unsigned int tran_call;
-       unsigned int size;
-       unsigned int av_size;
        struct trans_state *state;
        NTSTATUS result;
 
@@ -7545,8 +7710,6 @@ void reply_trans2(struct smb_request *req)
        psoff = SVAL(req->vwv+10, 0);
        pscnt = SVAL(req->vwv+9, 0);
        tran_call = SVAL(req->vwv+14, 0);
-       size = smb_len(req->inbuf) + 4;
-       av_size = smb_len(req->inbuf);
 
        result = allow_new_trans(conn->pending_trans, req->mid);
        if (!NT_STATUS_IS_OK(result)) {
@@ -7611,8 +7774,8 @@ void reply_trans2(struct smb_request *req)
                 */
                if ( (state->setup_count == 4)
                     && (tran_call == TRANSACT2_IOCTL)
-                    && (SVAL(req->inbuf,(smb_setup+4)) == LMCAT_SPL)
-                    && (SVAL(req->inbuf,(smb_setup+6)) == LMFUNC_GETJOBID)) {
+                    && (SVAL(req->vwv+16, 0) == LMCAT_SPL)
+                    && (SVAL(req->vwv+17, 0) == LMFUNC_GETJOBID)) {
                        DEBUG(2,("Got Trans2 DevIOctl jobid\n"));
                } else {
                        DEBUG(2,("Invalid smb_sucnt in trans2 call(%u)\n",state->setup_count));
@@ -7628,6 +7791,12 @@ void reply_trans2(struct smb_request *req)
                goto bad_param;
 
        if (state->total_data) {
+
+               if (trans_oob(state->total_data, 0, dscnt)
+                   || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
+                       goto bad_param;
+               }
+
                /* Can't use talloc here, the core routines do realloc on the
                 * params and data. */
                state->data = (char *)SMB_MALLOC(state->total_data);
@@ -7640,21 +7809,16 @@ void reply_trans2(struct smb_request *req)
                        return;
                }
 
-               if (dscnt > state->total_data ||
-                               dsoff+dscnt < dsoff) {
-                       goto bad_param;
-               }
-
-               if (dsoff > av_size ||
-                               dscnt > av_size ||
-                               dsoff+dscnt > av_size) {
-                       goto bad_param;
-               }
-
                memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
        }
 
        if (state->total_param) {
+
+               if (trans_oob(state->total_param, 0, pscnt)
+                   || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
+                       goto bad_param;
+               }
+
                /* Can't use talloc here, the core routines do realloc on the
                 * params and data. */
                state->param = (char *)SMB_MALLOC(state->total_param);
@@ -7668,17 +7832,6 @@ void reply_trans2(struct smb_request *req)
                        return;
                } 
 
-               if (pscnt > state->total_param ||
-                               psoff+pscnt < psoff) {
-                       goto bad_param;
-               }
-
-               if (psoff > av_size ||
-                               pscnt > av_size ||
-                               psoff+pscnt > av_size) {
-                       goto bad_param;
-               }
-
                memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
        }
 
@@ -7726,8 +7879,6 @@ void reply_transs2(struct smb_request *req)
        connection_struct *conn = req->conn;
        unsigned int pcnt,poff,dcnt,doff,pdisp,ddisp;
        struct trans_state *state;
-       unsigned int size;
-       unsigned int av_size;
 
        START_PROFILE(SMBtranss2);
 
@@ -7739,9 +7890,6 @@ void reply_transs2(struct smb_request *req)
                return;
        }
 
-       size = smb_len(req->inbuf)+4;
-       av_size = smb_len(req->inbuf);
-
        for (state = conn->pending_trans; state != NULL;
             state = state->next) {
                if (state->mid == req->mid) {
@@ -7773,47 +7921,25 @@ 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;
 
        if (pcnt) {
-               if (pdisp > state->total_param ||
-                               pcnt > state->total_param ||
-                               pdisp+pcnt > state->total_param ||
-                               pdisp+pcnt < pdisp) {
+               if (trans_oob(state->total_param, pdisp, pcnt)
+                   || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
                        goto bad_param;
                }
-
-               if (poff > av_size ||
-                               pcnt > av_size ||
-                               poff+pcnt > av_size ||
-                               poff+pcnt < poff) {
-                       goto bad_param;
-               }
-
-               memcpy(state->param+pdisp,smb_base(req->inbuf)+poff,
-                      pcnt);
+               memcpy(state->param+pdisp,smb_base(req->inbuf)+poff,pcnt);
        }
 
        if (dcnt) {
-               if (ddisp > state->total_data ||
-                               dcnt > state->total_data ||
-                               ddisp+dcnt > state->total_data ||
-                               ddisp+dcnt < ddisp) {
+               if (trans_oob(state->total_data, ddisp, dcnt)
+                   || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
                        goto bad_param;
                }
-
-               if (ddisp > av_size ||
-                               dcnt > av_size ||
-                               ddisp+dcnt > av_size ||
-                               ddisp+dcnt < ddisp) {
-                       goto bad_param;
-               }
-
-               memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,
-                      dcnt);      
+               memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
        }
 
        if ((state->received_param < state->total_param) ||
@@ -7822,12 +7948,6 @@ void reply_transs2(struct smb_request *req)
                return;
        }
 
-       /*
-        * construct_reply_common will copy smb_com from inbuf to
-        * outbuf. SMBtranss2 is wrong here.
-        */
-       SCVAL(req->inbuf,smb_com,SMBtrans2);
-
        handle_trans2(conn, req, state);
 
        DLIST_REMOVE(conn->pending_trans, state);