r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
[vlendec/samba-autobuild/.git] / source3 / smbd / nttrans.c
index aa6f79e16571c0c4829b46a8bca5aa04cb913478..0b1bdcadbb1bd88be35c3a7bdef1daa7081e87d9 100644 (file)
@@ -321,7 +321,7 @@ static int nt_open_pipe(char *fname, connection_struct *conn,
        smb_np_struct *p = NULL;
        uint16 vuid = SVAL(inbuf, smb_uid);
        int i;
-
        DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
     
        /* See if it is one we want to handle. */
@@ -350,6 +350,12 @@ static int nt_open_pipe(char *fname, connection_struct *conn,
                return(ERROR_DOS(ERRSRV,ERRnofids));
        }
 
+       /* TODO: Add pipe to db */
+       
+       if ( !store_pipe_opendb( p ) ) {
+               DEBUG(3,("nt_open_pipe: failed to store %s pipe open.\n", fname));
+       }
+       
        *ppnum = p->pnum;
        return 0;
 }
@@ -412,10 +418,14 @@ int reply_ntcreate_and_X_quota(connection_struct *conn,
        int result;
        char *p;
        uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
-       files_struct *fsp = open_fake_file(conn, fake_file_type, fname, desired_access);
+       files_struct *fsp;
+       NTSTATUS status;
 
-       if (!fsp) {
-               return ERROR_NT(NT_STATUS_ACCESS_DENIED);
+       status = open_fake_file(conn, fake_file_type, fname, desired_access,
+                               &fsp);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return ERROR_NT(status);
        }
 
        set_message(outbuf,34,0,True);
@@ -688,18 +698,18 @@ create_options = 0x%x root_dir_fid = 0x%x\n",
                        return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
                }
 
-               fsp = open_directory(conn, fname, &sbuf,
+               status = open_directory(conn, fname, &sbuf,
                                        access_mask,
                                        share_access,
                                        create_disposition,
                                        create_options,
-                                       &info);
+                                       &info, &fsp);
 
                restore_case_semantics(conn, file_attributes);
 
