r23779: Change from v2 or later to v3 or later.
[amitay/samba.git] / source3 / smbd / trans2.c
index 158642a58821cb13292dc6dba0b3dd73e08ff34a..5fa26ca1f733ce69deb5a69c5da149b1ab72d7f1 100644 (file)
@@ -11,7 +11,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -147,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)) {
@@ -487,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;
 }
@@ -577,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,
@@ -602,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
@@ -657,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);
@@ -739,9 +740,12 @@ int send_trans2_replies(char *outbuf,
  Reply to a TRANSACT2_OPEN.
 ****************************************************************************/
 
-static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, int bufsize,  
-                               char **pparams, int total_params, char **ppdata, int total_data,
-                               unsigned int max_data_bytes)
+static int call_trans2open(connection_struct *conn,
+                          struct smb_request *req,
+                          char *inbuf, char *outbuf, int bufsize,
+                          char **pparams, int total_params,
+                          char **ppdata, int total_data,
+                          unsigned int max_data_bytes)
 {
        char *params = *pparams;
        char *pdata = *ppdata;
@@ -800,7 +804,9 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
                return(ERROR_DOS(ERRSRV,ERRaccess));
        }
 
-       srvstr_get_path(inbuf, fname, pname, sizeof(fname), total_params - 28, STR_TERMINATE, &status);
+       srvstr_get_path(inbuf, SVAL(inbuf,smb_flg2), fname, pname,
+                       sizeof(fname), total_params - 28, STR_TERMINATE,
+                       &status);
        if (!NT_STATUS_IS_OK(status)) {
                return ERROR_NT(status);
        }
@@ -858,7 +864,7 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
                return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
        }
 
-       status = open_file_ntcreate(conn,fname,&sbuf,
+       status = open_file_ntcreate(conn, req, fname, &sbuf,
                access_mask,
                share_mode,
                create_disposition,
@@ -950,7 +956,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;
 }
@@ -1160,16 +1166,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
@@ -1178,21 +1196,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)) {
@@ -1230,12 +1252,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);
@@ -1252,7 +1275,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;
 
@@ -1260,8 +1283,6 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                }
        }
 
-       mangle_map(fname,False,True,conn->params);
-
        p = pdata;
        last_entry_ptr = p;
 
@@ -1601,13 +1622,17 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                                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. */
 
@@ -1724,7 +1749,9 @@ close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
                        return ERROR_NT(NT_STATUS_INVALID_LEVEL);
        }
 
-       srvstr_get_path_wcard(inbuf, directory, params+12, sizeof(directory), total_params - 12, STR_TERMINATE, &ntstatus, &mask_contains_wcard);
+       srvstr_get_path_wcard(inbuf, SVAL(inbuf,smb_flg2), directory,
+                             params+12, sizeof(directory), total_params - 12,
+                             STR_TERMINATE, &ntstatus, &mask_contains_wcard);
        if (!NT_STATUS_IS_OK(ntstatus)) {
                return ERROR_NT(ntstatus);
        }
