r23474: Here's a small patch that disables the libkrb5.so replay cache
[tprouty/samba.git] / source / smbd / trans2.c
index 60becc95f67aaed49c1b51221cdfd8ff7de11684..429fdc154d645f828aaeac5969bce99ae6a9e9d2 100644 (file)
@@ -5,6 +5,7 @@
    Copyright (C) Stefan (metze) Metzmacher     2003
    Copyright (C) Volker Lendecke               2005
    Copyright (C) Steve French                  2005
+   Copyright (C) James Peach                   2007
 
    Extensively modified by Andrew Tridgell, 1995
 
@@ -34,6 +35,16 @@ extern struct current_user current_user;
 #define get_file_size(sbuf) ((sbuf).st_size)
 #define DIR_ENTRY_SAFETY_MARGIN 4096
 
+static char *store_file_unix_basic(connection_struct *conn,
+                               char *pdata,
+                               files_struct *fsp,
+                               const SMB_STRUCT_STAT *psbuf);
+
+static char *store_file_unix_basic_info2(connection_struct *conn,
+                               char *pdata,
+                               files_struct *fsp,
+                               const SMB_STRUCT_STAT *psbuf);
+
 /********************************************************************
  Roundup a value to the nearest allocation roundup size boundary.
  Only do this for Windows clients.
@@ -56,7 +67,7 @@ SMB_BIG_UINT smb_roundup(connection_struct *conn, SMB_BIG_UINT val)
  account sparse files.
 ********************************************************************/
 
-SMB_BIG_UINT get_allocation_size(connection_struct *conn, files_struct *fsp, SMB_STRUCT_STAT *sbuf)
+SMB_BIG_UINT get_allocation_size(connection_struct *conn, files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
 {
        SMB_BIG_UINT ret;
 
@@ -136,7 +147,7 @@ static BOOL get_ea_value(TALLOC_CTX *mem_ctx, connection_struct *conn, files_str
        }
 
        DEBUG(10,("get_ea_value: EA %s is of length %u: ", ea_name, (unsigned int)sizeret));
-       dump_data(10, val, sizeret);
+       dump_data(10, (uint8 *)val, sizeret);
 
        pea->flags = 0;
        if (strnequal(ea_name, "user.", 5)) {
@@ -476,7 +487,7 @@ struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t da
        }
 
        DEBUG(10,("read_ea_list_entry: read ea name %s\n", eal->ea.name));
-       dump_data(10, (const char *)eal->ea.value.data, eal->ea.value.length);
+       dump_data(10, eal->ea.value.data, eal->ea.value.length);
 
        return eal;
 }
@@ -566,7 +577,8 @@ static struct ea_list *ea_list_union(struct ea_list *name_list, struct ea_list *
   HACK ! Always assumes smb_setup field is zero.
 ****************************************************************************/
 
-int send_trans2_replies(char *outbuf,
+int send_trans2_replies(const char *inbuf,
+                       char *outbuf,
                        int bufsize,
                        const char *params, 
                        int paramsize,
@@ -591,7 +603,7 @@ int send_trans2_replies(char *outbuf,
 
        /* Initially set the wcnt area to be 10 - this is true for all trans2 replies */
        
-       set_message(outbuf,10,0,True);
+       set_message(inbuf,outbuf,10,0,True);
 
        /* 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
@@ -646,7 +658,7 @@ int send_trans2_replies(char *outbuf,
 
                total_sent_thistime = MIN(total_sent_thistime, useable_space+ alignment_offset + data_alignment_offset);
 
-               set_message(outbuf, 10, total_sent_thistime, True);
+               set_message(inbuf, outbuf, 10, total_sent_thistime, True);
 
                /* Set total params and data to be sent */
                SSVAL(outbuf,smb_tprcnt,paramsize);
@@ -939,7 +951,7 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
        }
 
        /* Send the required number of replies */
-       send_trans2_replies(outbuf, bufsize, params, 30, *ppdata, 0, max_data_bytes);
+       send_trans2_replies(inbuf, outbuf, bufsize, params, 30, *ppdata, 0, max_data_bytes);
 
        return -1;
 }
@@ -1149,16 +1161,28 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                DEBUG(8,("get_lanman2_dir_entry:readdir on dirptr 0x%lx now at offset %ld\n",
                        (long)conn->dirptr,curr_dirpos));
       
-               if (!dname) 
+               if (!dname) {
                        return(False);
+               }
+
+               /*
+                * fname may get mangled, dname is never mangled.
+                * Whenever we're accessing the filesystem we use
+                * pathreal which is composed from dname.
+                */
 
                pstrcpy(fname,dname);      
 
-               if(!(got_match = *got_exact_match = exact_match(conn, fname, mask)))
+               /* This will mangle fname if it's an illegal name. */
+               mangle_map(fname,False,True,conn->params);
+
+               if(!(got_match = *got_exact_match = exact_match(conn, fname, mask))) {
                        got_match = mask_match(fname, mask, conn->case_sensitive);
+               }
 
                if(!got_match && check_mangled_names &&
                   !mangle_is_8_3(fname, False, conn->params)) {
+                       pstring mangled_name;
 
                        /*
                         * It turns out that NT matches wildcards against
@@ -1167,21 +1191,25 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                         * that some people have been seeing.... JRA.
                         */
 
-                       pstring newname;
-                       pstrcpy( newname, fname);
-                       mangle_map( newname, True, False, conn->params);
-                       if(!(got_match = *got_exact_match = exact_match(conn, newname, mask)))
-                               got_match = mask_match(newname, mask, conn->case_sensitive);
+                       pstrcpy(mangled_name, fname);
+
+                       /* Force the mangling into 8.3. */
+                       mangle_map( mangled_name, True, False, conn->params);
+                       if(!(got_match = *got_exact_match = exact_match(conn, mangled_name, mask))) {
+                               got_match = mask_match(mangled_name, mask, conn->case_sensitive);
+                       }
                }
 
-               if(got_match) {
-                       BOOL isdots = (strequal(fname,"..") || strequal(fname,"."));
-                       if (dont_descend && !isdots)
+               if (got_match) {
+                       BOOL isdots = (strequal(dname,"..") || strequal(dname,"."));
+                       if (dont_descend && !isdots) {
                                continue;
+                       }
          
                        pstrcpy(pathreal,conn->dirpath);
-                       if(needslash)
+                       if(needslash) {
                                pstrcat(pathreal,"/");
+                       }
                        pstrcat(pathreal,dname);
 
                        if (INFO_LEVEL_IS_UNIX(info_level)) {
@@ -1191,15 +1219,17 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                                        continue;
                                }
                        } else if (!VALID_STAT(sbuf) && SMB_VFS_STAT(conn,pathreal,&sbuf) != 0) {
+                               pstring link_target;
 
                                /* Needed to show the msdfs symlinks as 
                                 * directories */
 
                                if(lp_host_msdfs() && 
                                   lp_msdfs_root(SNUM(conn)) &&
-                                  ((ms_dfs_link = is_msdfs_link(NULL,conn, pathreal, NULL, NULL, &sbuf)) == True)) {
-
-                                       DEBUG(5,("get_lanman2_dir_entry: Masquerading msdfs link %s as a directory\n", pathreal));
+                                  ((ms_dfs_link = is_msdfs_link(conn, pathreal, link_target, &sbuf)) == True)) {
+                                       DEBUG(5,("get_lanman2_dir_entry: Masquerading msdfs link %s "
+                                               "as a directory\n",
+                                               pathreal));
                                        sbuf.st_mode = (sbuf.st_mode & 0xFFF) | S_IFDIR;
 
                                } else {
@@ -1217,12 +1247,13 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                        }
 
                        if (!dir_check_ftype(conn,mode,dirtype)) {
-                               DEBUG(5,("[%s] attribs didn't match %x\n",fname,dirtype));
+                               DEBUG(5,("get_lanman2_dir_entry: [%s] attribs didn't match %x\n",fname,dirtype));
                                continue;
                        }
 
-                       if (!(mode & aDIR))
+                       if (!(mode & aDIR)) {
                                file_size = get_file_size(sbuf);
+                       }
                        allocation_size = get_allocation_size(conn,NULL,&sbuf);
 
                        mdate_ts = get_mtimespec(&sbuf);
@@ -1239,7 +1270,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                        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;
 
@@ -1247,8 +1278,6 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                }
        }
 
-       mangle_map(fname,False,True,conn->params);
-
        p = pdata;
        last_entry_ptr = p;
 
@@ -1578,53 +1607,27 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                /* CIFS UNIX Extension. */
 
                case SMB_FIND_FILE_UNIX:
-                       DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_UNIX\n"));
+               case SMB_FIND_FILE_UNIX_INFO2:
                        p+= 4;
                        SIVAL(p,0,reskey); p+= 4;    /* Used for continuing search. */
 
                        /* Begin of SMB_QUERY_FILE_UNIX_BASIC */
-                       SOFF_T(p,0,get_file_size(sbuf));             /* File size 64 Bit */
-                       p+= 8;
-
-                       SOFF_T(p,0,get_allocation_size(conn,NULL,&sbuf)); /* Number of bytes used on disk - 64 Bit */
-                       p+= 8;
-
-                       put_long_date_timespec(p,get_ctimespec(&sbuf));       /* Inode change Time 64 Bit */
-                       put_long_date_timespec(p+8,get_atimespec(&sbuf));     /* Last access time 64 Bit */
-                       put_long_date_timespec(p+16,get_mtimespec(&sbuf));    /* Last modification time 64 Bit */
-                       p+= 24;
-
-                       SIVAL(p,0,sbuf.st_uid);               /* user id for the owner */
-                       SIVAL(p,4,0);
-                       p+= 8;
-
-                       SIVAL(p,0,sbuf.st_gid);               /* group id of owner */
-                       SIVAL(p,4,0);
-                       p+= 8;
-
-                       SIVAL(p,0,unix_filetype(sbuf.st_mode));
-                       p+= 4;
-
-                       SIVAL(p,0,unix_dev_major(sbuf.st_rdev));   /* Major device number if type is device */
-                       SIVAL(p,4,0);
-                       p+= 8;
 
-                       SIVAL(p,0,unix_dev_minor(sbuf.st_rdev));   /* Minor device number if type is device */
-                       SIVAL(p,4,0);
-                       p+= 8;
-
-                       SINO_T_VAL(p,0,(SMB_INO_T)sbuf.st_ino);   /* inode number */
-                       p+= 8;
-
-                       SIVAL(p,0, unix_perms_to_wire(sbuf.st_mode));     /* Standard UNIX file permissions */
-                       SIVAL(p,4,0);
-                       p+= 8;
-
-                       SIVAL(p,0,sbuf.st_nlink);             /* number of hard links */
-                       SIVAL(p,4,0);
-                       p+= 8;
+                       if (info_level == SMB_FIND_FILE_UNIX) {
+                               DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_UNIX\n"));
+                               p = store_file_unix_basic(conn, p,
+                                                       NULL, &sbuf);
+                               len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE);
+                       } else {
+                               DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_UNIX_INFO2\n"));
+                               p = store_file_unix_basic_info2(conn, p,
+                                                       NULL, &sbuf);
+                               nameptr = p;
+                               p += 4;
+                               len = srvstr_push(outbuf, p, fname, -1, 0);
+                               SIVAL(nameptr, 0, len);
+                       }
 
-                       len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE);
                        p += len;
                        SIVAL(p,0,0); /* Ensure any padding is null. */
 
@@ -1732,6 +1735,7 @@ close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
                case SMB_FIND_ID_BOTH_DIRECTORY_INFO:
                        break;
                case SMB_FIND_FILE_UNIX:
+               case SMB_FIND_FILE_UNIX_INFO2:
                        if (!lp_unix_extensions()) {
                                return ERROR_NT(NT_STATUS_INVALID_LEVEL);
                        }
@@ -1745,7 +1749,13 @@ close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
                return ERROR_NT(ntstatus);
        }
 
