Merge branch 'master' of ssh://git.samba.org/data/git/samba
[nivanova/samba-autobuild/.git] / source3 / smbd / nttrans.c
index 560b844a56c88da39f1b190d234d77a25dea1506..b79bb0b8f2b65a8b89530c82b0aba3aada64028b 100644 (file)
@@ -21,7 +21,6 @@
 #include "includes.h"
 #include "smbd/globals.h"
 
-extern enum protocol_types Protocol;
 extern const struct generic_mapping file_generic_mapping;
 
 static char *nttrans_realloc(char **ptr, size_t size)
@@ -68,7 +67,20 @@ void send_nt_replies(connection_struct *conn,
 
        if(params_to_send == 0 && data_to_send == 0) {
                reply_outbuf(req, 18, 0);
+               if (NT_STATUS_V(nt_error)) {
+                       error_packet_set((char *)req->outbuf,
+                                        0, 0, nt_error,
+                                        __LINE__,__FILE__);
+               }
                show_msg((char *)req->outbuf);
+               if (!srv_send_smb(smbd_server_fd(),
+                               (char *)req->outbuf,
+                               true, req->seqnum+1,
+                               IS_CONN_ENCRYPTED(conn),
+                               &req->pcd)) {
+                       exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
+               }
+               TALLOC_FREE(req->outbuf);
                return;
        }
 
@@ -258,77 +270,6 @@ void send_nt_replies(connection_struct *conn,
        }
 }
 
-/****************************************************************************
- Is it an NTFS stream name ?
- An NTFS file name is <path>.<extention>:<stream name>:<stream type>
- $DATA can be used as both a stream name and a stream type. A missing stream
- name or type implies $DATA.
-
- Both Windows stream names and POSIX files can contain the ':' character.
- This function first checks for the existence of a colon in the last component
- of the given name.  If the name contains a colon we differentiate between a
- stream and POSIX file by checking if the latter exists through a POSIX stat.
-
- Function assumes we've already chdir() to the "root" directory of fname.
-****************************************************************************/
-
-bool is_ntfs_stream_name(const char *fname)
-{
-       const char *lastcomp;
-       SMB_STRUCT_STAT sbuf;
-
-       /* If all pathnames are treated as POSIX we ignore streams. */
-       if (lp_posix_pathnames()) {
-               return false;
-       }
-
-       /* Find the last component of the name. */
-       if ((lastcomp = strrchr_m(fname, '/')) != NULL)
-               ++lastcomp;
-       else
-               lastcomp = fname;
-
-       /* If there is no colon in the last component, it's not a stream. */
-       if (strchr_m(lastcomp, ':') == NULL)
-               return false;
-
-       /*
-        * If file already exists on disk, it's not a stream. The stat must
-        * bypass the vfs layer so streams modules don't intefere.
-        */
-       if (sys_stat(fname, &sbuf) == 0) {
-               DEBUG(5, ("is_ntfs_stream_name: file %s contains a ':' but is "
-                       "not a stream\n", fname));
-               return false;
-       }
-
-       return true;
-}
-
-/****************************************************************************
- Simple check to determine if the filename is a stream.
- ***************************************************************************/
-bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname)
-{
-       if (lp_posix_pathnames()) {
-               return false;
-       }
-
-       return smb_fname->stream_name;
-}
-
-/****************************************************************************
- Returns true if the filename's stream == "::$DATA"
- ***************************************************************************/
-bool is_ntfs_default_stream_smb_fname(const struct smb_filename *smb_fname)
-{
-       if (!is_ntfs_stream_smb_fname(smb_fname)) {
-               return false;
-       }
-
-       return StrCaseCmp(smb_fname->stream_name, "::$DATA") == 0;
-}
-
 /****************************************************************************
  Reply to an NT create and X call on a pipe
 ****************************************************************************/
@@ -433,6 +374,53 @@ static void do_ntcreate_pipe_open(connection_struct *conn,
        chain_reply(req);
 }
 
+struct case_semantics_state {
+       connection_struct *conn;
+       bool case_sensitive;
+       bool case_preserve;
+       bool short_case_preserve;
+};
+
+/****************************************************************************
+ Restore case semantics.
+****************************************************************************/
+
+static int restore_case_semantics(struct case_semantics_state *state)
+{
+       state->conn->case_sensitive = state->case_sensitive;
+       state->conn->case_preserve = state->case_preserve;
+       state->conn->short_case_preserve = state->short_case_preserve;
+       return 0;
+}
+
+/****************************************************************************
+ Save case semantics.
+****************************************************************************/
+
+static struct case_semantics_state *set_posix_case_semantics(TALLOC_CTX *mem_ctx,
+                                               connection_struct *conn)
+{
+       struct case_semantics_state *result;
+
+       if (!(result = talloc(mem_ctx, struct case_semantics_state))) {
+               return NULL;
+       }
+
+       result->conn = conn;
+       result->case_sensitive = conn->case_sensitive;
+       result->case_preserve = conn->case_preserve;
+       result->short_case_preserve = conn->short_case_preserve;
+
+       /* Set to POSIX. */
+       conn->case_sensitive = True;
+       conn->case_preserve = True;
+       conn->short_case_preserve = True;
+
+       talloc_set_destructor(result, restore_case_semantics);
+
+       return result;
+}
+
 /****************************************************************************
  Reply to an NT create and X call.
 ****************************************************************************/
@@ -457,19 +445,22 @@ void reply_ntcreate_and_X(struct smb_request *req)
        int info = 0;
        files_struct *fsp = NULL;
        char *p = NULL;
+       struct timespec create_timespec;
        struct timespec c_timespec;
        struct timespec a_timespec;
        struct timespec m_timespec;
+       struct timespec write_time_ts;
        NTSTATUS status;
        int oplock_request;
        uint8_t oplock_granted = NO_OPLOCK_RETURN;
