Fix bug 7104 - "wide links" and "unix extensions" are incompatible.
[samba.git] / source3 / smbd / trans2.c
index 59b778cf45c74da4cd6a71588e94d6826cd0a4da..28862d1f4e8d78de92d71543895c192437117071 100644 (file)
@@ -28,8 +28,6 @@
 #include "smbd/globals.h"
 #include "../libcli/auth/libcli_auth.h"
 
-extern enum protocol_types Protocol;
-
 #define DIR_ENTRY_SAFETY_MARGIN 4096
 
 static char *store_file_unix_basic(connection_struct *conn,
@@ -72,8 +70,8 @@ static bool samba_private_attr_name(const char *unix_ea_name)
        static const char * const prohibited_ea_names[] = {
                SAMBA_POSIX_INHERITANCE_EA_NAME,
                SAMBA_XATTR_DOS_ATTRIB,
-               SAMBA_XATTR_DOSTIMESTAMPS,
                SAMBA_XATTR_MARKER,
+               XATTR_NTACL_NAME,
                NULL
        };
 
@@ -1014,7 +1012,7 @@ static void call_trans2open(connection_struct *conn,
        pname = &params[28];
 
        if (IS_IPC(conn)) {
-               reply_doserror(req, ERRSRV, ERRaccess);
+               reply_nterror(req, NT_STATUS_NETWORK_ACCESS_DENIED);
                goto out;
        }
 
@@ -1057,7 +1055,7 @@ static void call_trans2open(connection_struct *conn,
                                         &access_mask, &share_mode,
                                         &create_disposition,
                                         &create_options)) {
-               reply_doserror(req, ERRDOS, ERRbadaccess);
+               reply_nterror(req, NT_STATUS_ACCESS_DENIED);
                goto out;
        }
 
@@ -1123,7 +1121,7 @@ static void call_trans2open(connection_struct *conn,
        inode = smb_fname->st.st_ex_ino;
        if (fattr & aDIR) {
                close_file(req, fsp, ERROR_CLOSE);
-               reply_doserror(req, ERRDOS,ERRnoaccess);
+               reply_nterror(req, NT_STATUS_ACCESS_DENIED);
                goto out;
        }
 
@@ -1486,7 +1484,6 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
        char *nameptr;
        char *last_entry_ptr;
        bool was_8_3;
-       uint32_t nt_extmode; /* Used for NT connections instead of mode */
        off_t off;
        off_t pad = 0;
 
@@ -1525,7 +1522,9 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
        pad -= off;
        off += pad;
        /* initialize padding to 0 */
-       memset(pdata, 0, pad);
+       if (pad) {
+               memset(pdata, 0, pad);
+       }
        space_remaining -= pad;
 
        pdata += pad;
@@ -1535,11 +1534,9 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
        pad = 0;
        off = 0;
 
-       nt_extmode = mode ? mode : FILE_ATTRIBUTE_NORMAL;
-
        switch (info_level) {
        case SMB_FIND_INFO_STANDARD:
-               DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_INFO_STANDARD\n"));
+               DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_INFO_STANDARD\n"));
                if(requires_resume_key) {
                        SIVAL(p,0,reskey);
                        p += 4;
@@ -1575,7 +1572,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                break;
 
        case SMB_FIND_EA_SIZE:
-               DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_EA_SIZE\n"));
+               DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_EA_SIZE\n"));
                if (requires_resume_key) {
                        SIVAL(p,0,reskey);
                        p += 4;
@@ -1619,7 +1616,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                struct ea_list *file_list = NULL;
                size_t ea_len = 0;
 
-               DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_EA_LIST\n"));
+               DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_EA_LIST\n"));
                if (!name_list) {
                        return false;
                }
@@ -1644,7 +1641,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                /* Max string size is 255 bytes. */
                if (PTR_DIFF(p + 255 + ea_len,pdata) > space_remaining) {
                        *out_of_space = true;
-                       DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
+                       DEBUG(9,("smbd_marshall_dir_entry: out of space\n"));
                        return False; /* Not finished - just out of space */
                }
 
@@ -1674,7 +1671,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
        }
 
        case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
-               DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_BOTH_DIRECTORY_INFO\n"));
+               DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_BOTH_DIRECTORY_INFO\n"));
                was_8_3 = mangle_is_8_3(fname, True, conn->params);
                p += 4;
                SIVAL(p,0,reskey); p += 4;
@@ -1684,7 +1681,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                put_long_date_timespec(conn->ts_res,p,cdate_ts); p += 8;
                SOFF_T(p,0,file_size); p += 8;
                SOFF_T(p,0,allocation_size); p += 8;
-               SIVAL(p,0,nt_extmode); p += 4;
+               SIVAL(p,0,mode); p += 4;
                q = p; p += 4; /* q is placeholder for name length. */
                {
                        unsigned int ea_size = estimate_ea_size(conn, NULL,
@@ -1741,7 +1738,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                break;
 
        case SMB_FIND_FILE_DIRECTORY_INFO:
-               DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_DIRECTORY_INFO\n"));
+               DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_DIRECTORY_INFO\n"));
                p += 4;
                SIVAL(p,0,reskey); p += 4;
                put_long_date_timespec(conn->ts_res,p,create_date_ts); p += 8;
@@ -1750,7 +1747,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                put_long_date_timespec(conn->ts_res,p,cdate_ts); p += 8;
                SOFF_T(p,0,file_size); p += 8;
                SOFF_T(p,0,allocation_size); p += 8;
-               SIVAL(p,0,nt_extmode); p += 4;
+               SIVAL(p,0,mode); p += 4;
                len = srvstr_push(base_data, flags2,
                                  p + 4, fname, PTR_DIFF(end_data, p+4),
                                  STR_TERMINATE_ASCII);
@@ -1777,7 +1774,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                break;
 
        case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
-               DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_FULL_DIRECTORY_INFO\n"));
+               DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_FULL_DIRECTORY_INFO\n"));
                p += 4;
                SIVAL(p,0,reskey); p += 4;
                put_long_date_timespec(conn->ts_res,p,create_date_ts); p += 8;
@@ -1786,7 +1783,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                put_long_date_timespec(conn->ts_res,p,cdate_ts); p += 8;
                SOFF_T(p,0,file_size); p += 8;
                SOFF_T(p,0,allocation_size); p += 8;
-               SIVAL(p,0,nt_extmode); p += 4;
+               SIVAL(p,0,mode); p += 4;
                q = p; p += 4; /* q is placeholder for name length. */
                {
                        unsigned int ea_size = estimate_ea_size(conn, NULL,
@@ -1820,7 +1817,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                break;
 
        case SMB_FIND_FILE_NAMES_INFO:
-               DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_NAMES_INFO\n"));
+               DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_NAMES_INFO\n"));
                p += 4;
                SIVAL(p,0,reskey); p += 4;
                p += 4;
@@ -1852,7 +1849,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                break;
 
        case SMB_FIND_ID_FULL_DIRECTORY_INFO:
-               DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_ID_FULL_DIRECTORY_INFO\n"));
+               DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_ID_FULL_DIRECTORY_INFO\n"));
                p += 4;
                SIVAL(p,0,reskey); p += 4;
                put_long_date_timespec(conn->ts_res,p,create_date_ts); p += 8;
@@ -1861,7 +1858,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                put_long_date_timespec(conn->ts_res,p,cdate_ts); p += 8;
                SOFF_T(p,0,file_size); p += 8;
                SOFF_T(p,0,allocation_size); p += 8;
-               SIVAL(p,0,nt_extmode); p += 4;
+               SIVAL(p,0,mode); p += 4;
                q = p; p += 4; /* q is placeholder for name length. */
                {
                        unsigned int ea_size = estimate_ea_size(conn, NULL,
@@ -1898,7 +1895,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                break;
 
        case SMB_FIND_ID_BOTH_DIRECTORY_INFO:
-               DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_ID_BOTH_DIRECTORY_INFO\n"));
+               DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_ID_BOTH_DIRECTORY_INFO\n"));
                was_8_3 = mangle_is_8_3(fname, True, conn->params);
                p += 4;
                SIVAL(p,0,reskey); p += 4;
@@ -1908,7 +1905,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                put_long_date_timespec(conn->ts_res,p,cdate_ts); p += 8;
                SOFF_T(p,0,file_size); p += 8;
                SOFF_T(p,0,allocation_size); p += 8;
-               SIVAL(p,0,nt_extmode); p += 4;
+               SIVAL(p,0,mode); p += 4;
                q = p; p += 4; /* q is placeholder for name length */
                {
                        unsigned int ea_size = estimate_ea_size(conn, NULL,
@@ -1978,14 +1975,14 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
                /* Begin of SMB_QUERY_FILE_UNIX_BASIC */
 
                if (info_level == SMB_FIND_FILE_UNIX) {
-                       DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_UNIX\n"));
+                       DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_UNIX\n"));
                        p = store_file_unix_basic(conn, p,
                                                NULL, &smb_fname->st);
                        len = srvstr_push(base_data, flags2, p,
                                          fname, PTR_DIFF(end_data, p),
                                          STR_TERMINATE);
                } else {
-                       DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_UNIX_INFO2\n"));
+                       DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_UNIX_INFO2\n"));
                        p = store_file_unix_basic_info2(conn, p,
                                                NULL, &smb_fname->st);
                        nameptr = p;
@@ -2024,7 +2021,7 @@ static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
 
        if (PTR_DIFF(p,pdata) > space_remaining) {
                *out_of_space = true;
-               DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
+               DEBUG(9,("smbd_marshall_dir_entry: out of space\n"));
                return false; /* Not finished - just out of space */
        }
 
@@ -2146,7 +2143,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                                const char *path_mask,
                                uint32 dirtype,
                                int info_level,
-                               int requires_resume_key,
+                               bool requires_resume_key,
                                bool dont_descend,
                                bool ask_sharemode,
                                char **ppdata,
@@ -2158,17 +2155,17 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                                int *last_entry_off,
                                struct ea_list *name_list)
 {
-       bool resume_key = false;
-       const uint8_t align = 4;
+       uint8_t align = 4;
        const bool do_pad = true;
 
-       if (requires_resume_key) {
-               resume_key = true;
+       if (info_level >= 1 && info_level <= 3) {
+               /* No alignment on earlier info levels. */
+               align = 1;
        }
 
        return smbd_dirptr_lanman2_entry(ctx, conn, dirptr, flags2,
                                         path_mask, dirtype, info_level,
-                                        resume_key, dont_descend, ask_sharemode,
+                                        requires_resume_key, dont_descend, ask_sharemode,
                                         align, do_pad,
                                         ppdata, base_data, end_data,
                                         space_remaining,
@@ -2337,7 +2334,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                }
 
                if (!lp_ea_support(SNUM(conn))) {
-                       reply_doserror(req, ERRDOS, ERReasnotsupported);
+                       reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
                        goto out;
                }
 
@@ -2464,8 +2461,8 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
 
        if(numentries == 0) {
                dptr_close(sconn, &dptr_num);
-               if (Protocol < PROTOCOL_NT1) {
-                       reply_doserror(req, ERRDOS, ERRnofiles);
+               if (get_Protocol() < PROTOCOL_NT1) {
+                       reply_force_doserror(req, ERRDOS, ERRnofiles);
                        goto out;
                } else {
                        reply_botherror(req, NT_STATUS_NO_SUCH_FILE,
@@ -2575,23 +2572,26 @@ static void call_trans2findnext(connection_struct *conn,
        requires_resume_key = (findnext_flags & FLAG_TRANS2_FIND_REQUIRE_RESUME);
        continue_bit = (findnext_flags & FLAG_TRANS2_FIND_CONTINUE);
 
-       srvstr_get_path_wcard(ctx, params, req->flags2, &resume_name,
+       if (!continue_bit) {
+               /* We only need resume_name if continue_bit is zero. */
+               srvstr_get_path_wcard(ctx, params, req->flags2, &resume_name,
                              params+12,
                              total_params - 12, STR_TERMINATE, &ntstatus,
                              &mask_contains_wcard);
-       if (!NT_STATUS_IS_OK(ntstatus)) {
-               /* Win9x or OS/2 can send a resume name of ".." or ".". This will cause the parser to
-                  complain (it thinks we're asking for the directory above the shared
-                  path or an invalid name). Catch this as the resume name is only compared, never used in
-                  a file access. JRA. */
-               srvstr_pull_talloc(ctx, params, req->flags2,
+               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
+                          path or an invalid name). Catch this as the resume name is only compared, never used in
+                          a file access. JRA. */
+                       srvstr_pull_talloc(ctx, params, req->flags2,
                                &resume_name, params+12,
                                total_params - 12,
                                STR_TERMINATE);
 
-               if (!resume_name || !(ISDOT(resume_name) || ISDOTDOT(resume_name))) {
-                       reply_nterror(req, ntstatus);
-                       return;
+                       if (!resume_name || !(ISDOT(resume_name) || ISDOTDOT(resume_name))) {
+                               reply_nterror(req, ntstatus);
+                               return;
+                       }
                }
        }
 
@@ -2599,7 +2599,8 @@ static void call_trans2findnext(connection_struct *conn,
 close_after_request=%d, close_if_end = %d requires_resume_key = %d \
 resume_key = %d resume name = %s continue=%d level = %d\n",
                dptr_num, max_data_bytes, maxentries, close_after_request, close_if_end, 
-               requires_resume_key, resume_key, resume_name, continue_bit, info_level));
+               requires_resume_key, resume_key,
+               resume_name ? resume_name : "(NULL)", continue_bit, info_level));
 
        if (!maxentries) {
                /* W2K3 seems to treat zero as 1. */
@@ -2648,7 +2649,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                }
 
                if (!lp_ea_support(SNUM(conn))) {
-                       reply_doserror(req, ERRDOS, ERReasnotsupported);
+                       reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
                        return;
                }
 
@@ -2681,7 +2682,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
 
        /* Check that the dptr is valid */
        if(!(dirptr = dptr_fetch_lanman2(sconn, dptr_num))) {
-               reply_doserror(req, ERRDOS, ERRnofiles);
+               reply_nterror(req, STATUS_NO_MORE_FILES);
                return;
        }
 
@@ -2690,7 +2691,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        /* Get the wildcard mask from the dptr */
        if((p = dptr_wcard(sconn, dptr_num))== NULL) {
                DEBUG(2,("dptr_num %d has no wildcard\n", dptr_num));
-               reply_doserror(req, ERRDOS, ERRnofiles);
+               reply_nterror(req, STATUS_NO_MORE_FILES);
                return;
        }
 
@@ -2724,7 +2725,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
         * depend on the last file name instead.
         */
 
-       if(*resume_name && !continue_bit) {
+       if(!continue_bit && resume_name && *resume_name) {
                SMB_STRUCT_STAT st;
 
                long current_pos = 0;
@@ -2875,9 +2876,8 @@ NTSTATUS smbd_do_qfsinfo(connection_struct *conn,
        int snum = SNUM(conn);
        char *fstype = lp_fstype(SNUM(conn));
        uint32 additional_flags = 0;
-       struct smb_filename *smb_fname_dot = NULL;
+       struct smb_filename smb_fname_dot;
        SMB_STRUCT_STAT st;
-       NTSTATUS status;
 
        if (IS_IPC(conn)) {
                if (info_level != SMB_QUERY_CIFS_UNIX_INFO) {
@@ -2890,20 +2890,15 @@ NTSTATUS smbd_do_qfsinfo(connection_struct *conn,
 
        DEBUG(3,("smbd_do_qfsinfo: level = %d\n", info_level));
 
-       status = create_synthetic_smb_fname(talloc_tos(), ".", NULL, NULL,
-                                           &smb_fname_dot);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
+       ZERO_STRUCT(smb_fname_dot);
+       smb_fname_dot.base_name = discard_const_p(char, ".");
 
-       if(SMB_VFS_STAT(conn, smb_fname_dot) != 0) {
+       if(SMB_VFS_STAT(conn, &smb_fname_dot) != 0) {
                DEBUG(2,("stat of . failed (%s)\n", strerror(errno)));
-               TALLOC_FREE(smb_fname_dot);
                return map_nt_error_from_unix(errno);
        }
 
-       st = smb_fname_dot->st;
-       TALLOC_FREE(smb_fname_dot);
+       st = smb_fname_dot.st;
 
        *ppdata = (char *)SMB_REALLOC(
                *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
@@ -4189,8 +4184,6 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
        } else {
                mode = dos_mode(conn, smb_fname);
        }
-       if (!mode)
-               mode = FILE_ATTRIBUTE_NORMAL;
 
        nlink = psbuf->st_ex_nlink;
 
@@ -5238,8 +5231,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        }
 
                        if (!lp_ea_support(SNUM(conn))) {
-                               reply_doserror(req, ERRDOS,
-                                              ERReasnotsupported);
+                               reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
                                return;
                        }
 
@@ -5388,12 +5380,11 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
                           struct smb_file_time *ft,
                           bool setting_write_time)
 {
-       struct smb_filename *smb_fname_base = NULL;
+       struct smb_filename smb_fname_base;
        uint32 action =
                FILE_NOTIFY_CHANGE_LAST_ACCESS
                |FILE_NOTIFY_CHANGE_LAST_WRITE
                |FILE_NOTIFY_CHANGE_CREATION;
-       NTSTATUS status;
 
        if (!VALID_STAT(smb_fname->st)) {
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
@@ -5465,18 +5456,12 @@ NTSTATUS smb_set_file_time(connection_struct *conn,
        DEBUG(10,("smb_set_file_time: setting utimes to modified values.\n"));
 
        /* Always call ntimes on the base, even if a stream was passed in. */
-       status = create_synthetic_smb_fname(talloc_tos(), smb_fname->base_name,
-                                           NULL, &smb_fname->st,
-                                           &smb_fname_base);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
+       smb_fname_base = *smb_fname;
+       smb_fname_base.stream_name = NULL;
 
-       if(file_ntimes(conn, smb_fname_base, ft)!=0) {
-               TALLOC_FREE(smb_fname_base);
+       if(file_ntimes(conn, &smb_fname_base, ft)!=0) {
                return map_nt_error_from_unix(errno);
        }
-       TALLOC_FREE(smb_fname_base);
 
        notify_fname(conn, NOTIFY_ACTION_MODIFIED, action,
                     smb_fname->base_name);
@@ -5547,7 +5532,8 @@ static NTSTATUS smb_set_file_size(connection_struct *conn,
                                  files_struct *fsp,
                                  const struct smb_filename *smb_fname,
                                  const SMB_STRUCT_STAT *psbuf,
-                                 SMB_OFF_T size)
+                                 SMB_OFF_T size,
+                                 bool fail_after_createfile)
 {
        NTSTATUS status = NT_STATUS_OK;
        struct smb_filename *smb_fname_tmp = NULL;
@@ -5587,7 +5573,7 @@ static NTSTATUS smb_set_file_size(connection_struct *conn,
                req,                                    /* req */
                0,                                      /* root_dir_fid */
                smb_fname_tmp,                          /* fname */
-               FILE_WRITE_ATTRIBUTES,                  /* access_mask */
+               FILE_WRITE_DATA,                        /* access_mask */
                (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
                    FILE_SHARE_DELETE),
                FILE_OPEN,                              /* create_disposition*/
@@ -5607,6 +5593,12 @@ static NTSTATUS smb_set_file_size(connection_struct *conn,
                return status;
        }
 
+       /* See RAW-SFILEINFO-END-OF-FILE */
+       if (fail_after_createfile) {
+               close_file(req, new_fsp,NORMAL_CLOSE);
+               return NT_STATUS_INVALID_LEVEL;
+       }
+
        if (vfs_set_filelen(new_fsp, size) == -1) {
                status = map_nt_error_from_unix(errno);
                close_file(req, new_fsp,NORMAL_CLOSE);
@@ -5716,7 +5708,7 @@ static NTSTATUS smb_set_file_disposition_info(connection_struct *conn,
                                const char *pdata,
                                int total_data,
                                files_struct *fsp,
-                               const struct smb_filename *smb_fname)
+                               struct smb_filename *smb_fname)
 {
        NTSTATUS status = NT_STATUS_OK;
        bool delete_on_close;
@@ -5739,10 +5731,11 @@ static NTSTATUS smb_set_file_disposition_info(connection_struct *conn,
                (unsigned int)dosmode,
                (unsigned int)delete_on_close ));
 
-       status = can_set_delete_on_close(fsp, delete_on_close, dosmode);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
+       if (delete_on_close) {
+               status = can_set_delete_on_close(fsp, dosmode);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
        }
 
        /* The set is across all open files on this dev/inode pair. */
@@ -5843,42 +5836,6 @@ static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       /* !widelinks forces the target path to be within the share. */
-       /* This means we can interpret the target as a pathname. */
-       if (!lp_widelinks(SNUM(conn))) {
-               char *rel_name = NULL;
-               char *last_dirp = NULL;
-
-               if (*link_target == '/') {
-                       /* No absolute paths allowed. */
-                       return NT_STATUS_ACCESS_DENIED;
-               }
-               rel_name = talloc_strdup(ctx,newname);
-               if (!rel_name) {
-                       return NT_STATUS_NO_MEMORY;
-               }
-               last_dirp = strrchr_m(rel_name, '/');
-               if (last_dirp) {
-                       last_dirp[1] = '\0';
-               } else {
-                       rel_name = talloc_strdup(ctx,"./");
-                       if (!rel_name) {
-                               return NT_STATUS_NO_MEMORY;
-                       }
-               }
-               rel_name = talloc_asprintf_append(rel_name,
-                               "%s",
-                               link_target);
-               if (!rel_name) {
-                       return NT_STATUS_NO_MEMORY;
-               }
-
-               status = check_name(conn, rel_name);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return status;
-               }
-       }
-
        DEBUG(10,("smb_set_file_unix_link: SMB_SET_FILE_UNIX_LINK doing symlink %s -> %s\n",
                        newname, link_target ));
 
@@ -6483,7 +6440,8 @@ static NTSTATUS smb_set_file_end_of_file_info(connection_struct *conn,
                                        const char *pdata,
                                        int total_data,
                                        files_struct *fsp,
-                                       const struct smb_filename *smb_fname)
+                                       const struct smb_filename *smb_fname,
+                                       bool fail_after_createfile)
 {
        SMB_OFF_T size;
 
@@ -6508,7 +6466,8 @@ static NTSTATUS smb_set_file_end_of_file_info(connection_struct *conn,
                                fsp,
                                smb_fname,
                                &smb_fname->st,
-                               size);
+                               size,
+                               fail_after_createfile);
 }
 
 /****************************************************************************
@@ -6794,7 +6753,8 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
                                   fsp,
                                   smb_fname,
                                   &sbuf,
-                                  size);
+                                  size,
+                                  false);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -7390,11 +7350,22 @@ NTSTATUS smbd_do_setfilepathinfo(connection_struct *conn,
                case SMB_FILE_END_OF_FILE_INFORMATION:
                case SMB_SET_FILE_END_OF_FILE_INFO:
                {
+                       /*
+                        * XP/Win7 both fail after the createfile with
+                        * SMB_SET_FILE_END_OF_FILE_INFO but not
+                        * SMB_FILE_END_OF_FILE_INFORMATION (pass-through).
+                        * The level is known here, so pass it down
+                        * appropriately.
+                        */
+                       bool should_fail =
+                           (info_level == SMB_SET_FILE_END_OF_FILE_INFO);
+
                        status = smb_set_file_end_of_file_info(conn, req,
                                                                pdata,
                                                                total_data,
                                                                fsp,
-                                                               smb_fname);
+                                                               smb_fname,
+                                                               should_fail);
                        break;
                }
 
@@ -7656,7 +7627,8 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                                    max_data_bytes);
                                return;
                        } else {
-                               reply_doserror(req, ERRDOS, ERRbadpath);
+                               reply_nterror(req,
+                                       NT_STATUS_OBJECT_PATH_NOT_FOUND);
                                return;
                        }
                } else {
@@ -7796,7 +7768,7 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
        TALLOC_CTX *ctx = talloc_tos();
 
        if (!CAN_WRITE(conn)) {
-               reply_doserror(req, ERRSRV, ERRaccess);
+               reply_nterror(req, NT_STATUS_ACCESS_DENIED);
                return;
        }
 
@@ -8015,7 +7987,7 @@ static void call_trans2getdfsreferral(connection_struct *conn,
        max_referral_level = SVAL(params,0);
 
        if(!lp_host_msdfs()) {
-               reply_doserror(req, ERRDOS, ERRbadfunc);
+               reply_nterror(req, NT_STATUS_NOT_IMPLEMENTED);
                return;
        }
 
@@ -8057,7 +8029,7 @@ static void call_trans2ioctl(connection_struct *conn,
        /* check for an invalid fid before proceeding */
 
        if (!fsp) {
-               reply_doserror(req, ERRDOS, ERRbadfid);
+               reply_nterror(req, NT_STATUS_INVALID_HANDLE);
                return;
        }
 
@@ -8086,7 +8058,7 @@ static void call_trans2ioctl(connection_struct *conn,
        }
 
        DEBUG(2,("Unknown TRANS2_IOCTL\n"));
-       reply_doserror(req, ERRSRV, ERRerror);
+       reply_nterror(req, NT_STATUS_NOT_IMPLEMENTED);
 }
 
 /****************************************************************************
@@ -8155,7 +8127,7 @@ void reply_findnclose(struct smb_request *req)
 static void handle_trans2(connection_struct *conn, struct smb_request *req,
                          struct trans_state *state)
 {
-       if (Protocol >= PROTOCOL_NT1) {
+       if (get_Protocol() >= PROTOCOL_NT1) {
                req->flags2 |= 0x40; /* IS_LONG_NAME */
                SSVAL(req->inbuf,smb_flg2,req->flags2);
        }
@@ -8312,7 +8284,7 @@ static void handle_trans2(connection_struct *conn, struct smb_request *req,
        default:
                /* Error in request */
                DEBUG(2,("Unknown request %d in trans2 call\n", state->call));
-               reply_doserror(req, ERRSRV,ERRerror);
+               reply_nterror(req, NT_STATUS_NOT_IMPLEMENTED);
        }
 }
 
@@ -8364,7 +8336,7 @@ void reply_trans2(struct smb_request *req)
                case TRANSACT2_SETFSINFO:
                        break;
                default:
-                       reply_doserror(req, ERRSRV, ERRaccess);
+                       reply_nterror(req, NT_STATUS_ACCESS_DENIED);
                        END_PROFILE(SMBtrans2);
                        return;
                }