-       RESOLVE_DFSPATH_WCARD(directory, conn, inbuf, outbuf);
+       ntstatus = resolve_dfspath_wcard(conn, SVAL(inbuf,smb_flg2) & FLAGS2_DFS_PATHNAMES, directory, &mask_contains_wcard);
+       if (!NT_STATUS_IS_OK(ntstatus)) {
+               if (NT_STATUS_EQUAL(ntstatus,NT_STATUS_PATH_NOT_COVERED)) {
+                       return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED, ERRSRV, ERRbadpath);
+               }
+               return ERROR_NT(ntstatus);
+       }
 
        ntstatus = unix_convert(conn, directory, True, NULL, &sbuf);
        if (!NT_STATUS_IS_OK(ntstatus)) {
@@ -1920,7 +1930,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        SSVAL(params,6,0); /* Never an EA error */
        SSVAL(params,8,last_entry_off);
 
-       send_trans2_replies( outbuf, bufsize, params, 10, pdata, PTR_DIFF(p,pdata), max_data_bytes);
+       send_trans2_replies(inbuf, outbuf, bufsize, params, 10, pdata, PTR_DIFF(p,pdata), max_data_bytes);
 
        if ((! *directory) && dptr_path(dptr_num))
                slprintf(directory,sizeof(directory)-1, "(%s)",dptr_path(dptr_num));
@@ -2037,6 +2047,7 @@ resume_key = %d resume name = %s continue=%d level = %d\n",
                case SMB_FIND_ID_BOTH_DIRECTORY_INFO:
                        break;
                case SMB_FIND_FILE_UNIX:
+               case SMB_FIND_FILE_UNIX_INFO2:
                        if (!lp_unix_extensions()) {
                                return ERROR_NT(NT_STATUS_INVALID_LEVEL);
                        }
@@ -2212,7 +2223,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        SSVAL(params,4,0); /* Never an EA error */
        SSVAL(params,6,last_entry_off);
 
-       send_trans2_replies( outbuf, bufsize, params, 8, pdata, PTR_DIFF(p,pdata), max_data_bytes);
+       send_trans2_replies(inbuf, outbuf, bufsize, params, 8, pdata, PTR_DIFF(p,pdata), max_data_bytes);
 
        if ((! *directory) && dptr_path(dptr_num))
                slprintf(directory,sizeof(directory)-1, "(%s)",dptr_path(dptr_num));
@@ -2224,6 +2235,12 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        return(-1);
 }
 
+unsigned char *create_volume_objectid(connection_struct *conn, unsigned char objid[16])
+{
+       E_md4hash(lp_servicename(SNUM(conn)),objid);
+       return objid;
+}
+
 /****************************************************************************
  Reply to a TRANS2_QFSINFO (query filesystem info).
 ****************************************************************************/
@@ -2232,12 +2249,12 @@ static int call_trans2qfsinfo(connection_struct *conn, char *inbuf, char *outbuf
                                        char **pparams, int total_params, char **ppdata, int total_data,
                                        unsigned int max_data_bytes)
 {
-       char *pdata = *ppdata;
+       char *pdata;
        char *params = *pparams;
        uint16 info_level;
        int data_len, len;
        SMB_STRUCT_STAT st;
-       char *vname = volume_label(SNUM(conn));
+       const char *vname = volume_label(SNUM(conn));
        int snum = SNUM(conn);
        char *fstype = lp_fstype(SNUM(conn));
        int quota_flag = 0;
@@ -2331,6 +2348,8 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st.st_dev, (unsi
 
                        SIVAL(pdata,0,FILE_CASE_PRESERVED_NAMES|FILE_CASE_SENSITIVE_SEARCH|
                                (lp_nt_acl_support(SNUM(conn)) ? FILE_PERSISTENT_ACLS : 0)|
+                               FILE_SUPPORTS_OBJECT_IDS|
+                               FILE_UNICODE_ON_DISK|
                                quota_flag); /* FS ATTRIBUTES */
 
                        SIVAL(pdata,4,255); /* Max filename component length */
@@ -2358,9 +2377,11 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st.st_dev, (unsi
                        SIVAL(pdata,8,str_checksum(lp_servicename(snum)) ^ 
                                (str_checksum(get_local_machine_name())<<16));
 
+                       /* Max label len is 32 characters. */
                        len = srvstr_push(outbuf, pdata+18, vname, -1, STR_UNICODE);
                        SIVAL(pdata,12,len);
                        data_len = 18+len;
+
                        DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol=%s serv=%s\n", 
                                (int)strlen(vname),vname, lp_servicename(snum)));
                        break;
@@ -2510,8 +2531,12 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                }
 #endif /* HAVE_SYS_QUOTAS */
                case SMB_FS_OBJECTID_INFORMATION:
+               {
+                       unsigned char objid[16];
+                       memcpy(pdata,create_volume_objectid(conn, objid),16);
                        data_len = 64;
                        break;
+               }
 
                /*
                 * Query the version and capabilities of the CIFS UNIX extensions
@@ -2529,7 +2554,12 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                        SBIG_UINT(pdata,4,((SMB_BIG_UINT)(
                                        CIFS_UNIX_POSIX_ACLS_CAP|
                                        CIFS_UNIX_POSIX_PATHNAMES_CAP|
-                                       CIFS_UNIX_FCNTL_LOCKS_CAP)));
+                                       CIFS_UNIX_FCNTL_LOCKS_CAP|
+                                       CIFS_UNIX_EXTATTR_CAP|
+                                       CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP|
+                                       /* Ensure we don't do this on signed or sealed data. */
+                                       (srv_is_signing_active() ? 0 : CIFS_UNIX_LARGE_READ_CAP)
+                                       )));
                        break;
 
                case SMB_QUERY_POSIX_FS_INFO:
@@ -2565,6 +2595,114 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                        break;
                }
 
