Second part of fix for bug #6494 - Incorrect FileStatus returned in NT_CREATE_ANDX.
[nivanova/samba-autobuild/.git] / source3 / smbd / nttrans.c
index cf955d9651d8585f32938c2daf86b4f88b63581c..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)
@@ -375,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.
 ****************************************************************************/
@@ -407,13 +453,14 @@ void reply_ntcreate_and_X(struct smb_request *req)
        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);
@@ -465,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;
        }
 
@@ -475,6 +522,14 @@ 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,
@@ -483,6 +538,8 @@ void reply_ntcreate_and_X(struct smb_request *req)
                                NULL,
                                &smb_fname);
 
+       TALLOC_FREE(case_state);
+
        if (!NT_STATUS_IS_OK(status)) {
                if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
                        reply_botherror(req,
@@ -494,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 */
@@ -506,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 */
@@ -516,12 +581,7 @@ 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;
        }
 
@@ -555,10 +615,6 @@ void reply_ntcreate_and_X(struct smb_request *req)
        }
 
        file_len = smb_fname->st.st_ex_size;
-       fattr = dos_mode(conn, smb_fname);
-       if (fattr == 0) {
-               fattr = FILE_ATTRIBUTE_NORMAL;
-       }
 
        if (flags & EXTENDED_RESPONSE_REQUIRED) {
                /* This is very strange. We
@@ -587,6 +643,11 @@ 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);
@@ -692,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;
        }
 
@@ -722,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;
        }
 
@@ -879,6 +940,7 @@ static void call_nt_transact_create(connection_struct *conn,
        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"));
@@ -896,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;
        }
 
@@ -990,6 +1052,14 @@ 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,
@@ -998,6 +1068,8 @@ static void call_nt_transact_create(connection_struct *conn,
                                NULL,
                                &smb_fname);
 
+       TALLOC_FREE(case_state);
+
        if (!NT_STATUS_IS_OK(status)) {
                if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
                        reply_botherror(req,
@@ -1015,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 */
@@ -1027,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 */
@@ -1071,10 +1151,6 @@ static void call_nt_transact_create(connection_struct *conn,
        }
 
        file_len = smb_fname->st.st_ex_size;
-       fattr = dos_mode(conn, smb_fname);
-       if (fattr == 0) {
-               fattr = FILE_ATTRIBUTE_NORMAL;
-       }
 
        /* Realloc the size of parameters and data we will return */
        if (flags & EXTENDED_RESPONSE_REQUIRED) {
@@ -1085,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;
        }
 
@@ -1103,6 +1179,11 @@ 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);
@@ -1139,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);
@@ -1252,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 */
@@ -1274,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 */
@@ -1516,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;
        }
 
@@ -1527,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;
        }
 
@@ -1621,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;
        }
 
@@ -1690,13 +1791,13 @@ 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;
        }
 
@@ -1708,7 +1809,7 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
 
        params = nttrans_realloc(ppparams, 4);
        if(params == NULL) {
-               reply_doserror(req, ERRDOS, ERRnomem);
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
                return;
        }
 
@@ -1760,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;
        }
 
@@ -1801,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;
        }
 
@@ -1820,7 +1921,7 @@ static void call_nt_transact_set_security_desc(connection_struct *conn,
                 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;
        }
 
@@ -2036,7 +2137,7 @@ 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;
 
@@ -2164,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;
        }
 
@@ -2174,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;
        }
 
@@ -2209,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;
                                }
 
@@ -2229,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;
                        }
 
@@ -2237,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;
                        }
 
@@ -2246,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;
                        }
 
@@ -2309,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;
                        }
 
@@ -2353,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;
                        }
 
@@ -2393,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;
        }
@@ -2431,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;
        }
 
@@ -2441,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;
        }
 
@@ -2455,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;
        }
 
@@ -2469,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;
        }
 
@@ -2486,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 */
@@ -2500,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 */
@@ -2514,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 */
@@ -2525,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;
        }
 
@@ -2538,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);
        }
@@ -2659,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;
@@ -2695,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;
        }
@@ -2709,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;
        }
@@ -2755,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;
        }
@@ -2776,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;
                }
@@ -2798,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;
                }
@@ -2831,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;
                }