+       struct case_semantics_state *case_state = NULL;
        TALLOC_CTX *ctx = talloc_tos();
 
        START_PROFILE(SMBntcreateX);
 
        if (req->wct < 24) {
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-               return;
+               goto out;
        }
 
        flags = IVAL(req->vwv+3, 1);
@@ -521,7 +512,7 @@ void reply_ntcreate_and_X(struct smb_request *req)
                        do_ntcreate_pipe_open(conn, req);
                        goto out;
                }
-               reply_doserror(req, ERRDOS, ERRnoaccess);
+               reply_nterror(req, NT_STATUS_ACCESS_DENIED);
                goto out;
        }
 
@@ -531,12 +522,23 @@ void reply_ntcreate_and_X(struct smb_request *req)
                        ? BATCH_OPLOCK : 0;
        }
 
+       if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
+               case_state = set_posix_case_semantics(ctx, conn);
+               if (!case_state) {
+                       reply_nterror(req, NT_STATUS_NO_MEMORY);
+                       goto out;
+               }
+       }
+
        status = filename_convert(ctx,
                                conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
-                               &smb_fname,
-                               &fname);
+                               0,
+                               NULL,
+                               &smb_fname);
+
+       TALLOC_FREE(case_state);
 
        if (!NT_STATUS_IS_OK(status)) {
                if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
@@ -549,6 +551,13 @@ void reply_ntcreate_and_X(struct smb_request *req)
                goto out;
        }
 
+       /*
+        * Bug #6898 - clients using Windows opens should
+        * never be able to set this attribute into the
+        * VFS.
+        */
+       file_attributes &= ~FILE_FLAG_POSIX_SEMANTICS;
+
        status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                req,                                    /* req */
@@ -561,6 +570,7 @@ void reply_ntcreate_and_X(struct smb_request *req)
                file_attributes,                        /* file_attributes */
                oplock_request,                         /* oplock_request */
                allocation_size,                        /* allocation_size */
+               0,                                      /* private_flags */
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
                &fsp,                                   /* result */
@@ -571,15 +581,14 @@ void reply_ntcreate_and_X(struct smb_request *req)
                        /* We have re-scheduled this call, no error. */
                        goto out;
                }
-               if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
-                       reply_botherror(req, status, ERRDOS, ERRfilexists);
-               }
-               else {
-                       reply_nterror(req, status);
-               }
+               reply_openerror(req, status);
                goto out;
        }
 
+       /* Ensure we're pointing at the correct stat struct. */
+       TALLOC_FREE(smb_fname);
+       smb_fname = fsp->fsp_name;
+
        /*
         * If the caller set the extended oplock request bit
         * and we granted one (by whatever means) - set the
@@ -606,10 +615,6 @@ void reply_ntcreate_and_X(struct smb_request *req)
        }
 
        file_len = smb_fname->st.st_ex_size;
-       fattr = dos_mode(conn,fsp->fsp_name,&smb_fname->st);
-       if (fattr == 0) {
-               fattr = FILE_ATTRIBUTE_NORMAL;
-       }
 
        if (flags & EXTENDED_RESPONSE_REQUIRED) {
                /* This is very strange. We
@@ -638,24 +643,39 @@ void reply_ntcreate_and_X(struct smb_request *req)
        }
        p += 4;
 
+       fattr = dos_mode(conn, smb_fname);
+       if (fattr == 0) {
+               fattr = FILE_ATTRIBUTE_NORMAL;
+       }
+
+       /* Deal with other possible opens having a modified
+          write time. JRA. */
+       ZERO_STRUCT(write_time_ts);
+       get_file_infos(fsp->file_id, NULL, &write_time_ts);
+       if (!null_timespec(write_time_ts)) {
+               update_stat_ex_mtime(&smb_fname->st, write_time_ts);
+       }
+
        /* Create time. */
-       c_timespec = smb_fname->st.st_ex_btime;
+       create_timespec = get_create_timespec(conn, fsp, smb_fname);
        a_timespec = smb_fname->st.st_ex_atime;
        m_timespec = smb_fname->st.st_ex_mtime;
+       c_timespec = get_change_timespec(conn, fsp, smb_fname);
 
        if (lp_dos_filetime_resolution(SNUM(conn))) {
-               dos_filetime_timespec(&c_timespec);
+               dos_filetime_timespec(&create_timespec);
                dos_filetime_timespec(&a_timespec);
                dos_filetime_timespec(&m_timespec);
+               dos_filetime_timespec(&c_timespec);
        }
 
-       put_long_date_timespec(p, c_timespec); /* create time. */
+       put_long_date_timespec(conn->ts_res, p, create_timespec); /* create time. */
        p += 8;
-       put_long_date_timespec(p, a_timespec); /* access time */
+       put_long_date_timespec(conn->ts_res, p, a_timespec); /* access time */
        p += 8;
-       put_long_date_timespec(p, m_timespec); /* write time */
+       put_long_date_timespec(conn->ts_res, p, m_timespec); /* write time */
        p += 8;
-       put_long_date_timespec(p, m_timespec); /* change time */
+       put_long_date_timespec(conn->ts_res, p, c_timespec); /* change time */
        p += 8;
        SIVAL(p,0,fattr); /* File Attributes. */
        p += 4;
@@ -664,7 +684,25 @@ void reply_ntcreate_and_X(struct smb_request *req)
        SOFF_T(p,0,file_len);
        p += 8;
        if (flags & EXTENDED_RESPONSE_REQUIRED) {
-               SSVAL(p,2,0x7);
+               uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
+               size_t num_names = 0;
+               unsigned int num_streams;
+               struct stream_struct *streams = NULL;
+
+               /* Do we have any EA's ? */
+               status = get_ea_names_from_file(ctx, conn, fsp,
+                               smb_fname->base_name, NULL, &num_names);
+               if (NT_STATUS_IS_OK(status) && num_names) {
+                       file_status &= ~NO_EAS;
+               }
+               status = SMB_VFS_STREAMINFO(conn, NULL, smb_fname->base_name, ctx,
+                       &num_streams, &streams);
+               /* There is always one stream, ::$DATA. */
+               if (NT_STATUS_IS_OK(status) && num_streams > 1) {
+                       file_status &= ~NO_SUBSTREAMS;
+               }
+               TALLOC_FREE(streams);
+               SSVAL(p,2,file_status);
        }
        p += 4;
        SCVAL(p,0,fsp->is_directory ? 1 : 0);
