r12311: Reformatting
[kai/samba.git] / source3 / smbd / trans2.c
index e53b47c1f4c799ae125af13e0b4ae1f2c2e5309b..6a4b7111cdb5a5aeba727573f5af7dd222f0276d 100644 (file)
@@ -3,6 +3,8 @@
    SMB transaction2 handling
    Copyright (C) Jeremy Allison                        1994-2003
    Copyright (C) Stefan (metze) Metzmacher     2003
+   Copyright (C) Volker Lendecke               2005
+   Copyright (C) Steve French                  2005
 
    Extensively modified by Andrew Tridgell, 1995
 
@@ -23,9 +25,9 @@
 
 #include "includes.h"
 
+extern int max_send;
 extern enum protocol_types Protocol;
 extern int smb_read_error;
-extern int global_oplock_break;
 extern uint32 global_client_caps;
 extern struct current_user current_user;
 
@@ -58,14 +60,18 @@ SMB_BIG_UINT get_allocation_size(connection_struct *conn, files_struct *fsp, SMB
 {
        SMB_BIG_UINT ret;
 
+       if(S_ISDIR(sbuf->st_mode)) {
+               return 0;
+       }
+
 #if defined(HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
        ret = (SMB_BIG_UINT)STAT_ST_BLOCKSIZE * (SMB_BIG_UINT)sbuf->st_blocks;
 #else
        ret = (SMB_BIG_UINT)get_file_size(*sbuf);
 #endif
 
-       if (!ret && fsp && fsp->initial_allocation_size)
-               ret = fsp->initial_allocation_size;
+       if (fsp && fsp->initial_allocation_size)
+               ret = MAX(ret,fsp->initial_allocation_size);
 
        return smb_roundup(conn, ret);
 }
@@ -114,8 +120,8 @@ static BOOL get_ea_value(TALLOC_CTX *mem_ctx, connection_struct *conn, files_str
                return False;
        }
 
-       if (fsp && fsp->fd != -1) {
-               sizeret = SMB_VFS_FGETXATTR(fsp, fsp->fd, ea_name, val, attr_size);
+       if (fsp && fsp->fh->fd != -1) {
+               sizeret = SMB_VFS_FGETXATTR(fsp, fsp->fh->fd, ea_name, val, attr_size);
        } else {
                sizeret = SMB_VFS_GETXATTR(conn, fname, ea_name, val, attr_size);
        }
@@ -129,7 +135,7 @@ static BOOL get_ea_value(TALLOC_CTX *mem_ctx, connection_struct *conn, files_str
                return False;
        }
 
-       DEBUG(10,("get_ea_value: EA %s is of length %d: ", ea_name, sizeret));
+       DEBUG(10,("get_ea_value: EA %s is of length %u: ", ea_name, (unsigned int)sizeret));
        dump_data(10, val, sizeret);
 
        pea->flags = 0;
@@ -166,8 +172,8 @@ static struct ea_list *get_ea_list_from_file(TALLOC_CTX *mem_ctx, connection_str
 
        for (i = 0, ea_namelist = TALLOC(mem_ctx, ea_namelist_size); i < 6;
                        ea_namelist = TALLOC_REALLOC_ARRAY(mem_ctx, ea_namelist, char, ea_namelist_size), i++) {
-               if (fsp && fsp->fd != -1) {
-                       sizeret = SMB_VFS_FLISTXATTR(fsp, fsp->fd, ea_namelist, ea_namelist_size);
+               if (fsp && fsp->fh->fd != -1) {
+                       sizeret = SMB_VFS_FLISTXATTR(fsp, fsp->fh->fd, ea_namelist, ea_namelist_size);
                } else {
                        sizeret = SMB_VFS_LISTXATTR(conn, fname, ea_namelist, ea_namelist_size);
                }
@@ -182,7 +188,7 @@ static struct ea_list *get_ea_list_from_file(TALLOC_CTX *mem_ctx, connection_str
        if (sizeret == -1)
                return NULL;
 
-       DEBUG(10,("get_ea_list_from_file: ea_namelist size = %d\n", sizeret ));
+       DEBUG(10,("get_ea_list_from_file: ea_namelist size = %u\n", (unsigned int)sizeret ));
 
        if (sizeret) {
                for (p = ea_namelist; p - ea_namelist < sizeret; p += strlen(p) + 1) {
@@ -204,7 +210,7 @@ static struct ea_list *get_ea_list_from_file(TALLOC_CTX *mem_ctx, connection_str
                                push_ascii_fstring(dos_ea_name, listp->ea.name);
                                *pea_total_len += 4 + strlen(dos_ea_name) + 1 + listp->ea.value.length;
                                DEBUG(10,("get_ea_list_from_file: total_len = %u, %s, val len = %u\n",
-                                       *pea_total_len, dos_ea_name,
+                                       (unsigned int)*pea_total_len, dos_ea_name,
                                        (unsigned int)listp->ea.value.length ));
                        }
                        DLIST_ADD_END(ea_list_head, listp, tmp);
@@ -215,7 +221,7 @@ static struct ea_list *get_ea_list_from_file(TALLOC_CTX *mem_ctx, connection_str
                }
        }
 
-       DEBUG(10,("get_ea_list_from_file: total_len = %u\n", *pea_total_len));
+       DEBUG(10,("get_ea_list_from_file: total_len = %u\n", (unsigned int)*pea_total_len));
        return ea_list_head;
 }
 
@@ -323,7 +329,7 @@ NTSTATUS set_ea(connection_struct *conn, files_struct *fsp, const char *fname, s
 
                canonicalize_ea_name(conn, fsp, fname, unix_ea_name);
 
-               DEBUG(10,("set_ea: ea_name %s ealen = %u\n", unix_ea_name, ea_list->ea.value.length));
+               DEBUG(10,("set_ea: ea_name %s ealen = %u\n", unix_ea_name, (unsigned int)ea_list->ea.value.length));
 
                if (samba_private_attr_name(unix_ea_name)) {
                        DEBUG(10,("set_ea: ea name %s is a private Samba name.\n", unix_ea_name));
@@ -332,10 +338,10 @@ NTSTATUS set_ea(connection_struct *conn, files_struct *fsp, const char *fname, s
 
                if (ea_list->ea.value.length == 0) {
                        /* Remove the attribute. */
-                       if (fsp && (fsp->fd != -1)) {
+                       if (fsp && (fsp->fh->fd != -1)) {
                                DEBUG(10,("set_ea: deleting ea name %s on file %s by file descriptor.\n",
                                        unix_ea_name, fsp->fsp_name));
-                               ret = SMB_VFS_FREMOVEXATTR(fsp, fsp->fd, unix_ea_name);
+                               ret = SMB_VFS_FREMOVEXATTR(fsp, fsp->fh->fd, unix_ea_name);
                        } else {
                                DEBUG(10,("set_ea: deleting ea name %s on file %s.\n",
                                        unix_ea_name, fname));
@@ -350,10 +356,10 @@ NTSTATUS set_ea(connection_struct *conn, files_struct *fsp, const char *fname, s
                        }
 #endif
                } else {
-                       if (fsp && (fsp->fd != -1)) {
+                       if (fsp && (fsp->fh->fd != -1)) {
                                DEBUG(10,("set_ea: setting ea name %s on file %s by file descriptor.\n",
                                        unix_ea_name, fsp->fsp_name));
-                               ret = SMB_VFS_FSETXATTR(fsp, fsp->fd, unix_ea_name,
+                               ret = SMB_VFS_FSETXATTR(fsp, fsp->fh->fd, unix_ea_name,
                                                        ea_list->ea.value.data, ea_list->ea.value.length, 0);
                        } else {
                                DEBUG(10,("set_ea: setting ea name %s on file %s.\n",
@@ -466,7 +472,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, eal->ea.value.data, eal->ea.value.length);
+       dump_data(10, (const char *)eal->ea.value.data, eal->ea.value.length);
 
        return eal;
 }
@@ -570,7 +576,6 @@ static int send_trans2_replies(char *outbuf,
         global struct. These different max_xmit variables should
         be merged as this is now too confusing */
 
-       extern int max_send;
        int data_to_send = datasize;
        int params_to_send = paramsize;
        int useable_space;
@@ -587,6 +592,7 @@ static int send_trans2_replies(char *outbuf,
        /* If there genuinely are no parameters or data to send just send the empty packet */
 
        if(params_to_send == 0 && data_to_send == 0) {
+               show_msg(outbuf);
                if (!send_smb(smbd_server_fd(),outbuf))
                        exit_server("send_trans2_replies: send_smb failed.");
                return 0;
@@ -681,6 +687,7 @@ static int send_trans2_replies(char *outbuf,
                        params_to_send, data_to_send, paramsize, datasize));
 
                /* Send the packet */
+               show_msg(outbuf);
                if (!send_smb(smbd_server_fd(),outbuf))
                        exit_server("send_trans2_replies: send_smb failed.");
 
@@ -711,20 +718,20 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
 {
        char *params = *pparams;
        char *pdata = *ppdata;
-       int16 open_mode;
-       int16 open_attr;
+       int deny_mode;
+       int32 open_attr;
        BOOL oplock_request;
 #if 0
        BOOL return_additional_info;
        int16 open_sattr;
        time_t open_time;
 #endif
-       int16 open_ofun;
+       int open_ofun;
        int32 open_size;
        char *pname;
        pstring fname;
        SMB_OFF_T size=0;
-       int fmode=0,mtime=0,rmode;
+       int fattr=0,mtime=0;
        SMB_INO_T inode = 0;
        SMB_STRUCT_STAT sbuf;
        int smb_action = 0;
@@ -732,7 +739,12 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
        files_struct *fsp;
        TALLOC_CTX *ctx = NULL;
        struct ea_list *ea_list = NULL;
+       uint16 flags = 0;
        NTSTATUS status;
+       uint32 access_mask;
+       uint32 share_mode;
+       uint32 create_disposition;
+       uint32 create_options = 0;
 
        /*
         * Ensure we have enough parameters to perform the operation.
@@ -742,11 +754,12 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
                return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
        }
 
-       open_mode = SVAL(params, 2);
+       flags = SVAL(params, 0);
+       deny_mode = SVAL(params, 2);
        open_attr = SVAL(params,6);
-        oplock_request = (SVAL(params,0) & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
+        oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
         if (oplock_request) {
-                oplock_request |= (SVAL(params,0) & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
+                oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
         }
 
 #if 0
@@ -758,16 +771,18 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
        open_size = IVAL(params,14);
        pname = &params[28];
 
-       if (IS_IPC(conn))
+       if (IS_IPC(conn)) {
                return(ERROR_DOS(ERRSRV,ERRaccess));
+       }
 
-       srvstr_get_path(inbuf, fname, pname, sizeof(fname), -1, STR_TERMINATE, &status, False);
+       srvstr_get_path(inbuf, fname, pname, sizeof(fname), -1, STR_TERMINATE, &status);
        if (!NT_STATUS_IS_OK(status)) {
                return ERROR_NT(status);
        }
 
-       DEBUG(3,("call_trans2open %s mode=%d attr=%d ofun=%d size=%d\n",
-               fname,open_mode, open_attr, open_ofun, open_size));
+       DEBUG(3,("call_trans2open %s deny_mode=0x%x attr=%d ofun=0x%x size=%d\n",
+               fname, (unsigned int)deny_mode, (unsigned int)open_attr,
+               (unsigned int)open_ofun, open_size));
 
        /* XXXX we need to handle passed times, sattr and flags */
 
@@ -780,12 +795,20 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
                return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
        }
 
+       if (!map_open_params_to_ntcreate(fname, deny_mode, open_ofun,
+                               &access_mask,
+                               &share_mode,
+                               &create_disposition,
+                               &create_options)) {
+               return ERROR_DOS(ERRDOS, ERRbadaccess);
+       }
+
        /* Any data in this call is an EA list. */
-       if (total_data && !lp_ea_support(SNUM(conn))) {
+       if (total_data && (total_data != 4) && !lp_ea_support(SNUM(conn))) {
                return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
        }
 
-       if (total_data) {
+       if (total_data != 4) {
                if (total_data < 10) {
                        return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                }
@@ -805,26 +828,33 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
                        talloc_destroy(ctx);
                        return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                }
+       } else if (IVAL(pdata,0) != 4) {
+               return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
        }
 
-       fsp = open_file_shared(conn,fname,&sbuf,open_mode,open_ofun,(uint32)open_attr,
-               oplock_request, &rmode,&smb_action);
+       fsp = open_file_ntcreate(conn,fname,&sbuf,
+               access_mask,
+               share_mode,
+               create_disposition,
+               create_options,
+               open_attr,
+               oplock_request,
+               &smb_action);
       
        if (!fsp) {
                talloc_destroy(ctx);
                if (open_was_deferred(SVAL(inbuf,smb_mid))) {
                        /* We have re-scheduled this call. */
-                       clear_cached_errors();
                        return -1;
                }
                return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
        }
 
        size = get_file_size(sbuf);
-       fmode = dos_mode(conn,fname,&sbuf);
+       fattr = dos_mode(conn,fname,&sbuf);
        mtime = sbuf.st_mtime;
        inode = sbuf.st_ino;
-       if (fmode & aDIR) {
+       if (fattr & aDIR) {
                talloc_destroy(ctx);
                close_file(fsp,False);
                return(ERROR_DOS(ERRDOS,ERRnoaccess));
@@ -840,21 +870,23 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
        }
 
        /* Realloc the size of parameters and data we will return */
-       params = SMB_REALLOC(*pparams, 28);
+       params = SMB_REALLOC(*pparams, 30);
        if( params == NULL ) {
                return ERROR_NT(NT_STATUS_NO_MEMORY);
        }
        *pparams = params;
 
-       memset((char *)params,'\0',28);
        SSVAL(params,0,fsp->fnum);
-       SSVAL(params,2,fmode);
-       put_dos_date2(params,4, mtime);
+       SSVAL(params,2,open_attr);
+       srv_put_dos_date2(params,4, mtime);
        SIVAL(params,8, (uint32)size);
-       SSVAL(params,12,rmode);
+       SSVAL(params,12,deny_mode);
+       SSVAL(params,14,0); /* open_type - file or directory. */
+       SSVAL(params,16,0); /* open_state - only valid for IPC device. */
 
-       if (oplock_request && lp_fake_oplocks(SNUM(conn)))
+       if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
                smb_action |= EXTENDED_OPLOCK_GRANTED;
+       }
 
        SSVAL(params,18,smb_action);
 
@@ -862,9 +894,16 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
         * WARNING - this may need to be changed if SMB_INO_T <> 4 bytes.
         */
        SIVAL(params,20,inode);
+       SSVAL(params,24,0); /* Padding. */
+       if (flags & 8) {
+               uint32 ea_size = estimate_ea_size(conn, fsp, fname);
+               SIVAL(params, 26, ea_size);
+       } else {
+               SIVAL(params, 26, 0);
+       }
+
        /* Send the required number of replies */
-       send_trans2_replies(outbuf, bufsize, params, 28, *ppdata, 0);
+       send_trans2_replies(outbuf, bufsize, params, 30, *ppdata, 0);
 
        return -1;
 }
@@ -976,7 +1015,7 @@ static mode_t unix_perms_from_wire( connection_struct *conn, SMB_STRUCT_STAT *ps
 
 static BOOL get_lanman2_dir_entry(connection_struct *conn,
                                  void *inbuf, void *outbuf,
-                                char *path_mask,int dirtype,int info_level,
+                                char *path_mask,uint32 dirtype,int info_level,
                                 int requires_resume_key,
                                 BOOL dont_descend,char **ppdata, 
                                 char *base_data, int space_remaining, 
@@ -992,7 +1031,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
        char *p, *q, *pdata = *ppdata;
        uint32 reskey=0;
        long prev_dirpos=0;
-       int mode=0;
+       uint32 mode=0;
        SMB_OFF_T file_size = 0;
        SMB_BIG_UINT allocation_size = 0;
        uint32 len;
@@ -1000,8 +1039,9 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
        char *nameptr;
        char *last_entry_ptr;
        BOOL was_8_3;
-       int nt_extmode; /* Used for NT connections instead of mode */
+       uint32 nt_extmode; /* Used for NT connections instead of mode */
        BOOL needslash = ( conn->dirpath[strlen(conn->dirpath) -1] != '/');
+       BOOL check_mangled_names = lp_manglednames(SNUM(conn));
 
        *fname = 0;
        *out_of_space = False;
@@ -1046,7 +1086,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                if(!(got_match = *got_exact_match = exact_match(fname, mask, conn->case_sensitive)))
                        got_match = mask_match(fname, mask, conn->case_sensitive);
 
-               if(!got_match && !mangle_is_8_3(fname, False)) {
+               if(!got_match && check_mangled_names && !mangle_is_8_3(fname, False, SNUM(conn))) {
 
                        /*
                         * It turns out that NT matches wildcards against
@@ -1085,7 +1125,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
 
                                if(lp_host_msdfs() && 
                                   lp_msdfs_root(SNUM(conn)) &&
-                                  is_msdfs_link(conn, pathreal, NULL, NULL,
+                                  is_msdfs_link(NULL,conn, pathreal, NULL, NULL,
                                                 &sbuf)) {
 
                                        DEBUG(5,("get_lanman2_dir_entry: Masquerading msdfs link %s as a directory\n", pathreal));
@@ -1146,13 +1186,13 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                                SIVAL(p,0,reskey);
                                p += 4;
                        }
-                       put_dos_date2(p,l1_fdateCreation,cdate);
-                       put_dos_date2(p,l1_fdateLastAccess,adate);
-                       put_dos_date2(p,l1_fdateLastWrite,mdate);
-                       SIVAL(p,l1_cbFile,(uint32)file_size);
-                       SIVAL(p,l1_cbFileAlloc,(uint32)allocation_size);
-                       SSVAL(p,l1_attrFile,mode);
-                       p += l1_achName;
+                       srv_put_dos_date2(p,0,cdate);
+                       srv_put_dos_date2(p,4,adate);
+                       srv_put_dos_date2(p,8,mdate);
+                       SIVAL(p,12,(uint32)file_size);
+                       SIVAL(p,16,(uint32)allocation_size);
+                       SSVAL(p,20,mode);
+                       p += 23;
                        nameptr = p;
                        p += align_string(outbuf, p, 0);
                        len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE);
@@ -1178,17 +1218,17 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                                SIVAL(p,0,reskey);
                                p += 4;
                        }
-                       put_dos_date2(p,l2_fdateCreation,cdate);
-                       put_dos_date2(p,l2_fdateLastAccess,adate);
-                       put_dos_date2(p,l2_fdateLastWrite,mdate);
-                       SIVAL(p,l2_cbFile,(uint32)file_size);
-                       SIVAL(p,l2_cbFileAlloc,(uint32)allocation_size);
-                       SSVAL(p,l2_attrFile,mode);
+                       srv_put_dos_date2(p,0,cdate);
+                       srv_put_dos_date2(p,4,adate);
+                       srv_put_dos_date2(p,8,mdate);
+                       SIVAL(p,12,(uint32)file_size);
+                       SIVAL(p,16,(uint32)allocation_size);
+                       SSVAL(p,20,mode);
                        {
                                unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
-                               SIVAL(p,l2_cbList,ea_size); /* Extended attributes */
+                               SIVAL(p,22,ea_size); /* Extended attributes */
                        }
-                       p += l2_achName;
+                       p += 27;
                        nameptr = p - 1;
                        len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE | STR_NOALIGN);
                        if (SVAL(outbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS) {
@@ -1222,13 +1262,13 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                                SIVAL(p,0,reskey);
                                p += 4;
                        }
-                       put_dos_date2(p,l2_fdateCreation,cdate);
-                       put_dos_date2(p,l2_fdateLastAccess,adate);
-                       put_dos_date2(p,l2_fdateLastWrite,mdate);
-                       SIVAL(p,l2_cbFile,(uint32)file_size);
-                       SIVAL(p,l2_cbFileAlloc,(uint32)allocation_size);
-                       SSVAL(p,l2_attrFile,mode);
-                       p += l2_cbList; /* p now points to the EA area. */
+                       srv_put_dos_date2(p,0,cdate);
+                       srv_put_dos_date2(p,4,adate);
+                       srv_put_dos_date2(p,8,mdate);
+                       SIVAL(p,12,(uint32)file_size);
+                       SIVAL(p,16,(uint32)allocation_size);
+                       SSVAL(p,20,mode);
+                       p += 22; /* p now points to the EA area. */
 
                        file_list = get_ea_list_from_file(ea_ctx, conn, NULL, pathreal, &ea_len);
                        name_list = ea_list_union(name_list, file_list, &ea_len);
@@ -1268,7 +1308,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
 
                case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
                        DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_BOTH_DIRECTORY_INFO\n"));
-                       was_8_3 = mangle_is_8_3(fname, True);
+                       was_8_3 = mangle_is_8_3(fname, True, SNUM(conn));
                        p += 4;
                        SIVAL(p,0,reskey); p += 4;
                        put_long_date(p,cdate); p += 8;
@@ -1288,22 +1328,24 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                         * IMPORTANT as not doing so will trigger
                         * a Win2k client bug. JRA.
                         */
-                       memset(p,'\0',26);
-                       if (!was_8_3 && lp_manglednames(SNUM(conn))) {
+                       if (!was_8_3 && check_mangled_names) {
                                pstring mangled_name;
                                pstrcpy(mangled_name, fname);
                                mangle_map(mangled_name,True,True,SNUM(conn));
                                mangled_name[12] = 0;
                                len = srvstr_push(outbuf, p+2, mangled_name, 24, STR_UPPER|STR_UNICODE);
+                               if (len < 24) {
+                                       memset(p + 2 + len,'\0',24 - len);
+                               }
                                SSVAL(p, 0, len);
                        } else {
-                               SSVAL(p,0,0);
-                               *(p+2) = 0;
+                               memset(p,'\0',26);
                        }
                        p += 2 + 24;
                        len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII);
                        SIVAL(q,0,len);
                        p += len;
+                       SIVAL(p,0,0); /* Ensure any padding is null. */
                        len = PTR_DIFF(p, pdata);
                        len = (len + 3) & ~3;
                        SIVAL(pdata,0,len);
@@ -1324,6 +1366,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                        len = srvstr_push(outbuf, p + 4, fname, -1, STR_TERMINATE_ASCII);
                        SIVAL(p,0,len);
                        p += 4 + len;
+                       SIVAL(p,0,0); /* Ensure any padding is null. */
                        len = PTR_DIFF(p, pdata);
                        len = (len + 3) & ~3;
                        SIVAL(pdata,0,len);
@@ -1351,6 +1394,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                        SIVAL(q, 0, len);
                        p += len;
 
+                       SIVAL(p,0,0); /* Ensure any padding is null. */
                        len = PTR_DIFF(p, pdata);
                        len = (len + 3) & ~3;
                        SIVAL(pdata,0,len);
@@ -1367,6 +1411,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                        len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII);
                        SIVAL(p, -4, len);
                        p += len;
+                       SIVAL(p,0,0); /* Ensure any padding is null. */
                        len = PTR_DIFF(p, pdata);
                        len = (len + 3) & ~3;
                        SIVAL(pdata,0,len);
@@ -1391,11 +1436,12 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                                p +=4;
                        }
                        SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */
-                       SIVAL(p,0,sbuf.st_dev); p += 4;
-                       SIVAL(p,0,sbuf.st_ino); p += 4;
+                       SIVAL(p,0,sbuf.st_ino); p += 4; /* FileIndexLow */
+                       SIVAL(p,0,sbuf.st_dev); p += 4; /* FileIndexHigh */
                        len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII);
                        SIVAL(q, 0, len);
                        p += len; 
+                       SIVAL(p,0,0); /* Ensure any padding is null. */
                        len = PTR_DIFF(p, pdata);
                        len = (len + 3) & ~3;
                        SIVAL(pdata,0,len);
@@ -1404,7 +1450,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
 
                case SMB_FIND_ID_BOTH_DIRECTORY_INFO:
                        DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_ID_BOTH_DIRECTORY_INFO\n"));
-                       was_8_3 = mangle_is_8_3(fname, True);
+                       was_8_3 = mangle_is_8_3(fname, True, SNUM(conn));
                        p += 4;
                        SIVAL(p,0,reskey); p += 4;
                        put_long_date(p,cdate); p += 8;
@@ -1424,25 +1470,28 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                         * IMPORTANT as not doing so will trigger
                         * a Win2k client bug. JRA.
                         */
-                       memset(p,'\0',26);
-                       if (!was_8_3 && lp_manglednames(SNUM(conn))) {
+                       if (!was_8_3 && check_mangled_names) {
                                pstring mangled_name;
                                pstrcpy(mangled_name, fname);
                                mangle_map(mangled_name,True,True,SNUM(conn));
                                mangled_name[12] = 0;
                                len = srvstr_push(outbuf, p+2, mangled_name, 24, STR_UPPER|STR_UNICODE);
                                SSVAL(p, 0, len);
+                               if (len < 24) {
+                                       memset(p + 2 + len,'\0',24 - len);
+                               }
+                               SSVAL(p, 0, len);
                        } else {
-                               SSVAL(p,0,0);
-                               *(p+2) = 0;
+                               memset(p,'\0',26);
                        }
                        p += 26;
                        SSVAL(p,0,0); p += 2; /* Reserved ? */
-                       SIVAL(p,0,sbuf.st_dev); p += 4;
-                       SIVAL(p,0,sbuf.st_ino); p += 4;
+                       SIVAL(p,0,sbuf.st_ino); p += 4; /* FileIndexLow */
+                       SIVAL(p,0,sbuf.st_dev); p += 4; /* FileIndexHigh */
                        len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII);
                        SIVAL(q,0,len);
                        p += len;
+                       SIVAL(p,0,0); /* Ensure any padding is null. */
                        len = PTR_DIFF(p, pdata);
                        len = (len + 3) & ~3;
                        SIVAL(pdata,0,len);
@@ -1500,6 +1549,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
 
                        len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE);
                        p += len;
+                       SIVAL(p,0,0); /* Ensure any padding is null. */
 
                        len = PTR_DIFF(p, pdata);
                        len = (len + 3) & ~3;
@@ -1545,7 +1595,7 @@ static int call_trans2findfirst(connection_struct *conn, char *inbuf, char *outb
                requested. */
        char *params = *pparams;
        char *pdata = *ppdata;
-       int dirtype = SVAL(params,0);
+       uint32 dirtype = SVAL(params,0);
        int maxentries = SVAL(params,2);
        uint16 findfirst_flags = SVAL(params,4);
        BOOL close_after_first = (findfirst_flags & FLAG_TRANS2_FIND_CLOSE);
@@ -1564,6 +1614,7 @@ static int call_trans2findfirst(connection_struct *conn, char *inbuf, char *outb
        BOOL out_of_space = False;
        int space_remaining;
        BOOL bad_path = False;
+       BOOL mask_contains_wcard = False;
        SMB_STRUCT_STAT sbuf;
        TALLOC_CTX *ea_ctx = NULL;
        struct ea_list *ea_list = NULL;
@@ -1575,9 +1626,9 @@ static int call_trans2findfirst(connection_struct *conn, char *inbuf, char *outb
 
        *directory = *mask = 0;
 
-       DEBUG(3,("call_trans2findfirst: dirtype = %d, maxentries = %d, close_after_first=%d, \
+       DEBUG(3,("call_trans2findfirst: dirtype = %x, maxentries = %d, close_after_first=%d, \
 close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
-               dirtype, maxentries, close_after_first, close_if_end, requires_resume_key,
+               (unsigned int)dirtype, maxentries, close_after_first, close_if_end, requires_resume_key,
                info_level, max_data_bytes));
 
        if (!maxentries) {
@@ -1604,7 +1655,7 @@ close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
                        return(ERROR_DOS(ERRDOS,ERRunknownlevel));
        }
 
-       srvstr_get_path(inbuf, directory, params+12, sizeof(directory), -1, STR_TERMINATE, &ntstatus, True);
+       srvstr_get_path_wcard(inbuf, directory, params+12, sizeof(directory), -1, STR_TERMINATE, &ntstatus, &mask_contains_wcard);
        if (!NT_STATUS_IS_OK(ntstatus)) {
                return ERROR_NT(ntstatus);
        }
@@ -1622,10 +1673,12 @@ close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
        p = strrchr_m(directory,'/');
        if(p == NULL) {
                /* Windows and OS/2 systems treat search on the root '\' as if it were '\*' */
-               if((directory[0] == '.') && (directory[1] == '\0'))
+               if((directory[0] == '.') && (directory[1] == '\0')) {
                        pstrcpy(mask,"*");
-               else
+                       mask_contains_wcard = True;
+               } else {
                        pstrcpy(mask,directory);
+               }
                pstrcpy(directory,"./");
        } else {
                pstrcpy(mask,p+1);
@@ -1671,7 +1724,6 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        }
 
        *ppdata = pdata;
-       memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
 
        /* Realloc the params space */
        params = SMB_REALLOC(*pparams, 10);
@@ -1681,19 +1733,13 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        }
        *pparams = params;
 
-       dptr_num = dptr_create(conn,directory, False, True ,SVAL(inbuf,smb_pid));
-       if (dptr_num < 0) {
-               talloc_destroy(ea_ctx);
-               return(UNIXERROR(ERRDOS,ERRbadfile));
-       }
-
        /* Save the wildcard match and attribs we are using on this directory - 
                needed as lanman2 assumes these are being saved between calls */
 
-       if (!dptr_set_wcard_and_attributes(dptr_num, mask, dirtype)) {
-               dptr_close(&dptr_num);
+       dptr_num = dptr_create(conn,directory, False, True ,SVAL(inbuf,smb_pid), mask, mask_contains_wcard, dirtype);
+       if (dptr_num < 0) {
                talloc_destroy(ea_ctx);
-               return ERROR_NT(NT_STATUS_NO_MEMORY);
+               return(UNIXERROR(ERRDOS,ERRbadfile));
        }
 
        DEBUG(4,("dptr_num is %d, wcard = %s, attr = %d\n",dptr_num, mask, dirtype));
@@ -1795,7 +1841,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
         * (see PR#13758). JRA.
         */
 
-       if(!mangle_is_8_3_wildcards( mask, False))
+       if(!mangle_is_8_3_wildcards( mask, False, SNUM(conn)))
                mangle_map(mask, True, True, SNUM(conn));
 
        return(-1);
@@ -1825,6 +1871,7 @@ static int call_trans2findnext(connection_struct *conn, char *inbuf, char *outbu
        BOOL close_if_end = (findnext_flags & FLAG_TRANS2_FIND_CLOSE_IF_END);
        BOOL requires_resume_key = (findnext_flags & FLAG_TRANS2_FIND_REQUIRE_RESUME);
        BOOL continue_bit = (findnext_flags & FLAG_TRANS2_FIND_CONTINUE);
+       BOOL mask_contains_wcard = False;
        pstring resume_name;
        pstring mask;
        pstring directory;
@@ -1846,7 +1893,7 @@ static int call_trans2findnext(connection_struct *conn, char *inbuf, char *outbu
 
        *mask = *directory = *resume_name = 0;
 
-       srvstr_get_path(inbuf, resume_name, params+12, sizeof(resume_name), -1, STR_TERMINATE, &ntstatus, True);
+       srvstr_get_path_wcard(inbuf, resume_name, params+12, sizeof(resume_name), -1, 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
@@ -1926,7 +1973,6 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        }
 
        *ppdata = pdata;
-       memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
 
        /* Realloc the params space */
        params = SMB_REALLOC(*pparams, 6*SIZEOFWORD);
@@ -1989,8 +2035,8 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                 * could be mangled. Ensure we check the unmangled name.
                 */
 
-               if (mangle_is_mangled(resume_name)) {
-                       mangle_check_cache(resume_name, sizeof(resume_name)-1);
+               if (mangle_is_mangled(resume_name, SNUM(conn))) {
+                       mangle_check_cache(resume_name, sizeof(resume_name)-1, SNUM(conn));
                }
 
                /*
@@ -2105,7 +2151,7 @@ static int call_trans2qfsinfo(connection_struct *conn, char *inbuf, char *outbuf
                {
                        SMB_BIG_UINT dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
                        data_len = 18;
-                       if (SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
+                       if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
                                return(UNIXERROR(ERRHRD,ERRgeneral));
                        }
 
@@ -2206,7 +2252,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st.st_dev, (unsi
                {
                        SMB_BIG_UINT dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
                        data_len = 24;
-                       if (SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
+                       if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
                                return(UNIXERROR(ERRHRD,ERRgeneral));
                        }
                        block_size = lp_block_size(snum);
@@ -2238,7 +2284,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                {
                        SMB_BIG_UINT dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
                        data_len = 32;
-                       if (SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
+                       if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
                                return(UNIXERROR(ERRHRD,ERRgeneral));
                        }
                        block_size = lp_block_size(snum);
@@ -2307,7 +2353,6 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                        
                        fsp.conn = conn;
                        fsp.fnum = -1;
-                       fsp.fd = -1;
                        
                        /* access check */
                        if (current_user.uid != 0) {
@@ -2361,9 +2406,42 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                        data_len = 12;
                        SSVAL(pdata,0,CIFS_UNIX_MAJOR_VERSION);
                        SSVAL(pdata,2,CIFS_UNIX_MINOR_VERSION);
-                       SBIG_UINT(pdata,4,((SMB_BIG_UINT)CIFS_UNIX_POSIX_ACLS_CAP)); /* We have POSIX ACLs. */
+                       SBIG_UINT(pdata,4,((SMB_BIG_UINT)(CIFS_UNIX_POSIX_ACLS_CAP|
+                                       CIFS_UNIX_POSIX_PATHNAMES_CAP))); /* We have POSIX ACLs and pathname capability. */
                        break;
 
+               case SMB_QUERY_POSIX_FS_INFO:
+               {
+                       int rc;
+                       vfs_statvfs_struct svfs;
+
+                       if (!lp_unix_extensions())
+                               return ERROR_DOS(ERRDOS,ERRunknownlevel);
+                       
+                       rc = SMB_VFS_STATVFS(conn, ".", &svfs);
+
+                       if (!rc) {
+                               data_len = 56;
+                               SIVAL(pdata,0,svfs.OptimalTransferSize);
+                               SIVAL(pdata,4,svfs.BlockSize);
+                               SBIG_UINT(pdata,8,svfs.TotalBlocks);
+                               SBIG_UINT(pdata,16,svfs.BlocksAvail);
+                               SBIG_UINT(pdata,24,svfs.UserBlocksAvail);
+                               SBIG_UINT(pdata,32,svfs.TotalFileNodes);
+                               SBIG_UINT(pdata,40,svfs.FreeFileNodes);
+                               SBIG_UINT(pdata,48,svfs.FsIdentifier);
+                               DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_POSIX_FS_INFO succsessful\n"));
+#ifdef EOPNOTSUPP
+                       } else if (rc == EOPNOTSUPP) {
+                               return ERROR_DOS(ERRDOS, ERRunknownlevel);
+#endif /* EOPNOTSUPP */
+                       } else {
+                               DEBUG(0,("vfs_statvfs() failed for service [%s]\n",lp_servicename(SNUM(conn))));
+                               return ERROR_DOS(ERRSRV,ERRerror);
+                       }
+                       break;
+               }
+
                case SMB_MAC_QUERY_FS_INFO:
                        /*
                         * Thursby MAC extension... ONLY on NTFS filesystems
@@ -2387,7 +2465,6 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
        return -1;
 }
 
-#ifdef HAVE_SYS_QUOTAS
 /****************************************************************************
  Reply to a TRANS2_SETFSINFO (set filesystem info).
 ****************************************************************************/
@@ -2398,21 +2475,10 @@ static int call_trans2setfsinfo(connection_struct *conn, char *inbuf, char *outb
 {
        char *pdata = *ppdata;
        char *params = *pparams;
-       files_struct *fsp = NULL;
        uint16 info_level;
        int outsize;
-       SMB_NTQUOTA_STRUCT quotas;
-       
-       ZERO_STRUCT(quotas);
 
-       DEBUG(10,("call_trans2setfsinfo: SET_FS_QUOTA: for service [%s]\n",lp_servicename(SNUM(conn))));
-
-       /* access check */
-       if ((current_user.uid != 0)||!CAN_WRITE(conn)) {
-               DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
-                       lp_servicename(SNUM(conn)),conn->user));
-               return ERROR_DOS(ERRSRV,ERRaccess);
-       }
+       DEBUG(10,("call_trans2setfsinfo: for service [%s]\n",lp_servicename(SNUM(conn))));
 
        /*  */
        if (total_params < 4) {
@@ -2421,67 +2487,112 @@ static int call_trans2setfsinfo(connection_struct *conn, char *inbuf, char *outb
                return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
        }
 
-       fsp = file_fsp(params,0);
-
-       if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
-               DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
-               return ERROR_NT(NT_STATUS_INVALID_HANDLE);
-       }
-
        info_level = SVAL(params,2);
 
        switch(info_level) {
-               case SMB_FS_QUOTA_INFORMATION:
-                       /* note: normaly there're 48 bytes,
-                        * but we didn't use the last 6 bytes for now 
-                        * --metze 
-                        */
-                       if (total_data < 42) {
-                               DEBUG(0,("call_trans2setfsinfo: SET_FS_QUOTA: requires total_data(%d) >= 42 bytes!\n",
-                                       total_data));
-                               return ERROR_DOS(ERRDOS,ERRunknownlevel);
+               case SMB_SET_CIFS_UNIX_INFO:
+                       {
+                               uint16 client_unix_major;
+                               uint16 client_unix_minor;
+                               uint32 client_unix_cap_low;
+                               uint32 client_unix_cap_high;
+
+                               if (!lp_unix_extensions()) {
+                                       return ERROR_DOS(ERRDOS,ERRunknownlevel);
+                               }
+
+                               /* There should be 12 bytes of capabilities set. */
+                               if (total_data < 8) {
+                                       return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+                               }
+                               client_unix_major = SVAL(pdata,0);
+                               client_unix_minor = SVAL(pdata,2);
+                               client_unix_cap_low = IVAL(pdata,4);
+                               client_unix_cap_high = IVAL(pdata,8);
+                               /* Just print these values for now. */
+                               DEBUG(10,("call_trans2setfsinfo: set unix info. major = %u, minor = %u \
+cap_low = 0x%x, cap_high = 0x%x\n",
+                                       (unsigned int)client_unix_major,
+                                       (unsigned int)client_unix_minor,
+                                       (unsigned int)client_unix_cap_low,
+                                       (unsigned int)client_unix_cap_high ));
+
+                               /* Here is where we must switch to posix pathname processing... */
+                               lp_set_posix_pathnames();
+                               mangle_change_to_posix();
+                               break;
                        }
+               case SMB_FS_QUOTA_INFORMATION:
+                       {
+                               files_struct *fsp = NULL;
+                               SMB_NTQUOTA_STRUCT quotas;
+       
+                               ZERO_STRUCT(quotas);
+
+                               /* access check */
+                               if ((current_user.uid != 0)||!CAN_WRITE(conn)) {
+                                       DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
+                                               lp_servicename(SNUM(conn)),conn->user));
+                                       return ERROR_DOS(ERRSRV,ERRaccess);
+                               }
+
+                               /* note: normaly there're 48 bytes,
+                                * but we didn't use the last 6 bytes for now 
+                                * --metze 
+                                */
+                               fsp = file_fsp(params,0);
+                               if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
+                                       DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
+                                       return ERROR_NT(NT_STATUS_INVALID_HANDLE);
+                               }
+
+                               if (total_data < 42) {
+                                       DEBUG(0,("call_trans2setfsinfo: SET_FS_QUOTA: requires total_data(%d) >= 42 bytes!\n",
+                                               total_data));
+                                       return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+                               }
                        
-                       /* unknown_1 24 NULL bytes in pdata*/
+                               /* unknown_1 24 NULL bytes in pdata*/
                
-                       /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
-                       quotas.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
+                               /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
+                               quotas.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
 #ifdef LARGE_SMB_OFF_T
-                       quotas.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
+                               quotas.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
 #else /* LARGE_SMB_OFF_T */
-                       if ((IVAL(pdata,28) != 0)&&
-                               ((quotas.softlim != 0xFFFFFFFF)||
-                               (IVAL(pdata,28)!=0xFFFFFFFF))) {
-                               /* more than 32 bits? */
-                               return ERROR_DOS(ERRDOS,ERRunknownlevel);
-                       }
+                               if ((IVAL(pdata,28) != 0)&&
+                                       ((quotas.softlim != 0xFFFFFFFF)||
+                                       (IVAL(pdata,28)!=0xFFFFFFFF))) {
+                                       /* more than 32 bits? */
+                                       return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+                               }
 #endif /* LARGE_SMB_OFF_T */
                
-                       /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
-                       quotas.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
+                               /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
+                               quotas.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
 #ifdef LARGE_SMB_OFF_T
-                       quotas.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
+                               quotas.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
 #else /* LARGE_SMB_OFF_T */
-                       if ((IVAL(pdata,36) != 0)&&
-                               ((quotas.hardlim != 0xFFFFFFFF)||
-                               (IVAL(pdata,36)!=0xFFFFFFFF))) {
-                               /* more than 32 bits? */
-                               return ERROR_DOS(ERRDOS,ERRunknownlevel);
-                       }
+                               if ((IVAL(pdata,36) != 0)&&
+                                       ((quotas.hardlim != 0xFFFFFFFF)||
+                                       (IVAL(pdata,36)!=0xFFFFFFFF))) {
+                                       /* more than 32 bits? */
+                                       return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+                               }
 #endif /* LARGE_SMB_OFF_T */
                
-                       /* quota_flags 2 bytes **/
-                       quotas.qflags = SVAL(pdata,40);
+                               /* quota_flags 2 bytes **/
+                               quotas.qflags = SVAL(pdata,40);
                
-                       /* unknown_2 6 NULL bytes follow*/
+                               /* unknown_2 6 NULL bytes follow*/
                
-                       /* now set the quotas */
-                       if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, &quotas)!=0) {
-                               DEBUG(0,("vfs_set_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
-                               return ERROR_DOS(ERRSRV,ERRerror);
-                       }
+                               /* now set the quotas */
+                               if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, &quotas)!=0) {
+                                       DEBUG(0,("vfs_set_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
+                                       return ERROR_DOS(ERRSRV,ERRerror);
+                               }
                        
-                       break;
+                               break;
+                       }
                default:
                        DEBUG(3,("call_trans2setfsinfo: unknown level (0x%X) not implemented yet.\n",
                                info_level));
@@ -2499,7 +2610,6 @@ static int call_trans2setfsinfo(connection_struct *conn, char *inbuf, char *outb
 
        return outsize;
 }
-#endif /* HAVE_SYS_QUOTAS */
 
 /****************************************************************************
  Utility function to set bad path error.
@@ -2643,14 +2753,15 @@ static BOOL marshall_posix_acl(connection_struct *conn, char *pdata, SMB_STRUCT_
 ****************************************************************************/
 
 static int call_trans2qfilepathinfo(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;
-       uint16 tran_call = SVAL(inbuf, smb_setup0);
        uint16 info_level;
        int mode=0;
+       int nlink;
        SMB_OFF_T file_size=0;
        SMB_BIG_UINT allocation_size=0;
        unsigned int data_size = 0;
@@ -2668,7 +2779,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
        files_struct *fsp = NULL;
        TALLOC_CTX *ea_ctx = NULL;
        struct ea_list *ea_list = NULL;
-       uint32 desired_access = 0x12019F; /* Default - GENERIC_EXECUTE mapping from Windows */
+       uint32 access_mask = 0x12019F; /* Default - GENERIC_EXECUTE mapping from Windows */
 
        if (!params)
                return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
@@ -2693,7 +2804,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                        pstrcpy(fname, fsp->fsp_name);
                        /* We know this name is ok, it's already passed the checks. */
                        
-               } else if(fsp && (fsp->is_directory || fsp->fd == -1)) {
+               } else if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
                        /*
                         * This is actually a QFILEINFO on a directory
                         * handle (returned from an NT SMB). NT5.0 seems
@@ -2713,7 +2824,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                                return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
                        }
 
-                       delete_pending = fsp->is_directory ? fsp->directory_delete_on_close : 0;
+                       delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino);
                } else {
                        /*
                         * Original code - this is an open file.
@@ -2721,13 +2832,13 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                        CHECK_FSP(fsp,conn);
 
                        pstrcpy(fname, fsp->fsp_name);
-                       if (SMB_VFS_FSTAT(fsp,fsp->fd,&sbuf) != 0) {
+                       if (SMB_VFS_FSTAT(fsp,fsp->fh->fd,&sbuf) != 0) {
                                DEBUG(3,("fstat of fnum %d failed (%s)\n", fsp->fnum, strerror(errno)));
                                return(UNIXERROR(ERRDOS,ERRbadfid));
                        }
-                       pos = fsp->position_information;
-                       delete_pending = fsp->delete_on_close;
-                       desired_access = fsp->desired_access;
+                       pos = fsp->fh->position_information;
+                       delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino);
+                       access_mask = fsp->access_mask;
                }
        } else {
                NTSTATUS status = NT_STATUS_OK;
@@ -2741,7 +2852,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
 
                DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QPATHINFO: level = %d\n", info_level));
 
-               srvstr_get_path(inbuf, fname, &params[6], sizeof(fname), -1, STR_TERMINATE, &status, False);
+               srvstr_get_path(inbuf, fname, &params[6], sizeof(fname), -1, STR_TERMINATE, &status);
                if (!NT_STATUS_IS_OK(status)) {
                        return ERROR_NT(status);
                }
@@ -2767,6 +2878,22 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                        DEBUG(3,("call_trans2qfilepathinfo: SMB_VFS_STAT of %s failed (%s)\n",fname,strerror(errno)));
                        return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
                }
+
+               delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino);
+               if (delete_pending) {
+                       return ERROR_NT(NT_STATUS_DELETE_PENDING);
+               }
+       }
+
+       nlink = sbuf.st_nlink;
+
+       if ((nlink > 0) && S_ISDIR(sbuf.st_mode)) {
+               /* NTFS does not seem to count ".." */
+               nlink -= 1;
+       }
+
+       if ((nlink > 0) && delete_pending) {
+               nlink -= 1;
        }
 
        if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions())
@@ -2787,7 +2914,6 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
 
        fullpathname = fname;
        file_size = get_file_size(sbuf);
-       allocation_size = get_allocation_size(conn,fsp,&sbuf);
        if (mode & aDIR) {
                /* This is necessary, as otherwise the desktop.ini file in
                 * this folder is ignored */
@@ -2832,7 +2958,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                return ERROR_NT(NT_STATUS_NO_MEMORY);
        }
        *pparams = params;
-       memset((char *)params,'\0',2);
+       SSVAL(params,0,0);
        data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
        pdata = SMB_REALLOC(*ppdata, data_size); 
        if ( pdata == NULL ) {
@@ -2841,10 +2967,10 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        }
        *ppdata = pdata;
 
-       memset((char *)pdata,'\0',data_size);
-
        c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
 
+       allocation_size = get_allocation_size(conn,fsp,&sbuf);
+
        if (fsp) {
                if (fsp->pending_modtime) {
                        /* the pending modtime overrides the current modtime */
@@ -2857,6 +2983,9 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        /* the pending modtime overrides the current modtime */
                        sbuf.st_mtime = fsp1->pending_modtime;
                }
+               if (fsp1 && fsp1->initial_allocation_size) {
+                       allocation_size = get_allocation_size(conn, fsp1, &sbuf);
+               }
        }
 
        if (lp_dos_filetime_resolution(SNUM(conn))) {
@@ -2879,9 +3008,9 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                case SMB_INFO_STANDARD:
                        DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_STANDARD\n"));
                        data_size = 22;
-                       put_dos_date2(pdata,l1_fdateCreation,c_time);
-                       put_dos_date2(pdata,l1_fdateLastAccess,sbuf.st_atime);
-                       put_dos_date2(pdata,l1_fdateLastWrite,sbuf.st_mtime); /* write time */
+                       srv_put_dos_date2(pdata,l1_fdateCreation,c_time);
+                       srv_put_dos_date2(pdata,l1_fdateLastAccess,sbuf.st_atime);
+                       srv_put_dos_date2(pdata,l1_fdateLastWrite,sbuf.st_mtime); /* write time */
                        SIVAL(pdata,l1_cbFile,(uint32)file_size);
                        SIVAL(pdata,l1_cbFileAlloc,(uint32)allocation_size);
                        SSVAL(pdata,l1_attrFile,mode);
@@ -2892,13 +3021,13 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
                        DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n"));
                        data_size = 26;
-                       put_dos_date2(pdata,l1_fdateCreation,c_time);
-                       put_dos_date2(pdata,l1_fdateLastAccess,sbuf.st_atime);
-                       put_dos_date2(pdata,l1_fdateLastWrite,sbuf.st_mtime); /* write time */
-                       SIVAL(pdata,l1_cbFile,(uint32)file_size);
-                       SIVAL(pdata,l1_cbFileAlloc,(uint32)allocation_size);
-                       SSVAL(pdata,l1_attrFile,mode);
-                       SIVAL(pdata,l1_attrFile+2,ea_size);
+                       srv_put_dos_date2(pdata,0,c_time);
+                       srv_put_dos_date2(pdata,4,sbuf.st_atime);
+                       srv_put_dos_date2(pdata,8,sbuf.st_mtime); /* write time */
+                       SIVAL(pdata,12,(uint32)file_size);
+                       SIVAL(pdata,16,(uint32)allocation_size);
+                       SSVAL(pdata,20,mode);
+                       SIVAL(pdata,22,ea_size);
                        break;
                }
 
@@ -2985,7 +3114,6 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        DEBUG(5,("write: %s ", ctime(&sbuf.st_mtime)));
                        DEBUG(5,("change: %s ", ctime(&sbuf.st_mtime)));
                        DEBUG(5,("mode: %x\n", mode));
-
                        break;
 
                case SMB_FILE_STANDARD_INFORMATION:
@@ -2995,12 +3123,10 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        data_size = 24;
                        SOFF_T(pdata,0,allocation_size);
                        SOFF_T(pdata,8,file_size);
-                       if (delete_pending & sbuf.st_nlink)
-                               SIVAL(pdata,16,sbuf.st_nlink - 1);
-                       else
-                               SIVAL(pdata,16,sbuf.st_nlink);
-                       SCVAL(pdata,20,0);
+                       SIVAL(pdata,16,nlink);
+                       SCVAL(pdata,20,delete_pending?1:0);
                        SCVAL(pdata,21,(mode&aDIR)?1:0);
+                       SSVAL(pdata,22,0); /* Padding. */
                        break;
 
                case SMB_FILE_EA_INFORMATION:
@@ -3022,7 +3148,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ALTERNATE_NAME_INFORMATION\n"));
                        pstrcpy(short_name,base_name);
                        /* Mangle if not already 8.3 */
-                       if(!mangle_is_8_3(short_name, True)) {
+                       if(!mangle_is_8_3(short_name, True, SNUM(conn))) {
                                mangle_map(short_name,True,True,SNUM(conn));
                        }
                        len = srvstr_push(outbuf, pdata+4, short_name, -1, STR_UNICODE);
@@ -3065,15 +3191,14 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        put_long_date(pdata+16,sbuf.st_mtime); /* write time */
                        put_long_date(pdata+24,sbuf.st_mtime); /* change time */
                        SIVAL(pdata,32,mode);
+                       SIVAL(pdata,36,0); /* padding. */
                        pdata += 40;
                        SOFF_T(pdata,0,allocation_size);
                        SOFF_T(pdata,8,file_size);
-                       if (delete_pending && sbuf.st_nlink)
-                               SIVAL(pdata,16,sbuf.st_nlink - 1);
-                       else
-                               SIVAL(pdata,16,sbuf.st_nlink);
+                       SIVAL(pdata,16,nlink);
                        SCVAL(pdata,20,delete_pending);
                        SCVAL(pdata,21,(mode&aDIR)?1:0);
+                       SSVAL(pdata,22,0);
                        pdata += 24;
                        SIVAL(pdata,0,ea_size);
                        pdata += 4; /* EA info */
@@ -3091,14 +3216,14 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                           BasicFileInformationTest. -tpot */
 
                        DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_INTERNAL_INFORMATION\n"));
-                       SIVAL(pdata,0,sbuf.st_dev);
-                       SIVAL(pdata,4,sbuf.st_ino);
+                       SIVAL(pdata,4,sbuf.st_ino); /* FileIndexLow */
+                       SIVAL(pdata,0,sbuf.st_dev); /* FileIndexHigh */
                        data_size = 8;
                        break;
 
                case SMB_FILE_ACCESS_INFORMATION:
                        DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ACCESS_INFORMATION\n"));
-                       SIVAL(pdata,0,desired_access);
+                       SIVAL(pdata,0,access_mask);
                        data_size = 4;
                        break;
 
@@ -3281,8 +3406,8 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                uint16 num_file_acls = 0;
                                uint16 num_def_acls = 0;
 
-                               if (fsp && !fsp->is_directory && (fsp->fd != -1)) {
-                                       file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp, fsp->fd);
+                               if (fsp && !fsp->is_directory && (fsp->fh->fd != -1)) {
+                                       file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp, fsp->fh->fd);
                                } else {
                                        file_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fname, SMB_ACL_TYPE_ACCESS);
                                }
@@ -3361,92 +3486,6 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        return(-1);
 }
 
-/****************************************************************************
- Deal with the internal needs of setting the delete on close flag. Note that
- as the tdb locking is recursive, it is safe to call this from within 
- open_file_shared. JRA.
-****************************************************************************/
-
-NTSTATUS set_delete_on_close_internal(files_struct *fsp, BOOL delete_on_close, uint32 dosmode)
-{
-       if (delete_on_close) {
-               /*
-                * Only allow delete on close for writable files.
-                */
-
-               if (!lp_delete_readonly(SNUM(fsp->conn))) {
-                       if (dosmode & aRONLY) {
-                               DEBUG(10,("set_delete_on_close_internal: file %s delete on close flag set but file attribute is readonly.\n",
-                                       fsp->fsp_name ));
-                               return NT_STATUS_CANNOT_DELETE;
-                       }
-               }
-
-               /*
-                * Only allow delete on close for writable shares.
-                */
-
-               if (!CAN_WRITE(fsp->conn)) {
-                       DEBUG(10,("set_delete_on_close_internal: file %s delete on close flag set but write access denied on share.\n",
-                               fsp->fsp_name ));
-                       return NT_STATUS_ACCESS_DENIED;
-               }
-
-               /*
-                * Only allow delete on close for files/directories opened with delete intent.
-                */
-
-               if (!(fsp->desired_access & DELETE_ACCESS)) {
-                       DEBUG(10,("set_delete_on_close_internal: file %s delete on close flag set but delete access denied.\n",
-                               fsp->fsp_name ));
-                       return NT_STATUS_ACCESS_DENIED;
-               }
-       }
-
-       if(fsp->is_directory) {
-               fsp->directory_delete_on_close = delete_on_close;
-               DEBUG(10, ("set_delete_on_close_internal: %s delete on close flag for fnum = %d, directory %s\n",
-                       delete_on_close ? "Added" : "Removed", fsp->fnum, fsp->fsp_name ));
-       } else {
-               fsp->delete_on_close = delete_on_close;
-               DEBUG(10, ("set_delete_on_close_internal: %s delete on close flag for fnum = %d, file %s\n",
-                       delete_on_close ? "Added" : "Removed", fsp->fnum, fsp->fsp_name ));
-       }
-
-       return NT_STATUS_OK;
-}
-
-/****************************************************************************
- Sets the delete on close flag over all share modes on this file.
- Modify the share mode entry for all files open
- on this device and inode to tell other smbds we have
- changed the delete on close flag. This will be noticed
- in the close code, the last closer will delete the file
- if flag is set.
-****************************************************************************/
-
-NTSTATUS set_delete_on_close_over_all(files_struct *fsp, BOOL delete_on_close)
-{
-       DEBUG(10,("set_delete_on_close_over_all: %s delete on close flag for fnum = %d, file %s\n",
-               delete_on_close ? "Adding" : "Removing", fsp->fnum, fsp->fsp_name ));
-
-       if (fsp->is_directory || fsp->is_stat)
-               return NT_STATUS_OK;
-
-       if (lock_share_entry_fsp(fsp) == False)
-               return NT_STATUS_ACCESS_DENIED;
-
-       if (!modify_delete_flag(fsp->dev, fsp->inode, delete_on_close)) {
-               DEBUG(0,("set_delete_on_close_over_all: failed to change delete on close flag for file %s\n",
-                       fsp->fsp_name ));
-               unlock_share_entry_fsp(fsp);
-               return NT_STATUS_ACCESS_DENIED;
-       }
-
-       unlock_share_entry_fsp(fsp);
-       return NT_STATUS_OK;
-}
-
 /****************************************************************************
  Set a hard link (called by UNIX extensions and by NT rename with HARD link
  code.
@@ -3536,12 +3575,12 @@ NTSTATUS hardlink_internals(connection_struct *conn, char *oldname, char *newnam
 ****************************************************************************/
 
 static int call_trans2setfilepathinfo(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;
-       uint16 tran_call = SVAL(inbuf, smb_setup0);
        uint16 info_level;
        int dosmode=0;
        SMB_OFF_T size=0;
@@ -3560,6 +3599,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
 
        ZERO_STRUCT(sbuf);
+       ZERO_STRUCT(tvs);
 
        if (tran_call == TRANSACT2_SETFILEINFO) {
                if (total_params < 4) {
@@ -3569,7 +3609,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                fsp = file_fsp(params,0);
                info_level = SVAL(params,2);    
 
-               if(fsp && (fsp->is_directory || fsp->fd == -1)) {
+               if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
                        /*
                         * This is actually a SETFILEINFO on a directory
                         * handle (returned from an NT SMB). NT5.0 seems
@@ -3585,7 +3625,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                         * Doing a DELETE_ON_CLOSE should cancel a print job.
                         */
                        if ((info_level == SMB_SET_FILE_DISPOSITION_INFO) && CVAL(pdata,0)) {
-                               fsp->share_mode = FILE_DELETE_ON_CLOSE;
+                               fsp->fh->private_options |= FILE_DELETE_ON_CLOSE;
 
                                DEBUG(3,("call_trans2setfilepathinfo: Cancelling print job (%s)\n", fsp->fsp_name ));
        
@@ -3601,7 +3641,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                        CHECK_FSP(fsp,conn);
 
                        pstrcpy(fname, fsp->fsp_name);
-                       fd = fsp->fd;
+                       fd = fsp->fh->fd;
 
                        if (SMB_VFS_FSTAT(fsp,fd,&sbuf) != 0) {
                                DEBUG(3,("call_trans2setfilepathinfo: fstat of fnum %d failed (%s)\n",fsp->fnum, strerror(errno)));
@@ -3615,7 +3655,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                }
 
                info_level = SVAL(params,0);    
-               srvstr_get_path(inbuf, fname, &params[6], sizeof(fname), -1, STR_TERMINATE, &status, False);
+               srvstr_get_path(inbuf, fname, &params[6], sizeof(fname), -1, STR_TERMINATE, &status);
                if (!NT_STATUS_IS_OK(status)) {
                        return ERROR_NT(status);
                }
@@ -3682,9 +3722,9 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                        }
 
                        /* access time */
-                       tvs.actime = make_unix_date2(pdata+l1_fdateLastAccess);
+                       tvs.actime = srv_make_unix_date2(pdata+l1_fdateLastAccess);
                        /* write time */
-                       tvs.modtime = make_unix_date2(pdata+l1_fdateLastWrite);
+                       tvs.modtime = srv_make_unix_date2(pdata+l1_fdateLastWrite);
                        break;
                }
 
@@ -3694,6 +3734,17 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                        TALLOC_CTX *ctx = NULL;
 
                        if (total_data < 10) {
+
+                               /* OS/2 workplace shell seems to send SET_EA requests of "null"
+                                  length. They seem to have no effect. Bug #3212. JRA */
+
+                               if ((total_data == 4) && (IVAL(pdata,0) == 4)) {
+                                       /* We're done. We only get EA info in this call. */
+                                       SSVAL(params,0,0);
+                                       send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0);
+                                       return(-1);
+                               }
+
                                return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                        }
 
@@ -3718,7 +3769,11 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                        if (!NT_STATUS_IS_OK(status)) {
                                return ERROR_NT(status);
                        }
-                       break;
+
+                       /* We're done. We only get EA info in this call. */
+                       SSVAL(params,0,0);
+                       send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0);
+                       return(-1);
                }
 
 #if 0
@@ -3814,29 +3869,21 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
  
                                if (fd == -1) {
                                        files_struct *new_fsp = NULL;
-                                       int access_mode = 0;
-                                       int action = 0;
-                                       if(global_oplock_break) {
-                                               /* Queue this file modify as we are the process of an oplock break.  */
  
-                                               DEBUG(2,("call_trans2setfilepathinfo: queueing message due to being "));
-                                               DEBUGADD(2,( "in oplock break state.\n"));
-                                               push_oplock_pending_smb_message(inbuf, length);
-                                               return -1;
-                                       }
-                                       new_fsp = open_file_shared1(conn, fname, &sbuf,FILE_WRITE_DATA,
-                                                                       SET_OPEN_MODE(DOS_OPEN_RDWR),
-                                                                       (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN),
+                                       new_fsp = open_file_ntcreate(conn, fname, &sbuf,
+                                                                       FILE_WRITE_DATA,
+                                                                       FILE_SHARE_READ|FILE_SHARE_WRITE,
+                                                                       FILE_OPEN,
+                                                                       0,
                                                                        FILE_ATTRIBUTE_NORMAL,
-                                                                       INTERNAL_OPEN_ONLY, &access_mode, &action);
+                                                                       INTERNAL_OPEN_ONLY,
+                                                                       NULL);
  
-                                       if (new_fsp == NULL)
+                                       if (new_fsp == NULL) {
                                                return(UNIXERROR(ERRDOS,ERRbadpath));
+                                       }
                                        ret = vfs_allocate_file_space(new_fsp, allocation_size);
-                                       if (SMB_VFS_FSTAT(new_fsp,new_fsp->fd,&new_sbuf) != 0) {
+                                       if (SMB_VFS_FSTAT(new_fsp,new_fsp->fh->fd,&new_sbuf) != 0) {
                                                DEBUG(3,("call_trans2setfilepathinfo: fstat of fnum %d failed (%s)\n",
                                                                        new_fsp->fnum, strerror(errno)));
                                                ret = -1;
@@ -3896,19 +3943,21 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                        if (fsp == NULL)
                                return(UNIXERROR(ERRDOS,ERRbadfid));
 
-                       status = set_delete_on_close_internal(fsp, delete_on_close, dosmode);
+                       status = can_set_delete_on_close(fsp, delete_on_close,
+                                                        dosmode);
  
                        if (!NT_STATUS_IS_OK(status)) {
                                return ERROR_NT(status);
                        }
 
                        /* The set is across all open files on this dev/inode pair. */
-                       status =set_delete_on_close_over_all(fsp, delete_on_close);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               return ERROR_NT(status);
+                       if (!set_delete_on_close(fsp, delete_on_close)) {
+                               return ERROR_NT(NT_STATUS_ACCESS_DENIED);
                        }
 
-                       break;
+                       SSVAL(params,0,0);
+                       send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0);
+                       return(-1);
                }
 
                case SMB_FILE_POSITION_INFORMATION:
@@ -3928,9 +3977,14 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
 #endif /* LARGE_SMB_OFF_T */
                        DEBUG(10,("call_trans2setfilepathinfo: Set file position information for file %s to %.0f\n",
                                        fname, (double)position_information ));
-                       if (fsp)
-                               fsp->position_information = position_information;
-                       break;
+                       if (fsp) {
+                               fsp->fh->position_information = position_information;
+                       }
+
+                       /* We're done. We only get position info in this call. */
+                       SSVAL(params,0,0);
+                       send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0);
+                       return(-1);
                }
 
                /* From tridge Samba4 : 
@@ -3950,7 +4004,11 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                        if (mode != 0 && mode != 2 && mode != 4 && mode != 6) {
                                return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                        }
-                       break;
+
+                       /* We're done. We only get mode info in this call. */
+                       SSVAL(params,0,0);
+                       send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0);
+                       return(-1);
                }
 
                /*
@@ -4155,7 +4213,7 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
                        char *newname = fname;
 
                        /* Set a hard link. */
-                       srvstr_get_path(inbuf, oldname, pdata, sizeof(oldname), -1, STR_TERMINATE, &status, False);
+                       srvstr_get_path(inbuf, oldname, pdata, sizeof(oldname), -1, STR_TERMINATE, &status);
                        if (!NT_STATUS_IS_OK(status)) {
                                return ERROR_NT(status);
                        }
@@ -4189,7 +4247,7 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
                        overwrite = (CVAL(pdata,0) ? True : False);
                        root_fid = IVAL(pdata,4);
                        len = IVAL(pdata,8);
-                       srvstr_get_path(inbuf, newname, &pdata[12], sizeof(newname), len, 0, &status, False);
+                       srvstr_get_path(inbuf, newname, &pdata[12], sizeof(newname), len, 0, &status);
                        if (!NT_STATUS_IS_OK(status)) {
                                return ERROR_NT(status);
                        }
@@ -4216,7 +4274,7 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
                        } else {
                                DEBUG(10,("call_trans2setfilepathinfo: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
                                        fname, newname ));
-                               status = rename_internals(conn, fname, base_name, 0, overwrite);
+                               status = rename_internals(conn, fname, base_name, 0, overwrite, False);
                        }
                        if (!NT_STATUS_IS_OK(status)) {
                                return ERROR_NT(status);
@@ -4344,35 +4402,28 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
 
                if (fd == -1) {
                        files_struct *new_fsp = NULL;
-                       int access_mode = 0;
-                       int action = 0;
 
-                       if(global_oplock_break) {
-                               /* Queue this file modify as we are the process of an oplock break.  */
-
-                               DEBUG(2,("call_trans2setfilepathinfo: queueing message due to being "));
-                               DEBUGADD(2,( "in oplock break state.\n"));
-
-                               push_oplock_pending_smb_message(inbuf, length);
-                               return -1;
-                       }
-
-                       new_fsp = open_file_shared(conn, fname, &sbuf,
-                                               SET_OPEN_MODE(DOS_OPEN_RDWR),
-                                               (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN),
+                       new_fsp = open_file_ntcreate(conn, fname, &sbuf,
+                                               FILE_WRITE_DATA,
+                                               FILE_SHARE_READ|FILE_SHARE_WRITE,
+                                               FILE_OPEN,
+                                               0,
                                                FILE_ATTRIBUTE_NORMAL,
-                                               INTERNAL_OPEN_ONLY, &access_mode, &action);
+                                               INTERNAL_OPEN_ONLY,
+                                               NULL);
        
-                       if (new_fsp == NULL)
+                       if (new_fsp == NULL) {
                                return(UNIXERROR(ERRDOS,ERRbadpath));
+                       }
                        ret = vfs_set_filelen(new_fsp, size);
                        close_file(new_fsp,True);
                } else {
                        ret = vfs_set_filelen(fsp, size);
                }
 
-               if (ret == -1)
+               if (ret == -1) {
                        return (UNIXERROR(ERRHRD,ERRdiskfull));
+               }
        }
 
        /*
@@ -4434,7 +4485,7 @@ 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), -1, STR_TERMINATE, &status, False);
+       srvstr_get_path(inbuf, directory, &params[4], sizeof(directory), -1, STR_TERMINATE, &status);
        if (!NT_STATUS_IS_OK(status)) {
                return ERROR_NT(status);
        }
@@ -4447,11 +4498,17 @@ static int call_trans2mkdir(connection_struct *conn, char *inbuf, char *outbuf,
        }
 
        /* Any data in this call is an EA list. */
-       if (total_data && !lp_ea_support(SNUM(conn))) {
+       if (total_data && (total_data != 4) && !lp_ea_support(SNUM(conn))) {
                return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
        }
 
-       if (total_data) {
+       /*
+        * OS/2 workplace shell seems to send SET_EA requests of "null"
+        * length (4 bytes containing IVAL 4).
+        * They seem to have no effect. Bug #3212. JRA.
+        */
+
+       if (total_data != 4) {
                if (total_data < 10) {
                        return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                }
@@ -4471,6 +4528,8 @@ static int call_trans2mkdir(connection_struct *conn, char *inbuf, char *outbuf,
                        talloc_destroy(ctx);
                        return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                }
+       } else if (IVAL(pdata,0) != 4) {
+               return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
        }
 
        if (check_name(directory,conn)) {
@@ -4745,18 +4804,6 @@ int reply_trans2(connection_struct *conn,
        unsigned int num_params, num_params_sofar, num_data, num_data_sofar;
        START_PROFILE(SMBtrans2);
 
-       if(global_oplock_break && (tran_call == TRANSACT2_OPEN)) {
-               /* Queue this open message as we are the process of an
-                * oplock break.  */
-
-               DEBUG(2,("reply_trans2: queueing message trans2open due to being "));
-               DEBUGADD(2,( "in oplock break state.\n"));
-
-               push_oplock_pending_smb_message(inbuf, length);
-               END_PROFILE(SMBtrans2);
-               return -1;
-       }
-       
        if (IS_IPC(conn) && (tran_call != TRANSACT2_OPEN)
             && (tran_call != TRANSACT2_GET_DFS_REFERRAL)) {
                END_PROFILE(SMBtrans2);
@@ -4836,6 +4883,7 @@ int reply_trans2(connection_struct *conn,
                   of the parameter/data bytes */
                outsize = set_message(outbuf,0,0,True);
                srv_signing_trans_stop();
+               show_msg(outbuf);
                if (!send_smb(smbd_server_fd(),outbuf))
                        exit_server("reply_trans2: send_smb failed.");
 
@@ -4848,6 +4896,9 @@ int reply_trans2(connection_struct *conn,
                        unsigned int data_off;
 
                        ret = receive_next_smb(inbuf,bufsize,SMB_SECONDARY_WAIT);
+
+                       /* We need to re-calcuate the new length after we've read the secondary packet. */
+                       length = smb_len(inbuf) + 4;
                        
                        /*
                         * The sequence number for the trans reply is always
@@ -4895,7 +4946,7 @@ int reply_trans2(connection_struct *conn,
                                        goto bad_param;
                                if (param_disp > total_params)
                                        goto bad_param;
-                               if ((smb_base(inbuf) + param_off + num_params >= inbuf + bufsize) ||
+                               if ((smb_base(inbuf) + param_off + num_params > inbuf + length) ||
                                                (smb_base(inbuf) + param_off + num_params < smb_base(inbuf)))
                                        goto bad_param;
                                if (params + param_disp < params)
@@ -4911,7 +4962,7 @@ int reply_trans2(connection_struct *conn,
                                        goto bad_param;
                                if (data_disp > total_data)
                                        goto bad_param;
-                               if ((smb_base(inbuf) + data_off + num_data >= inbuf + bufsize) ||
+                               if ((smb_base(inbuf) + data_off + num_data > inbuf + length) ||
                                                (smb_base(inbuf) + data_off + num_data < smb_base(inbuf)))
                                        goto bad_param;
                                if (data + data_disp < data)
@@ -4956,25 +5007,24 @@ int reply_trans2(connection_struct *conn,
                END_PROFILE_NESTED(Trans2_qfsinfo);
            break;
 
-#ifdef HAVE_SYS_QUOTAS
        case TRANSACT2_SETFSINFO:
                START_PROFILE_NESTED(Trans2_setfsinfo);
                outsize = call_trans2setfsinfo(conn, inbuf, outbuf, length, bufsize, 
                                          &params, total_params, &data, total_data, max_data_bytes);
                END_PROFILE_NESTED(Trans2_setfsinfo);
                break;
-#endif
+
        case TRANSACT2_QPATHINFO:
        case TRANSACT2_QFILEINFO:
                START_PROFILE_NESTED(Trans2_qpathinfo);
-               outsize = call_trans2qfilepathinfo(conn, inbuf, outbuf, length, bufsize, 
+               outsize = call_trans2qfilepathinfo(conn, inbuf, outbuf, length, bufsize, tran_call,
                                          &params, total_params, &data, total_data, max_data_bytes);
                END_PROFILE_NESTED(Trans2_qpathinfo);
                break;
        case TRANSACT2_SETPATHINFO:
        case TRANSACT2_SETFILEINFO:
                START_PROFILE_NESTED(Trans2_setpathinfo);
-               outsize = call_trans2setfilepathinfo(conn, inbuf, outbuf, length, bufsize, 
+               outsize = call_trans2setfilepathinfo(conn, inbuf, outbuf, length, bufsize, tran_call,
                                          &params, total_params, &data, total_data, max_data_bytes);
                END_PROFILE_NESTED(Trans2_setpathinfo);
                break;