@@ -1910,7 +1937,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));
@@ -1989,7 +2016,10 @@ static int call_trans2findnext(connection_struct *conn, char *inbuf, char *outbu
 
        *mask = *directory = *resume_name = 0;
 
-       srvstr_get_path_wcard(inbuf, resume_name, params+12, sizeof(resume_name), total_params - 12, STR_TERMINATE, &ntstatus, &mask_contains_wcard);
+       srvstr_get_path_wcard(inbuf, SVAL(inbuf,smb_flg2), resume_name,
+                             params+12, sizeof(resume_name),
+                             total_params - 12, STR_TERMINATE, &ntstatus,
+                             &mask_contains_wcard);
        if (!NT_STATUS_IS_OK(ntstatus)) {
                /* Win9x or OS/2 can send a resume name of ".." or ".". This will cause the parser to
                   complain (it thinks we're asking for the directory above the shared
@@ -2203,7 +2233,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));
@@ -2215,6 +2245,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).
 ****************************************************************************/
@@ -2228,7 +2264,7 @@ static int call_trans2qfsinfo(connection_struct *conn, char *inbuf, char *outbuf
        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;
@@ -2322,6 +2358,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 */
@@ -2349,9 +2387,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;
@@ -2501,8 +2541,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
@@ -2522,7 +2566,10 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                                        CIFS_UNIX_POSIX_PATHNAMES_CAP|
                                        CIFS_UNIX_FCNTL_LOCKS_CAP|
                                        CIFS_UNIX_EXTATTR_CAP|
-                                       CIFS_UNIX_POSIX_PATH_OPERATIONS_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:
@@ -2682,7 +2729,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) );
 
@@ -2761,6 +2808,7 @@ cap_low = 0x%x, cap_high = 0x%x\n",
                case SMB_REQUEST_TRANSPORT_ENCRYPTION:
                        {
                                NTSTATUS status;
+                               size_t param_len = 0;
                                size_t data_len = total_data;
 
                                if (!lp_unix_extensions()) {
@@ -2769,7 +2817,12 @@ cap_low = 0x%x, cap_high = 0x%x\n",
 
                                DEBUG( 4,("call_trans2setfsinfo: request transport encrption.\n"));
 
-                               status = srv_request_encryption_setup((unsigned char **)&pdata, &data_len);
+                               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__);
@@ -2777,11 +2830,11 @@ cap_low = 0x%x, cap_high = 0x%x\n",
                                        return ERROR_NT(status);
                                }
 
-                               send_trans2_replies( outbuf, bufsize, params, 0, pdata, data_len, max_data_bytes);
+                               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();
+                                       status = srv_encryption_start(conn);
                                        if (!NT_STATUS_IS_OK(status)) {
                                                exit_server_cleanly("Failure in setting up encrypted transport");
                                        }
@@ -2872,7 +2925,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;
 }
@@ -3165,6 +3218,68 @@ static char *store_file_unix_basic_info2(connection_struct *conn,
        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).
@@ -3210,6 +3325,20 @@ 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);
 
@@ -3247,7 +3376,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.
@@ -3260,7 +3389,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 {
@@ -3279,7 +3408,9 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                        return ERROR_NT(NT_STATUS_INVALID_LEVEL);
                }
 
-               srvstr_get_path(inbuf, fname, &params[6], sizeof(fname), total_params - 6, STR_TERMINATE, &status);
+               srvstr_get_path(inbuf, SVAL(inbuf,smb_flg2), fname, &params[6],
+                               sizeof(fname), total_params - 6,
+                               STR_TERMINATE, &status);
                if (!NT_STATUS_IS_OK(status)) {
                        return ERROR_NT(status);
                }
@@ -3313,7 +3444,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);
                }
@@ -3401,7 +3532,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);
@@ -3440,7 +3571,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                }
        } else {
                /* Do we have this path open ? */
-               files_struct *fsp1 = file_find_di_first(sbuf.st_dev, sbuf.st_ino);
+               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 = fsp1->pending_modtime;
@@ -3741,8 +3872,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;
@@ -3762,7 +3892,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); /* ??? */
@@ -3991,7 +4121,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);
 }
@@ -4047,7 +4177,7 @@ NTSTATUS hardlink_internals(connection_struct *conn, pstring oldname, pstring ne
        }
 
        /* Ensure this is within the share. */