@@ -673,7 +711,7 @@ void reply_ntcreate_and_X(struct smb_request *req)
                uint32 perms = 0;
                p += 25;
                if (fsp->is_directory ||
-                   can_write_to_file(conn, fsp->fsp_name, &smb_fname->st)) {
+                   can_write_to_file(conn, smb_fname)) {
                        perms = FILE_GENERIC_ALL;
                } else {
                        perms = FILE_GENERIC_READ|FILE_EXECUTE;
@@ -682,11 +720,10 @@ void reply_ntcreate_and_X(struct smb_request *req)
        }
 
        DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
-                fsp->fnum, fsp->fsp_name));
+               fsp->fnum, smb_fname_str_dbg(smb_fname)));
 
        chain_reply(req);
  out:
-       TALLOC_FREE(smb_fname);
        END_PROFILE(SMBntcreateX);
        return;
 }
@@ -716,7 +753,7 @@ static void do_nt_transact_create_pipe(connection_struct *conn,
 
        if(parameter_count < 54) {
                DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
-               reply_doserror(req, ERRDOS, ERRnoaccess);
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                return;
        }
 
@@ -746,7 +783,7 @@ static void do_nt_transact_create_pipe(connection_struct *conn,
        }
        params = nttrans_realloc(ppparams, param_len);
        if(params == NULL) {
-               reply_doserror(req, ERRDOS, ERRnomem);
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
                return;
        }
 
@@ -819,7 +856,7 @@ static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
        security_acl_map_generic(psd->sacl, &file_generic_mapping);
 
        if (DEBUGLEVEL >= 10) {
-               DEBUG(10,("set_sd for file %s\n", fsp->fsp_name ));
+               DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp)));
                NDR_PRINT_DEBUG(security_descriptor, psd);
        }
 
@@ -834,7 +871,7 @@ static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
  Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
 ****************************************************************************/
 
-static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
+struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
 {
        struct ea_list *ea_list_head = NULL;
        size_t offset = 0;
@@ -892,15 +929,18 @@ static void call_nt_transact_create(connection_struct *conn,
        struct security_descriptor *sd = NULL;
        uint32 ea_len;
        uint16 root_dir_fid;
+       struct timespec create_timespec;
        struct timespec c_timespec;
        struct timespec a_timespec;
        struct timespec m_timespec;
+       struct timespec write_time_ts;
        struct ea_list *ea_list = NULL;
        NTSTATUS status;
        size_t param_len;
        uint64_t allocation_size;
        int oplock_request;
        uint8_t oplock_granted;
+       struct case_semantics_state *case_state = NULL;
        TALLOC_CTX *ctx = talloc_tos();
 
        DEBUG(5,("call_nt_transact_create\n"));
@@ -918,7 +958,7 @@ static void call_nt_transact_create(connection_struct *conn,
                                ppdata, data_count);
                        goto out;
                }
-               reply_doserror(req, ERRDOS, ERRnoaccess);
+               reply_nterror(req, NT_STATUS_ACCESS_DENIED);
                goto out;
        }
 
@@ -1012,12 +1052,23 @@ static void call_nt_transact_create(connection_struct *conn,
                goto out;
        }
 