+               case SMB_QUERY_POSIX_WHOAMI:
+               {
+                       uint32_t flags = 0;
+                       uint32_t sid_bytes;
+                       int i;
+
+                       if (!lp_unix_extensions()) {
+                               return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+                       }
+
+                       if (max_data_bytes < 40) {
+                               return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL);
+                       }
+
+                       /* We ARE guest if global_sid_Builtin_Guests is
+                        * in our list of SIDs.
+                        */
+                       if (nt_token_check_sid(&global_sid_Builtin_Guests,
+                                   current_user.nt_user_token)) {
+                               flags |= SMB_WHOAMI_GUEST;
+                       }
+
+                       /* We are NOT guest if global_sid_Authenticated_Users
+                        * is in our list of SIDs.
+                        */
+                       if (nt_token_check_sid(&global_sid_Authenticated_Users,
+                                   current_user.nt_user_token)) {
+                               flags &= ~SMB_WHOAMI_GUEST;
+                       }
+
+                       /* NOTE: 8 bytes for UID/GID, irrespective of native
+                        * platform size. This matches
+                        * SMB_QUERY_FILE_UNIX_BASIC and friends.
+                        */
+                       data_len = 4 /* flags */
+                           + 4 /* flag mask */
+                           + 8 /* uid */
+                           + 8 /* gid */
+                           + 4 /* ngroups */
+                           + 4 /* num_sids */
+                           + 4 /* SID bytes */
+                           + 4 /* pad/reserved */
+                           + (current_user.ut.ngroups * 8)
+                               /* groups list */
+                           + (current_user.nt_user_token->num_sids *
+                                   SID_MAX_SIZE)
+                               /* SID list */;
+
+                       SIVAL(pdata, 0, flags);
+                       SIVAL(pdata, 4, SMB_WHOAMI_MASK);
+                       SBIG_UINT(pdata, 8, (SMB_BIG_UINT)current_user.ut.uid);
+                       SBIG_UINT(pdata, 16, (SMB_BIG_UINT)current_user.ut.gid);
+
+
+                       if (data_len >= max_data_bytes) {
+                               /* Potential overflow, skip the GIDs and SIDs. */
+
+                               SIVAL(pdata, 24, 0); /* num_groups */
+                               SIVAL(pdata, 28, 0); /* num_sids */
+                               SIVAL(pdata, 32, 0); /* num_sid_bytes */
+                               SIVAL(pdata, 36, 0); /* reserved */
+
+                               data_len = 40;
+                               break;
+                       }
+
+                       SIVAL(pdata, 24, current_user.ut.ngroups);
+                       SIVAL(pdata, 28,
+                               current_user.nt_user_token->num_sids);
+
+                       /* We walk the SID list twice, but this call is fairly
+                        * infrequent, and I don't expect that it's performance
+                        * sensitive -- jpeach
+                        */
+                       for (i = 0, sid_bytes = 0;
+                           i < current_user.nt_user_token->num_sids; ++i) {
+                               sid_bytes +=
+                                   sid_size(&current_user.nt_user_token->user_sids[i]);
+                       }
+
+                       /* SID list byte count */
+                       SIVAL(pdata, 32, sid_bytes);
+
+                       /* 4 bytes pad/reserved - must be zero */
+                       SIVAL(pdata, 36, 0);
+                       data_len = 40;
+
+                       /* GID list */
+                       for (i = 0; i < current_user.ut.ngroups; ++i) {
+                               SBIG_UINT(pdata, data_len,
+                                       (SMB_BIG_UINT)current_user.ut.groups[i]);
+                               data_len += 8;
+                       }
+
+                       /* SID list */
+                       for (i = 0;
+                           i < current_user.nt_user_token->num_sids; ++i) {
+                               int sid_len =
+                                   sid_size(&current_user.nt_user_token->user_sids[i]);
+
+                               sid_linearize(pdata + data_len, sid_len,
+                                   &current_user.nt_user_token->user_sids[i]);
+                               data_len += sid_len;
+                       }
+
+                       break;
+               }
+
                case SMB_MAC_QUERY_FS_INFO:
                        /*
                         * Thursby MAC extension... ONLY on NTFS filesystems
@@ -2581,7 +2719,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
        }
 
 
-       send_trans2_replies( outbuf, bufsize, params, 0, pdata, data_len, max_data_bytes);
+       send_trans2_replies(inbuf, outbuf, bufsize, params, 0, pdata, data_len, max_data_bytes);
 
        DEBUG( 4, ( "%s info_level = %d\n", smb_fn_name(CVAL(inbuf,smb_com)), info_level) );
 
@@ -2646,11 +2784,53 @@ cap_low = 0x%x, cap_high = 0x%x\n",
                                        mangle_change_to_posix();
                                }
 
-                               if (client_unix_cap_low & CIFS_UNIX_FCNTL_LOCKS_CAP) {
-                                       lp_set_posix_cifsx_locktype(POSIX_LOCK);
+                               if ((client_unix_cap_low & CIFS_UNIX_FCNTL_LOCKS_CAP) &&
+                                   !(client_unix_cap_low & CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP)) {
+                                       /* Client that knows how to do posix locks,
+                                        * but not posix open/mkdir operations. Set a
+                                        * default type for read/write checks. */
+
+                                       lp_set_posix_default_cifsx_readwrite_locktype(POSIX_LOCK);
+
                                }
                                break;
                        }
+               case SMB_REQUEST_TRANSPORT_ENCRYPTION:
+                       {
+                               NTSTATUS status;
+                               size_t param_len = 0;
+                               size_t data_len = total_data;
+
+                               if (!lp_unix_extensions()) {
+                                       return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+                               }
+
+                               DEBUG( 4,("call_trans2setfsinfo: request transport encrption.\n"));
+
+                               status = srv_request_encryption_setup(conn,
+                                                                       (unsigned char **)ppdata,
+                                                                       &data_len,
+                                                                       (unsigned char **)pparams,
+                                                                       &param_len
+                                                                       );
+
+                               if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
+                                       error_packet_set(outbuf, 0, 0, status, __LINE__,__FILE__);
+                               } else if (!NT_STATUS_IS_OK(status)) {
+                                       return ERROR_NT(status);
+                               }
+
+                               send_trans2_replies(inbuf, outbuf, bufsize, *pparams, param_len, *ppdata, data_len, max_data_bytes);
+
+                               if (NT_STATUS_IS_OK(status)) {
+                                       /* Server-side transport encryption is now *on*. */
+                                       status = srv_encryption_start(conn);
+                                       if (!NT_STATUS_IS_OK(status)) {
+                                               exit_server_cleanly("Failure in setting up encrypted transport");
+                                       }
+                               }
+                               return -1;
+                       }
                case SMB_FS_QUOTA_INFORMATION:
                        {
                                files_struct *fsp = NULL;
@@ -2735,7 +2915,7 @@ cap_low = 0x%x, cap_high = 0x%x\n",
         * like windows do...
         * --metze
         */ 
-       outsize = set_message(outbuf,10,0,True);
+       outsize = set_message(inbuf, outbuf,10,0,True);
 
        return outsize;
 }
@@ -2857,6 +3037,239 @@ static BOOL marshall_posix_acl(connection_struct *conn, char *pdata, SMB_STRUCT_
 }
 #endif
 
+/****************************************************************************
+ Store the FILE_UNIX_BASIC info.
+****************************************************************************/
+
+static char *store_file_unix_basic(connection_struct *conn,
+                               char *pdata,
+                               files_struct *fsp,
+                               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));
+
+       SOFF_T(pdata,0,get_file_size(*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 */
+       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 */
+       pdata += 24;
+
+       SIVAL(pdata,0,psbuf->st_uid);               /* user id for the owner */
+       SIVAL(pdata,4,0);
+       pdata += 8;
+
+       SIVAL(pdata,0,psbuf->st_gid);               /* group id of owner */
+       SIVAL(pdata,4,0);
+       pdata += 8;
+
+       SIVAL(pdata,0,unix_filetype(psbuf->st_mode));
+       pdata += 4;
+
+       SIVAL(pdata,0,unix_dev_major(psbuf->st_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,4,0);
+       pdata += 8;
+
+       SINO_T_VAL(pdata,0,(SMB_INO_T)psbuf->st_ino);   /* inode number */
+       pdata += 8;
+                               
+       SIVAL(pdata,0, unix_perms_to_wire(psbuf->st_mode));     /* Standard UNIX file permissions */
+       SIVAL(pdata,4,0);
+       pdata += 8;
+
+       SIVAL(pdata,0,psbuf->st_nlink);             /* number of hard links */
+       SIVAL(pdata,4,0);
+       pdata += 8;
+
+       return pdata;
+}
+
+/* Forward and reverse mappings from the UNIX_INFO2 file flags field and
+ * the chflags(2) (or equivalent) flags.
+ *
+ * XXX: this really should be behind the VFS interface. To do this, we would
+ * need to alter SMB_STRUCT_STAT so that it included a flags and a mask field.
+ * Each VFS module could then implement it's own mapping as appropriate for the
+ * platform. We would then pass the SMB flags into SMB_VFS_CHFLAGS.
+ */
+static const struct {unsigned stat_fflag; unsigned smb_fflag;}
+       info2_flags_map[] =
+{
+#ifdef UF_NODUMP
+    { UF_NODUMP, EXT_DO_NOT_BACKUP },
+#endif
+
+#ifdef UF_IMMUTABLE
+    { UF_IMMUTABLE, EXT_IMMUTABLE },
+#endif
+
+#ifdef UF_APPEND
+    { UF_APPEND, EXT_OPEN_APPEND_ONLY },
+#endif
+
+#ifdef UF_HIDDEN
+    { UF_HIDDEN, EXT_HIDDEN },
+#endif
+
+    /* Do not remove. We need to guarantee that this array has at least one
+     * entry to build on HP-UX.
+     */
+    { 0, 0 }
+
+};
+
+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) {
+                   *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,
+                               const uint32 smb_fflags,
+                               const uint32 smb_fmask,
+                               int *stat_fflags)
+{
+#ifdef HAVE_STAT_ST_FLAGS
+       uint32 max_fmask = 0;
+       int i;
+
+       *stat_fflags = psbuf->st_flags;
+
+       /* For each flags requested in smb_fmask, check the state of the
+        * corresponding flag in smb_fflags and set or clear the matching
+        * stat flag.
+        */
+
+       for (i = 0; i < ARRAY_SIZE(info2_flags_map); ++i) {
+           max_fmask |= info2_flags_map[i].smb_fflag;
+           if (smb_fmask & info2_flags_map[i].smb_fflag) {
+                   if (smb_fflags & info2_flags_map[i].smb_fflag) {
+                           *stat_fflags |= info2_flags_map[i].stat_fflag;
+                   } else {
+                           *stat_fflags &= ~info2_flags_map[i].stat_fflag;
+                   }
+           }
+       }
+
+       /* If smb_fmask is asking to set any bits that are not supported by
+        * our flag mappings, we should fail.
+        */
+       if ((smb_fmask & max_fmask) != smb_fmask) {
+               return False;
+       }
+
+       return True;
+#else
+       return False;
+#endif /* HAVE_STAT_ST_FLAGS */
+}
+
+
+/* Just like SMB_QUERY_FILE_UNIX_BASIC, but with the addition
+ * of file flags and birth (create) time.
+ */
+static char *store_file_unix_basic_info2(connection_struct *conn,
+                               char *pdata,
+                               files_struct *fsp,
+                               const SMB_STRUCT_STAT *psbuf)
+{
+       uint32 file_flags = 0;
+       uint32 flags_mask = 0;
+
+       pdata = store_file_unix_basic(conn, pdata, fsp, psbuf);
+
+       /* Create (birth) time 64 bit */
+       put_long_date_timespec(pdata, get_create_timespec(psbuf, False));
+       pdata += 8;
+
+       map_info2_flags_from_sbuf(psbuf, &file_flags, &flags_mask);
+       SIVAL(pdata, 0, file_flags); /* flags */
+       SIVAL(pdata, 4, flags_mask); /* mask */
+       pdata += 8;
+
+       return pdata;
+}
+
+/****************************************************************************
+ Reply to a TRANSACT2_QFILEINFO on a PIPE !
+****************************************************************************/
+
+static int call_trans2qpipeinfo(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
+                                       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;
+       unsigned int data_size = 0;
+       unsigned int param_size = 2;
+       uint16 info_level;
+       smb_np_struct *p_pipe = NULL;
+
+       if (!params) {
+               return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+       }
+
+       if (total_params < 4) {
+               return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+       }
+
+       p_pipe = get_rpc_pipe_p(params,0);
+       if (p_pipe == NULL) {
+               return ERROR_NT(NT_STATUS_INVALID_HANDLE);
+       }
+
+       info_level = SVAL(params,2);
+
+       *pparams = (char *)SMB_REALLOC(*pparams,2);
+       if (*pparams == NULL) {
+               return ERROR_NT(NT_STATUS_NO_MEMORY);
+       }
+       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 ) {
+               return ERROR_NT(NT_STATUS_NO_MEMORY);
+       }
+       pdata = *ppdata;
+
+       switch (info_level) {
+               case SMB_FILE_STANDARD_INFORMATION:
+                       memset(pdata,24,0);
+                       SOFF_T(pdata,0,4096LL);
+                       SIVAL(pdata,16,1);
+                       SIVAL(pdata,20,1);
+                       data_size = 24;
+                       break;
+
+               default:
+                       return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+       }
+
+       send_trans2_replies(inbuf, outbuf, bufsize, params, param_size, *ppdata, data_size, max_data_bytes);
+
+       return(-1);
+}
+
 /****************************************************************************
  Reply to a TRANS2_QFILEPATHINFO or TRANSACT2_QFILEINFO (query file info by
  file name or file id).
@@ -2902,11 +3315,29 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                        return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                }
 
+               if (IS_IPC(conn)) {
+                       return call_trans2qpipeinfo(conn,
+                                                       inbuf,
+                                                       outbuf,
+                                                       length,
+                                                       bufsize,
+                                                       tran_call,
+                                                       pparams,
+                                                       total_params,
+                                                       ppdata,
+                                                       total_data,
+                                                       max_data_bytes);
+               }
+
                fsp = file_fsp(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()) {
+                       return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+               }
+
                if(fsp && (fsp->fake_file_handle)) {
                        /*
                         * This is actually for the QUOTA_FAKE_FILE --metze
@@ -2935,7 +3366,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                                return UNIXERROR(ERRDOS,ERRbadpath);
                        }
 
-                       delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino);
+                       delete_pending = get_delete_on_close_flag(file_id_sbuf(&sbuf));
                } else {
                        /*
                         * Original code - this is an open file.
@@ -2948,7 +3379,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                                return(UNIXERROR(ERRDOS,ERRbadfid));
                        }
                        pos = fsp->fh->position_information;
-                       delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino);
+                       delete_pending = get_delete_on_close_flag(file_id_sbuf(&sbuf));
                        access_mask = fsp->access_mask;
                }
        } else {
@@ -2963,12 +3394,22 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
 
                DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QPATHINFO: level = %d\n", info_level));
 
+               if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
+                       return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+               }
+
                srvstr_get_path(inbuf, fname, &params[6], sizeof(fname), total_params - 6, STR_TERMINATE, &status);
                if (!NT_STATUS_IS_OK(status)) {
                        return ERROR_NT(status);
                }
 
-               RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
+               status = resolve_dfspath(conn, SVAL(inbuf,smb_flg2) & FLAGS2_DFS_PATHNAMES, fname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+                               return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED, ERRSRV, ERRbadpath);
+                       }
+                       return ERROR_NT(status);
+               }
 
                status = unix_convert(conn, fname, False, NULL, &sbuf);
                if (!NT_STATUS_IS_OK(status)) {
@@ -2991,7 +3432,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                        return UNIXERROR(ERRDOS,ERRbadpath);
                }
 
-               delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino);
+               delete_pending = get_delete_on_close_flag(file_id_sbuf(&sbuf));
                if (delete_pending) {
                        return ERROR_NT(NT_STATUS_DELETE_PENDING);
                }
@@ -3079,7 +3520,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        }
 
                        /* Copy the lock range data. */
