Removed some calls to NtOpenProcess. They aren't necessary because the process data structure contains already a process handle.
Modified: trunk/reactos/subsys/csrss/api/process.c
Modified: trunk/reactos/subsys/csrss/win32csr/conio.c

Modified: trunk/reactos/subsys/csrss/api/process.c
--- trunk/reactos/subsys/csrss/api/process.c	2005-04-03 14:38:42 UTC (rev 14479)
+++ trunk/reactos/subsys/csrss/api/process.c	2005-04-03 15:47:15 UTC (rev 14480)
@@ -95,7 +95,7 @@
          /* using OpenProcess is not optimal due to HANDLE vs. DWORD PIDs... */
          Status = NtOpenProcess(&pProcessData->Process,
                                 PROCESS_DUP_HANDLE | PROCESS_VM_OPERATION |
-                                PROCESS_VM_WRITE | PROCESS_CREATE_THREAD,
+                                PROCESS_VM_WRITE | PROCESS_CREATE_THREAD | SYNCHRONIZE,
                                 &ObjectAttributes,
                                 &ClientId);
          if (!NT_SUCCESS(Status))
@@ -195,7 +195,6 @@
 {
    PCSRSS_PROCESS_DATA NewProcessData;
    NTSTATUS Status;
-   HANDLE Process;
    CSRSS_API_REQUEST ApiRequest;
    CSRSS_API_REPLY ApiReply;
 
@@ -240,8 +239,6 @@
      }
    else
      {
-       CLIENT_ID ClientId;
-
        NewProcessData->Console = ProcessData->Console;
        InterlockedIncrement( &(ProcessData->Console->Header.ReferenceCount) );
        CsrInsertObject(NewProcessData,
@@ -253,27 +250,15 @@
           &(NewProcessData->Console->ActiveBuffer->Header) );
 
        RtlLeaveCriticalSection(&ProcessDataLock);
-       ClientId.UniqueProcess = (HANDLE)NewProcessData->ProcessId;
-       Status = NtOpenProcess( &Process, PROCESS_DUP_HANDLE, 0, &ClientId );
+       Status = NtDuplicateObject( NtCurrentProcess(), NewProcessData->Console->ActiveEvent, NewProcessData->Process, &NewProcessData->ConsoleEvent, SYNCHRONIZE, FALSE, 0 );
        if( !NT_SUCCESS( Status ) )
 	 {
-	   DbgPrint( "CSR: NtOpenProcess() failed for handle duplication\n" );
-	   InterlockedDecrement( &(NewProcessData->Console->Header.ReferenceCount) );
-	   CsrFreeProcessData( NewProcessData->ProcessId );
-	   Reply->Status = Status;
-	   return Status;
-	 }
-       Status = NtDuplicateObject( NtCurrentProcess(), NewProcessData->Console->ActiveEvent, Process, &NewProcessData->ConsoleEvent, SYNCHRONIZE, FALSE, 0 );
-       if( !NT_SUCCESS( Status ) )
-	 {
 	   DbgPrint( "CSR: NtDuplicateObject() failed: %x\n", Status );
-	   NtClose( Process );
 	   InterlockedDecrement( &(NewProcessData->Console->Header.ReferenceCount) );
 	   CsrFreeProcessData( NewProcessData->ProcessId );
 	   Reply->Status = Status;
 	   return Status;
 	 }
-       NtClose( Process );
        NewProcessData->CtrlDispatcher = Request->Data.CreateProcessRequest.CtrlDispatcher;
        RtlEnterCriticalSection(&ProcessDataLock );
        InsertHeadList(&NewProcessData->Console->ProcessList, &NewProcessData->ProcessEntry);

Modified: trunk/reactos/subsys/csrss/win32csr/conio.c
--- trunk/reactos/subsys/csrss/win32csr/conio.c	2005-04-03 14:38:42 UTC (rev 14479)
+++ trunk/reactos/subsys/csrss/win32csr/conio.c	2005-04-03 15:47:15 UTC (rev 14480)
@@ -238,9 +238,6 @@
 CSR_API(CsrAllocConsole)
 {
   PCSRSS_CONSOLE Console;
-  OBJECT_ATTRIBUTES ObjectAttributes;
-  CLIENT_ID ClientId;
-  HANDLE Process;
   NTSTATUS Status;
 
   DPRINT("CsrAllocConsole\n");
@@ -293,35 +290,10 @@
       return Reply->Status = Status;
     }
 
-  ClientId.UniqueThread = NULL;
-  ClientId.UniqueProcess = ProcessData->ProcessId;
-  InitializeObjectAttributes(&ObjectAttributes,
-                             NULL,
-                             0,
-                             NULL,
-                             NULL);
-
-  /* using OpenProcess is not optimal due to HANDLE vs. DWORD PIDs... */
-  Status = NtOpenProcess(&Process,
-                         PROCESS_DUP_HANDLE,
-                         &ObjectAttributes,
-                         &ClientId);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("NtOpenProcess() failed for handle duplication, Status: 0x%x\n", Status);
-      Console->Header.ReferenceCount--;
-      ProcessData->Console = 0;
-      Win32CsrReleaseObject(ProcessData, Reply->Data.AllocConsoleReply.OutputHandle);
-      Win32CsrReleaseObject(ProcessData, Reply->Data.AllocConsoleReply.InputHandle);
-      Reply->Status = Status;
-      return Status;
-    }
-
   if (! DuplicateHandle(GetCurrentProcess(), ProcessData->Console->ActiveEvent,
-                        Process, &ProcessData->ConsoleEvent, EVENT_ALL_ACCESS, FALSE, 0))
+                        ProcessData->Process, &ProcessData->ConsoleEvent, EVENT_ALL_ACCESS, FALSE, 0))
     {
       DPRINT1("DuplicateHandle() failed: %d\n", GetLastError);
-      CloseHandle(Process);
       Console->Header.ReferenceCount--;
       Win32CsrReleaseObject(ProcessData, Reply->Data.AllocConsoleReply.OutputHandle);
       Win32CsrReleaseObject(ProcessData, Reply->Data.AllocConsoleReply.InputHandle);
@@ -329,7 +301,6 @@
       Reply->Status = Status;
       return Status;
     }
-  CloseHandle(Process);
   ProcessData->CtrlDispatcher = Request->Data.AllocConsoleRequest.CtrlDispatcher;
   DPRINT("CSRSS:CtrlDispatcher address: %x\n", ProcessData->CtrlDispatcher);      
   InsertHeadList(&ProcessData->Console->ProcessList, &ProcessData->ProcessEntry);