+       if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
+               case_state = set_posix_case_semantics(ctx, conn);
+               if (!case_state) {
+                       reply_nterror(req, NT_STATUS_NO_MEMORY);
+                       goto out;
+               }
+       }
+
        status = filename_convert(ctx,
                                conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
-                               &smb_fname,
-                               &fname);
+                               0,
+                               NULL,
+                               &smb_fname);
+
+       TALLOC_FREE(case_state);
 
        if (!NT_STATUS_IS_OK(status)) {
                if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
@@ -1036,6 +1087,13 @@ static void call_nt_transact_create(connection_struct *conn,
                        ? BATCH_OPLOCK : 0;
        }
 
+       /*
+        * Bug #6898 - clients using Windows opens should
+        * never be able to set this attribute into the
+        * VFS.
+        */
+       file_attributes &= ~FILE_FLAG_POSIX_SEMANTICS;
+
        status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                req,                                    /* req */
@@ -1048,6 +1106,7 @@ static void call_nt_transact_create(connection_struct *conn,
                file_attributes,                        /* file_attributes */
                oplock_request,                         /* oplock_request */
                allocation_size,                        /* allocation_size */
+               0,                                      /* private_flags */
                sd,                                     /* sd */
                ea_list,                                /* ea_list */
                &fsp,                                   /* result */
@@ -1062,6 +1121,10 @@ static void call_nt_transact_create(connection_struct *conn,
                goto out;
        }
 
+       /* Ensure we're pointing at the correct stat struct. */
+       TALLOC_FREE(smb_fname);
+       smb_fname = fsp->fsp_name;
+
        /*
         * If the caller set the extended oplock request bit
         * and we granted one (by whatever means) - set the
@@ -1088,10 +1151,6 @@ static void call_nt_transact_create(connection_struct *conn,
        }
 
        file_len = smb_fname->st.st_ex_size;
-       fattr = dos_mode(conn, fsp->fsp_name, &smb_fname->st);
-       if (fattr == 0) {
-               fattr = FILE_ATTRIBUTE_NORMAL;
-       }
 
        /* Realloc the size of parameters and data we will return */
        if (flags & EXTENDED_RESPONSE_REQUIRED) {
@@ -1102,7 +1161,7 @@ static void call_nt_transact_create(connection_struct *conn,
        }
        params = nttrans_realloc(ppparams, param_len);
        if(params == NULL) {
-               reply_doserror(req, ERRDOS, ERRnomem);
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
                goto out;
        }
 
@@ -1120,24 +1179,39 @@ static void call_nt_transact_create(connection_struct *conn,
        }
        p += 8;
 
+       fattr = dos_mode(conn, smb_fname);
+       if (fattr == 0) {
+               fattr = FILE_ATTRIBUTE_NORMAL;
+       }
+
+       /* Deal with other possible opens having a modified
+          write time. JRA. */
+       ZERO_STRUCT(write_time_ts);
+       get_file_infos(fsp->file_id, NULL, &write_time_ts);
+       if (!null_timespec(write_time_ts)) {
+               update_stat_ex_mtime(&smb_fname->st, write_time_ts);
+       }
+
        /* Create time. */
-       c_timespec = smb_fname->st.st_ex_btime;
+       create_timespec = get_create_timespec(conn, fsp, smb_fname);
        a_timespec = smb_fname->st.st_ex_atime;
        m_timespec = smb_fname->st.st_ex_mtime;
+       c_timespec = get_change_timespec(conn, fsp, smb_fname);
 
        if (lp_dos_filetime_resolution(SNUM(conn))) {
-               dos_filetime_timespec(&c_timespec);
+               dos_filetime_timespec(&create_timespec);
                dos_filetime_timespec(&a_timespec);
                dos_filetime_timespec(&m_timespec);
+               dos_filetime_timespec(&c_timespec);
        }
 
-       put_long_date_timespec(p, c_timespec); /* create time. */
+       put_long_date_timespec(conn->ts_res, p, create_timespec); /* create time. */
        p += 8;
-       put_long_date_timespec(p, a_timespec); /* access time */
+       put_long_date_timespec(conn->ts_res, p, a_timespec); /* access time */
        p += 8;
-       put_long_date_timespec(p, m_timespec); /* write time */
+       put_long_date_timespec(conn->ts_res, p, m_timespec); /* write time */
        p += 8;
-       put_long_date_timespec(p, m_timespec); /* change time */
+       put_long_date_timespec(conn->ts_res, p, c_timespec); /* change time */
        p += 8;
        SIVAL(p,0,fattr); /* File Attributes. */
        p += 4;
@@ -1146,7 +1220,25 @@ static void call_nt_transact_create(connection_struct *conn,
        SOFF_T(p,0,file_len);
        p += 8;
        if (flags & EXTENDED_RESPONSE_REQUIRED) {
-               SSVAL(p,2,0x7);
+               uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
+               size_t num_names = 0;
+               unsigned int num_streams;
+               struct stream_struct *streams = NULL;
+
+               /* Do we have any EA's ? */
+               status = get_ea_names_from_file(ctx, conn, fsp,
+                               smb_fname->base_name, NULL, &num_names);
+               if (NT_STATUS_IS_OK(status) && num_names) {
+                       file_status &= ~NO_EAS;
+               }
+               status = SMB_VFS_STREAMINFO(conn, NULL, smb_fname->base_name, ctx,
+                       &num_streams, &streams);
+               /* There is always one stream, ::$DATA. */
+               if (NT_STATUS_IS_OK(status) && num_streams > 1) {
+                       file_status &= ~NO_SUBSTREAMS;
+               }
+               TALLOC_FREE(streams);
+               SSVAL(p,2,file_status);
        }
        p += 4;
        SCVAL(p,0,fsp->is_directory ? 1 : 0);
@@ -1155,7 +1247,7 @@ static void call_nt_transact_create(connection_struct *conn,
                uint32 perms = 0;
                p += 25;
                if (fsp->is_directory ||
-                   can_write_to_file(conn, fsp->fsp_name, &smb_fname->st)) {
+                   can_write_to_file(conn, smb_fname)) {
                        perms = FILE_GENERIC_ALL;
                } else {
                        perms = FILE_GENERIC_READ|FILE_EXECUTE;
@@ -1163,12 +1255,12 @@ static void call_nt_transact_create(connection_struct *conn,
                SIVAL(p,0,perms);
        }
 
-       DEBUG(5,("call_nt_transact_create: open name = %s\n", fsp->fsp_name));
+       DEBUG(5,("call_nt_transact_create: open name = %s\n",
+                smb_fname_str_dbg(smb_fname)));
 
        /* Send the required number of replies */
        send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
  out:
-       TALLOC_FREE(smb_fname);
        return;
 }
 
@@ -1205,8 +1297,6 @@ static NTSTATUS copy_internals(TALLOC_CTX *ctx,
                                struct smb_filename *smb_fname_dst,
                                uint32 attrs)
 {
-       char *oldname = NULL;
-       char *newname = NULL;
        files_struct *fsp1,*fsp2;
        uint32 fattr;
        int info;
@@ -1225,13 +1315,8 @@ static NTSTATUS copy_internals(TALLOC_CTX *ctx,
                goto out;
        }
 
-       status = get_full_smb_filename(ctx, smb_fname_src, &oldname);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto out;
-       }
-
        /* Ensure attributes match. */
-       fattr = dos_mode(conn, oldname, &smb_fname_src->st);
+       fattr = dos_mode(conn, smb_fname_src);
        if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
                status = NT_STATUS_NO_SUCH_FILE;
                goto out;
@@ -1266,6 +1351,7 @@ static NTSTATUS copy_internals(TALLOC_CTX *ctx,
                FILE_ATTRIBUTE_NORMAL,                  /* file_attributes */
                NO_OPLOCK,                              /* oplock_request */
                0,                                      /* allocation_size */
+               0,                                      /* private_flags */
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
                &fsp1,                                  /* result */
@@ -1288,6 +1374,7 @@ static NTSTATUS copy_internals(TALLOC_CTX *ctx,
                fattr,                                  /* file_attributes */
                NO_OPLOCK,                              /* oplock_request */
                0,                                      /* allocation_size */
+               0,                                      /* private_flags */
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
                &fsp2,                                  /* result */
@@ -1315,20 +1402,15 @@ static NTSTATUS copy_internals(TALLOC_CTX *ctx,
 
        status = close_file(NULL, fsp2, NORMAL_CLOSE);
 
-       status = get_full_smb_filename(ctx, smb_fname_dst, &newname);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto out;
-       }
-
        /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
           creates the file. This isn't the correct thing to do in the copy
           case. JRA */
-       if (!parent_dirname(talloc_tos(), newname, &parent, NULL)) {
+       if (!parent_dirname(talloc_tos(), smb_fname_dst->base_name, &parent,
+                           NULL)) {
                status = NT_STATUS_NO_MEMORY;
                goto out;
        }
-       file_set_dosmode(conn, newname, fattr, &smb_fname_dst->st, parent,
-                        false);
+       file_set_dosmode(conn, smb_fname_dst, fattr, parent, false);
        TALLOC_FREE(parent);
 
        if (ret < (SMB_OFF_T)smb_fname_src->st.st_ex_size) {
@@ -1342,9 +1424,6 @@ static NTSTATUS copy_internals(TALLOC_CTX *ctx,
                        smb_fname_str_dbg(smb_fname_dst)));
        }
 
-       TALLOC_FREE(oldname);
-       TALLOC_FREE(newname);
-
        return status;
 }
 
@@ -1364,6 +1443,8 @@ void reply_ntrename(struct smb_request *req)
        bool src_has_wcard = False;
        bool dest_has_wcard = False;
        uint32 attrs;
+       uint32_t ucf_flags_src = 0;
+       uint32_t ucf_flags_dst = 0;
        uint16 rename_type;
        TALLOC_CTX *ctx = talloc_tos();
 
@@ -1371,8 +1452,7 @@ void reply_ntrename(struct smb_request *req)
 
        if (req->wct < 4) {
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-               END_PROFILE(SMBntrename);
-               return;
+               goto out;
        }
 
        attrs = SVAL(req->vwv+0, 0);
@@ -1383,14 +1463,12 @@ void reply_ntrename(struct smb_request *req)
                                       &status, &src_has_wcard);
        if (!NT_STATUS_IS_OK(status)) {
                reply_nterror(req, status);
-               END_PROFILE(SMBntrename);
-               return;
+               goto out;
        }
 
        if (ms_has_wild(oldname)) {
                reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
-               END_PROFILE(SMBntrename);
-               return;
+               goto out;
        }
 
        p++;
@@ -1398,68 +1476,81 @@ void reply_ntrename(struct smb_request *req)
                                       &status, &dest_has_wcard);
        if (!NT_STATUS_IS_OK(status)) {
                reply_nterror(req, status);
-               END_PROFILE(SMBntrename);
-               return;
+               goto out;
        }
 
+       /* The newname must begin with a ':' if the oldname contains a ':'. */
+       if (strchr_m(oldname, ':') && (newname[0] != ':')) {
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               goto out;
+       }
+
+       /*
+        * If this is a rename operation, allow wildcards and save the
+        * destination's last component.
+        */
+       if (rename_type == RENAME_FLAG_RENAME) {
+               ucf_flags_src = UCF_COND_ALLOW_WCARD_LCOMP;
+               ucf_flags_dst = UCF_COND_ALLOW_WCARD_LCOMP | UCF_SAVE_LCOMP;
+       }
+
+       /* rename_internals() calls unix_convert(), so don't call it here. */
        status = filename_convert(ctx, conn,
-                               req->flags2 & FLAGS2_DFS_PATHNAMES,
-                               oldname,
-                               &smb_fname_old,
-                               &oldname);
+                                 req->flags2 & FLAGS2_DFS_PATHNAMES,
+                                 oldname,
+                                 ucf_flags_src,
+                                 NULL,
+                                 &smb_fname_old);
        if (!NT_STATUS_IS_OK(status)) {
-               if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
-                       reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
+               if (NT_STATUS_EQUAL(status,
+                                   NT_STATUS_PATH_NOT_COVERED)) {
+                       reply_botherror(req,
+                                       NT_STATUS_PATH_NOT_COVERED,
                                        ERRSRV, ERRbadpath);
-                       END_PROFILE(SMBntrename);
-                       return;
+                       goto out;
                }
                reply_nterror(req, status);
-               END_PROFILE(SMBntrename);
-               return;
+               goto out;
        }
 
        status = filename_convert(ctx, conn,
-                               req->flags2 & FLAGS2_DFS_PATHNAMES,
-                               newname,
-                               &smb_fname_new,
-                               &newname);
+                                 req->flags2 & FLAGS2_DFS_PATHNAMES,
+                                 newname,
+                                 ucf_flags_dst,
+                                 &dest_has_wcard,
+                                 &smb_fname_new);
        if (!NT_STATUS_IS_OK(status)) {
-               if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
-                       reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
+               if (NT_STATUS_EQUAL(status,
+                                   NT_STATUS_PATH_NOT_COVERED)) {
+                       reply_botherror(req,
+                                       NT_STATUS_PATH_NOT_COVERED,
                                        ERRSRV, ERRbadpath);
-                       END_PROFILE(SMBntrename);
-                       return;
+                       goto out;
                }
                reply_nterror(req, status);
-               END_PROFILE(SMBntrename);
-               return;
-       }
-
-       /* The new name must begin with a ':' if the old name is a stream. */
-       if (is_ntfs_stream_name(oldname) && (newname[0] != ':')) {
-               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-               END_PROFILE(SMBntrename);
-               return;
+               goto out;
        }
 
-       DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
+       DEBUG(3,("reply_ntrename: %s -> %s\n",
+                smb_fname_str_dbg(smb_fname_old),
+                smb_fname_str_dbg(smb_fname_new)));
 
        switch(rename_type) {
                case RENAME_FLAG_RENAME:
-                       status = rename_internals(ctx, conn, req, oldname,
-                                       newname, attrs, False, src_has_wcard,
-                                       dest_has_wcard, DELETE_ACCESS);
+                       status = rename_internals(ctx, conn, req,
+                                                 smb_fname_old, smb_fname_new,
+                                                 attrs, False, src_has_wcard,
+                                                 dest_has_wcard,
+                                                 DELETE_ACCESS);
                        break;
                case RENAME_FLAG_HARD_LINK:
                        if (src_has_wcard || dest_has_wcard) {
                                /* No wildcards. */
                                status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
                        } else {
-                               status = hardlink_internals(ctx,
-                                               conn,
-                                               smb_fname_old,
-                                               smb_fname_new);
+                               status = hardlink_internals(ctx, conn,
+                                                           smb_fname_old,
+                                                           smb_fname_new);
                        }
                        break;
                case RENAME_FLAG_COPY:
@@ -1484,17 +1575,15 @@ void reply_ntrename(struct smb_request *req)
        if (!NT_STATUS_IS_OK(status)) {
                if (open_was_deferred(req->mid)) {
                        /* We have re-scheduled this call. */
-                       END_PROFILE(SMBntrename);
-                       return;
+                       goto out;
                }
 
                reply_nterror(req, status);
-               END_PROFILE(SMBntrename);
-               return;
+               goto out;
        }
 
        reply_outbuf(req, 0, 0);
-
+ out:
        END_PROFILE(SMBntrename);
        return;
 }
@@ -1504,6 +1593,13 @@ void reply_ntrename(struct smb_request *req)
  don't allow a directory to be opened.
 ****************************************************************************/
 
+static void smbd_smb1_notify_reply(struct smb_request *req,
+                                  NTSTATUS error_code,
+                                  uint8_t *buf, size_t len)
+{
+       send_nt_replies(req->conn, req, error_code, (char *)buf, len, NULL, 0);
+}
+
 static void call_nt_transact_notify_change(connection_struct *conn,
                                           struct smb_request *req,
                                           uint16 **ppsetup,
@@ -1521,7 +1617,7 @@ static void call_nt_transact_notify_change(connection_struct *conn,
        bool recursive;
 
        if(setup_count < 6) {
-               reply_doserror(req, ERRDOS, ERRbadfunc);
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                return;
        }
 
@@ -1532,7 +1628,7 @@ static void call_nt_transact_notify_change(connection_struct *conn,
        DEBUG(3,("call_nt_transact_notify_change\n"));
 
        if(!fsp) {
-               reply_doserror(req, ERRDOS, ERRbadfid);
+               reply_nterror(req, NT_STATUS_INVALID_HANDLE);
                return;
        }
 
@@ -1546,7 +1642,7 @@ static void call_nt_transact_notify_change(connection_struct *conn,
 
                DEBUG(3,("call_nt_transact_notify_change: notify change "
                         "called on %s, filter = %s, recursive = %d\n",
-                        fsp->fsp_name, filter_string, recursive));
+                        fsp_str_dbg(fsp), filter_string, recursive));
 
                TALLOC_FREE(filter_string);
        }
@@ -1579,8 +1675,11 @@ static void call_nt_transact_notify_change(connection_struct *conn,
                 * here.
                 */
 
-               change_notify_reply(fsp->conn, req, max_param_count,
-                                   fsp->notify);
+               change_notify_reply(fsp->conn, req,
+                                   NT_STATUS_OK,
+                                   max_param_count,
+                                   fsp->notify,
+                                   smbd_smb1_notify_reply);
 
                /*
                 * change_notify_reply() above has independently sent its
@@ -1596,7 +1695,8 @@ static void call_nt_transact_notify_change(connection_struct *conn,
        status = change_notify_add_request(req,
                        max_param_count,
                        filter,
-                       recursive, fsp);
+                       recursive, fsp,
+                       smbd_smb1_notify_reply);
        if (!NT_STATUS_IS_OK(status)) {
                reply_nterror(req, status);
        }
@@ -1622,7 +1722,7 @@ static void call_nt_transact_rename(connection_struct *conn,
        TALLOC_CTX *ctx = talloc_tos();
 
         if(parameter_count < 5) {
-               reply_doserror(req, ERRDOS, ERRbadfunc);
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                return;
        }
 
@@ -1645,7 +1745,7 @@ static void call_nt_transact_rename(connection_struct *conn,
        send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
 
        DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
-                fsp->fsp_name, new_name));
+                fsp_str_dbg(fsp), new_name));
 
        return;
 }
@@ -1691,24 +1791,25 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
        DATA_BLOB blob;
 
         if(parameter_count < 8) {
-               reply_doserror(req, ERRDOS, ERRbadfunc);
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                return;
        }
 
        fsp = file_fsp(req, SVAL(params,0));
        if(!fsp) {
-               reply_doserror(req, ERRDOS, ERRbadfid);
+               reply_nterror(req, NT_STATUS_INVALID_HANDLE);
                return;
        }
 
        security_info_wanted = IVAL(params,4);
 
-       DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
-                       (unsigned int)security_info_wanted ));
+       DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
+                "info_wanted = 0x%x\n", fsp_str_dbg(fsp),
+                (unsigned int)security_info_wanted));
 
        params = nttrans_realloc(ppparams, 4);
        if(params == NULL) {
-               reply_doserror(req, ERRDOS, ERRnomem);
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
                return;
        }
 
@@ -1741,7 +1842,8 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
        DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
 
        if (DEBUGLEVEL >= 10) {
-               DEBUG(10,("call_nt_transact_query_security_desc for file %s\n", fsp->fsp_name));
+               DEBUG(10,("call_nt_transact_query_security_desc for file %s\n",
+                         fsp_str_dbg(fsp)));
                NDR_PRINT_DEBUG(security_descriptor, psd);
        }
 
@@ -1759,7 +1861,7 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
 
        data = nttrans_realloc(ppdata, sd_size);
        if(data == NULL) {
-               reply_doserror(req, ERRDOS, ERRnomem);
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
                return;
        }
 
@@ -1800,12 +1902,12 @@ static void call_nt_transact_set_security_desc(connection_struct *conn,
        NTSTATUS status;
 
        if(parameter_count < 8) {
-               reply_doserror(req, ERRDOS, ERRbadfunc);
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                return;
        }
 
        if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
-               reply_doserror(req, ERRDOS, ERRbadfid);
+               reply_nterror(req, NT_STATUS_INVALID_HANDLE);
                return;
        }
 
@@ -1815,11 +1917,11 @@ static void call_nt_transact_set_security_desc(connection_struct *conn,
 
        security_info_sent = IVAL(params,4);
 
-       DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
-               (unsigned int)security_info_sent ));
+       DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
+                fsp_str_dbg(fsp), (unsigned int)security_info_sent));
 
        if (data_count == 0) {
-               reply_doserror(req, ERRDOS, ERRnoaccess);
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                return;
        }
 
@@ -2035,12 +2137,12 @@ static void call_nt_transact_ioctl(connection_struct *conn,
                }
 
                /* needed_data_count 4 bytes */
-               SIVAL(pdata,8,labels_data_count);
+               SIVAL(pdata, 8, labels_data_count+4);
 
                cur_pdata+=12;
 
                DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
-                       shadow_data->num_volumes,fsp->fsp_name));
+                         shadow_data->num_volumes, fsp_str_dbg(fsp)));
                if (labels && shadow_data->labels) {
                        for (i=0;i<shadow_data->num_volumes;i++) {
                                srvstr_push(pdata, req->flags2,
@@ -2163,7 +2265,7 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
                DEBUG(1,("get_user_quota: access_denied service [%s] user "
                         "[%s]\n", lp_servicename(SNUM(conn)),
                         conn->server_info->unix_name));
-               reply_doserror(req, ERRDOS, ERRnoaccess);
+               reply_nterror(req, NT_STATUS_ACCESS_DENIED);
                return;
        }
 
@@ -2173,7 +2275,7 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
 
        if (parameter_count < 4) {
                DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
-               reply_doserror(req, ERRDOS, ERRinvalidparam);
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                return;
        }
 
@@ -2208,7 +2310,7 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
                                param_len = 4;
                                params = nttrans_realloc(ppparams, param_len);
                                if(params == NULL) {
-                                       reply_doserror(req, ERRDOS, ERRnomem);
+                                       reply_nterror(req, NT_STATUS_NO_MEMORY);
                                        return;
                                }
 
@@ -2228,7 +2330,7 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
                        }
 
                        if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
-                               reply_doserror(req, ERRSRV, ERRerror);
+                               reply_nterror(req, NT_STATUS_INTERNAL_ERROR);
                                return;
                        }
 