-                       lock_data = (char *)talloc_memdup(
+                       lock_data = (char *)TALLOC_MEMDUP(
                                data_ctx, pdata, total_data);
                        if (!lock_data) {
                                talloc_destroy(data_ctx);
@@ -3112,18 +3553,16 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        allocation_size = get_allocation_size(conn,fsp,&sbuf);
 
        if (fsp) {
-               if (fsp->pending_modtime) {
+               if (!null_timespec(fsp->pending_modtime)) {
                        /* the pending modtime overrides the current modtime */
-                       mtime_ts.tv_sec = fsp->pending_modtime;
-                       mtime_ts.tv_nsec = 0;
+                       mtime_ts = fsp->pending_modtime;
                }
        } else {
                /* Do we have this path open ? */
-               files_struct *fsp1 = file_find_di_first(sbuf.st_dev, sbuf.st_ino);
-               if (fsp1 && fsp1->pending_modtime) {
+               files_struct *fsp1 = file_find_di_first(file_id_sbuf(&sbuf));
+               if (fsp1 && !null_timespec(fsp1->pending_modtime)) {
                        /* the pending modtime overrides the current modtime */
-                       mtime_ts.tv_sec = fsp1->pending_modtime;
-                       mtime_ts.tv_nsec = 0;
+                       mtime_ts = fsp1->pending_modtime;
                }
                if (fsp1 && fsp1->initial_allocation_size) {
                        allocation_size = get_allocation_size(conn, fsp1, &sbuf);
@@ -3421,8 +3860,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                SIVAL(pdata,0,0); /* ??? */
                                SIVAL(pdata,4,byte_len); /* Byte length of unicode string ::$DATA */
                                SOFF_T(pdata,8,file_size);
-                               SIVAL(pdata,16,allocation_size);
-                               SIVAL(pdata,20,0); /* ??? */
+                               SOFF_T(pdata,16,allocation_size);
                                data_size = 24 + byte_len;
                        }
                        break;
@@ -3442,7 +3880,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        put_long_date_timespec(pdata+8,atime_ts);
                        put_long_date_timespec(pdata+16,mtime_ts); /* write time */
                        put_long_date_timespec(pdata+24,mtime_ts); /* change time */
-                       SIVAL(pdata,32,allocation_size);
+                       SOFF_T(pdata,32,allocation_size);
                        SOFF_T(pdata,40,file_size);
                        SIVAL(pdata,48,mode);
                        SIVAL(pdata,52,0); /* ??? */
@@ -3462,54 +3900,28 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
 
                case SMB_QUERY_FILE_UNIX_BASIC:
 
-                       DEBUG(10,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_BASIC\n"));
-                       DEBUG(4,("call_trans2qfilepathinfo: st_mode=%o\n",(int)sbuf.st_mode));
-
-                       SOFF_T(pdata,0,get_file_size(sbuf));             /* File size 64 Bit */
-                       pdata += 8;
-
-                       SOFF_T(pdata,0,get_allocation_size(conn,fsp,&sbuf)); /* Number of bytes used on disk - 64 Bit */
-                       pdata += 8;
-
-                       put_long_date_timespec(pdata,get_ctimespec(&sbuf));       /* Creation Time 64 Bit */
-                       put_long_date_timespec(pdata+8,get_atimespec(&sbuf));     /* Last access time 64 Bit */
-                       put_long_date_timespec(pdata+16,get_mtimespec(&sbuf));    /* Last modification time 64 Bit */
-                       pdata += 24;
-
-                       SIVAL(pdata,0,sbuf.st_uid);               /* user id for the owner */
-                       SIVAL(pdata,4,0);
-                       pdata += 8;
-
-                       SIVAL(pdata,0,sbuf.st_gid);               /* group id of owner */
-                       SIVAL(pdata,4,0);
-                       pdata += 8;
+                       pdata = store_file_unix_basic(conn, pdata, fsp, &sbuf);
+                       data_size = PTR_DIFF(pdata,(*ppdata));
 
-                       SIVAL(pdata,0,unix_filetype(sbuf.st_mode));
-                       pdata += 4;
+                       {
+                               int i;
+                               DEBUG(4,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_BASIC "));
 
-                       SIVAL(pdata,0,unix_dev_major(sbuf.st_rdev));   /* Major device number if type is device */
-                       SIVAL(pdata,4,0);
-                       pdata += 8;
+                               for (i=0; i<100; i++)
+                                       DEBUG(4,("%d=%x, ",i, (*ppdata)[i]));
+                               DEBUG(4,("\n"));
+                       }
 
-                       SIVAL(pdata,0,unix_dev_minor(sbuf.st_rdev));   /* Minor device number if type is device */
-                       SIVAL(pdata,4,0);
-                       pdata += 8;
+                       break;
 
-                       SINO_T_VAL(pdata,0,(SMB_INO_T)sbuf.st_ino);   /* inode number */
-                       pdata += 8;
-                               
-                       SIVAL(pdata,0, unix_perms_to_wire(sbuf.st_mode));     /* Standard UNIX file permissions */
-                       SIVAL(pdata,4,0);
-                       pdata += 8;
+               case SMB_QUERY_FILE_UNIX_INFO2:
 
-                       SIVAL(pdata,0,sbuf.st_nlink);             /* number of hard links */
-                       SIVAL(pdata,4,0);
-                       pdata += 8;
+                       pdata = store_file_unix_basic_info2(conn, pdata, fsp, &sbuf);
                        data_size = PTR_DIFF(pdata,(*ppdata));
 
                        {
                                int i;
-                               DEBUG(4,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_BASIC "));
+                               DEBUG(4,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_INFO2 "));
 
                                for (i=0; i<100; i++)
                                        DEBUG(4,("%d=%x, ",i, (*ppdata)[i]));
@@ -3697,7 +4109,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        return ERROR_NT(NT_STATUS_INVALID_LEVEL);
        }
 
-       send_trans2_replies(outbuf, bufsize, params, param_size, *ppdata, data_size, max_data_bytes);
+       send_trans2_replies(inbuf, outbuf, bufsize, params, param_size, *ppdata, data_size, max_data_bytes);
 
        return(-1);
 }
@@ -3722,17 +4134,22 @@ NTSTATUS hardlink_internals(connection_struct *conn, pstring oldname, pstring ne
                return status;
        }
 
+       status = check_name(conn, oldname);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
        /* source must already exist. */
        if (!VALID_STAT(sbuf1)) {
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
-       status = check_name(conn, oldname);
+       status = unix_convert(conn, newname, False, last_component_newname, &sbuf2);
        if (!NT_STATUS_IS_OK(status)) {
-               return NT_STATUS_ACCESS_DENIED;
+               return status;
        }
 
-       status = unix_convert(conn, newname, False, last_component_newname, &sbuf2);
+       status = check_name(conn, newname);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -3742,11 +4159,6 @@ NTSTATUS hardlink_internals(connection_struct *conn, pstring oldname, pstring ne
                return NT_STATUS_OBJECT_NAME_COLLISION;
        }
 
-       status = check_name(conn, newname);
-       if (!NT_STATUS_IS_OK(status)) {
-               return NT_STATUS_ACCESS_DENIED;
-       }
-
        /* No links from a directory. */
        if (S_ISDIR(sbuf1.st_mode)) {
                return NT_STATUS_FILE_IS_A_DIRECTORY;
@@ -3777,31 +4189,42 @@ static NTSTATUS smb_set_file_time(connection_struct *conn,
                                files_struct *fsp,
                                const char *fname,
                                const SMB_STRUCT_STAT *psbuf,
-                               struct utimbuf tvs)
+                               struct timespec ts[2])
 {
+       uint32 action =
+               FILE_NOTIFY_CHANGE_LAST_ACCESS
+               |FILE_NOTIFY_CHANGE_LAST_WRITE;
+
+       
        if (!VALID_STAT(*psbuf)) {
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
        /* get some defaults (no modifications) if any info is zero or -1. */
-       if (null_mtime(tvs.actime)) {
-               tvs.actime = psbuf->st_atime;
+       if (null_timespec(ts[0])) {
+               ts[0] = get_atimespec(psbuf);
+               action &= ~FILE_NOTIFY_CHANGE_LAST_ACCESS;
        }
 
-       if (null_mtime(tvs.modtime)) {
-               tvs.modtime = psbuf->st_mtime;
+       if (null_timespec(ts[1])) {
+               ts[1] = get_mtimespec(psbuf);
+               action &= ~FILE_NOTIFY_CHANGE_LAST_WRITE;
        }
 
-       DEBUG(6,("smb_set_file_time: actime: %s " , ctime(&tvs.actime)));
-       DEBUG(6,("smb_set_file_time: modtime: %s ", ctime(&tvs.modtime)));
+       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])) ));
 
        /*
         * Try and set the times of this file if
         * they are different from the current values.
         */
 
-       if (psbuf->st_mtime == tvs.modtime && psbuf->st_atime == tvs.actime) {
-               return NT_STATUS_OK;
+       {
+               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)) {
+                       return NT_STATUS_OK;
+               }
        }
 
        if(fsp != NULL) {
@@ -3815,17 +4238,21 @@ static NTSTATUS smb_set_file_time(connection_struct *conn,
                 * away and will set it on file close and after a write. JRA.
                 */
 
-               if (tvs.modtime != (time_t)0 && tvs.modtime != (time_t)-1) {
-                       DEBUG(10,("smb_set_file_time: setting pending modtime to %s\n", ctime(&tvs.modtime) ));
-                       fsp_set_pending_modtime(fsp, tvs.modtime);
+               if (!null_timespec(ts[1])) {
+                       DEBUG(10,("smb_set_file_time: setting pending modtime to %s\n",
+                               time_to_asc(convert_timespec_to_time_t(ts[1])) ));
+                       fsp_set_pending_modtime(fsp, ts[1]);
                }
 
        }
        DEBUG(10,("smb_set_file_time: setting utimes to modified values.\n"));
 
-       if(file_utime(conn, fname, &tvs)!=0) {
+       if(file_ntimes(conn, fname, ts)!=0) {
                return map_nt_error_from_unix(errno);
        }
+       if (action != 0) {
+               notify_fname(conn, NOTIFY_ACTION_MODIFIED, action, fname);
+       }
        return NT_STATUS_OK;
 }
 
@@ -3890,7 +4317,7 @@ static NTSTATUS smb_set_file_size(connection_struct *conn,
                return NT_STATUS_OK;
        }
 
-       DEBUG(10,("call_trans2setfilepathinfo: file %s : setting new size to %.0f\n",
+       DEBUG(10,("smb_set_file_size: file %s : setting new size to %.0f\n",
                fname, (double)size ));
 
        if (fsp && fsp->fh->fd != -1) {
@@ -3999,6 +4426,12 @@ static NTSTATUS smb_set_file_disposition_info(connection_struct *conn,
        delete_on_close = (CVAL(pdata,0) ? True : False);
        dosmode = dos_mode(conn, fname, psbuf);
 
+       DEBUG(10,("smb_set_file_disposition_info: file %s, dosmode = %u, "
+               "delete_on_close = %u\n",
+               fsp->fsp_name,
+               (unsigned int)dosmode,
+               (unsigned int)delete_on_close ));
+
        status = can_set_delete_on_close(fsp, delete_on_close, dosmode);
  
        if (!NT_STATUS_IS_OK(status)) {
@@ -4038,7 +4471,7 @@ static NTSTATUS smb_file_position_information(connection_struct *conn,
 #else /* LARGE_SMB_OFF_T */
        if (IVAL(pdata,4) != 0) {
                /* more than 32 bits? */
-               return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+               return NT_STATUS_INVALID_PARAMETER;
        }
 #endif /* LARGE_SMB_OFF_T */
 
@@ -4101,7 +4534,6 @@ static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
                pstring rel_name;
                char *last_dirp = NULL;
 
-               unix_format(link_target);
                if (*link_target == '/') {
                        /* No absolute paths allowed. */
                        return NT_STATUS_ACCESS_DENIED;
@@ -4137,6 +4569,7 @@ static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
 
 static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
                                char *inbuf,
+                               char *outbuf,
                                const char *pdata,
                                int total_data,
                                pstring fname)
@@ -4154,6 +4587,11 @@ static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
                return status;
        }
 
+       status = resolve_dfspath(conn, SVAL(inbuf,smb_flg2) & FLAGS2_DFS_PATHNAMES, oldname);
+       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));
 
@@ -4177,6 +4615,7 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
        uint32 len;
        pstring newname;
        pstring base_name;
+       BOOL dest_has_wcard = False;
        NTSTATUS status = NT_STATUS_OK;
        char *p;
 
@@ -4192,7 +4631,12 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       srvstr_get_path(inbuf, newname, &pdata[12], sizeof(newname), len, 0, &status);
+       srvstr_get_path_wcard(inbuf, newname, &pdata[12], sizeof(newname), len, 0, &status, &dest_has_wcard);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       status = resolve_dfspath_wcard(conn, SVAL(inbuf,smb_flg2) & FLAGS2_DFS_PATHNAMES, newname, &dest_has_wcard);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -4202,16 +4646,15 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                return NT_STATUS_NOT_SUPPORTED;
        }
 
-       RESOLVE_DFSPATH_STATUS(newname, conn, inbuf, outbuf);
-
        /* Create the base directory. */
        pstrcpy(base_name, fname);
        p = strrchr_m(base_name, '/');
        if (p) {
-               *p = '\0';
+               p[1] = '\0';
+       } else {
+               pstrcpy(base_name, "./");
        }
        /* Append the new name. */
-       pstrcat(base_name, "/");
        pstrcat(base_name, newname);
 
        if (fsp) {
@@ -4221,7 +4664,7 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
        } else {
                DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
                        fname, newname ));
-               status = rename_internals(conn, fname, base_name, 0, overwrite, False);
+               status = rename_internals(conn, fname, base_name, 0, overwrite, False, dest_has_wcard);
        }
 
        return status;
@@ -4271,6 +4714,11 @@ static NTSTATUS smb_set_posix_acl(connection_struct *conn,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
+       DEBUG(10,("smb_set_posix_acl: file %s num_file_acls = %u, num_def_acls = %u\n",
+               fname ? fname : fsp->fsp_name,
+               (unsigned int)num_file_acls,
+               (unsigned int)num_def_acls));
+
        if (valid_file_acls && !set_unix_posix_acl(conn, fsp, fname, num_file_acls,
                        pdata + SMB_POSIX_ACL_HEADER_SIZE)) {
                return map_nt_error_from_unix(errno);
@@ -4352,21 +4800,34 @@ static NTSTATUS smb_set_posix_lock(connection_struct *conn,
        count = (SMB_BIG_UINT)IVAL(pdata,POSIX_LOCK_LEN_OFFSET);
 #endif /* HAVE_LONGLONG */
 
+       DEBUG(10,("smb_set_posix_lock: file %s, lock_type = %u,"
+                       "lock_pid = %u, count = %.0f, offset = %.0f\n",
+               fsp->fsp_name,
+               (unsigned int)lock_type,
+               (unsigned int)lock_pid,
+               (double)count,
+               (double)offset ));
+
        if (lock_type == UNLOCK_LOCK) {
-               status = do_unlock(fsp,
+               status = do_unlock(smbd_messaging_context(),
+                               fsp,
                                lock_pid,
                                count,
                                offset,
                                POSIX_LOCK);
        } else {
-               struct byte_range_lock *br_lck = do_lock(fsp,
+               uint32 block_smbpid;
+
+               struct byte_range_lock *br_lck = do_lock(smbd_messaging_context(),
+                                                       fsp,
                                                        lock_pid,
                                                        count,
                                                        offset,
                                                        lock_type,
                                                        POSIX_LOCK,
                                                        blocking_lock,
-                                                       &status);
+                                                       &status,
+                                                       &block_smbpid);
 
                if (br_lck && blocking_lock && ERROR_WAS_LOCK_DENIED(status)) {
                        /*
@@ -4383,7 +4844,8 @@ static NTSTATUS smb_set_posix_lock(connection_struct *conn,
                                                lock_type,
                                                POSIX_LOCK,
                                                offset,
-                                               count)) {
+                                               count,
+                                               block_smbpid)) {
                                TALLOC_FREE(br_lck);
                                return status;
                        }
@@ -4405,22 +4867,25 @@ static NTSTATUS smb_set_info_standard(connection_struct *conn,
                                        const char *fname,
                                        const SMB_STRUCT_STAT *psbuf)
 {
-       struct utimbuf tvs;
+       struct timespec ts[2];
 
        if (total_data < 12) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
        /* access time */
-       tvs.actime = srv_make_unix_date2(pdata+l1_fdateLastAccess);
+       ts[0] = convert_time_t_to_timespec(srv_make_unix_date2(pdata+l1_fdateLastAccess));
        /* write time */
-       tvs.modtime = srv_make_unix_date2(pdata+l1_fdateLastWrite);
+       ts[1] = convert_time_t_to_timespec(srv_make_unix_date2(pdata+l1_fdateLastWrite));
+
+       DEBUG(10,("smb_set_info_standard: file %s\n",
+               fname ? fname : fsp->fsp_name ));
 
        return smb_set_file_time(conn,
                                fsp,
                                fname,
                                psbuf,
-                               tvs);
+                               ts);
 }
 
 /****************************************************************************
@@ -4435,10 +4900,10 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
                                        SMB_STRUCT_STAT *psbuf)
 {
        /* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
-       time_t write_time;
-       time_t changed_time;
+       struct timespec write_time;
+       struct timespec changed_time;
        uint32 dosmode = 0;
-       struct utimbuf tvs;
+       struct timespec ts[2];
        NTSTATUS status = NT_STATUS_OK;
 
        if (total_data < 36) {
@@ -4458,26 +4923,31 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
        /* Ignore create time at offset pdata. */
 
        /* access time */
-       tvs.actime = convert_timespec_to_time_t(interpret_long_date(pdata+8));
+       ts[0] = interpret_long_date(pdata+8);
 
-       write_time = convert_timespec_to_time_t(interpret_long_date(pdata+16));
-       changed_time = convert_timespec_to_time_t(interpret_long_date(pdata+24));
+       write_time = interpret_long_date(pdata+16);
+       changed_time = interpret_long_date(pdata+24);
 
-       tvs.modtime = MIN(write_time, changed_time);
+       /* mtime */
+       ts[1] = timespec_min(&write_time, &changed_time);
 
-       if (write_time > tvs.modtime && write_time != (time_t)-1) {
-               tvs.modtime = write_time;
+       if ((timespec_compare(&write_time, &ts[1]) == 1) && !null_timespec(write_time)) {
+               ts[1] = write_time;
        }
+
        /* Prefer a defined time to an undefined one. */
-       if (null_mtime(tvs.modtime)) {
-               tvs.modtime = null_mtime(write_time) ? changed_time : write_time;
+       if (null_timespec(ts[1])) {
+               ts[1] = null_timespec(write_time) ? changed_time : write_time;
        }
 
+       DEBUG(10,("smb_set_file_basic_info: file %s\n",
+               fname ? fname : fsp->fsp_name ));
+
        return smb_set_file_time(conn,
                                fsp,
                                fname,
                                psbuf,
-                               tvs);
+                               ts);
 }
 
 /****************************************************************************
@@ -4691,7 +5161,7 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
                                        const char *fname,
                                        SMB_STRUCT_STAT *psbuf)
 {
-       struct utimbuf tvs;
+       struct timespec ts[2];
        uint32 raw_unixmode;
        mode_t unixmode;
        SMB_OFF_T size = 0;
@@ -4718,8 +5188,8 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
 #endif /* LARGE_SMB_OFF_T */
        }
 
-       tvs.actime = convert_timespec_to_time_t(interpret_long_date(pdata+24)); /* access_time */
-       tvs.modtime = convert_timespec_to_time_t(interpret_long_date(pdata+32)); /* modification_time */
+       ts[0] = interpret_long_date(pdata+24); /* access_time */
+       ts[1] = 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);
@@ -4762,8 +5232,8 @@ 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);
-               tvs.modtime = psbuf->st_mtime;
-               tvs.actime = psbuf->st_atime;
+               ts[0] = get_atimespec(psbuf);
+               ts[1] = get_mtimespec(psbuf);
                /* 
                 * We continue here as we might want to change the 
                 * owner uid/gid.
@@ -4771,6 +5241,16 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
                delete_on_fail = True;
        }
 
+#if 1
+       /* Horrible backwards compatibility hack as an old server bug
+        * allowed a CIFS client bug to remain unnoticed :-(. JRA.
+        * */
+
+       if (!size) {
+               size = get_file_size(*psbuf);
+       }
+#endif
+
        /*
         * Deal with the UNIX specific mode set.
         */
@@ -4788,9 +5268,18 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
         */
 
        if ((set_owner != (uid_t)SMB_UID_NO_CHANGE) && (psbuf->st_uid != set_owner)) {
-               DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC changing owner %u for file %s\n",
+               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 (SMB_VFS_CHOWN(conn, fname, set_owner, (gid_t)-1) != 0) {
+
+               if (S_ISLNK(psbuf->st_mode)) {
+                       ret = SMB_VFS_LCHOWN(conn, fname, set_owner, (gid_t)-1);
+               } else {
+                       ret = SMB_VFS_CHOWN(conn, fname, set_owner, (gid_t)-1);
+               }
+
+               if (ret != 0) {
                        status = map_nt_error_from_unix(errno);
                        if (delete_on_fail) {
                                SMB_VFS_UNLINK(conn,fname);
@@ -4832,7 +5321,431 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
                                fsp,
                                fname,
                                psbuf,
-                               tvs);
+                               ts);
+}
+
+/****************************************************************************
+ Deal with SMB_SET_FILE_UNIX_INFO2.
+****************************************************************************/
+
+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)
+{
+       NTSTATUS status;
+       uint32 smb_fflags;
+       uint32 smb_fmask;
+
+       if (total_data < 116) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       /* Start by setting all the fields that are common between UNIX_BASIC
+        * and UNIX_INFO2.
+        */
+       status = smb_set_file_unix_basic(conn, pdata, total_data,
+                               fsp, fname, psbuf);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       smb_fflags = IVAL(pdata, 108);
+       smb_fmask = IVAL(pdata, 112);
+
+       /* NB: We should only attempt to alter the file flags if the client
+        * sends a non-zero mask.
+        */
+       if (smb_fmask != 0) {
+               int stat_fflags = 0;
+
+               if (!map_info2_flags_to_sbuf(psbuf, smb_fflags, smb_fmask,
+                           &stat_fflags)) {
+                       /* Client asked to alter a flag we don't understand. */
+                       return NT_STATUS_INVALID_PARAMETER;
+               }
+
+               if (fsp && fsp->fh->fd != -1) {
+                       /* XXX: we should be  using SMB_VFS_FCHFLAGS here. */
+                       return NT_STATUS_NOT_SUPPORTED;
+               } else {
+                       if (SMB_VFS_CHFLAGS(conn, fname, stat_fflags) != 0) {
+                               return map_nt_error_from_unix(errno);
+                       }
+               }
+       }
+
+       /* XXX: need to add support for changing the create_time here. You
+        * can do this for paths on Darwin with setattrlist(2). The right way
+        * to hook this up is probably by extending the VFS utimes interface.
+        */
+
+       return NT_STATUS_OK;
+}
+
+/****************************************************************************
+ Create a directory with POSIX semantics.
+****************************************************************************/
+
+static NTSTATUS smb_posix_mkdir(connection_struct *conn,
+                               char **ppdata,
+                               int total_data,
+                               const char *fname,
+                               SMB_STRUCT_STAT *psbuf,
+                               int *pdata_return_size)
+{
+       NTSTATUS status = NT_STATUS_OK;
+       uint32 raw_unixmode = 0;
+       uint32 mod_unixmode = 0;
+       mode_t unixmode = (mode_t)0;
+       files_struct *fsp = NULL;
+       uint16 info_level_return = 0;
+       int info;
+       char *pdata = *ppdata;
+
+       if (total_data < 18) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       raw_unixmode = IVAL(pdata,8);
+       /* Next 4 bytes are not yet defined. */
+
+       status = unix_perms_from_wire(conn, psbuf, raw_unixmode, PERM_NEW_DIR, &unixmode);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       mod_unixmode = (uint32)unixmode | FILE_FLAG_POSIX_SEMANTICS;
+
+       DEBUG(10,("smb_posix_mkdir: file %s, mode 0%o\n",
+               fname, (unsigned int)unixmode ));
+
+       status = open_directory(conn,
+                               fname,
+                               psbuf,
+                               FILE_READ_ATTRIBUTES, /* Just a stat open */
+                               FILE_SHARE_NONE, /* Ignored for stat opens */
+                               FILE_CREATE,
+                               0,
+                               mod_unixmode,
+                               &info,
+                               &fsp);
+
+        if (NT_STATUS_IS_OK(status)) {
+                close_file(fsp, NORMAL_CLOSE);
+        }
+
+       info_level_return = SVAL(pdata,16);
+       if (info_level_return == SMB_QUERY_FILE_UNIX_BASIC) {
+               *pdata_return_size = 12 + SMB_FILE_UNIX_BASIC_SIZE;
+       } else if (info_level_return ==  SMB_QUERY_FILE_UNIX_INFO2) {
+               *pdata_return_size = 12 + SMB_FILE_UNIX_INFO2_SIZE;
+       } else {
+               *pdata_return_size = 12;
+       }
+
+       /* Realloc the data size */
+       *ppdata = (char *)SMB_REALLOC(*ppdata,*pdata_return_size);
+       if (*ppdata == NULL) {
+               *pdata_return_size = 0;
+               return NT_STATUS_NO_MEMORY;
+       }
+       pdata = *ppdata;
+
+       SSVAL(pdata,0,NO_OPLOCK_RETURN);
+       SSVAL(pdata,2,0); /* No fnum. */
+       SIVAL(pdata,4,info); /* Was directory created. */
+
+       switch (info_level_return) {
+               case SMB_QUERY_FILE_UNIX_BASIC:
+                       SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_BASIC);
+                       SSVAL(pdata,10,0); /* Padding. */
+                       store_file_unix_basic(conn, pdata + 12, fsp, psbuf);
+                       break;
+               case SMB_QUERY_FILE_UNIX_INFO2:
+                       SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_INFO2);
+                       SSVAL(pdata,10,0); /* Padding. */
+                       store_file_unix_basic_info2(conn, pdata + 12, fsp, psbuf);
+                       break;
+               default:
+                       SSVAL(pdata,8,SMB_NO_INFO_LEVEL_RETURNED);
+                       SSVAL(pdata,10,0); /* Padding. */
+                       break;
+       }
+
+       return status;
+}
+
+/****************************************************************************
+ Open/Create a file with POSIX semantics.
+****************************************************************************/
+
+static NTSTATUS smb_posix_open(connection_struct *conn,
+                               char **ppdata,
+                               int total_data,
+                               const char *fname,
+                               SMB_STRUCT_STAT *psbuf,
+                               int *pdata_return_size)
+{
+       BOOL extended_oplock_granted = False;
+       char *pdata = *ppdata;
+       uint32 flags = 0;
+       uint32 wire_open_mode = 0;
+       uint32 raw_unixmode = 0;
+       uint32 mod_unixmode = 0;
+       uint32 create_disp = 0;
+       uint32 access_mask = 0;
+       uint32 create_options = 0;
+       NTSTATUS status = NT_STATUS_OK;
+       mode_t unixmode = (mode_t)0;
+       files_struct *fsp = NULL;
+       int oplock_request = 0;
+       int info = 0;
+       uint16 info_level_return = 0;
+
+       if (total_data < 18) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       flags = IVAL(pdata,0);
+       oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
+       if (oplock_request) {
+               oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
+       }
+
+       wire_open_mode = IVAL(pdata,4);
+
+       if (wire_open_mode == (SMB_O_CREAT|SMB_O_DIRECTORY)) {
+               return smb_posix_mkdir(conn,
+                                       ppdata,
+                                       total_data,
+                                       fname,
+                                       psbuf,
+                                       pdata_return_size);
+       }
+
+       switch (wire_open_mode & SMB_ACCMODE) {
+               case SMB_O_RDONLY:
+                       access_mask = FILE_READ_DATA;
+                       break;
+               case SMB_O_WRONLY:
+                       access_mask = FILE_WRITE_DATA;
+                       break;
+               case SMB_O_RDWR:
+                       access_mask = FILE_READ_DATA|FILE_WRITE_DATA;
+                       break;
+               default:
+                       DEBUG(5,("smb_posix_open: invalid open mode 0x%x\n",
+                               (unsigned int)wire_open_mode ));
+                       return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       wire_open_mode &= ~SMB_ACCMODE;
+
+       if((wire_open_mode & (SMB_O_CREAT | SMB_O_EXCL)) == (SMB_O_CREAT | SMB_O_EXCL)) {
+               create_disp = FILE_CREATE;
+       } else if((wire_open_mode & (SMB_O_CREAT | SMB_O_TRUNC)) == (SMB_O_CREAT | SMB_O_TRUNC)) {
+               create_disp = FILE_OVERWRITE_IF;
+       } else if((wire_open_mode & SMB_O_CREAT) == SMB_O_CREAT) {
+               create_disp = FILE_OPEN_IF;
+       } else {
+               DEBUG(5,("smb_posix_open: invalid create mode 0x%x\n",
+                       (unsigned int)wire_open_mode ));
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       raw_unixmode = IVAL(pdata,8);
+       /* Next 4 bytes are not yet defined. */
+
+       status = unix_perms_from_wire(conn,
+                               psbuf,
+                               raw_unixmode,
+                               VALID_STAT(*psbuf) ? PERM_EXISTING_FILE : PERM_NEW_FILE,
+                               &unixmode);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       mod_unixmode = (uint32)unixmode | FILE_FLAG_POSIX_SEMANTICS;
+
+       if (wire_open_mode & SMB_O_SYNC) {
+               create_options |= FILE_WRITE_THROUGH;
+       }
+       if (wire_open_mode & SMB_O_APPEND) {
+               access_mask |= FILE_APPEND_DATA;
+       }
+       if (wire_open_mode & SMB_O_DIRECT) {
+               mod_unixmode |= FILE_FLAG_NO_BUFFERING;
+       }
+
+       DEBUG(10,("smb_posix_open: file %s, smb_posix_flags = %u, mode 0%o\n",
+               fname,
+               (unsigned int)wire_open_mode,
+               (unsigned int)unixmode ));
+
+       status = open_file_ntcreate(conn,
+                               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);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
+               extended_oplock_granted = True;
+       }
+
+       if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
+               extended_oplock_granted = True;
+       }
+
+       info_level_return = SVAL(pdata,16);
+       /* Allocate the correct return size. */
+
+       if (info_level_return == SMB_QUERY_FILE_UNIX_BASIC) {
+               *pdata_return_size = 12 + SMB_FILE_UNIX_BASIC_SIZE;
+       } else if (info_level_return ==  SMB_QUERY_FILE_UNIX_INFO2) {
+               *pdata_return_size = 12 + SMB_FILE_UNIX_INFO2_SIZE;
+       } else {
+               *pdata_return_size = 12;
+       }
+
+       /* Realloc the data size */
+       *ppdata = (char *)SMB_REALLOC(*ppdata,*pdata_return_size);
+       if (*ppdata == NULL) {
+               close_file(fsp,ERROR_CLOSE);
+               *pdata_return_size = 0;
+               return NT_STATUS_NO_MEMORY;
+       }
+       pdata = *ppdata;
+
+       if (extended_oplock_granted) {
+               if (flags & REQUEST_BATCH_OPLOCK) {
+                       SSVAL(pdata,0, BATCH_OPLOCK_RETURN);
+               } else {
+                       SSVAL(pdata,0, EXCLUSIVE_OPLOCK_RETURN);
+               }
+       } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
+               SSVAL(pdata,0, LEVEL_II_OPLOCK_RETURN);
+       } else {
+               SSVAL(pdata,0,NO_OPLOCK_RETURN);
+       }
+
+       SSVAL(pdata,2,fsp->fnum);
+       SIVAL(pdata,4,info); /* Was file created etc. */
+
+       switch (info_level_return) {
+               case SMB_QUERY_FILE_UNIX_BASIC:
+                       SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_BASIC);
+                       SSVAL(pdata,10,0); /* padding. */
+                       store_file_unix_basic(conn, pdata + 12, fsp, psbuf);
+                       break;
+               case SMB_QUERY_FILE_UNIX_INFO2:
+                       SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_INFO2);
+                       SSVAL(pdata,10,0); /* padding. */
+                       store_file_unix_basic_info2(conn, pdata + 12, fsp, psbuf);
+                       break;
+               default:
+                       SSVAL(pdata,8,SMB_NO_INFO_LEVEL_RETURNED);
+                       SSVAL(pdata,10,0); /* padding. */
+                       break;
+       }
+       return NT_STATUS_OK;
+}
+
+/****************************************************************************
+ Delete a file with POSIX semantics.
+****************************************************************************/
+
+static NTSTATUS smb_posix_unlink(connection_struct *conn,
+                               const char *pdata,
+                               int total_data,
+                               const char *fname,
+                               SMB_STRUCT_STAT *psbuf)
+{
+       NTSTATUS status = NT_STATUS_OK;
+       files_struct *fsp = NULL;
+       uint16 flags = 0;
+       int info = 0;
+
+       if (total_data < 2) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       flags = SVAL(pdata,0);
+
+       if (!VALID_STAT(*psbuf)) {
+               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+       }
+
+       if ((flags == SMB_POSIX_UNLINK_DIRECTORY_TARGET) &&
+                       !VALID_STAT_OF_DIR(*psbuf)) {
+               return NT_STATUS_NOT_A_DIRECTORY;
+       }
+
+       DEBUG(10,("smb_posix_unlink: %s %s\n",
+               (flags == SMB_POSIX_UNLINK_DIRECTORY_TARGET) ? "directory" : "file",
+               fname));
+
+       if (VALID_STAT_OF_DIR(*psbuf)) {
+               status = open_directory(conn,
+                                       fname,
+                                       psbuf,
+                                       DELETE_ACCESS,
+                                       FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                                       FILE_OPEN,
+                                       FILE_DELETE_ON_CLOSE,
+                                       FILE_FLAG_POSIX_SEMANTICS|0777,
+                                       &info,                          
+                                       &fsp);
+       } else {
+               char del = 1;
+
+               status = open_file_ntcreate(conn,
+                               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);
+               /* 
+                * For file opens we must set the delete on close
+                * after the open.
+                */
+
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+
+               status = smb_set_file_disposition_info(conn,
+                                                       &del,
+                                                       1,
+                                                       fsp,
+                                                       fname,
+                                                       psbuf);
+       }
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+       return close_file(fsp, NORMAL_CLOSE);
 }
 
 /****************************************************************************
@@ -4851,6 +5764,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
        pstring fname;
        files_struct *fsp = NULL;
        NTSTATUS status = NT_STATUS_OK;
+       int data_return_size = 0;
 
        if (!params) {
                return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
@@ -4873,9 +5787,17 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                         * to do this call. JRA.
                         */
                        pstrcpy(fname, fsp->fsp_name);
-                       if (SMB_VFS_STAT(conn,fname,&sbuf) != 0) {
-                               DEBUG(3,("call_trans2setfilepathinfo: fileinfo of %s failed (%s)\n",fname,strerror(errno)));
-                               return UNIXERROR(ERRDOS,ERRbadpath);
+                       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)));
+                                       return UNIXERROR(ERRDOS,ERRbadpath);
+                               }
+                       } else {
+                               if (SMB_VFS_STAT(conn,fname,&sbuf) != 0) {
+                                       DEBUG(3,("call_trans2setfilepathinfo: fileinfo of %s failed (%s)\n",fname,strerror(errno)));
+                                       return UNIXERROR(ERRDOS,ERRbadpath);
+                               }
                        }
                } else if (fsp && fsp->print_file) {
                        /*
@@ -4887,7 +5809,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                                DEBUG(3,("call_trans2setfilepathinfo: Cancelling print job (%s)\n", fsp->fsp_name ));
        
                                SSVAL(params,0,0);
-                               send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
+                               send_trans2_replies(inbuf, outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
                                return(-1);
                        } else
                                return (UNIXERROR(ERRDOS,ERRbadpath));
@@ -4915,25 +5837,37 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                if (!NT_STATUS_IS_OK(status)) {
                        return ERROR_NT(status);
                }
-               status = unix_convert(conn, fname, False, NULL, &sbuf);
+
+               status = resolve_dfspath(conn, SVAL(inbuf,smb_flg2) & FLAGS2_DFS_PATHNAMES, fname);
                if (!NT_STATUS_IS_OK(status)) {
+                       if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+                               return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED, ERRSRV, ERRbadpath);
+                       }
                        return ERROR_NT(status);
                }
 
-               /*
-                * For CIFS UNIX extensions the target name may not exist.
-                */
-
-               if(!VALID_STAT(sbuf) && !INFO_LEVEL_IS_UNIX(info_level)) {
-                       DEBUG(3,("call_trans2setfilepathinfo: stat of %s failed (%s)\n", fname, strerror(errno)));
-                       return UNIXERROR(ERRDOS,ERRbadpath);
-               }    
+               status = unix_convert(conn, fname, False, NULL, &sbuf);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return ERROR_NT(status);
+               }
 
                status = check_name(conn, fname);
                if (!NT_STATUS_IS_OK(status)) {
                        return ERROR_NT(status);
                }
 
