r10656: BIG merge from trunk. Features not copied over
[vlendec/samba-autobuild/.git] / source3 / smbd / trans2.c
index adc6322ac33110798fb69c2fea0a0a44302cf2ba..f0b7812a1e04dd8d50afe2aac48c95ec27390738 100644 (file)
@@ -3,6 +3,7 @@
    SMB transaction2 handling
    Copyright (C) Jeremy Allison                        1994-2003
    Copyright (C) Stefan (metze) Metzmacher     2003
+   Copyright (C) Volker Lendecke               2005
 
    Extensively modified by Andrew Tridgell, 1995
 
@@ -26,7 +27,6 @@
 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;
 
@@ -119,8 +119,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);
        }
@@ -134,7 +134,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;
@@ -171,8 +171,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);
                }
@@ -187,7 +187,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) {
@@ -209,7 +209,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);
@@ -220,7 +220,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;
 }
 
@@ -328,7 +328,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));
@@ -337,10 +337,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));
@@ -355,10 +355,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",
@@ -471,7 +471,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;
 }
@@ -591,6 +591,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;
@@ -685,6 +686,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.");
 
@@ -715,20 +717,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;
@@ -738,6 +740,10 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
        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.
@@ -748,7 +754,7 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
        }
 
        flags = SVAL(params, 0);
-       open_mode = SVAL(params, 2);
+       deny_mode = SVAL(params, 2);
        open_attr = SVAL(params,6);
         oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
         if (oplock_request) {
@@ -764,16 +770,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);
        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 */
 
@@ -786,11 +794,12 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
                return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
        }
 
-       /* Strange open mode mapping. */
-       if (open_ofun == 0) {
-               if (GET_OPEN_MODE(open_mode) == DOS_OPEN_EXEC) {
-                       open_ofun = FILE_EXISTS_FAIL | FILE_CREATE_IF_NOT_EXIST;
-               }
+       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. */
@@ -820,8 +829,14 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
                }
        }
 
-       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);
@@ -833,10 +848,10 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
        }
 
        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));
@@ -858,12 +873,13 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
        }
        *pparams = params;
 
-       memset((char *)params,'\0',30);
        SSVAL(params,0,fsp->fnum);
-       SSVAL(params,2,fmode);
+       SSVAL(params,2,open_attr);
        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))) {
                smb_action |= EXTENDED_OPLOCK_GRANTED;
@@ -875,9 +891,12 @@ 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 */
@@ -993,7 +1012,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, 
@@ -1009,7 +1028,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;
@@ -1017,8 +1036,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;
@@ -1063,7 +1083,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
@@ -1102,7 +1122,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));
@@ -1163,13 +1183,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;
+                       put_dos_date2(p,0,cdate);
+                       put_dos_date2(p,4,adate);
+                       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);
@@ -1195,17 +1215,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);
+                       put_dos_date2(p,0,cdate);
+                       put_dos_date2(p,4,adate);
+                       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) {
@@ -1239,13 +1259,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. */
+                       put_dos_date2(p,0,cdate);
+                       put_dos_date2(p,4,adate);
+                       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);
@@ -1285,7 +1305,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;
@@ -1305,22 +1325,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);
@@ -1341,6 +1363,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);
@@ -1368,6 +1391,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);
@@ -1384,6 +1408,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);
@@ -1413,6 +1438,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                        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);
@@ -1421,7 +1447,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;
@@ -1441,17 +1467,19 @@ 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 ? */
@@ -1460,6 +1488,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                        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);
@@ -1517,6 +1546,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;
@@ -1562,7 +1592,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);
@@ -1592,9 +1622,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) {
@@ -1688,7 +1718,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);
@@ -1698,19 +1727,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, 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));
@@ -1812,7 +1835,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);
@@ -1943,7 +1966,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);
@@ -2006,8 +2028,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));
                }
 
                /*
@@ -2324,7 +2346,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
                        
                        fsp.conn = conn;
                        fsp.fnum = -1;
-                       fsp.fd = -1;
+                       fsp.fh->fd = -1;
                        
                        /* access check */
                        if (current_user.uid != 0) {
@@ -2378,7 +2400,8 @@ 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_MAC_QUERY_FS_INFO:
@@ -2404,7 +2427,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).
 ****************************************************************************/
@@ -2415,21 +2437,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) {
@@ -2438,67 +2449,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));
@@ -2516,7 +2572,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.
@@ -2660,14 +2715,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;
@@ -2685,7 +2741,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);
@@ -2710,7 +2766,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
@@ -2730,7 +2786,10 @@ 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,
+                                                        fname);
                } else {
                        /*
                         * Original code - this is an open file.
@@ -2738,13 +2797,16 @@ 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,
+                                                        fname);
+                       access_mask = fsp->access_mask;
                }
        } else {
                NTSTATUS status = NT_STATUS_OK;
@@ -2784,6 +2846,24 @@ 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,
+                                                         fname);
+               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())
@@ -2848,7 +2928,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 ) {
@@ -2857,8 +2937,6 @@ 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);
@@ -2913,13 +2991,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);
+                       put_dos_date2(pdata,0,c_time);
+                       put_dos_date2(pdata,4,sbuf.st_atime);
+                       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;
                }
 
@@ -3006,7 +3084,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:
@@ -3016,12 +3093,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:
@@ -3043,7 +3118,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);
@@ -3086,15 +3161,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 */
@@ -3119,7 +3193,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
 
                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;
 
@@ -3302,8 +3376,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);
                                }
@@ -3382,92 +3456,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.
@@ -3557,12 +3545,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;
@@ -3591,7 +3579,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
@@ -3607,7 +3595,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 ));
        
@@ -3623,7 +3611,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)));
@@ -3840,29 +3828,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;
@@ -3922,16 +3902,16 @@ 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);
                        }
 
                        SSVAL(params,0,0);
@@ -3957,7 +3937,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
                        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;
+                               fsp->fh->position_information = position_information;
                        }
 
                        /* We're done. We only get position info in this call. */
@@ -4381,35 +4361,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));
+               }
        }
 
        /*
@@ -4782,18 +4755,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);
@@ -4873,6 +4834,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.");
 
@@ -4996,25 +4958,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;