@@ -2236,7 +2338,7 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
                        param_len = 4;
                        params = nttrans_realloc(ppparams, param_len);
                        if(params == NULL) {
-                               reply_doserror(req, ERRDOS, ERRnomem);
+                               reply_nterror(req, NT_STATUS_NO_MEMORY);
                                return;
                        }
 
@@ -2245,7 +2347,7 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
 
                        pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
                        if(pdata == NULL) {
-                               reply_doserror(req, ERRDOS, ERRnomem);
+                               reply_nterror(req, NT_STATUS_NO_MEMORY);
                                return;
                        }
 
@@ -2308,20 +2410,20 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
 
                        if (data_count < 8) {
                                DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
-                               reply_doserror(req, ERRDOS, ERRunknownlevel);
+                               reply_nterror(req, NT_STATUS_INVALID_LEVEL);
                                return;
                        }
 
                        sid_len = IVAL(pdata,4);
                        /* Ensure this is less than 1mb. */
                        if (sid_len > (1024*1024)) {
-                               reply_doserror(req, ERRDOS, ERRnomem);
+                               reply_nterror(req, NT_STATUS_NO_MEMORY);
                                return;
                        }
 
                        if (data_count < 8+sid_len) {
                                DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
-                               reply_doserror(req, ERRDOS, ERRunknownlevel);
+                               reply_nterror(req, NT_STATUS_INVALID_LEVEL);
                                return;
                        }
 