-               if(!fsp) {
+               if(!NT_STATUS_IS_OK(status)) {
                        END_PROFILE(SMBntcreateX);
-                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
+                       return ERROR_NT(status);
                }
        } else {
                /*
@@ -719,15 +729,15 @@ create_options = 0x%x root_dir_fid = 0x%x\n",
                 * before issuing an oplock break request to
                 * our client. JRA.  */
 
-               fsp = open_file_ntcreate(conn,fname,&sbuf,
+               status = open_file_ntcreate(conn,fname,&sbuf,
                                        access_mask,
                                        share_access,
                                        create_disposition,
                                        create_options,
                                        file_attributes,
                                        oplock_request,
-                                       &info);
-               if (!fsp) { 
+                                       &info, &fsp);
+               if (!NT_STATUS_IS_OK(status)) { 
                        /* We cheat here. There are two cases we
                         * care about. One is a directory rename,
                         * where the NT client will attempt to
@@ -747,7 +757,8 @@ create_options = 0x%x root_dir_fid = 0x%x\n",
                         * we handle in the open_file_stat case. JRA.
                         */
 
-                       if(errno == EISDIR) {
+                       if (NT_STATUS_EQUAL(status,
+                                           NT_STATUS_FILE_IS_A_DIRECTORY)) {
 
                                /*
                                 * Fail the open if it was explicitly a non-directory file.
@@ -760,17 +771,17 @@ create_options = 0x%x root_dir_fid = 0x%x\n",
                                }
        
                                oplock_request = 0;
-                               fsp = open_directory(conn, fname, &sbuf,
+                               status = open_directory(conn, fname, &sbuf,
                                                        access_mask,
                                                        share_access,
                                                        create_disposition,
                                                        create_options,
-                                                       &info);
+                                                       &info, &fsp);
 
-                               if(!fsp) {
+                               if(!NT_STATUS_IS_OK(status)) {
                                        restore_case_semantics(conn, file_attributes);
                                        END_PROFILE(SMBntcreateX);
-                                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
+                                       return ERROR_NT(status);
                                }
                        } else {
 
@@ -780,7 +791,7 @@ create_options = 0x%x root_dir_fid = 0x%x\n",
                                        /* We have re-scheduled this call. */
                                        return -1;
                                }
-                               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
+                               return ERROR_NT(status);
                        }
                } 
        }
@@ -1331,16 +1342,16 @@ static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *o
                 * CreateDirectory() call.
                 */
 
-               fsp = open_directory(conn, fname, &sbuf,
+               status = open_directory(conn, fname, &sbuf,
                                        access_mask,
                                        share_access,
                                        create_disposition,
                                        create_options,
-                                       &info);
-               if(!fsp) {
+                                       &info, &fsp);
+               if(!NT_STATUS_IS_OK(status)) {
                        talloc_destroy(ctx);
                        restore_case_semantics(conn, file_attributes);
-                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
+                       return ERROR_NT(status);
                }
 
        } else {
@@ -1349,17 +1360,18 @@ static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *o
                 * Ordinary file case.
                 */
 
-               fsp = open_file_ntcreate(conn,fname,&sbuf,
+               status = open_file_ntcreate(conn,fname,&sbuf,
                                        access_mask,
                                        share_access,
                                        create_disposition,
                                        create_options,
                                        file_attributes,
                                        oplock_request,
-                                       &info);
+                                       &info, &fsp);
 
-               if (!fsp) { 
-                       if(errno == EISDIR) {
+               if (!NT_STATUS_IS_OK(status)) { 
+                       if (NT_STATUS_EQUAL(status,
+                                           NT_STATUS_FILE_IS_A_DIRECTORY)) {
 
                                /*
                                 * Fail the open if it was explicitly a non-directory file.
@@ -1371,16 +1383,16 @@ static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *o
                                }
        
                                oplock_request = 0;
-                               fsp = open_directory(conn, fname, &sbuf,
+                               status = open_directory(conn, fname, &sbuf,
                                                        access_mask,
                                                        share_access,
                                                        create_disposition,
                                                        create_options,
-                                                       &info);
-                               if(!fsp) {
+                                                       &info, &fsp);
+                               if(!NT_STATUS_IS_OK(status)) {
                                        talloc_destroy(ctx);
                                        restore_case_semantics(conn, file_attributes);
-                                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
+                                       return ERROR_NT(status);
                                }
                        } else {
                                talloc_destroy(ctx);
@@ -1389,7 +1401,7 @@ static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *o
                                        /* We have re-scheduled this call. */
                                        return -1;
                                }
-                               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
+                               return ERROR_NT(status);
                        }
                } 
        }
@@ -1655,39 +1667,29 @@ static NTSTATUS copy_internals(connection_struct *conn, char *oldname, char *new
 
        DEBUG(10,("copy_internals: doing file copy %s to %s\n", oldname, newname));
 
-        fsp1 = open_file_ntcreate(conn,oldname,&sbuf1,
+        status = open_file_ntcreate(conn,oldname,&sbuf1,
                        FILE_READ_DATA, /* Read-only. */
                        FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
                        FILE_OPEN,
                        0, /* No create options. */
                        FILE_ATTRIBUTE_NORMAL,
                        NO_OPLOCK,
-                       &info);
+                       &info, &fsp1);
 
-       if (!fsp1) {
-               status = get_saved_ntstatus();
-               if (NT_STATUS_IS_OK(status)) {
-                       status = NT_STATUS_ACCESS_DENIED;
-               }
-               set_saved_ntstatus(NT_STATUS_OK);
+       if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
-        fsp2 = open_file_ntcreate(conn,newname,&sbuf2,
-                       FILE_WRITE_DATA, /* Write-only. */
+        status = open_file_ntcreate(conn,newname,&sbuf2,
+                       FILE_WRITE_DATA, /* Read-only. */
                        FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
                        FILE_CREATE,
                        0, /* No create options. */
                        fattr,
                        NO_OPLOCK,
-                       &info);
+                       &info, &fsp2);
 
-       if (!fsp2) {
-               status = get_saved_ntstatus();
-               if (NT_STATUS_IS_OK(status)) {
-                       status = NT_STATUS_ACCESS_DENIED;
-               }
-               set_saved_ntstatus(NT_STATUS_OK);
+       if (!NT_STATUS_IS_OK(status)) {
                close_file(fsp1,ERROR_CLOSE);
                return status;
        }
@@ -2389,7 +2391,7 @@ static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf,
                return ERROR_NT(NT_STATUS_INVALID_HANDLE);
        }
 
-       /* the NULL pointer cheking for fsp->fake_file_handle->pd
+       /* the NULL pointer checking for fsp->fake_file_handle->pd
         * is done by CHECK_NTQUOTA_HANDLE_OK()
         */
        qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;