+               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)));
+                       return UNIXERROR(ERRDOS,ERRbadpath);
+               }
        }
 
        if (!CAN_WRITE(conn)) {
@@ -4956,9 +5890,9 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
 
        SSVAL(params,0,0);
 
-       if (fsp && fsp->pending_modtime) {
+       if (fsp && !null_timespec(fsp->pending_modtime)) {
                /* the pending modtime overrides the current modtime */
-               sbuf.st_mtime = fsp->pending_modtime;
+               set_mtimespec(&sbuf, fsp->pending_modtime);
        }
 
        switch (info_level) {
@@ -5070,10 +6004,6 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
 
                case SMB_SET_FILE_UNIX_BASIC:
                {
-                       if (tran_call == TRANSACT2_SETFILEINFO) {
-                               return ERROR_NT(NT_STATUS_INVALID_LEVEL);
-                       }
-
                        status = smb_set_file_unix_basic(conn,
                                                        pdata,
                                                        total_data,
@@ -5083,6 +6013,17 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                        break;
                }
 
+               case SMB_SET_FILE_UNIX_INFO2:
+               {
+                       status = smb_set_file_unix_info2(conn,
+                                                       pdata,
+                                                       total_data,
+                                                       fsp,
+                                                       fname,
+                                                       &sbuf);
+                       break;
+               }
+
                case SMB_SET_FILE_UNIX_LINK:
                {
                        if (tran_call != TRANSACT2_SETPATHINFO) {
@@ -5105,6 +6046,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                        }
                        status = smb_set_file_unix_hlink(conn,
                                                inbuf,
+                                               outbuf,
                                                pdata,
                                                total_data,
                                                fname);
@@ -5138,6 +6080,9 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
 
                case SMB_SET_POSIX_LOCK:
                {
+                       if (tran_call != TRANSACT2_SETFILEINFO) {
+                               return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+                       }
                        status = smb_set_posix_lock(conn,
                                                inbuf,
                                                length,
@@ -5147,6 +6092,37 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                        break;
                }
 
+               case SMB_POSIX_PATH_OPEN:
+               {
+                       if (tran_call != TRANSACT2_SETPATHINFO) {
+                               /* We must have a pathname for this. */
+                               return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+                       }
+
+                       status = smb_posix_open(conn,
+                                               ppdata,
+                                               total_data,
+                                               fname,
+                                               &sbuf,
+                                               &data_return_size);
+                       break;
+               }
+
+               case SMB_POSIX_PATH_UNLINK:
+               {
+                       if (tran_call != TRANSACT2_SETPATHINFO) {
+                               /* We must have a pathname for this. */
+                               return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+                       }
+
+                       status = smb_posix_unlink(conn,
+                                               pdata,
+                                               total_data,
+                                               fname,
+                                               &sbuf);
+                       break;
+               }
+
                default:
                        return ERROR_NT(NT_STATUS_INVALID_LEVEL);
        }
@@ -5168,7 +6144,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
        }
 
        SSVAL(params,0,0);
-       send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
+       send_trans2_replies(inbuf, outbuf, bufsize, params, 2, *ppdata, data_return_size, max_data_bytes);
   
        return -1;
 }
@@ -5207,6 +6183,12 @@ static int call_trans2mkdir(connection_struct *conn, char *inbuf, char *outbuf,
                return ERROR_NT(status);
        }
 
+       status = check_name(conn, directory);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(5,("call_trans2mkdir error (%s)\n", nt_errstr(status)));
+               return ERROR_NT(status);
+       }
+
        /* Any data in this call is an EA list. */
        if (total_data && (total_data != 4) && !lp_ea_support(SNUM(conn))) {
                return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
@@ -5238,12 +6220,6 @@ static int call_trans2mkdir(connection_struct *conn, char *inbuf, char *outbuf,
                return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
        }
 
-       status = check_name(conn, directory);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(5,("call_trans2mkdir error (%s)\n", nt_errstr(status)));
-               return ERROR_NT(status);
-       }
-
        status = create_directory(conn, directory);
 
        if (!NT_STATUS_IS_OK(status)) {
@@ -5267,7 +6243,7 @@ static int call_trans2mkdir(connection_struct *conn, char *inbuf, char *outbuf,
 
        SSVAL(params,0,0);
 
-       send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
+       send_trans2_replies(inbuf, outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
   
        return(-1);
 }
@@ -5316,7 +6292,7 @@ static int call_trans2findnotifyfirst(connection_struct *conn, char *inbuf, char
        if(fnf_handle == 0)
                fnf_handle = 257;
 
-       send_trans2_replies(outbuf, bufsize, params, 6, *ppdata, 0, max_data_bytes);
+       send_trans2_replies(inbuf, outbuf, bufsize, params, 6, *ppdata, 0, max_data_bytes);
   
        return(-1);
 }
@@ -5344,7 +6320,7 @@ static int call_trans2findnotifynext(connection_struct *conn, char *inbuf, char
        SSVAL(params,0,0); /* No changes */
        SSVAL(params,2,0); /* No EA errors */
 
-       send_trans2_replies(outbuf, bufsize, params, 4, *ppdata, 0, max_data_bytes);
+       send_trans2_replies(inbuf, outbuf, bufsize, params, 4, *ppdata, 0, max_data_bytes);
   
        return(-1);
 }
@@ -5361,6 +6337,7 @@ static int call_trans2getdfsreferral(connection_struct *conn, char* inbuf, char*
        pstring pathname;
        int reply_size = 0;
        int max_referral_level;
+       NTSTATUS status = NT_STATUS_OK;
 
        DEBUG(10,("call_trans2getdfsreferral\n"));
 
@@ -5374,11 +6351,11 @@ static int call_trans2getdfsreferral(connection_struct *conn, char* inbuf, char*
                return ERROR_DOS(ERRDOS,ERRbadfunc);
 
        srvstr_pull(inbuf, pathname, &params[2], sizeof(pathname), total_params - 2, STR_TERMINATE);
-       if((reply_size = setup_dfs_referral(conn, pathname,max_referral_level,ppdata)) < 0)
-               return UNIXERROR(ERRDOS,ERRbadfile);
+       if((reply_size = setup_dfs_referral(conn, pathname,max_referral_level,ppdata,&status)) < 0)
+               return ERROR_NT(status);
     
        SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | FLAGS2_DFS_PATHNAMES);
-       send_trans2_replies(outbuf,bufsize,0,0,*ppdata,reply_size, max_data_bytes);
+       send_trans2_replies(inbuf, outbuf,bufsize,0,0,*ppdata,reply_size, max_data_bytes);
 
        return(-1);
 }
@@ -5416,7 +6393,7 @@ static int call_trans2ioctl(connection_struct *conn, char* inbuf, char* outbuf,
                SSVAL(pdata,0,fsp->rap_print_jobid);                     /* Job number */
                srvstr_push( outbuf, pdata + 2, global_myname(), 15, STR_ASCII|STR_TERMINATE); /* Our NetBIOS name */
                srvstr_push( outbuf, pdata+18, lp_servicename(SNUM(conn)), 13, STR_ASCII|STR_TERMINATE); /* Service name */
-               send_trans2_replies(outbuf,bufsize,*pparams,0,*ppdata,32, max_data_bytes);
+               send_trans2_replies(inbuf, outbuf,bufsize,*pparams,0,*ppdata,32, max_data_bytes);
                return(-1);
        } else {
                DEBUG(2,("Unknown TRANS2_IOCTL\n"));
@@ -5439,7 +6416,7 @@ int reply_findclose(connection_struct *conn,
 
        dptr_close(&dptr_num);
 
-       outsize = set_message(outbuf,0,0,False);
+       outsize = set_message(inbuf, outbuf,0,0,False);
 
        DEBUG(3,("SMBfindclose dptr_num = %d\n", dptr_num));
 
@@ -5466,7 +6443,7 @@ int reply_findnclose(connection_struct *conn,
           findnotifyfirst - so any dptr_num is ok here. 
           Just ignore it. */
 
-       outsize = set_message(outbuf,0,0,False);
+       outsize = set_message(inbuf, outbuf,0,0,False);
 
        DEBUG(3,("SMB_findnclose dptr_num = %d\n", dptr_num));
 
@@ -5668,7 +6645,8 @@ int reply_trans2(connection_struct *conn, char *inbuf,char *outbuf,
        }
 
        if (IS_IPC(conn) && (tran_call != TRANSACT2_OPEN)
-            && (tran_call != TRANSACT2_GET_DFS_REFERRAL)) {
+            && (tran_call != TRANSACT2_GET_DFS_REFERRAL)
+            && (tran_call != TRANSACT2_QFILEINFO)) {
                END_PROFILE(SMBtrans2);
                return ERROR_DOS(ERRSRV,ERRaccess);
        }
@@ -5784,7 +6762,7 @@ int reply_trans2(connection_struct *conn, char *inbuf,char *outbuf,
 
        /* We need to send an interim response then receive the rest
           of the parameter/data bytes */
-       outsize = set_message(outbuf,0,0,False);
+       outsize = set_message(inbuf, outbuf,0,0,False);
        show_msg(outbuf);
        END_PROFILE(SMBtrans2);
        return outsize;