@@ -2352,13 +2454,13 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
                        param_len = 4;
                        params = nttrans_realloc(ppparams, param_len);
                        if(params == NULL) {
-                               reply_doserror(req, ERRDOS, ERRnomem);
+                               reply_nterror(req, NT_STATUS_NO_MEMORY);
                                return;
                        }
 
                        pdata = nttrans_realloc(ppdata, data_len);
                        if(pdata == NULL) {
-                               reply_doserror(req, ERRDOS, ERRnomem);
+                               reply_nterror(req, NT_STATUS_NO_MEMORY);
                                return;
                        }
 
@@ -2392,7 +2494,7 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
 
                default:
                        DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
-                       reply_doserror(req, ERRSRV, ERRerror);
+                       reply_nterror(req, NT_STATUS_INVALID_LEVEL);
                        return;
                        break;
        }
@@ -2430,7 +2532,7 @@ static void call_nt_transact_set_user_quota(connection_struct *conn,
                DEBUG(1,("set_user_quota: access_denied service [%s] user "
                         "[%s]\n", lp_servicename(SNUM(conn)),
                         conn->server_info->unix_name));
-               reply_doserror(req, ERRDOS, ERRnoaccess);
+               reply_nterror(req, NT_STATUS_ACCESS_DENIED);
                return;
        }
 