-       status = reduce_name(conn, oldname);
+       status = check_reduced_name(conn, oldname);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -4181,6 +4311,7 @@ static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_set_file_size(connection_struct *conn,
+                                 struct smb_request *req,
                                files_struct *fsp,
                                const char *fname,
                                SMB_STRUCT_STAT *psbuf,
@@ -4210,7 +4341,7 @@ static NTSTATUS smb_set_file_size(connection_struct *conn,
                return NT_STATUS_OK;
        }
 
-       status = open_file_ntcreate(conn, fname, psbuf,
+       status = open_file_ntcreate(conn, req, fname, psbuf,
                                FILE_WRITE_DATA,
                                FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
                                FILE_OPEN,
@@ -4408,7 +4539,8 @@ static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
                return NT_STATUS_ACCESS_DENIED;
        }
 
-       srvstr_pull(inbuf, link_target, pdata, sizeof(link_target), total_data, STR_TERMINATE);
+       srvstr_pull(inbuf, SVAL(inbuf, smb_flg2), link_target, pdata,
+                   sizeof(link_target), total_data, STR_TERMINATE);
 
        /* !widelinks forces the target path to be within the share. */
        /* This means we can interpret the target as a pathname. */
@@ -4464,7 +4596,8 @@ static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       srvstr_get_path(inbuf, oldname, pdata, sizeof(oldname), total_data, STR_TERMINATE, &status);
+       srvstr_get_path(inbuf, SVAL(inbuf,smb_flg2), oldname, pdata,
+                       sizeof(oldname), total_data, STR_TERMINATE, &status);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -4485,6 +4618,7 @@ static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_file_rename_information(connection_struct *conn,
+                                           struct smb_request *req,
                                char *inbuf,
                                char *outbuf,
                                const char *pdata,
@@ -4493,7 +4627,7 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
                                pstring fname)
 {
        BOOL overwrite;
-       /* uint32 root_fid; */  /* Not used */
+       uint32 root_fid;
        uint32 len;
        pstring newname;
        pstring base_name;
@@ -4506,14 +4640,16 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
        }
 
        overwrite = (CVAL(pdata,0) ? True : False);
-       /* root_fid = IVAL(pdata,4); */
+       root_fid = IVAL(pdata,4);
        len = IVAL(pdata,8);
 
-       if (len > (total_data - 12) || (len == 0)) {
+       if (len > (total_data - 12) || (len == 0) || (root_fid != 0)) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       srvstr_get_path_wcard(inbuf, newname, &pdata[12], sizeof(newname), len, 0, &status, &dest_has_wcard);
+       srvstr_get_path_wcard(inbuf, SVAL(inbuf,smb_flg2), newname, &pdata[12],
+                             sizeof(newname), len, 0, &status,
+                             &dest_has_wcard);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -4532,10 +4668,11 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
        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) {
@@ -4545,7 +4682,8 @@ 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, dest_has_wcard);
+               status = rename_internals(conn, req, fname, base_name, 0,
+                                         overwrite, False, dest_has_wcard);
        }
 
        return status;
@@ -4690,20 +4828,25 @@ static NTSTATUS smb_set_posix_lock(connection_struct *conn,
                (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)) {
                        /*
@@ -4720,7 +4863,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;
                        }
@@ -4830,6 +4974,7 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
+                                            struct smb_request *req,
                                        const char *pdata,
                                        int total_data,
                                        files_struct *fsp,
@@ -4882,7 +5027,7 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
 
        /* Pathname or stat or directory file. */
 
-       status = open_file_ntcreate(conn, fname, psbuf,
+       status = open_file_ntcreate(conn, req, fname, psbuf,
                                FILE_WRITE_DATA,
                                FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
                                FILE_OPEN,
@@ -4910,6 +5055,7 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_set_file_end_of_file_info(connection_struct *conn,
+                                             struct smb_request *req,
                                        const char *pdata,
                                        int total_data,
                                        files_struct *fsp,
@@ -4934,7 +5080,7 @@ static NTSTATUS smb_set_file_end_of_file_info(connection_struct *conn,
        DEBUG(10,("smb_set_file_end_of_file_info: Set end of file info for "
                "file %s to %.0f\n", fname, (double)size ));
 
-       return smb_set_file_size(conn,
+       return smb_set_file_size(conn, req,
                                fsp,
                                fname,
                                psbuf,
@@ -5030,6 +5176,7 @@ static NTSTATUS smb_unix_mknod(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
+                                       struct smb_request *req,
                                        const char *pdata,
                                        int total_data,
                                        files_struct *fsp,
@@ -5143,9 +5290,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);
@@ -5172,7 +5328,7 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
 
        /* Deal with any size changes. */
 
-       status = smb_set_file_size(conn,
+       status = smb_set_file_size(conn, req,
                                fsp,
                                fname,
                                psbuf,
@@ -5195,6 +5351,7 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
 ****************************************************************************/
 
 static NTSTATUS smb_set_file_unix_info2(connection_struct *conn,
+                                       struct smb_request *req,
                                        const char *pdata,
                                        int total_data,
                                        files_struct *fsp,
@@ -5212,7 +5369,7 @@ static NTSTATUS smb_set_file_unix_info2(connection_struct *conn,
        /* 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,
+       status = smb_set_file_unix_basic(conn, req, pdata, total_data,
                                fsp, fname, psbuf);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -5256,6 +5413,7 @@ static NTSTATUS smb_set_file_unix_info2(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_posix_mkdir(connection_struct *conn,
+                               struct smb_request *req,
                                char **ppdata,
                                int total_data,
                                const char *fname,
@@ -5288,7 +5446,7 @@ static NTSTATUS smb_posix_mkdir(connection_struct *conn,
        DEBUG(10,("smb_posix_mkdir: file %s, mode 0%o\n",
                fname, (unsigned int)unixmode ));
 
-       status = open_directory(conn,
+       status = open_directory(conn, req,
                                fname,
                                psbuf,
                                FILE_READ_ATTRIBUTES, /* Just a stat open */
@@ -5319,23 +5477,27 @@ static NTSTATUS smb_posix_mkdir(connection_struct *conn,
                *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);
-       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);
-       default:
-               SSVAL(pdata,8,SMB_NO_INFO_LEVEL_RETURNED);
-               SSVAL(pdata,10,0); /* Padding. */
+               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;
@@ -5346,6 +5508,7 @@ static NTSTATUS smb_posix_mkdir(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_posix_open(connection_struct *conn,
+                              struct smb_request *req,
                                char **ppdata,
                                int total_data,
                                const char *fname,
@@ -5381,7 +5544,7 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
        wire_open_mode = IVAL(pdata,4);
 
        if (wire_open_mode == (SMB_O_CREAT|SMB_O_DIRECTORY)) {
-               return smb_posix_mkdir(conn,
+               return smb_posix_mkdir(conn, req,
                                        ppdata,
                                        total_data,
                                        fname,
@@ -5449,7 +5612,7 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
                (unsigned int)wire_open_mode,
                (unsigned int)unixmode ));
 
-       status = open_file_ntcreate(conn,
+       status = open_file_ntcreate(conn, req,
                                fname,
                                psbuf,
                                access_mask,
@@ -5492,6 +5655,7 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
                *pdata_return_size = 0;
                return NT_STATUS_NO_MEMORY;
        }
+       pdata = *ppdata;
 
        if (extended_oplock_granted) {
                if (flags & REQUEST_BATCH_OPLOCK) {
@@ -5509,17 +5673,20 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
        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);
-       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);
-       default:
-               SSVAL(pdata,8,SMB_NO_INFO_LEVEL_RETURNED);
-               SSVAL(pdata,10,0); /* padding. */
+               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;
 }
@@ -5529,6 +5696,7 @@ static NTSTATUS smb_posix_open(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS smb_posix_unlink(connection_struct *conn,
+                                struct smb_request *req,
                                const char *pdata,
                                int total_data,
                                const char *fname,
@@ -5559,7 +5727,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
                fname));
 
        if (VALID_STAT_OF_DIR(*psbuf)) {
-               status = open_directory(conn,
+               status = open_directory(conn, req,
                                        fname,
                                        psbuf,
                                        DELETE_ACCESS,
@@ -5572,7 +5740,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
        } else {
                char del = 1;
 
-               status = open_file_ntcreate(conn,
+               status = open_file_ntcreate(conn, req,
                                fname,
                                psbuf,
                                DELETE_ACCESS,
@@ -5610,7 +5778,10 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
  Reply to a TRANS2_SETFILEINFO (set file info by fileid or pathname).
 ****************************************************************************/
 
-static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
+static int call_trans2setfilepathinfo(connection_struct *conn,
+                                     struct smb_request *req,
+                                     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)
@@ -5645,9 +5816,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) {
                        /*
@@ -5659,7 +5838,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));
@@ -5683,7 +5862,9 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                }
 
                info_level = SVAL(params,0);    
-               srvstr_get_path(inbuf, fname, &params[6], sizeof(fname), total_params - 6, STR_TERMINATE, &status);
+               srvstr_get_path(inbuf, SVAL(inbuf,smb_flg2), fname, &params[6],
+                               sizeof(fname), total_params - 6, STR_TERMINATE,
+                               &status);
                if (!NT_STATUS_IS_OK(status)) {
                        return ERROR_NT(status);
                }
@@ -5706,14 +5887,18 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                        return ERROR_NT(status);
                }
 
-               /*
-                * For CIFS UNIX extensions the target name may not exist.
-                */
+               if (INFO_LEVEL_IS_UNIX(info_level)) {
+                       /*
+                        * 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)));
+                       /* 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)) {
@@ -5779,7 +5964,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                case SMB_FILE_ALLOCATION_INFORMATION:
                case SMB_SET_FILE_ALLOCATION_INFO:
                {
-                       status = smb_set_file_allocation_info(conn,
+                       status = smb_set_file_allocation_info(conn, req,
                                                                pdata,
                                                                total_data,
                                                                fsp,
@@ -5791,7 +5976,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                case SMB_FILE_END_OF_FILE_INFORMATION:
                case SMB_SET_FILE_END_OF_FILE_INFO:
                {
-                       status = smb_set_file_end_of_file_info(conn,
+                       status = smb_set_file_end_of_file_info(conn, req,
                                                                pdata,
                                                                total_data,
                                                                fsp,
@@ -5850,7 +6035,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
 
                case SMB_SET_FILE_UNIX_BASIC:
                {
-                       status = smb_set_file_unix_basic(conn,
+                       status = smb_set_file_unix_basic(conn, req,
                                                        pdata,
                                                        total_data,
                                                        fsp,
@@ -5861,7 +6046,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
 
                case SMB_SET_FILE_UNIX_INFO2:
                {
-                       status = smb_set_file_unix_info2(conn,
+                       status = smb_set_file_unix_info2(conn, req,
                                                        pdata,
                                                        total_data,
                                                        fsp,
@@ -5901,7 +6086,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
 
                case SMB_FILE_RENAME_INFORMATION:
                {
-                       status = smb_file_rename_information(conn,
+                       status = smb_file_rename_information(conn, req,
                                                        inbuf,
                                                        outbuf,
                                                        pdata,
@@ -5945,7 +6130,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                                return ERROR_NT(NT_STATUS_INVALID_LEVEL);
                        }
 
-                       status = smb_posix_open(conn,
+                       status = smb_posix_open(conn, req,
                                                ppdata,
                                                total_data,
                                                fname,
@@ -5961,7 +6146,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                                return ERROR_NT(NT_STATUS_INVALID_LEVEL);
                        }
 
-                       status = smb_posix_unlink(conn,
+                       status = smb_posix_unlink(conn, req,
                                                pdata,
                                                total_data,
                                                fname,
@@ -5990,7 +6175,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
        }
 
        SSVAL(params,0,0);
-       send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, data_return_size, max_data_bytes);
+       send_trans2_replies(inbuf, outbuf, bufsize, params, 2, *ppdata, data_return_size, max_data_bytes);
   
        return -1;
 }
@@ -6017,7 +6202,9 @@ static int call_trans2mkdir(connection_struct *conn, char *inbuf, char *outbuf,
                return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
        }
 
-       srvstr_get_path(inbuf, directory, &params[4], sizeof(directory), total_params - 4, STR_TERMINATE, &status);
+       srvstr_get_path(inbuf, SVAL(inbuf,smb_flg2), directory, &params[4],
+                       sizeof(directory), total_params - 4, STR_TERMINATE,
+                       &status);
        if (!NT_STATUS_IS_OK(status)) {
                return ERROR_NT(status);
        }
@@ -6089,7 +6276,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);
 }
@@ -6138,7 +6325,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);
 }
@@ -6166,7 +6353,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);
 }
@@ -6183,6 +6370,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"));
 
@@ -6195,12 +6383,13 @@ static int call_trans2getdfsreferral(connection_struct *conn, char* inbuf, char*
        if(!lp_host_msdfs())
                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);
+       srvstr_pull(inbuf, SVAL(inbuf, smb_flg2), pathname, &params[2],
+                   sizeof(pathname), total_params - 2, STR_TERMINATE);
+       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);
 }
@@ -6238,7 +6427,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"));
@@ -6261,7 +6450,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));
 
@@ -6288,7 +6477,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));
 
@@ -6296,9 +6485,9 @@ int reply_findnclose(connection_struct *conn,
        return(outsize);
 }
 
-int handle_trans2(connection_struct *conn,
-                 struct trans_state *state,
-                 char *inbuf, char *outbuf, int size, int bufsize)
+static int handle_trans2(connection_struct *conn, struct smb_request *req,
+                        struct trans_state *state,
+                        char *inbuf, char *outbuf, int size, int bufsize)
 {
        int outsize;
 
@@ -6312,7 +6501,7 @@ int handle_trans2(connection_struct *conn,
        {
                START_PROFILE(Trans2_open);
                outsize = call_trans2open(
-                       conn, inbuf, outbuf, bufsize, 
+                       conn, req, inbuf, outbuf, bufsize,
                        &state->param, state->total_param,
                        &state->data, state->total_data,
                        state->max_data_return);
@@ -6386,7 +6575,7 @@ int handle_trans2(connection_struct *conn,
        {
                START_PROFILE(Trans2_setpathinfo);
                outsize = call_trans2setfilepathinfo(
-                       conn, inbuf, outbuf, size, bufsize, state->call,
+                       conn, req, inbuf, outbuf, size, bufsize, state->call,
                        &state->param, state->total_param,
                        &state->data, state->total_data,
                        state->max_data_return);
@@ -6490,7 +6679,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);
        }
@@ -6593,7 +6783,10 @@ int reply_trans2(connection_struct *conn, char *inbuf,char *outbuf,
        if ((state->received_param == state->total_param) &&
            (state->received_data == state->total_data)) {
 
-               outsize = handle_trans2(conn, state, inbuf, outbuf,
+               struct smb_request req;
+               init_smb_request(&req, (uint8 *)inbuf);
+
+               outsize = handle_trans2(conn, &req, state, inbuf, outbuf,
                                        size, bufsize);
                SAFE_FREE(state->data);
                SAFE_FREE(state->param);
@@ -6606,7 +6799,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;
@@ -6632,6 +6825,7 @@ int reply_transs2(connection_struct *conn,
        int outsize = 0;
        unsigned int pcnt,poff,dcnt,doff,pdisp,ddisp;
        struct trans_state *state;
+       struct smb_request req;
 
        START_PROFILE(SMBtranss2);
 
@@ -6717,7 +6911,10 @@ int reply_transs2(connection_struct *conn,
         */
        SCVAL(outbuf,smb_com,SMBtrans2);
 
-       outsize = handle_trans2(conn, state, inbuf, outbuf, size, bufsize);
+       init_smb_request(&req, (uint8 *)inbuf);
+
+       outsize = handle_trans2(conn, &req, state, inbuf, outbuf, size,
+                               bufsize);
 
        DLIST_REMOVE(conn->pending_trans, state);
        SAFE_FREE(state->data);