@@ -2440,7 +2542,7 @@ static void call_nt_transact_set_user_quota(connection_struct *conn,
 
        if (parameter_count < 2) {
                DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
-               reply_doserror(req, ERRDOS, ERRinvalidparam);
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                return;
        }
 
@@ -2454,7 +2556,7 @@ static void call_nt_transact_set_user_quota(connection_struct *conn,
 
        if (data_count < 40) {
                DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
-               reply_doserror(req, ERRDOS, ERRunknownlevel);
+               reply_nterror(req, NT_STATUS_INVALID_LEVEL);
                return;
        }
 
@@ -2468,7 +2570,7 @@ static void call_nt_transact_set_user_quota(connection_struct *conn,
 
        if (data_count < 40+sid_len) {
                DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
-               reply_doserror(req, ERRDOS, ERRunknownlevel);
+               reply_nterror(req, NT_STATUS_INVALID_LEVEL);
                return;
        }
 
@@ -2485,7 +2587,7 @@ static void call_nt_transact_set_user_quota(connection_struct *conn,
                ((qt.usedspace != 0xFFFFFFFF)||
                (IVAL(pdata,20)!=0xFFFFFFFF))) {
                /* more than 32 bits? */
-               reply_doserror(req, ERRDOS, ERRunknownlevel);
+               reply_nterror(req, NT_STATUS_INVALID_LEVEL);
                return;
        }
 #endif /* LARGE_SMB_OFF_T */
@@ -2499,7 +2601,7 @@ static void call_nt_transact_set_user_quota(connection_struct *conn,
                ((qt.softlim != 0xFFFFFFFF)||
                (IVAL(pdata,28)!=0xFFFFFFFF))) {
                /* more than 32 bits? */
-               reply_doserror(req, ERRDOS, ERRunknownlevel);
+               reply_nterror(req, NT_STATUS_INVALID_LEVEL);
                return;
        }
 #endif /* LARGE_SMB_OFF_T */
@@ -2513,7 +2615,7 @@ static void call_nt_transact_set_user_quota(connection_struct *conn,
                ((qt.hardlim != 0xFFFFFFFF)||
                (IVAL(pdata,36)!=0xFFFFFFFF))) {
                /* more than 32 bits? */
-               reply_doserror(req, ERRDOS, ERRunknownlevel);
+               reply_nterror(req, NT_STATUS_INVALID_LEVEL);
                return;
        }
 #endif /* LARGE_SMB_OFF_T */
@@ -2524,7 +2626,7 @@ static void call_nt_transact_set_user_quota(connection_struct *conn,
        /* 44 unknown bytes left... */
 
        if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
-               reply_doserror(req, ERRSRV, ERRerror);
+               reply_nterror(req, NT_STATUS_INTERNAL_ERROR);
                return;
        }
 
@@ -2537,7 +2639,7 @@ static void handle_nttrans(connection_struct *conn,
                           struct trans_state *state,
                           struct smb_request *req)
 {
-       if (Protocol >= PROTOCOL_NT1) {
+       if (get_Protocol() >= PROTOCOL_NT1) {
                req->flags2 |= 0x40; /* IS_LONG_NAME */
                SSVAL(req->inbuf,smb_flg2,req->flags2);
        }
@@ -2658,7 +2760,7 @@ static void handle_nttrans(connection_struct *conn,
                        /* Error in request */
                        DEBUG(0,("handle_nttrans: Unknown request %d in "
                                 "nttrans call\n", state->call));
-                       reply_doserror(req, ERRSRV, ERRerror);
+                       reply_nterror(req, NT_STATUS_INVALID_LEVEL);
                        return;
        }
        return;
@@ -2694,7 +2796,7 @@ void reply_nttrans(struct smb_request *req)
        function_code = SVAL(req->vwv+18, 0);
 
        if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
-               reply_doserror(req, ERRSRV, ERRaccess);
+               reply_nterror(req, NT_STATUS_ACCESS_DENIED);
                END_PROFILE(SMBnttrans);
                return;
        }
@@ -2708,7 +2810,7 @@ void reply_nttrans(struct smb_request *req)
        }
 
        if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
-               reply_doserror(req, ERRSRV, ERRaccess);
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
                END_PROFILE(SMBnttrans);
                return;
        }
@@ -2754,7 +2856,7 @@ void reply_nttrans(struct smb_request *req)
        /* Don't allow more than 128mb for each value. */
        if ((state->total_data > (1024*1024*128)) ||
            (state->total_param > (1024*1024*128))) {
-               reply_doserror(req, ERRDOS, ERRnomem);
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
                END_PROFILE(SMBnttrans);
                return;
        }
@@ -2775,7 +2877,7 @@ void reply_nttrans(struct smb_request *req)
                        DEBUG(0,("reply_nttrans: data malloc fail for %u "
                                 "bytes !\n", (unsigned int)state->total_data));
                        TALLOC_FREE(state);
-                       reply_doserror(req, ERRDOS, ERRnomem);
+                       reply_nterror(req, NT_STATUS_NO_MEMORY);
                        END_PROFILE(SMBnttrans);
                        return;
                }
@@ -2797,7 +2899,7 @@ void reply_nttrans(struct smb_request *req)
                                 "bytes !\n", (unsigned int)state->total_param));
                        SAFE_FREE(state->data);
                        TALLOC_FREE(state);
-                       reply_doserror(req, ERRDOS, ERRnomem);
+                       reply_nterror(req, NT_STATUS_NO_MEMORY);
                        END_PROFILE(SMBnttrans);
                        return;
                }
@@ -2830,7 +2932,7 @@ void reply_nttrans(struct smb_request *req)
                        SAFE_FREE(state->data);
                        SAFE_FREE(state->param);
                        TALLOC_FREE(state);
-                       reply_doserror(req, ERRDOS, ERRnomem);
+                       reply_nterror(req, NT_STATUS_NO_MEMORY);
                        END_PROFILE(SMBnttrans);
                        return;
                }