[NTDLL]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 9 Mar 2013 21:08:23 +0000 (21:08 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 9 Mar 2013 21:08:23 +0000 (21:08 +0000)
Fix CsrCaptureTimeout (verified against Windows Server 2003).

[KERNEL32-CSRSRV-BASESRV-CONSRV-WINSRV]
Clean the code: remove unuseful comments and dprints, reorganize a little bit few source files.

svn path=/branches/ros-csrss/; revision=58453

27 files changed:
dll/ntdll/csr/capture.c
dll/ntdll/csr/connect.c
dll/win32/kernel32/client/console/console.c
dll/win32/kernel32/client/console/readwrite.c
include/reactos/subsys/csr/csrmsg.h
include/reactos/subsys/win/base.h
include/reactos/subsys/win/basemsg.h
include/reactos/subsys/win/conmsg.h
include/reactos/subsys/win/winmsg.h
subsystems/win/basesrv/CMakeLists.txt
subsystems/win/basesrv/basesrv.h
subsystems/win/basesrv/dosdev.c [moved from subsystems/win/basesrv/server.c with 53% similarity]
subsystems/win/basesrv/init.c
subsystems/win/basesrv/proc.c [new file with mode: 0644]
subsystems/win/basesrv/sndsntry.c [new file with mode: 0644]
subsystems/win32/csrsrv/api.h [moved from subsystems/win32/csrsrv/include/api.h with 98% similarity]
subsystems/win32/csrsrv/srv.h
win32ss/user/consrv/consrv.h
win32ss/user/consrv/handle.c
win32ss/user/consrv/init.c
win32ss/user/winsrv/CMakeLists.txt
win32ss/user/winsrv/harderror.c
win32ss/user/winsrv/init.c
win32ss/user/winsrv/register.c [new file with mode: 0644]
win32ss/user/winsrv/server.c [deleted file]
win32ss/user/winsrv/shutdown.c
win32ss/user/winsrv/winsrv.h

index 3835def..637786f 100644 (file)
@@ -263,7 +263,7 @@ CsrCaptureTimeout(IN ULONG Milliseconds,
     if (Milliseconds == -1) return NULL;
 
     /* Convert to relative ticks */
-    Timeout->QuadPart = Int32x32To64(Milliseconds, -100000);
+    Timeout->QuadPart = Int32x32To64(Milliseconds, -10000);
     return Timeout;
 }
 
index 63d14d3..82c91c8 100644 (file)
@@ -173,10 +173,10 @@ NTSTATUS
 NTAPI
 CsrpConnectToServer(IN PWSTR ObjectDirectory)
 {
+    NTSTATUS Status;
     ULONG PortNameLength;
     UNICODE_STRING PortName;
     LARGE_INTEGER CsrSectionViewSize;
-    NTSTATUS Status;
     HANDLE CsrSectionHandle;
     PORT_VIEW LpcWrite;
     REMOTE_PORT_VIEW LpcRead;
index 738a86c..9dc5629 100644 (file)
@@ -840,8 +840,6 @@ AllocConsole(VOID)
     PCSR_CAPTURE_BUFFER CaptureBuffer;
     SIZE_T Length = 0;
 
-    DPRINT1("AllocConsole\n");
-
     if (Parameters->ConsoleHandle)
     {
         DPRINT1("AllocConsole: Allocating a console to a process already having one\n");
@@ -1572,8 +1570,7 @@ IntGetConsoleTitle(LPVOID lpConsoleTitle, DWORD nSize, BOOL bUnicode)
     PCONSOLE_GETSETCONSOLETITLE TitleRequest = &ApiMessage.Data.TitleRequest;
     PCSR_CAPTURE_BUFFER CaptureBuffer;
 
-    if (nSize == 0)
-        return 0;
+    if (nSize == 0) return 0;
 
     TitleRequest->Length = nSize * (bUnicode ? 1 : sizeof(WCHAR));
     CaptureBuffer = CsrAllocateCaptureBuffer(1, TitleRequest->Length);
@@ -1996,8 +1993,6 @@ AttachConsole(DWORD dwProcessId)
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_ATTACHCONSOLE AttachConsoleRequest = &ApiMessage.Data.AttachConsoleRequest;
 
-    DPRINT1("AttachConsole(%lu)\n", dwProcessId);
-
     if (Parameters->ConsoleHandle)
     {
         DPRINT1("AttachConsole: Attaching a console to a process already having one\n");
index 51d550e..ecb3b9e 100644 (file)
@@ -186,21 +186,6 @@ IntGetConsoleInput(HANDLE hConsoleInput,
 
         /* Error out */
         BaseSetLastNTError(ApiMessage.Status);
-
-/*********
-        // BaseSetLastNTError(Status); ????
-        if (GetInputRequest->InputsRead == 0)
-        {
-            /\* we couldn't read a single record, fail *\/
-            BaseSetLastNTError(Status);
-            return FALSE;
-        }
-        else
-        {
-            /\* FIXME - fail gracefully in case we already read at least one record? *\/
-            // break;
-        }
-*********/
     }
 
     /* Release the capture buffer */
@@ -310,7 +295,7 @@ IntReadConsoleOutputCode(HANDLE hConsoleOutput,
     PCONSOLE_READOUTPUTCODE ReadOutputCodeRequest = &ApiMessage.Data.ReadOutputCodeRequest;
     PCSR_CAPTURE_BUFFER CaptureBuffer;
     ULONG SizeBytes, CodeSize;
-    DWORD /*CodesRead = 0,*/ BytesRead;
+    DWORD CodesRead;
 
     /* Determine the needed size */
     switch (CodeType)
@@ -363,13 +348,13 @@ IntReadConsoleOutputCode(HANDLE hConsoleOutput,
     /* Check for success */
     if (NT_SUCCESS(Status) || NT_SUCCESS(Status = ApiMessage.Status))
     {
-        BytesRead = ReadOutputCodeRequest->CodesRead * CodeSize;
-        memcpy(pCode, ReadOutputCodeRequest->pCode.pCode, BytesRead);
+        CodesRead = ReadOutputCodeRequest->CodesRead;
+        memcpy(pCode, ReadOutputCodeRequest->pCode.pCode, CodesRead * CodeSize);
 
         // ReadOutputCodeRequest->ReadCoord = ReadOutputCodeRequest->EndCoord;
 
         if (lpNumberOfCodesRead != NULL)
-            *lpNumberOfCodesRead = ReadOutputCodeRequest->CodesRead;
+            *lpNumberOfCodesRead = CodesRead;
 
         bRet = TRUE;
     }
@@ -407,9 +392,7 @@ IntWriteConsole(HANDLE hConsoleOutput,
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_WRITECONSOLE WriteConsoleRequest = &ApiMessage.Data.WriteConsoleRequest;
     PCSR_CAPTURE_BUFFER CaptureBuffer;
-    // USHORT nChars;
-    ULONG /* SizeBytes, */ CharSize;
-    // DWORD Written = 0;
+    ULONG CharSize;
 
     /* Determine the needed size */
     CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
@@ -435,39 +418,16 @@ IntWriteConsole(HANDLE hConsoleOutput,
     WriteConsoleRequest->OutputHandle = hConsoleOutput;
     WriteConsoleRequest->Unicode = bUnicode;
 
-    // while (nNumberOfCharsToWrite > 0) {
-    //// nChars = (USHORT)min(nNumberOfCharsToWrite, CSRSS_MAX_WRITE_CONSOLE / CharSize);
-    // nChars = nNumberOfCharsToWrite;
-    // WriteConsoleRequest->NrCharactersToWrite = nChars;
-
-    // SizeBytes = nChars * CharSize;
-
-    // memcpy(WriteConsoleRequest->Buffer, lpBuffer, SizeBytes);
-
     /* Call the server */
     Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  CaptureBuffer,
                                  CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepWriteConsole),
                                  sizeof(CONSOLE_WRITECONSOLE));
-/** FIXME: Added in 47359 for pausing
 
-    if (Status == STATUS_PENDING)
-    {
-        WaitForSingleObject(WriteConsoleRequest->UnpauseEvent, INFINITE);
-        CloseHandle(WriteConsoleRequest->UnpauseEvent);
-        continue;
-    }
-**/
     /* Check for success */
     if (NT_SUCCESS(Status) || NT_SUCCESS(Status = ApiMessage.Status))
     {
-        // nNumberOfCharsToWrite -= nChars;
-        // lpBuffer = (PVOID)((ULONG_PTR)lpBuffer + (ULONG_PTR)SizeBytes);
-        // Written += WriteConsoleRequest->NrCharactersWritten;
-        // }
-
         if (lpNumberOfCharsWritten != NULL)
-            // *lpNumberOfCharsWritten = Written;
             *lpNumberOfCharsWritten = WriteConsoleRequest->NrCharactersWritten;
 
         bRet = TRUE;
@@ -651,16 +611,9 @@ IntWriteConsoleOutputCode(HANDLE hConsoleOutput,
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_WRITEOUTPUTCODE WriteOutputCodeRequest = &ApiMessage.Data.WriteOutputCodeRequest;
     PCSR_CAPTURE_BUFFER CaptureBuffer;
-    ULONG CodeSize; //, nChars;
-    // ULONG SizeBytes;
-    // DWORD Written = 0;
+    ULONG CodeSize;
 
     /* Determine the needed size */
-/*
-    CodeSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
-    nChars = min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR / CodeSize);
-    SizeBytes = nChars * CodeSize;
-*/
     switch (CodeType)
     {
         case CODE_ASCII:
@@ -690,12 +643,6 @@ IntWriteConsoleOutputCode(HANDLE hConsoleOutput,
         return FALSE;
     }
 
-/*
-    /\* Allocate space in the Buffer *\/
-    CsrAllocateMessagePointer(CaptureBuffer,
-                              SizeBytes,
-                              (PVOID*)&WriteOutputCodeRequest->pCode.pCode);
-*/
     /* Capture the buffer to write */
     CsrCaptureMessageBuffer(CaptureBuffer,
                             (PVOID)pCode,
@@ -707,10 +654,7 @@ IntWriteConsoleOutputCode(HANDLE hConsoleOutput,
     WriteOutputCodeRequest->CodeType = CodeType;
     WriteOutputCodeRequest->Coord = dwWriteCoord;
 
-    WriteOutputCodeRequest->Length = nLength; // (WORD)min(nLength, nChars);
-    // BytesWrite = WriteOutputCodeRequest->Length * CodeSize;
-
-    // memcpy(WriteOutputCodeRequest->pCode.pCode, pCode, BytesWrite);
+    WriteOutputCodeRequest->Length = nLength;
 
     /* Call the server */
     Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
@@ -721,14 +665,9 @@ IntWriteConsoleOutputCode(HANDLE hConsoleOutput,
     /* Check for success */
     if (NT_SUCCESS(Status) || NT_SUCCESS(Status = ApiMessage.Status))
     {
-        // nLength -= WriteOutputCodeRequest->NrCharactersWritten;
-        // pCode = (PVOID)((ULONG_PTR)pCode + /*(ULONG_PTR)(*/WriteOutputCodeRequest->NrCharactersWritten * CodeSize/*)*/);
-        // Written += WriteOutputCodeRequest->NrCharactersWritten;
-
         // WriteOutputCodeRequest->Coord = WriteOutputCodeRequest->EndCoord;
 
         if (lpNumberOfCodesWritten != NULL)
-            // *lpNumberOfCodesWritten = Written;
             // *lpNumberOfCodesWritten = WriteOutputCodeRequest->NrCharactersWritten;
             *lpNumberOfCodesWritten = WriteOutputCodeRequest->Length;
 
index 17164ac..26680d6 100644 (file)
@@ -112,7 +112,7 @@ typedef struct _CSR_API_MESSAGE
         {
             PCSR_CAPTURE_BUFFER CsrCaptureData;
             CSR_API_NUMBER ApiNumber;
-            ULONG Status; // ReturnValue; // NTSTATUS Status
+            NTSTATUS Status; // ReturnValue;
             ULONG Reserved;
             union
             {
index f08a76c..b359234 100644 (file)
@@ -14,7 +14,6 @@
 typedef VOID (CALLBACK * BASE_PROCESS_CREATE_NOTIFY_ROUTINE)(PVOID);
 
 NTSTATUS WINAPI BaseSetProcessCreateNotify(BASE_PROCESS_CREATE_NOTIFY_ROUTINE);
-// CSR_SERVER_DLL_INIT(ServerDllInitialization);
 
 typedef struct _NLS_USER_INFO
 {
index 05a0702..97c0f6a 100644 (file)
@@ -15,8 +15,7 @@
 #define BASESRV_SERVERDLL_INDEX     1
 #define BASESRV_FIRST_API_NUMBER    0
 
-// Windows NT 4 table, adapted from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_NT
-// It is for testing purposes. After that I will update it to 2k3 version and add stubs.
+// Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
 typedef enum _BASESRV_API_NUMBER
 {
     BasepCreateProcess = BASESRV_FIRST_API_NUMBER,
@@ -35,8 +34,7 @@ typedef enum _BASESRV_API_NUMBER
     BasepGetProcessShutdownParam,
     // BasepNlsSetUserInfo,
     // BasepNlsSetMultipleUserInfo,
-    // BasepNlsCreateSortSection,
-    // BasepNlsPreserveSection,
+    // BasepNlsCreateSection,
     // BasepSetVDMCurDirs,
     // BasepGetVDMCurDirs,
     // BasepBatNotification,
@@ -44,6 +42,12 @@ typedef enum _BASESRV_API_NUMBER
     BasepSoundSentryNotification,
     // BasepRefreshIniFileMapping,
     BasepDefineDosDevice,
+    // BasepSetTermsrvAppInstallMode,
+    // BasepNlsUpdateCacheCount,
+    // BasepSetTermsrvClientTimeZone,
+    // BasepSxsCreateActivationContext,
+    // BasepRegisterThread,
+    // BasepNlsGetUserInfo,
 
     BasepMaxApiNumber
 } BASESRV_API_NUMBER, *PBASESRV_API_NUMBER;
@@ -180,7 +184,7 @@ typedef struct _BASE_API_MESSAGE
 
     PCSR_CAPTURE_BUFFER CsrCaptureData;
     CSR_API_NUMBER ApiNumber;
-    ULONG Status; // ReturnValue; // NTSTATUS Status
+    NTSTATUS Status; // ReturnValue;
     ULONG Reserved;
     union
     {
index 0d092fb..2417aef 100644 (file)
@@ -15,9 +15,8 @@
 #define CONSRV_SERVERDLL_INDEX      2
 #define CONSRV_FIRST_API_NUMBER     512
 
-// Windows 2k3 tables, adapted from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
-// plus a little bit of Windows 7. It is for testing purposes. After that I will add stubs.
-// Some names are also deduced from the subsystems/win32/csrss/csrsrv/server.c ones.
+// Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
+// plus a little bit of Windows 7.
 typedef enum _CONSRV_API_NUMBER
 {
     ConsolepOpenConsole = CONSRV_FIRST_API_NUMBER,
@@ -564,7 +563,7 @@ typedef struct _CONSOLE_API_MESSAGE
 
     PCSR_CAPTURE_BUFFER CsrCaptureData;
     CSR_API_NUMBER ApiNumber;
-    ULONG Status; // ReturnValue; // NTSTATUS Status
+    NTSTATUS Status; // ReturnValue;
     ULONG Reserved;
     union
     {
index 9b1bfc6..10ed3da 100644 (file)
@@ -15,8 +15,7 @@
 #define USERSRV_SERVERDLL_INDEX     3
 #define USERSRV_FIRST_API_NUMBER    1024
 
-// CSR_SERVER_DLL_INIT(UserServerDllInitialization);
-
+// Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
 typedef enum _USERSRV_API_NUMBER
 {
     UserpExitWindowsEx = USERSRV_FIRST_API_NUMBER,
@@ -70,7 +69,7 @@ typedef struct _USER_API_MESSAGE
 
     PCSR_CAPTURE_BUFFER CsrCaptureData;
     CSR_API_NUMBER ApiNumber;
-    ULONG Status; // ReturnValue; // NTSTATUS Status
+    NTSTATUS Status; // ReturnValue;
     ULONG Reserved;
     union
     {
index cb2467f..fc8b00f 100644 (file)
@@ -4,8 +4,10 @@ include_directories(${REACTOS_SOURCE_DIR}/include/reactos/subsys)
 spec2def(basesrv.dll basesrv.spec)
 
 list(APPEND SOURCE
+    dosdev.c
     init.c
-    server.c
+    proc.c
+    sndsntry.c
     basesrv.rc
     ${CMAKE_CURRENT_BINARY_DIR}/basesrv.def)
 
index 4835cd9..69d9398 100644 (file)
@@ -29,16 +29,22 @@ extern HANDLE BaseSrvHeap;
 extern HANDLE BaseSrvSharedHeap;
 extern PBASE_STATIC_SERVER_DATA BaseStaticServerData;
 
+/* dosdev.c */
+VOID BaseInitDefineDosDevice(VOID);
 VOID BaseCleanupDefineDosDevice(VOID);
 
+CSR_API(BaseSrvDefineDosDevice);
+
+/* proc.c */
+CSR_API(BaseSrvGetTempFile);
 CSR_API(BaseSrvCreateProcess);
 CSR_API(BaseSrvCreateThread);
-CSR_API(BaseSrvGetTempFile);
 CSR_API(BaseSrvExitProcess);
 CSR_API(BaseSrvGetProcessShutdownParam);
 CSR_API(BaseSrvSetProcessShutdownParam);
+
+/* sndsntry.c */
 CSR_API(BaseSrvSoundSentryNotification);
-CSR_API(BaseSrvDefineDosDevice);
 
 #endif // __BASESRV_H__
 
similarity index 53%
rename from subsystems/win/basesrv/server.c
rename to subsystems/win/basesrv/dosdev.c
index c39010a..dd31b8f 100644 (file)
 /*
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS/Win32 Base enviroment Subsystem Server
- * FILE:            subsystems/win/basesrv/server.c
- * PURPOSE:         Server APIs
- * PROGRAMMERS:     Hermes Belusca-Maito (hermes.belusca@sfr.fr)
+ * FILE:            subsystems/win/basesrv/dosdev.c
+ * PURPOSE:         DOS Devices Management
+ * PROGRAMMERS:     Pierre Schweitzer (pierre.schweitzer@reactos.org)
  */
 
+/* INCLUDES *******************************************************************/
+
 #include "basesrv.h"
 
 #define NDEBUG
 #include <debug.h>
 
-CSR_API(BaseSrvCreateProcess)
-{
-    NTSTATUS Status;
-    PBASE_CREATE_PROCESS CreateProcessRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.CreateProcessRequest;
-    HANDLE ProcessHandle, ThreadHandle;
-    PCSR_THREAD CsrThread;
-    PCSR_PROCESS Process;
-    ULONG Flags = 0, VdmPower = 0, DebugFlags = 0;
-
-    /* Get the current client thread */
-    CsrThread = CsrGetClientThread();
-    ASSERT(CsrThread != NULL);
-
-    Process = CsrThread->Process;
-
-    /* Extract the flags out of the process handle */
-    Flags = (ULONG_PTR)CreateProcessRequest->ProcessHandle & 3;
-    CreateProcessRequest->ProcessHandle = (HANDLE)((ULONG_PTR)CreateProcessRequest->ProcessHandle & ~3);
-
-    /* Duplicate the process handle */
-    Status = NtDuplicateObject(Process->ProcessHandle,
-                               CreateProcessRequest->ProcessHandle,
-                               NtCurrentProcess(),
-                               &ProcessHandle,
-                               0,
-                               0,
-                               DUPLICATE_SAME_ACCESS);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("Failed to duplicate process handle\n");
-        return Status;
-    }
-
-    /* Duplicate the thread handle */
-    Status = NtDuplicateObject(Process->ProcessHandle,
-                               CreateProcessRequest->ThreadHandle,
-                               NtCurrentProcess(),
-                               &ThreadHandle,
-                               0,
-                               0,
-                               DUPLICATE_SAME_ACCESS);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("Failed to duplicate process handle\n");
-        NtClose(ProcessHandle);
-        return Status;
-    }
-
-    /* See if this is a VDM process */
-    if (VdmPower)
-    {
-        /* Request VDM powers */
-        Status = NtSetInformationProcess(ProcessHandle,
-                                         ProcessWx86Information,
-                                         &VdmPower,
-                                         sizeof(VdmPower));
-        if (!NT_SUCCESS(Status))
-        {
-            DPRINT1("Failed to get VDM powers\n");
-            NtClose(ProcessHandle);
-            NtClose(ThreadHandle);
-            return Status;
-        }
-    }
-
-    /* Flags conversion. FIXME: More need conversion */
-    if (CreateProcessRequest->CreationFlags & CREATE_NEW_PROCESS_GROUP)
-    {
-        DebugFlags |= CsrProcessCreateNewGroup;
-    }
-    if ((Flags & 2) == 0)
-    {
-        /* We are launching a console process */
-        DebugFlags |= CsrProcessIsConsoleApp;
-    }
-
-    /* FIXME: SxS Stuff */
-
-    /* Call CSRSRV to create the CSR_PROCESS structure and the first CSR_THREAD */
-    Status = CsrCreateProcess(ProcessHandle,
-                              ThreadHandle,
-                              &CreateProcessRequest->ClientId,
-                              Process->NtSession,
-                              DebugFlags,
-                              NULL);
-    if (Status == STATUS_THREAD_IS_TERMINATING)
-    {
-        DPRINT1("Thread already dead\n");
-
-        /* Set the special reply value so we don't reply this message back */
-        *ReplyCode = CsrReplyDeadClient;
-
-        return Status;
-    }
-
-    /* Check for other failures */
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("Failed to create process/thread structures: %lx\n", Status);
-        return Status;
-    }
-
-    /* FIXME: Should notify user32 */
-
-    /* FIXME: VDM vodoo */
-
-    /* Return the result of this operation */
-    return Status;
-}
-
-CSR_API(BaseSrvCreateThread)
-{
-    NTSTATUS Status;
-    PBASE_CREATE_THREAD CreateThreadRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.CreateThreadRequest;
-    PCSR_THREAD CurrentThread;
-    HANDLE ThreadHandle;
-    PCSR_PROCESS CsrProcess;
-
-    /* Get the current CSR thread */
-    CurrentThread = CsrGetClientThread();
-    if (!CurrentThread)
-    {
-        DPRINT1("Server Thread TID: [%lx.%lx]\n",
-                CreateThreadRequest->ClientId.UniqueProcess,
-                CreateThreadRequest->ClientId.UniqueThread);
-        return STATUS_SUCCESS; // server-to-server
-    }
-
-    /* Get the CSR Process for this request */
-    CsrProcess = CurrentThread->Process;
-    if (CsrProcess->ClientId.UniqueProcess !=
-        CreateThreadRequest->ClientId.UniqueProcess)
-    {
-        /* This is a remote thread request -- is it within the server itself? */
-        if (CreateThreadRequest->ClientId.UniqueProcess == NtCurrentTeb()->ClientId.UniqueProcess)
-        {
-            /* Accept this without any further work */
-            return STATUS_SUCCESS;
-        }
-
-        /* Get the real CSR Process for the remote thread's process */
-        Status = CsrLockProcessByClientId(CreateThreadRequest->ClientId.UniqueProcess,
-                                          &CsrProcess);
-        if (!NT_SUCCESS(Status)) return Status;
-    }
-
-    /* Duplicate the thread handle so we can own it */
-    Status = NtDuplicateObject(CurrentThread->Process->ProcessHandle,
-                               CreateThreadRequest->ThreadHandle,
-                               NtCurrentProcess(),
-                               &ThreadHandle,
-                               0,
-                               0,
-                               DUPLICATE_SAME_ACCESS);
-    if (NT_SUCCESS(Status))
-    {
-        /* Call CSRSRV to tell it about the new thread */
-        Status = CsrCreateThread(CsrProcess,
-                                 ThreadHandle,
-                                 &CreateThreadRequest->ClientId,
-                                 TRUE);
-    }
-
-    /* Unlock the process and return */
-    if (CsrProcess != CurrentThread->Process) CsrUnlockProcess(CsrProcess);
-    return Status;
-}
-
-CSR_API(BaseSrvGetTempFile)
-{
-    static UINT CsrGetTempFileUnique = 0;
-    PBASE_GET_TEMP_FILE GetTempFile = &((PBASE_API_MESSAGE)ApiMessage)->Data.GetTempFile;
-
-    /* Return 16-bits ID */
-    GetTempFile->UniqueID = (++CsrGetTempFileUnique & 0xFFFF);
-
-    DPRINT("Returning: %u\n", GetTempFile->UniqueID);
-
-    return STATUS_SUCCESS;
-}
-
-CSR_API(BaseSrvExitProcess)
-{
-    PCSR_THREAD CsrThread = CsrGetClientThread();
-    ASSERT(CsrThread != NULL);
-
-    /* Set the special reply value so we don't reply this message back */
-    *ReplyCode = CsrReplyDeadClient;
+/* GLOBALS ********************************************************************/
 
-    /* Remove the CSR_THREADs and CSR_PROCESS */
-    return CsrDestroyProcess(&CsrThread->ClientId,
-                             (NTSTATUS)((PBASE_API_MESSAGE)ApiMessage)->Data.ExitProcessRequest.uExitCode);
-}
-
-CSR_API(BaseSrvGetProcessShutdownParam)
+typedef struct _BASE_DOS_DEVICE_HISTORY_ENTRY
 {
-    PBASE_GET_PROCESS_SHUTDOWN_PARAMS GetShutdownParametersRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.GetShutdownParametersRequest;
-    PCSR_THREAD CsrThread = CsrGetClientThread();
-    ASSERT(CsrThread);
-
-    GetShutdownParametersRequest->Level = CsrThread->Process->ShutdownLevel;
-    GetShutdownParametersRequest->Flags = CsrThread->Process->ShutdownFlags;
-
-    return STATUS_SUCCESS;
-}
-
-CSR_API(BaseSrvSetProcessShutdownParam)
-{
-    PBASE_SET_PROCESS_SHUTDOWN_PARAMS SetShutdownParametersRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.SetShutdownParametersRequest;
-    PCSR_THREAD CsrThread = CsrGetClientThread();
-    ASSERT(CsrThread);
-
-    CsrThread->Process->ShutdownLevel = SetShutdownParametersRequest->Level;
-    CsrThread->Process->ShutdownFlags = SetShutdownParametersRequest->Flags;
-
-    return STATUS_SUCCESS;
-}
-
-
-/***
- *** Sound sentry
- ***/
-
-typedef BOOL (WINAPI *PUSER_SOUND_SENTRY)(VOID);
-BOOL NTAPI FirstSoundSentry(VOID);
-
-PUSER_SOUND_SENTRY _UserSoundSentry = FirstSoundSentry;
-
-BOOL
-NTAPI
-FailSoundSentry(VOID)
-{
-    /* In case the function can't be found/is unimplemented */
-    return FALSE;
-}
+    LIST_ENTRY     Entry;
+    UNICODE_STRING Device;
+    UNICODE_STRING Target;
+} BASE_DOS_DEVICE_HISTORY_ENTRY, *PBASE_DOS_DEVICE_HISTORY_ENTRY;
 
-BOOL
-NTAPI
-FirstSoundSentry(VOID)
-{
-    UNICODE_STRING DllString = RTL_CONSTANT_STRING(L"winsrv");
-    STRING FuncString = RTL_CONSTANT_STRING("_UserSoundSentry");
-    HANDLE DllHandle;
-    NTSTATUS Status;
-    PUSER_SOUND_SENTRY NewSoundSentry = FailSoundSentry;
+static RTL_CRITICAL_SECTION BaseDefineDosDeviceCritSec;
+static LIST_ENTRY DosDeviceHistory;
 
-    /* Load winsrv manually */
-    Status = LdrGetDllHandle(NULL, NULL, &DllString, &DllHandle);
-    if (NT_SUCCESS(Status))
-    {
-        /* If it was found, get SoundSentry export */
-        Status = LdrGetProcedureAddress(DllHandle,
-                                        &FuncString,
-                                        0,
-                                        (PVOID*)&NewSoundSentry);
-    }
-    
-    /* Set it as the callback for the future, and call it */
-    _UserSoundSentry = NewSoundSentry;
-    return _UserSoundSentry();
-}
+/* PRIVATE FUNCTIONS **********************************************************/
 
-CSR_API(BaseSrvSoundSentryNotification)
+VOID BaseInitDefineDosDevice(VOID)
 {
-    /* Call the API and see if it succeeds */
-    return _UserSoundSentry() ? STATUS_SUCCESS : STATUS_ACCESS_DENIED;
+    RtlInitializeCriticalSection(&BaseDefineDosDeviceCritSec);
+    InitializeListHead(&DosDeviceHistory);
 }
 
-
-/***
- *** Dos Devices (C) Pierre Schweitzer (pierre.schweitzer@reactos.org)
- ***/
-
-typedef struct tagBASE_DOS_DEVICE_HISTORY_ENTRY
-{
-    UNICODE_STRING Device;
-    UNICODE_STRING Target;
-    LIST_ENTRY Entry;
-} BASE_DOS_DEVICE_HISTORY_ENTRY, *PBASE_DOS_DEVICE_HISTORY_ENTRY;
-
-LIST_ENTRY DosDeviceHistory;
-RTL_CRITICAL_SECTION BaseDefineDosDeviceCritSec;
-
 VOID BaseCleanupDefineDosDevice(VOID)
 {
     PLIST_ENTRY Entry, ListHead;
     PBASE_DOS_DEVICE_HISTORY_ENTRY HistoryEntry;
 
-    (void) RtlDeleteCriticalSection(&BaseDefineDosDeviceCritSec);
+    RtlDeleteCriticalSection(&BaseDefineDosDeviceCritSec);
 
     ListHead = &DosDeviceHistory;
     Entry = ListHead->Flink;
@@ -314,20 +53,26 @@ VOID BaseCleanupDefineDosDevice(VOID)
         if (HistoryEntry)
         {
             if (HistoryEntry->Target.Buffer)
-                (void) RtlFreeHeap(BaseSrvHeap,
-                                   0,
-                                   HistoryEntry->Target.Buffer);
+            {
+                RtlFreeHeap(BaseSrvHeap,
+                            0,
+                            HistoryEntry->Target.Buffer);
+            }
             if (HistoryEntry->Device.Buffer)
-                (void) RtlFreeHeap(BaseSrvHeap,
-                                   0,
-                                   HistoryEntry->Device.Buffer);
-            (void) RtlFreeHeap(BaseSrvHeap,
-                               0,
-                               HistoryEntry);
+            {
+                RtlFreeHeap(BaseSrvHeap,
+                            0,
+                            HistoryEntry->Device.Buffer);
+            }
+            RtlFreeHeap(BaseSrvHeap,
+                        0,
+                        HistoryEntry);
         }
     }
 }
 
+/* PUBLIC SERVER APIS *********************************************************/
+
 CSR_API(BaseSrvDefineDosDevice)
 {
     NTSTATUS Status;
@@ -369,13 +114,13 @@ CSR_API(BaseSrvDefineDosDevice)
     /* Validate the flags */
     if ( (dwFlags & 0xFFFFFFF0) ||
         ((dwFlags & DDD_EXACT_MATCH_ON_REMOVE) &&
-            ! (dwFlags & DDD_REMOVE_DEFINITION)) )
+            !(dwFlags & DDD_REMOVE_DEFINITION)) )
     {
         return STATUS_INVALID_PARAMETER;
     }
 
     Status = RtlEnterCriticalSection(&BaseDefineDosDeviceCritSec);
-    if (! NT_SUCCESS(Status))
+    if (!NT_SUCCESS(Status))
     {
         DPRINT1("RtlEnterCriticalSection() failed (Status %lx)\n",
                 Status);
@@ -388,14 +133,14 @@ CSR_API(BaseSrvDefineDosDevice)
             RtlUpcaseUnicodeString(&RequestDeviceName,
                                    &DefineDosDeviceRequest->DeviceName,
                                    TRUE);
-        if (! NT_SUCCESS(Status))
+        if (!NT_SUCCESS(Status))
             _SEH2_LEAVE;
 
         RequestLinkTarget = &DefineDosDeviceRequest->TargetName;
         lpBuffer = (PWSTR) RtlAllocateHeap(BaseSrvHeap,
                                            HEAP_ZERO_MEMORY,
                                            RequestDeviceName.MaximumLength + 5 * sizeof(WCHAR));
-        if (! lpBuffer)
+        if (!lpBuffer)
         {
             DPRINT1("Failed to allocate memory\n");
             Status = STATUS_NO_MEMORY;
@@ -420,7 +165,7 @@ CSR_API(BaseSrvDefineDosDevice)
             Status = NtQuerySymbolicLinkObject(LinkHandle,
                                                &LinkTarget,
                                                &Length);
-            if (! NT_SUCCESS(Status) &&
+            if (!NT_SUCCESS(Status) &&
                 Status == STATUS_BUFFER_TOO_SMALL)
             {
                 LinkTarget.Length = 0;
@@ -429,7 +174,7 @@ CSR_API(BaseSrvDefineDosDevice)
                     RtlAllocateHeap(BaseSrvHeap,
                                     HEAP_ZERO_MEMORY,
                                     Length);
-                if (! LinkTarget.Buffer)
+                if (!LinkTarget.Buffer)
                 {
                     DPRINT1("Failed to allocate memory\n");
                     Status = STATUS_NO_MEMORY;
@@ -441,7 +186,7 @@ CSR_API(BaseSrvDefineDosDevice)
                                                    &Length);
             }
 
-            if (! NT_SUCCESS(Status))
+            if (!NT_SUCCESS(Status))
             {
                 DPRINT1("NtQuerySymbolicLinkObject(%wZ) failed (Status %lx)\n",
                      &DeviceName, Status);
@@ -456,9 +201,9 @@ CSR_API(BaseSrvDefineDosDevice)
                 else
                 {
                     if (dwFlags & DDD_EXACT_MATCH_ON_REMOVE)
-                        Matched = ! RtlCompareUnicodeString(RequestLinkTarget,
-                                                            &LinkTarget,
-                                                            TRUE);
+                        Matched = !RtlCompareUnicodeString(RequestLinkTarget,
+                                                           &LinkTarget,
+                                                           TRUE);
                     else
                         Matched = RtlPrefixUnicodeString(RequestLinkTarget,
                                                          &LinkTarget,
@@ -470,10 +215,12 @@ CSR_API(BaseSrvDefineDosDevice)
                     /* Current symlink target macthed and there is nothing to revert to */
                     RequestLinkTarget = NULL;
                 }
-                else if (Matched && ! IsListEmpty(ListHead))
+                else if (Matched && !IsListEmpty(ListHead))
                 {
-                    /* Fetch the first history entry we come across for the device name */
-                    /* This will become the current symlink target for the device name */
+                    /*
+                     * Fetch the first history entry we come across for the device name.
+                     * This will become the current symlink target for the device name.
+                     */
                     Matched = FALSE;
                     Entry = ListHead->Flink;
                     while (Entry != ListHead)
@@ -483,9 +230,9 @@ CSR_API(BaseSrvDefineDosDevice)
                                               BASE_DOS_DEVICE_HISTORY_ENTRY,
                                               Entry);
                         Matched =
-                            ! RtlCompareUnicodeString(&RequestDeviceName,
-                                                      &HistoryEntry->Device,
-                                                      FALSE);
+                            !RtlCompareUnicodeString(&RequestDeviceName,
+                                                     &HistoryEntry->Device,
+                                                     FALSE);
                         if (Matched)
                         {
                             RemoveEntryList(&HistoryEntry->Entry);
@@ -497,13 +244,15 @@ CSR_API(BaseSrvDefineDosDevice)
                     }
 
                     /* Nothing to revert to so delete the symlink */
-                    if (! Matched)
+                    if (!Matched)
                         RequestLinkTarget = NULL;
                 }
-                else if (! Matched)
+                else if (!Matched)
                 {
-                    /* Locate a previous symlink target as we did not get a hit earlier */
-                    /* If we find one we need to remove it */
+                    /*
+                     * Locate a previous symlink target as we did not get
+                     * a hit earlier. If we find one we need to remove it.
+                     */
                     Entry = ListHead->Flink;
                     while (Entry != ListHead)
                     {
@@ -512,10 +261,10 @@ CSR_API(BaseSrvDefineDosDevice)
                                               BASE_DOS_DEVICE_HISTORY_ENTRY,
                                               Entry);
                         Matched =
-                            ! RtlCompareUnicodeString(&RequestDeviceName,
-                                                      &HistoryEntry->Device,
-                                                      FALSE);
-                        if (! Matched)
+                            !RtlCompareUnicodeString(&RequestDeviceName,
+                                                     &HistoryEntry->Device,
+                                                     FALSE);
+                        if (!Matched)
                         {
                             HistoryEntry = NULL;
                             Entry = Entry->Flink;
@@ -525,9 +274,9 @@ CSR_API(BaseSrvDefineDosDevice)
                         Matched = FALSE;
                         if (dwFlags & DDD_EXACT_MATCH_ON_REMOVE)
                         {
-                            if (! RtlCompareUnicodeString(RequestLinkTarget,
-                                                          &HistoryEntry->Target,
-                                                          TRUE))
+                            if (!RtlCompareUnicodeString(RequestLinkTarget,
+                                                         &HistoryEntry->Target,
+                                                         TRUE))
                             {
                                 Matched = TRUE;
                             }
@@ -549,7 +298,7 @@ CSR_API(BaseSrvDefineDosDevice)
                     }
 
                     /* Leave existing symlink as is */
-                    if (! Matched)
+                    if (!Matched)
                         Status = STATUS_OBJECT_NAME_NOT_FOUND;
                     else
                         Status = STATUS_SUCCESS;
@@ -562,7 +311,7 @@ CSR_API(BaseSrvDefineDosDevice)
             }
 
             Status = NtMakeTemporaryObject(LinkHandle);
-            if (! NT_SUCCESS(Status))
+            if (!NT_SUCCESS(Status))
             {
                 DPRINT1("NtMakeTemporaryObject(%wZ) failed (Status %lx)\n",
                      &DeviceName, Status);
@@ -571,7 +320,7 @@ CSR_API(BaseSrvDefineDosDevice)
 
             Status = NtClose(LinkHandle);
             LinkHandle = NULL;
-            if (! NT_SUCCESS(Status))
+            if (!NT_SUCCESS(Status))
             {
                 DPRINT1("NtClose(%wZ) failed (Status %lx)\n",
                      &DeviceName, Status);
@@ -580,7 +329,7 @@ CSR_API(BaseSrvDefineDosDevice)
         }
 
         /* Don't create symlink if we don't have a target */
-        if (! RequestLinkTarget || RequestLinkTarget->Length == 0)
+        if (!RequestLinkTarget || RequestLinkTarget->Length == 0)
             _SEH2_LEAVE;
 
         if (AddHistory)
@@ -589,7 +338,7 @@ CSR_API(BaseSrvDefineDosDevice)
                 RtlAllocateHeap(BaseSrvHeap,
                                 HEAP_ZERO_MEMORY,
                                 sizeof(BASE_DOS_DEVICE_HISTORY_ENTRY));
-            if (! HistoryEntry)
+            if (!HistoryEntry)
             {
                 DPRINT1("Failed to allocate memory\n");
                 Status = STATUS_NO_MEMORY;
@@ -600,7 +349,7 @@ CSR_API(BaseSrvDefineDosDevice)
                 RtlAllocateHeap(BaseSrvHeap,
                                 HEAP_ZERO_MEMORY,
                                 LinkTarget.Length);
-            if (! HistoryEntry->Target.Buffer)
+            if (!HistoryEntry->Target.Buffer)
             {
                 DPRINT1("Failed to allocate memory\n");
                 Status = STATUS_NO_MEMORY;
@@ -616,7 +365,7 @@ CSR_API(BaseSrvDefineDosDevice)
                 RtlAllocateHeap(BaseSrvHeap,
                                 HEAP_ZERO_MEMORY,
                                 RequestDeviceName.Length);
-            if (! HistoryEntry->Device.Buffer)
+            if (!HistoryEntry->Device.Buffer)
             {
                 DPRINT1("Failed to allocate memory\n");
                 Status = STATUS_NO_MEMORY;
@@ -678,7 +427,7 @@ CSR_API(BaseSrvDefineDosDevice)
         SecurityDescriptor = RtlAllocateHeap(BaseSrvHeap,
                                              0,
                                              SECURITY_DESCRIPTOR_MIN_LENGTH + Length);
-        if (! SecurityDescriptor)
+        if (!SecurityDescriptor)
         {
             DPRINT1("Failed to allocate memory\n");
             Status = STATUS_NO_MEMORY;
@@ -688,44 +437,41 @@ CSR_API(BaseSrvDefineDosDevice)
         Dacl = (PACL)((ULONG_PTR)SecurityDescriptor + SECURITY_DESCRIPTOR_MIN_LENGTH);
         Status = RtlCreateSecurityDescriptor(SecurityDescriptor,
                                              SECURITY_DESCRIPTOR_REVISION);
-        if (! NT_SUCCESS(Status))
+        if (!NT_SUCCESS(Status))
         {
-            DPRINT1("RtlCreateSecurityDescriptor() failed (Status %lx)\n",
-                 Status);
+            DPRINT1("RtlCreateSecurityDescriptor() failed (Status %lx)\n", Status);
             _SEH2_LEAVE;
         }
 
         Status = RtlCreateAcl(Dacl,
                               Length,
                               ACL_REVISION);
-        if (! NT_SUCCESS(Status))
+        if (!NT_SUCCESS(Status))
         {
-            DPRINT1("RtlCreateAcl() failed (Status %lx)\n",
-                 Status);
+            DPRINT1("RtlCreateAcl() failed (Status %lx)\n", Status);
             _SEH2_LEAVE;
         }
 
-        (void) RtlAddAccessAllowedAce(Dacl,
-                                      ACL_REVISION,
-                                      GENERIC_ALL,
-                                      SystemSid);
-        (void) RtlAddAccessAllowedAce(Dacl,
-                                      ACL_REVISION,
-                                      GENERIC_ALL,
-                                      AdminSid);
-        (void) RtlAddAccessAllowedAce(Dacl,
-                                      ACL_REVISION,
-                                      STANDARD_RIGHTS_READ,
-                                      WorldSid);
+        RtlAddAccessAllowedAce(Dacl,
+                               ACL_REVISION,
+                               GENERIC_ALL,
+                               SystemSid);
+        RtlAddAccessAllowedAce(Dacl,
+                               ACL_REVISION,
+                               GENERIC_ALL,
+                               AdminSid);
+        RtlAddAccessAllowedAce(Dacl,
+                               ACL_REVISION,
+                               STANDARD_RIGHTS_READ,
+                               WorldSid);
 
         Status = RtlSetDaclSecurityDescriptor(SecurityDescriptor,
                                               TRUE,
                                               Dacl,
                                               FALSE);
-        if (! NT_SUCCESS(Status))
+        if (!NT_SUCCESS(Status))
         {
-            DPRINT1("RtlSetDaclSecurityDescriptor() failed (Status %lx)\n",
-                 Status);
+            DPRINT1("RtlSetDaclSecurityDescriptor() failed (Status %lx)\n", Status);
             _SEH2_LEAVE;
         }
 
@@ -741,10 +487,10 @@ CSR_API(BaseSrvDefineDosDevice)
         if (NT_SUCCESS(Status))
         {
             Status = NtMakePermanentObject(LinkHandle);
-            if (! NT_SUCCESS(Status))
+            if (!NT_SUCCESS(Status))
             {
                 DPRINT1("NtMakePermanentObject(%wZ) failed (Status %lx)\n",
-                     &DeviceName, Status);
+                        &DeviceName, Status);
             }
         }
         else
@@ -755,41 +501,50 @@ CSR_API(BaseSrvDefineDosDevice)
     }
     _SEH2_FINALLY
     {
-        (void) RtlLeaveCriticalSection(&BaseDefineDosDeviceCritSec);
+        RtlLeaveCriticalSection(&BaseDefineDosDeviceCritSec);
         if (DeviceName.Buffer)
-            (void) RtlFreeHeap(BaseSrvHeap,
-                               0,
-                               DeviceName.Buffer);
+        {
+            RtlFreeHeap(BaseSrvHeap,
+                        0,
+                        DeviceName.Buffer);
+        }
         if (LinkTarget.Buffer)
-            (void) RtlFreeHeap(BaseSrvHeap,
-                               0,
-                               LinkTarget.Buffer);
+        {
+            RtlFreeHeap(BaseSrvHeap,
+                        0,
+                        LinkTarget.Buffer);
+        }
         if (SecurityDescriptor)
-            (void) RtlFreeHeap(BaseSrvHeap,
-                               0,
-                               SecurityDescriptor);
-        if (LinkHandle)
-            (void) NtClose(LinkHandle);
-        if (SystemSid)
-            (void) RtlFreeSid(SystemSid);
-        if (AdminSid)
-            (void) RtlFreeSid(AdminSid);
-        if (WorldSid)
-            (void) RtlFreeSid(WorldSid);
+        {
+            RtlFreeHeap(BaseSrvHeap,
+                        0,
+                        SecurityDescriptor);
+        }
+
+        if (LinkHandle) NtClose(LinkHandle);
+        if (SystemSid)  RtlFreeSid(SystemSid);
+        if (AdminSid)   RtlFreeSid(AdminSid);
+        if (WorldSid)   RtlFreeSid(WorldSid);
+
         RtlFreeUnicodeString(&RequestDeviceName);
+
         if (HistoryEntry)
         {
             if (HistoryEntry->Target.Buffer)
-                (void) RtlFreeHeap(BaseSrvHeap,
-                                   0,
-                                   HistoryEntry->Target.Buffer);
+            {
+                RtlFreeHeap(BaseSrvHeap,
+                            0,
+                            HistoryEntry->Target.Buffer);
+            }
             if (HistoryEntry->Device.Buffer)
-                (void) RtlFreeHeap(BaseSrvHeap,
-                                   0,
-                                   HistoryEntry->Device.Buffer);
-            (void) RtlFreeHeap(BaseSrvHeap,
-                               0,
-                               HistoryEntry);
+            {
+                RtlFreeHeap(BaseSrvHeap,
+                            0,
+                            HistoryEntry->Device.Buffer);
+            }
+            RtlFreeHeap(BaseSrvHeap,
+                        0,
+                        HistoryEntry);
         }
     }
     _SEH2_END
@@ -798,17 +553,4 @@ CSR_API(BaseSrvDefineDosDevice)
     return Status;
 }
 
-
-
-
-
-
-/* PUBLIC API *****************************************************************/
-
-NTSTATUS NTAPI BaseSetProcessCreateNotify(IN BASE_PROCESS_CREATE_NOTIFY_ROUTINE ProcessCreateNotifyProc)
-{
-    DPRINT("BASESRV: %s(%08lx) called\n", __FUNCTION__, ProcessCreateNotifyProc);
-    return STATUS_NOT_IMPLEMENTED;
-}
-
 /* EOF */
index 9ec433b..2b0e9ae 100644 (file)
@@ -6,25 +6,23 @@
  * PROGRAMMERS:     Hermes Belusca-Maito (hermes.belusca@sfr.fr)
  */
 
+/* INCLUDES *******************************************************************/
+
 #include "basesrv.h"
 
 #define NDEBUG
 #include <debug.h>
 
-HANDLE DllHandle = NULL;
-HANDLE BaseApiPort = NULL;
+/* GLOBALS ********************************************************************/
+
+HANDLE BaseSrvDllInstance = NULL;
 
 /* Memory */
 HANDLE BaseSrvHeap = NULL;          // Our own heap.
 HANDLE BaseSrvSharedHeap = NULL;    // Shared heap with CSR. (CsrSrvSharedSectionHeap)
 PBASE_STATIC_SERVER_DATA BaseStaticServerData = NULL;   // Data that we can share amongst processes. Initialized inside BaseSrvSharedHeap.
 
-extern LIST_ENTRY DosDeviceHistory;
-extern RTL_CRITICAL_SECTION BaseDefineDosDeviceCritSec;
-
-// Windows NT 4 tables, adapted from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_NT
-// It is for testing purposes. After that I will update it to 2k3 version and add stubs.
-// Some names are also deduced from the subsystems/win32/csrss/csrsrv/server.c ones.
+// Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
 PCSR_API_ROUTINE BaseServerApiDispatchTable[BasepMaxApiNumber] =
 {
     BaseSrvCreateProcess,
@@ -43,45 +41,54 @@ PCSR_API_ROUTINE BaseServerApiDispatchTable[BasepMaxApiNumber] =
     BaseSrvGetProcessShutdownParam,
     // BaseSrvNlsSetUserInfo,
     // BaseSrvNlsSetMultipleUserInfo,
-    // BaseSrvNlsCreateSortSection,
-    // BaseSrvNlsPreserveSection,
+    // BaseSrvNlsCreateSection,
     // BaseSrvSetVDMCurDirs,
     // BaseSrvGetVDMCurDirs,
     // BaseSrvBatNotification,
     // BaseSrvRegisterWowExec,
     BaseSrvSoundSentryNotification,
     // BaseSrvRefreshIniFileMapping,
-    BaseSrvDefineDosDevice
+    BaseSrvDefineDosDevice,
+    // BaseSrvSetTermsrvAppInstallMode,
+    // BaseSrvNlsUpdateCacheCount,
+    // BaseSrvSetTermsrvClientTimeZone,
+    // BaseSrvSxsCreateActivationContext,
+    // BaseSrvRegisterThread,
+    // BaseSrvNlsGetUserInfo,
 };
 
 BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber] =
 {
-    TRUE,    // SrvCreateProcess,
-    TRUE,    // SrvCreateThread,
-    TRUE,    // SrvGetTempFile,
-    FALSE,   // SrvExitProcess,
-    // FALSE,   // SrvDebugProcess,
-    // TRUE,    // SrvCheckVDM,
-    // TRUE,    // SrvUpdateVDMEntry
-    // TRUE,    // SrvGetNextVDMCommand
-    // TRUE,    // SrvExitVDM
-    // TRUE,    // SrvIsFirstVDM
-    // TRUE,    // SrvGetVDMExitCode
-    // TRUE,    // SrvSetReenterCount
-    TRUE,    // SrvSetProcessShutdownParam
-    TRUE,    // SrvGetProcessShutdownParam
-    // TRUE,    // SrvNlsSetUserInfo
-    // TRUE,    // SrvNlsSetMultipleUserInfo
-    // TRUE,    // SrvNlsCreateSortSection
-    // TRUE,    // SrvNlsPreserveSection
-    // TRUE,    // SrvSetVDMCurDirs
-    // TRUE,    // SrvGetVDMCurDirs
-    // TRUE,    // SrvBatNotification
-    // TRUE,    // SrvRegisterWowExec
-    TRUE,    // SrvSoundSentryNotification
-    // TRUE,    // SrvRefreshIniFileMapping
-    TRUE,    // SrvDefineDosDevice
-    // FALSE
+    TRUE,   // BaseSrvCreateProcess
+    TRUE,   // BaseSrvCreateThread
+    TRUE,   // BaseSrvGetTempFile
+    FALSE,  // BaseSrvExitProcess
+    // FALSE,  // BaseSrvDebugProcess
+    // TRUE,   // BaseSrvCheckVDM
+    // TRUE,   // BaseSrvUpdateVDMEntry
+    // TRUE,   // BaseSrvGetNextVDMCommand
+    // TRUE,   // BaseSrvExitVDM
+    // TRUE,   // BaseSrvIsFirstVDM
+    // TRUE,   // BaseSrvGetVDMExitCode
+    // TRUE,   // BaseSrvSetReenterCount
+    TRUE,   // BaseSrvSetProcessShutdownParam
+    TRUE,   // BaseSrvGetProcessShutdownParam
+    // TRUE,   // BaseSrvNlsSetUserInfo
+    // TRUE,   // BaseSrvNlsSetMultipleUserInfo
+    // TRUE,   // BaseSrvNlsCreateSection
+    // TRUE,   // BaseSrvSetVDMCurDirs
+    // TRUE,   // BaseSrvGetVDMCurDirs
+    // TRUE,   // BaseSrvBatNotification
+    // TRUE,   // BaseSrvRegisterWowExec
+    TRUE,   // BaseSrvSoundSentryNotification
+    // TRUE,   // BaseSrvRefreshIniFileMapping
+    TRUE,   // BaseSrvDefineDosDevice
+    // FALSE,  // BaseSrvSetTermsrvAppInstallMode
+    // FALSE,  // BaseSrvNlsUpdateCacheCount
+    // FALSE,  // BaseSrvSetTermsrvClientTimeZone
+    // FALSE,  // BaseSrvSxsCreateActivationContext
+    // FALSE,  // BaseSrvRegisterThread
+    // FALSE,  // BaseSrvNlsGetUserInfo
 };
 
 PCHAR BaseServerApiNameTable[BasepMaxApiNumber] =
@@ -102,16 +109,20 @@ PCHAR BaseServerApiNameTable[BasepMaxApiNumber] =
     "BaseGetProcessShutdownParam",
     // "BaseNlsSetUserInfo",
     // "BaseNlsSetMultipleUserInfo",
-    // "BaseNlsCreateSortSection",
-    // "BaseNlsPreserveSection",
+    // "BaseNlsCreateSection",
     // "BaseSetVDMCurDirs",
     // "BaseGetVDMCurDirs",
     // "BaseBatNotification",
     // "BaseRegisterWowExec",
     "BaseSoundSentryNotification",
-    // "BaseSrvRefreshIniFileMapping"
+    // "BaseRefreshIniFileMapping",
     "BaseDefineDosDevice",
-    // NULL
+    // "BaseSetTermsrvAppInstallMode",
+    // "BaseNlsUpdateCacheCount",
+    // "BaseSetTermsrvClientTimeZone",
+    // "BaseSxsCreateActivationContext",
+    // "BaseRegisterThread",
+    // "BaseNlsGetUserInfo",
 };
 
 
@@ -269,8 +280,8 @@ BaseInitializeStaticServerData(IN PCSR_SERVER_DLL LoadedServerDll)
         {0}
     };
 
-    /* Initialize memory */
-    BaseSrvHeap = RtlGetProcessHeap();  // Initialize our own heap.
+    /* Initialize the memory */
+    BaseSrvHeap = RtlGetProcessHeap();                  // Initialize our own heap.
     BaseSrvSharedHeap = LoadedServerDll->SharedSection; // Get the CSR shared heap.
 
     /* Get the session ID */
@@ -505,45 +516,8 @@ BaseInitializeStaticServerData(IN PCSR_SERVER_DLL LoadedServerDll)
     LoadedServerDll->SharedSection = BaseStaticServerData;
 }
 
-/*
-VOID WINAPI BaseStaticServerThread(PVOID x)
-{
-    // NTSTATUS Status = STATUS_SUCCESS;
-    PPORT_MESSAGE Request = (PPORT_MESSAGE)x;
-    PPORT_MESSAGE Reply = NULL;
-    ULONG MessageType = 0;
-
-    DPRINT("BASESRV: %s called\n", __FUNCTION__);
-
-    MessageType = Request->u2.s2.Type;
-    DPRINT("BASESRV: %s received a message (Type=%d)\n",
-           __FUNCTION__, MessageType);
-    switch (MessageType)
-    {
-        default:
-            Reply = Request;
-            /\* Status =*\/ NtReplyPort(BaseApiPort, Reply);
-            break;
-    }
-}
-*/
-
 CSR_SERVER_DLL_INIT(ServerDllInitialization)
 {
-    // NTSTATUS Status = STATUS_SUCCESS;
-
-/*
-    DPRINT("BASSRV: %s(%ld,...) called\n", __FUNCTION__, ArgumentCount);
-
-    BaseApiPort = CsrQueryApiPort ();
-    Status = CsrAddStaticServerThread(BaseStaticServerThread);
-    if (NT_SUCCESS(Status))
-    {
-        //TODO initialize the BASE server
-    }
-    return STATUS_SUCCESS;
-*/
-
     /* Setup the DLL Object */
     LoadedServerDll->ApiBase = BASESRV_FIRST_API_NUMBER; // ApiNumberBase
     LoadedServerDll->HighestApiSupported = BasepMaxApiNumber; // MaxApiNumber
@@ -553,10 +527,14 @@ CSR_SERVER_DLL_INIT(ServerDllInitialization)
     LoadedServerDll->SizeOfProcessData = 0;
     LoadedServerDll->ConnectCallback = NULL;
     LoadedServerDll->DisconnectCallback = NULL;
+    LoadedServerDll->ShutdownProcessCallback = NULL;
+
+    BaseSrvDllInstance = LoadedServerDll->ServerHandle;
+
     BaseInitializeStaticServerData(LoadedServerDll);
 
-    RtlInitializeCriticalSection(&BaseDefineDosDeviceCritSec);
-    InitializeListHead(&DosDeviceHistory);
+    /* Initialize DOS devices management */
+    BaseInitDefineDosDevice();
 
     /* All done */
     return STATUS_SUCCESS;
@@ -568,14 +546,11 @@ DllMain(IN HINSTANCE hInstanceDll,
         IN DWORD dwReason,
         IN LPVOID lpReserved)
 {
+    UNREFERENCED_PARAMETER(hInstanceDll);
     UNREFERENCED_PARAMETER(dwReason);
     UNREFERENCED_PARAMETER(lpReserved);
 
-    if (DLL_PROCESS_ATTACH == dwReason)
-    {
-        DllHandle = hInstanceDll;
-    }
-    else if (DLL_PROCESS_DETACH == dwReason)
+    if (DLL_PROCESS_DETACH == dwReason)
     {
         BaseCleanupDefineDosDevice();
     }
diff --git a/subsystems/win/basesrv/proc.c b/subsystems/win/basesrv/proc.c
new file mode 100644 (file)
index 0000000..41a0dea
--- /dev/null
@@ -0,0 +1,246 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS/Win32 Base enviroment Subsystem Server
+ * FILE:            subsystems/win/basesrv/proc.c
+ * PURPOSE:         Process and Thread Management
+ * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
+ */
+
+/* INCLUDES *******************************************************************/
+
+#include "basesrv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+/* PUBLIC SERVER APIS *********************************************************/
+
+CSR_API(BaseSrvGetTempFile)
+{
+    static UINT CsrGetTempFileUnique = 0;
+    PBASE_GET_TEMP_FILE GetTempFile = &((PBASE_API_MESSAGE)ApiMessage)->Data.GetTempFile;
+
+    /* Return 16-bits ID */
+    GetTempFile->UniqueID = (++CsrGetTempFileUnique & 0xFFFF);
+
+    DPRINT("Returning: %u\n", GetTempFile->UniqueID);
+
+    return STATUS_SUCCESS;
+}
+
+CSR_API(BaseSrvCreateProcess)
+{
+    NTSTATUS Status;
+    PBASE_CREATE_PROCESS CreateProcessRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.CreateProcessRequest;
+    HANDLE ProcessHandle, ThreadHandle;
+    PCSR_THREAD CsrThread;
+    PCSR_PROCESS Process;
+    ULONG Flags = 0, VdmPower = 0, DebugFlags = 0;
+
+    /* Get the current client thread */
+    CsrThread = CsrGetClientThread();
+    ASSERT(CsrThread != NULL);
+
+    Process = CsrThread->Process;
+
+    /* Extract the flags out of the process handle */
+    Flags = (ULONG_PTR)CreateProcessRequest->ProcessHandle & 3;
+    CreateProcessRequest->ProcessHandle = (HANDLE)((ULONG_PTR)CreateProcessRequest->ProcessHandle & ~3);
+
+    /* Duplicate the process handle */
+    Status = NtDuplicateObject(Process->ProcessHandle,
+                               CreateProcessRequest->ProcessHandle,
+                               NtCurrentProcess(),
+                               &ProcessHandle,
+                               0,
+                               0,
+                               DUPLICATE_SAME_ACCESS);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to duplicate process handle\n");
+        return Status;
+    }
+
+    /* Duplicate the thread handle */
+    Status = NtDuplicateObject(Process->ProcessHandle,
+                               CreateProcessRequest->ThreadHandle,
+                               NtCurrentProcess(),
+                               &ThreadHandle,
+                               0,
+                               0,
+                               DUPLICATE_SAME_ACCESS);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to duplicate process handle\n");
+        NtClose(ProcessHandle);
+        return Status;
+    }
+
+    /* See if this is a VDM process */
+    if (VdmPower)
+    {
+        /* Request VDM powers */
+        Status = NtSetInformationProcess(ProcessHandle,
+                                         ProcessWx86Information,
+                                         &VdmPower,
+                                         sizeof(VdmPower));
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT1("Failed to get VDM powers\n");
+            NtClose(ProcessHandle);
+            NtClose(ThreadHandle);
+            return Status;
+        }
+    }
+
+    /* Flags conversion. FIXME: More need conversion */
+    if (CreateProcessRequest->CreationFlags & CREATE_NEW_PROCESS_GROUP)
+    {
+        DebugFlags |= CsrProcessCreateNewGroup;
+    }
+    if ((Flags & 2) == 0)
+    {
+        /* We are launching a console process */
+        DebugFlags |= CsrProcessIsConsoleApp;
+    }
+
+    /* FIXME: SxS Stuff */
+
+    /* Call CSRSRV to create the CSR_PROCESS structure and the first CSR_THREAD */
+    Status = CsrCreateProcess(ProcessHandle,
+                              ThreadHandle,
+                              &CreateProcessRequest->ClientId,
+                              Process->NtSession,
+                              DebugFlags,
+                              NULL);
+    if (Status == STATUS_THREAD_IS_TERMINATING)
+    {
+        DPRINT1("Thread already dead\n");
+
+        /* Set the special reply value so we don't reply this message back */
+        *ReplyCode = CsrReplyDeadClient;
+
+        return Status;
+    }
+
+    /* Check for other failures */
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to create process/thread structures: %lx\n", Status);
+        return Status;
+    }
+
+    /* FIXME: Should notify user32 */
+
+    /* FIXME: VDM vodoo */
+
+    /* Return the result of this operation */
+    return Status;
+}
+
+CSR_API(BaseSrvCreateThread)
+{
+    NTSTATUS Status;
+    PBASE_CREATE_THREAD CreateThreadRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.CreateThreadRequest;
+    PCSR_THREAD CurrentThread;
+    HANDLE ThreadHandle;
+    PCSR_PROCESS CsrProcess;
+
+    /* Get the current CSR thread */
+    CurrentThread = CsrGetClientThread();
+    if (!CurrentThread)
+    {
+        DPRINT1("Server Thread TID: [%lx.%lx]\n",
+                CreateThreadRequest->ClientId.UniqueProcess,
+                CreateThreadRequest->ClientId.UniqueThread);
+        return STATUS_SUCCESS; // server-to-server
+    }
+
+    /* Get the CSR Process for this request */
+    CsrProcess = CurrentThread->Process;
+    if (CsrProcess->ClientId.UniqueProcess !=
+        CreateThreadRequest->ClientId.UniqueProcess)
+    {
+        /* This is a remote thread request -- is it within the server itself? */
+        if (CreateThreadRequest->ClientId.UniqueProcess == NtCurrentTeb()->ClientId.UniqueProcess)
+        {
+            /* Accept this without any further work */
+            return STATUS_SUCCESS;
+        }
+
+        /* Get the real CSR Process for the remote thread's process */
+        Status = CsrLockProcessByClientId(CreateThreadRequest->ClientId.UniqueProcess,
+                                          &CsrProcess);
+        if (!NT_SUCCESS(Status)) return Status;
+    }
+
+    /* Duplicate the thread handle so we can own it */
+    Status = NtDuplicateObject(CurrentThread->Process->ProcessHandle,
+                               CreateThreadRequest->ThreadHandle,
+                               NtCurrentProcess(),
+                               &ThreadHandle,
+                               0,
+                               0,
+                               DUPLICATE_SAME_ACCESS);
+    if (NT_SUCCESS(Status))
+    {
+        /* Call CSRSRV to tell it about the new thread */
+        Status = CsrCreateThread(CsrProcess,
+                                 ThreadHandle,
+                                 &CreateThreadRequest->ClientId,
+                                 TRUE);
+    }
+
+    /* Unlock the process and return */
+    if (CsrProcess != CurrentThread->Process) CsrUnlockProcess(CsrProcess);
+    return Status;
+}
+
+CSR_API(BaseSrvExitProcess)
+{
+    PCSR_THREAD CsrThread = CsrGetClientThread();
+    ASSERT(CsrThread != NULL);
+
+    /* Set the special reply value so we don't reply this message back */
+    *ReplyCode = CsrReplyDeadClient;
+
+    /* Remove the CSR_THREADs and CSR_PROCESS */
+    return CsrDestroyProcess(&CsrThread->ClientId,
+                             (NTSTATUS)((PBASE_API_MESSAGE)ApiMessage)->Data.ExitProcessRequest.uExitCode);
+}
+
+CSR_API(BaseSrvGetProcessShutdownParam)
+{
+    PBASE_GET_PROCESS_SHUTDOWN_PARAMS GetShutdownParametersRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.GetShutdownParametersRequest;
+    PCSR_THREAD CsrThread = CsrGetClientThread();
+    ASSERT(CsrThread);
+
+    GetShutdownParametersRequest->Level = CsrThread->Process->ShutdownLevel;
+    GetShutdownParametersRequest->Flags = CsrThread->Process->ShutdownFlags;
+
+    return STATUS_SUCCESS;
+}
+
+CSR_API(BaseSrvSetProcessShutdownParam)
+{
+    PBASE_SET_PROCESS_SHUTDOWN_PARAMS SetShutdownParametersRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.SetShutdownParametersRequest;
+    PCSR_THREAD CsrThread = CsrGetClientThread();
+    ASSERT(CsrThread);
+
+    CsrThread->Process->ShutdownLevel = SetShutdownParametersRequest->Level;
+    CsrThread->Process->ShutdownFlags = SetShutdownParametersRequest->Flags;
+
+    return STATUS_SUCCESS;
+}
+
+/* PUBLIC API *****************************************************************/
+
+NTSTATUS
+NTAPI
+BaseSetProcessCreateNotify(IN BASE_PROCESS_CREATE_NOTIFY_ROUTINE ProcessCreateNotifyProc)
+{
+    DPRINT("BASESRV: %s(%08lx) called\n", __FUNCTION__, ProcessCreateNotifyProc);
+    return STATUS_NOT_IMPLEMENTED;
+}
+
+/* EOF */
diff --git a/subsystems/win/basesrv/sndsntry.c b/subsystems/win/basesrv/sndsntry.c
new file mode 100644 (file)
index 0000000..2e22b48
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS/Win32 Base enviroment Subsystem Server
+ * FILE:            subsystems/win/basesrv/sndsntry.c
+ * PURPOSE:         Sound Sentry Notifications
+ * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
+ */
+
+/* INCLUDES *******************************************************************/
+
+#include "basesrv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+/* GLOBALS ********************************************************************/
+
+typedef BOOL (WINAPI *PUSER_SOUND_SENTRY)(VOID);
+BOOL NTAPI FirstSoundSentry(VOID);
+
+static PUSER_SOUND_SENTRY _UserSoundSentry = FirstSoundSentry;
+
+/* PRIVATE FUNCTIONS **********************************************************/
+
+BOOL
+NTAPI
+FailSoundSentry(VOID)
+{
+    /* In case the function can't be found/is unimplemented */
+    return FALSE;
+}
+
+BOOL
+NTAPI
+FirstSoundSentry(VOID)
+{
+    UNICODE_STRING DllString = RTL_CONSTANT_STRING(L"winsrv");
+    STRING FuncString = RTL_CONSTANT_STRING("_UserSoundSentry");
+    HANDLE DllHandle;
+    NTSTATUS Status;
+    PUSER_SOUND_SENTRY NewSoundSentry = FailSoundSentry;
+
+    /* Load winsrv manually */
+    Status = LdrGetDllHandle(NULL, NULL, &DllString, &DllHandle);
+    if (NT_SUCCESS(Status))
+    {
+        /* If it was found, get SoundSentry export */
+        Status = LdrGetProcedureAddress(DllHandle,
+                                        &FuncString,
+                                        0,
+                                        (PVOID*)&NewSoundSentry);
+    }
+    
+    /* Set it as the callback for the future, and call it */
+    _UserSoundSentry = NewSoundSentry;
+    return _UserSoundSentry();
+}
+
+/* PUBLIC SERVER APIS *********************************************************/
+
+CSR_API(BaseSrvSoundSentryNotification)
+{
+    /* Call the API and see if it succeeds */
+    return (_UserSoundSentry() ? STATUS_SUCCESS : STATUS_ACCESS_DENIED);
+}
+
+/* EOF */
similarity index 98%
rename from subsystems/win32/csrsrv/include/api.h
rename to subsystems/win32/csrsrv/api.h
index a240618..a499079 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
- * FILE:            subsys/csrss/include/api.h
- * PURPOSE:         CSRSS API interface
+ * FILE:            subsystems/win32/csrsrv/api.h
+ * PURPOSE:         CSRSS Internal API
  */
 
 #pragma once
index 7d9cbc3..0f2b5a2 100644 (file)
@@ -40,7 +40,7 @@
 #include <sm/smmsg.h>
 
 /* Internal CSRSS Header */
-#include "include/api.h"
+#include "api.h"
 
 /* Defines */
 #define SM_REG_KEY \
index 41f0b1f..67c64ab 100644 (file)
@@ -46,8 +46,6 @@
 
 extern HINSTANCE ConSrvDllInstance;
 extern HANDLE ConSrvHeap;
-// extern HANDLE BaseSrvSharedHeap;
-// extern PBASE_STATIC_SERVER_DATA BaseStaticServerData;
 
 /* Object type magic numbers */
 #define CONIO_INPUT_BUFFER_MAGIC    0x00000001  // -->  Input-type handles
index 42314ce..44a4fba 100644 (file)
@@ -749,7 +749,7 @@ ConSrvConnect(IN PCSR_PROCESS CsrProcess,
 }
 
 VOID
-WINAPI
+NTAPI
 ConSrvDisconnect(PCSR_PROCESS Process)
 {
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(Process);
index f3bec2c..9feb75e 100644 (file)
@@ -6,23 +6,23 @@
  * PROGRAMMERS:     Hermes Belusca-Maito (hermes.belusca@sfr.fr)
  */
 
+/* INCLUDES *******************************************************************/
+
 #include "consrv.h"
 #include "conio.h"
 
 #define NDEBUG
 #include <debug.h>
 
+/* GLOBALS ********************************************************************/
+
 HINSTANCE ConSrvDllInstance = NULL;
-// HANDLE BaseApiPort = NULL;
 
 /* Memory */
-HANDLE ConSrvHeap = NULL;          // Our own heap.
-// HANDLE BaseSrvSharedHeap = NULL;    // Shared heap with CSR. (CsrSrvSharedSectionHeap)
-// PBASE_STATIC_SERVER_DATA BaseStaticServerData = NULL;   // Data that we can share amongst processes. Initialized inside BaseSrvSharedHeap.
+HANDLE ConSrvHeap = NULL;   // Our own heap.
 
-// Windows 2k3 tables, adapted from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
-// plus a little bit of Windows 7. It is for testing purposes. After that I will add stubs.
-// Some names are also deduced from the subsystems/win32/csrss/csrsrv/server.c ones.
+// Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
+// plus a little bit of Windows 7.
 PCSR_API_ROUTINE ConsoleServerApiDispatchTable[ConsolepMaxApiNumber] =
 {
     SrvOpenConsole,
@@ -111,7 +111,7 @@ PCSR_API_ROUTINE ConsoleServerApiDispatchTable[ConsolepMaxApiNumber] =
     SrvGetConsoleSelectionInfo,
     SrvGetConsoleProcessList,
     SrvGetConsoleHistory,
-    SrvSetConsoleHistory
+    SrvSetConsoleHistory,
 };
 
 BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber] =
@@ -203,8 +203,6 @@ BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber] =
     FALSE,   // SrvGetConsoleProcessList,
     FALSE,   // SrvGetConsoleHistory,
     FALSE,   // SrvSetConsoleHistory
-
-    // FALSE
 };
 
 PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber] =
@@ -295,161 +293,16 @@ PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber] =
     "GetConsoleSelectionInfo",
     "GetConsoleProcessList",
     "GetConsoleHistory",
-    "SetConsoleHistory"
-
-    // NULL
-};
-
-
-/*
-PCSR_API_ROUTINE ConSrvApiDefinitions[] =
-{
-    CsrGetHandle,
-    CsrGetHandle,
-    CsrCloseHandle,
-    CsrVerifyHandle,
-    CsrDuplicateHandle,
-    CsrGetInputWaitHandle,
-    CsrFillOutputChar,
-    CsrReadInputEvent,
-    CsrWriteConsoleOutputChar,
-    CsrWriteConsoleOutputAttrib,
-    CsrFillOutputAttrib,
-    CsrSetTextAttrib,
-    CsrWriteConsoleOutput,
-    CsrFlushInputBuffer,
-    CsrReadConsoleOutputChar,
-    CsrReadConsoleOutputAttrib,
-    CsrExitReactos,
-    CsrHardwareStateProperty,
-    CsrCreateDesktop,
-    CsrShowDesktop,
-    CsrHideDesktop,
-    CsrSetLogonNotifyWindow,
-    CsrRegisterLogonProcess,
-    CsrGenerateCtrlEvent,
-};
-
-static CSRSS_API_DEFINITION ConSrvApiDefinitions[] =
-{
-    CSRSS_DEFINE_API(GET_INPUT_HANDLE,             CsrGetHandle),
-    CSRSS_DEFINE_API(GET_OUTPUT_HANDLE,            CsrGetHandle),
-    CSRSS_DEFINE_API(CLOSE_HANDLE,                 CsrCloseHandle),
-    CSRSS_DEFINE_API(VERIFY_HANDLE,                CsrVerifyHandle),
-    CSRSS_DEFINE_API(DUPLICATE_HANDLE,             CsrDuplicateHandle),
-    CSRSS_DEFINE_API(GET_INPUT_WAIT_HANDLE,        CsrGetInputWaitHandle),
-    CSRSS_DEFINE_API(WRITE_CONSOLE,                CsrWriteConsole),
-    CSRSS_DEFINE_API(READ_CONSOLE,                 CsrReadConsole),
-    CSRSS_DEFINE_API(ALLOC_CONSOLE,                CsrAllocConsole),
-    CSRSS_DEFINE_API(FREE_CONSOLE,                 CsrFreeConsole),
-    CSRSS_DEFINE_API(SCREEN_BUFFER_INFO,           CsrGetScreenBufferInfo),
-    CSRSS_DEFINE_API(SET_CURSOR,                   CsrSetCursor),
-    CSRSS_DEFINE_API(FILL_OUTPUT,                  CsrFillOutputChar),
-    CSRSS_DEFINE_API(READ_INPUT,                   CsrReadInputEvent),
-    CSRSS_DEFINE_API(WRITE_CONSOLE_OUTPUT_CHAR,    CsrWriteConsoleOutputChar),
-    CSRSS_DEFINE_API(WRITE_CONSOLE_OUTPUT_ATTRIB,  CsrWriteConsoleOutputAttrib),
-    CSRSS_DEFINE_API(FILL_OUTPUT_ATTRIB,           CsrFillOutputAttrib),
-    CSRSS_DEFINE_API(GET_CURSOR_INFO,              CsrGetCursorInfo),
-    CSRSS_DEFINE_API(SET_CURSOR_INFO,              CsrSetCursorInfo),
-    CSRSS_DEFINE_API(SET_ATTRIB,                   CsrSetTextAttrib),
-    CSRSS_DEFINE_API(GET_CONSOLE_MODE,             CsrGetConsoleMode),
-    CSRSS_DEFINE_API(SET_CONSOLE_MODE,             CsrSetConsoleMode),
-    CSRSS_DEFINE_API(CREATE_SCREEN_BUFFER,         CsrCreateScreenBuffer),
-    CSRSS_DEFINE_API(SET_SCREEN_BUFFER,            CsrSetScreenBuffer),
-    CSRSS_DEFINE_API(SET_TITLE,                    CsrSetTitle),
-    CSRSS_DEFINE_API(GET_TITLE,                    CsrGetTitle),
-    CSRSS_DEFINE_API(WRITE_CONSOLE_OUTPUT,         CsrWriteConsoleOutput),
-    CSRSS_DEFINE_API(FLUSH_INPUT_BUFFER,           CsrFlushInputBuffer),
-    CSRSS_DEFINE_API(SCROLL_CONSOLE_SCREEN_BUFFER, CsrScrollConsoleScreenBuffer),
-    CSRSS_DEFINE_API(READ_CONSOLE_OUTPUT_CHAR,     CsrReadConsoleOutputChar),
-    CSRSS_DEFINE_API(READ_CONSOLE_OUTPUT_ATTRIB,   CsrReadConsoleOutputAttrib),
-    CSRSS_DEFINE_API(GET_NUM_INPUT_EVENTS,         CsrGetNumberOfConsoleInputEvents),
-    CSRSS_DEFINE_API(EXIT_REACTOS,                 CsrExitReactos),
-    CSRSS_DEFINE_API(PEEK_CONSOLE_INPUT,           CsrPeekConsoleInput),
-    CSRSS_DEFINE_API(READ_CONSOLE_OUTPUT,          CsrReadConsoleOutput),
-    CSRSS_DEFINE_API(WRITE_CONSOLE_INPUT,          CsrWriteConsoleInput),
-    CSRSS_DEFINE_API(SETGET_CONSOLE_HW_STATE,      CsrHardwareStateProperty),
-    CSRSS_DEFINE_API(GET_CONSOLE_WINDOW,           CsrGetConsoleWindow),
-    CSRSS_DEFINE_API(CREATE_DESKTOP,               CsrCreateDesktop),
-    CSRSS_DEFINE_API(SHOW_DESKTOP,                 CsrShowDesktop),
-    CSRSS_DEFINE_API(HIDE_DESKTOP,                 CsrHideDesktop),
-    CSRSS_DEFINE_API(SET_CONSOLE_ICON,             CsrSetConsoleIcon),
-    CSRSS_DEFINE_API(SET_LOGON_NOTIFY_WINDOW,      CsrSetLogonNotifyWindow),
-    CSRSS_DEFINE_API(REGISTER_LOGON_PROCESS,       CsrRegisterLogonProcess),
-    CSRSS_DEFINE_API(GET_CONSOLE_CP,               CsrGetConsoleCodePage),
-    CSRSS_DEFINE_API(SET_CONSOLE_CP,               CsrSetConsoleCodePage),
-    CSRSS_DEFINE_API(GET_CONSOLE_OUTPUT_CP,        CsrGetConsoleOutputCodePage),
-    CSRSS_DEFINE_API(SET_CONSOLE_OUTPUT_CP,        CsrSetConsoleOutputCodePage),
-    CSRSS_DEFINE_API(GET_PROCESS_LIST,             CsrGetProcessList),
-    CSRSS_DEFINE_API(ADD_CONSOLE_ALIAS,      CsrAddConsoleAlias),
-    CSRSS_DEFINE_API(GET_CONSOLE_ALIAS,      CsrGetConsoleAlias),
-    CSRSS_DEFINE_API(GET_ALL_CONSOLE_ALIASES,         CsrGetAllConsoleAliases),
-    CSRSS_DEFINE_API(GET_ALL_CONSOLE_ALIASES_LENGTH,  CsrGetAllConsoleAliasesLength),
-    CSRSS_DEFINE_API(GET_CONSOLE_ALIASES_EXES,        CsrGetConsoleAliasesExes),
-    CSRSS_DEFINE_API(GET_CONSOLE_ALIASES_EXES_LENGTH, CsrGetConsoleAliasesExesLength),
-    CSRSS_DEFINE_API(GENERATE_CTRL_EVENT,          CsrGenerateCtrlEvent),
-    CSRSS_DEFINE_API(SET_SCREEN_BUFFER_SIZE,       CsrSetScreenBufferSize),
-    CSRSS_DEFINE_API(GET_CONSOLE_SELECTION_INFO,   CsrGetConsoleSelectionInfo),
-    CSRSS_DEFINE_API(GET_COMMAND_HISTORY_LENGTH,   CsrGetCommandHistoryLength),
-    CSRSS_DEFINE_API(GET_COMMAND_HISTORY,          CsrGetCommandHistory),
-    CSRSS_DEFINE_API(EXPUNGE_COMMAND_HISTORY,      CsrExpungeCommandHistory),
-    CSRSS_DEFINE_API(SET_HISTORY_NUMBER_COMMANDS,  CsrSetHistoryNumberCommands),
-    CSRSS_DEFINE_API(GET_HISTORY_INFO,             CsrGetHistoryInfo),
-    CSRSS_DEFINE_API(SET_HISTORY_INFO,             CsrSetHistoryInfo),
-    { 0, 0, NULL }
+    "SetConsoleHistory",
 };
-*/
 
 
 /* FUNCTIONS ******************************************************************/
 
-/*
-VOID WINAPI ConsoleStaticServerThread(PVOID x)
-{
-    // NTSTATUS Status = STATUS_SUCCESS;
-    PPORT_MESSAGE Request = (PPORT_MESSAGE)x;
-    PPORT_MESSAGE Reply = NULL;
-    ULONG MessageType = 0;
-
-    DPRINT("BASESRV: %s called\n", __FUNCTION__);
-
-    MessageType = Request->u2.s2.Type;
-    DPRINT("BASESRV: %s received a message (Type=%d)\n",
-           __FUNCTION__, MessageType);
-    switch (MessageType)
-    {
-        default:
-            Reply = Request;
-            /\* Status = *\/ NtReplyPort(BaseApiPort, Reply);
-            break;
-    }
-}
-*/
-
 CSR_SERVER_DLL_INIT(ConServerDllInitialization)
 {
-/*
-    NTSTATUS Status = STATUS_SUCCESS;
-
-    DPRINT("BASSRV: %s(%ld,...) called\n", __FUNCTION__, ArgumentCount);
-
-    // Get the listening port from csrsrv.dll
-    BaseApiPort = CsrQueryApiPort();
-    if (BaseApiPort == NULL) return STATUS_UNSUCCESSFUL;
-
-    // Register our message dispatcher
-    Status = CsrAddStaticServerThread(ConsoleStaticServerThread);
-    if (NT_SUCCESS(Status))
-    {
-        //TODO initialize the BASE server
-    }
-    return STATUS_SUCCESS;
-*/
-
-    /* Initialize memory */
-    ConSrvHeap = RtlGetProcessHeap();  // Initialize our own heap.
-    // BaseSrvSharedHeap = LoadedServerDll->SharedSection; // Get the CSR shared heap.
-    // LoadedServerDll->SharedSection = BaseStaticServerData;
+    /* Initialize the memory */
+    ConSrvHeap = RtlGetProcessHeap();
 
     ConSrvInitConsoleSupport();
 
@@ -464,6 +317,7 @@ CSR_SERVER_DLL_INIT(ConServerDllInitialization)
     LoadedServerDll->DisconnectCallback = ConSrvDisconnect;
     LoadedServerDll->NewProcessCallback = ConSrvNewProcess;
     // LoadedServerDll->HardErrorCallback = ConSrvHardError;
+    LoadedServerDll->ShutdownProcessCallback = NULL;
 
     ConSrvDllInstance = LoadedServerDll->ServerHandle;
 
@@ -477,6 +331,7 @@ DllMain(IN HINSTANCE hInstanceDll,
         IN DWORD dwReason,
         IN LPVOID lpReserved)
 {
+    UNREFERENCED_PARAMETER(hInstanceDll);
     UNREFERENCED_PARAMETER(dwReason);
     UNREFERENCED_PARAMETER(lpReserved);
     return TRUE;
index d369d37..d81b1f0 100644 (file)
@@ -8,7 +8,7 @@ spec2def(winsrv.dll winsrv.spec)
 list(APPEND SOURCE
     harderror.c
     init.c
-    server.c
+    register.c
     shutdown.c
     winsrv.rc
     ${CMAKE_CURRENT_BINARY_DIR}/winsrv.def)
index c295698..e77867a 100644 (file)
@@ -7,7 +7,7 @@
  *                  Timo Kreuzer (timo.kreuzer@reactos.org)
  */
 
-/* INCLUDES ******************************************************************/
+/* INCLUDES *******************************************************************/
 
 #include "winsrv.h"
 
@@ -19,7 +19,7 @@
 #define IDTRYAGAIN 10
 #define IDCONTINUE 11
 
-/* FUNCTIONS *****************************************************************/
+/* FUNCTIONS ******************************************************************/
 
 static
 NTSTATUS
@@ -493,15 +493,15 @@ CsrpMessageBox(
     /* Return response value */
     switch (MessageBoxResponse)
     {
-    case IDOK:       return ResponseOk;
-    case IDCANCEL:   return ResponseCancel;
-    case IDYES:      return ResponseYes;
-    case IDNO:       return ResponseNo;
-    case IDABORT:    return ResponseAbort;
-    case IDIGNORE:   return ResponseIgnore;
-    case IDRETRY:    return ResponseRetry;
-    case IDTRYAGAIN: return ResponseTryAgain;
-    case IDCONTINUE: return ResponseContinue;
+        case IDOK:       return ResponseOk;
+        case IDCANCEL:   return ResponseCancel;
+        case IDYES:      return ResponseYes;
+        case IDNO:       return ResponseNo;
+        case IDABORT:    return ResponseAbort;
+        case IDIGNORE:   return ResponseIgnore;
+        case IDRETRY:    return ResponseRetry;
+        case IDTRYAGAIN: return ResponseTryAgain;
+        case IDCONTINUE: return ResponseContinue;
     }
 
     return ResponseNotHandled;
@@ -509,7 +509,7 @@ CsrpMessageBox(
 
 VOID
 WINAPI
-Win32CsrHardError(
+UserServerHardError(
     IN PCSR_THREAD ThreadData,
     IN PHARDERROR_MSG Message)
 {
@@ -583,3 +583,4 @@ Win32CsrHardError(
     return;
 }
 
+/* EOF */
index 90384ea..6af815b 100644 (file)
@@ -7,6 +7,8 @@
  *                  Hermes Belusca-Maito (hermes.belusca@sfr.fr)
  */
 
+/* INCLUDES *******************************************************************/
+
 #include "winsrv.h"
 
 /* Public Win32K Headers */
 #define NDEBUG
 #include <debug.h>
 
-HINSTANCE UserSrvDllInstance = NULL;
-// HANDLE WinSrvApiPort = NULL;
+/* GLOBALS ********************************************************************/
 
-/* Memory */
-HANDLE UserSrvHeap = NULL;          // Our own heap.
-// HANDLE BaseSrvSharedHeap = NULL;    // Shared heap with CSR. (CsrSrvSharedSectionHeap)
-// PBASE_STATIC_SERVER_DATA BaseStaticServerData = NULL;   // Data that we can share amongst processes. Initialized inside BaseSrvSharedHeap.
+HINSTANCE UserServerDllInstance = NULL;
 
+/* Memory */
+HANDLE UserServerHeap = NULL;   // Our own heap.
 
+// Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
 PCSR_API_ROUTINE UserServerApiDispatchTable[UserpMaxApiNumber] =
 {
     SrvExitWindowsEx,
@@ -42,7 +43,7 @@ PCSR_API_ROUTINE UserServerApiDispatchTable[UserpMaxApiNumber] =
     // SrvGetSetShutdownBlockReason,   // Added in Vista
 
     /// HACK: ReactOS-specific
-    RosSetLogonNotifyWindow
+    RosSetLogonNotifyWindow,
 };
 
 BOOLEAN UserServerApiServerValidTable[UserpMaxApiNumber] =
@@ -63,8 +64,6 @@ BOOLEAN UserServerApiServerValidTable[UserpMaxApiNumber] =
 
     /// HACK: ReactOS-specific
     FALSE,   // RosSetLogonNotifyWindow
-
-    // FALSE
 };
 
 PCHAR UserServerApiNameTable[UserpMaxApiNumber] =
@@ -85,35 +84,17 @@ PCHAR UserServerApiNameTable[UserpMaxApiNumber] =
 
     /// HACK: ReactOS-specific
     "RosSetLogonNotifyWindow",
-
-    // NULL
 };
 
 
 /* FUNCTIONS ******************************************************************/
 
-/*
-VOID WINAPI UserStaticServerThread(PVOID x)
+// PUSER_SOUND_SENTRY. Used in basesrv.dll
+BOOL WINAPI _UserSoundSentry(VOID)
 {
-    // NTSTATUS Status = STATUS_SUCCESS;
-    PPORT_MESSAGE Request = (PPORT_MESSAGE)x;
-    PPORT_MESSAGE Reply = NULL;
-    ULONG MessageType = 0;
-
-    DPRINT("WINSRV: %s(%08lx) called\n", __FUNCTION__, x);
-
-    MessageType = Request->u2.s2.Type;
-    DPRINT("WINSRV: %s(%08lx) received a message (Type=%d)\n",
-           __FUNCTION__, x, MessageType);
-    switch (MessageType)
-    {
-        default:
-            Reply = Request;
-            /\* Status = *\/ NtReplyPort(WinSrvApiPort, Reply);
-            break;
-    }
+    // TODO: Do something.
+    return TRUE;
 }
-*/
 
 ULONG
 InitializeVideoAddressSpace(VOID)
@@ -290,26 +271,6 @@ CreateSystemThreads(PVOID pParam)
 
 CSR_SERVER_DLL_INIT(UserServerDllInitialization)
 {
-/*
-    NTSTATUS Status = STATUS_SUCCESS;
-
-    DPRINT("WINSRV: %s called\n", __FUNCTION__);
-
-    // Get the listening port from csrsrv.dll
-    WinSrvApiPort = CsrQueryApiPort ();
-    if (NULL == WinSrvApiPort)
-    {
-        return STATUS_UNSUCCESSFUL;
-    }
-    // Register our message dispatcher
-    Status = CsrAddStaticServerThread (UserStaticServerThread);
-    if (NT_SUCCESS(Status))
-    {
-        //TODO: perform the real user server internal initialization here
-    }
-    return Status;
-*/
-
 /*** From win32csr... ***/
     HANDLE ServerThread;
     CLIENT_ID ClientId;
@@ -317,11 +278,10 @@ CSR_SERVER_DLL_INIT(UserServerDllInitialization)
     UINT i;
 /*** END - From win32csr... ***/
 
-    /* Initialize memory */
-    UserSrvHeap = RtlGetProcessHeap();  // Initialize our own heap.
-    // BaseSrvSharedHeap = LoadedServerDll->SharedSection; // Get the CSR shared heap.
-    // LoadedServerDll->SharedSection = BaseStaticServerData;
+    /* Initialize the memory */
+    UserServerHeap = RtlGetProcessHeap();
 
+    /* Initialize the video */
     CsrpInitVideo();
     NtUserInitialize(0, NULL, NULL);
     PrivateCsrssManualGuiCheck(0);
@@ -334,9 +294,11 @@ CSR_SERVER_DLL_INIT(UserServerDllInitialization)
     LoadedServerDll->NameTable = UserServerApiNameTable;
     LoadedServerDll->SizeOfProcessData = 0;
     LoadedServerDll->ConnectCallback = NULL;
-    // LoadedServerDll->DisconnectCallback = Win32CsrReleaseConsole;
-    // LoadedServerDll->NewProcessCallback = Win32CsrDuplicateHandleTable;
-    LoadedServerDll->HardErrorCallback = Win32CsrHardError;
+    LoadedServerDll->DisconnectCallback = NULL;
+    LoadedServerDll->HardErrorCallback = UserServerHardError;
+    LoadedServerDll->ShutdownProcessCallback = NULL;
+
+    UserServerDllInstance = LoadedServerDll->ServerHandle;
 
 /*** From win32csr... See r54125 ***/
     /* Start the Raw Input Thread and the Desktop Thread */
@@ -357,28 +319,20 @@ CSR_SERVER_DLL_INIT(UserServerDllInitialization)
     return STATUS_SUCCESS;
 }
 
-// PUSER_SOUND_SENTRY. Used in basesrv.dll
-BOOL WINAPI _UserSoundSentry(VOID)
-{
-    // Do something.
-    return TRUE;
-}
-
 BOOL
 WINAPI
 DllMain(IN HINSTANCE hInstanceDll,
         IN DWORD dwReason,
         IN LPVOID lpReserved)
 {
+    UNREFERENCED_PARAMETER(hInstanceDll);
     UNREFERENCED_PARAMETER(dwReason);
     UNREFERENCED_PARAMETER(lpReserved);
 
     if (DLL_PROCESS_ATTACH == dwReason)
     {
-        UserSrvDllInstance = hInstanceDll;
-
+        DPRINT1("WINSRV - HACK: Use keyboard hook hack\n");
 /*** HACK from win32csr... ***/
-
 //
 // HACK HACK HACK ReactOS to BOOT! Initialization BUG ALERT! See bug 5655.
 //
diff --git a/win32ss/user/winsrv/register.c b/win32ss/user/winsrv/register.c
new file mode 100644 (file)
index 0000000..23cf251
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS User API Server DLL
+ * FILE:            win32ss/user/winsrv/register.c
+ * PURPOSE:         Register logon window and services process
+ * PROGRAMMERS:     Eric Kohl
+ *                  Hermes Belusca-Maito (hermes.belusca@sfr.fr)
+ */
+
+/* INCLUDES *******************************************************************/
+
+#include "winsrv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+/* GLOBALS ********************************************************************/
+
+static BOOLEAN ServicesProcessIdValid = FALSE;
+static ULONG_PTR ServicesProcessId = 0;
+
+HWND LogonNotifyWindow = NULL;
+ULONG_PTR LogonProcessId = 0;
+
+/* PUBLIC SERVER APIS *********************************************************/
+
+CSR_API(SrvRegisterLogonProcess)
+{
+    PCSRSS_REGISTER_LOGON_PROCESS RegisterLogonProcessRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.RegisterLogonProcessRequest;
+
+    if (RegisterLogonProcessRequest->Register)
+    {
+        if (LogonProcessId != 0)
+            return STATUS_LOGON_SESSION_EXISTS;
+
+        LogonProcessId = RegisterLogonProcessRequest->ProcessId;
+    }
+    else
+    {
+        if (ApiMessage->Header.ClientId.UniqueProcess != (HANDLE)LogonProcessId)
+        {
+            DPRINT1("Current logon process 0x%x, can't deregister from process 0x%x\n",
+                    LogonProcessId, ApiMessage->Header.ClientId.UniqueProcess);
+            return STATUS_NOT_LOGON_PROCESS;
+        }
+
+        LogonProcessId = 0;
+    }
+
+    return STATUS_SUCCESS;
+}
+
+/// HACK: ReactOS-specific
+CSR_API(RosSetLogonNotifyWindow)
+{
+    PCSRSS_SET_LOGON_NOTIFY_WINDOW SetLogonNotifyWindowRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.SetLogonNotifyWindowRequest;
+    DWORD WindowCreator;
+
+    if (0 == GetWindowThreadProcessId(SetLogonNotifyWindowRequest->LogonNotifyWindow,
+                                      &WindowCreator))
+    {
+        DPRINT1("Can't get window creator\n");
+        return STATUS_INVALID_HANDLE;
+    }
+    if (WindowCreator != LogonProcessId)
+    {
+        DPRINT1("Trying to register window not created by winlogon as notify window\n");
+        return STATUS_ACCESS_DENIED;
+    }
+
+    LogonNotifyWindow = SetLogonNotifyWindowRequest->LogonNotifyWindow;
+
+    return STATUS_SUCCESS;
+}
+
+CSR_API(SrvRegisterServicesProcess)
+{
+    PCSRSS_REGISTER_SERVICES_PROCESS RegisterServicesProcessRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.RegisterServicesProcessRequest;
+
+    if (ServicesProcessIdValid == TRUE)
+    {
+        /* Only accept a single call */
+        return STATUS_INVALID_PARAMETER;
+    }
+    else
+    {
+        ServicesProcessId = RegisterServicesProcessRequest->ProcessId;
+        ServicesProcessIdValid = TRUE;
+        return STATUS_SUCCESS;
+    }
+}
+
+/* EOF */
diff --git a/win32ss/user/winsrv/server.c b/win32ss/user/winsrv/server.c
deleted file mode 100644 (file)
index 2dca470..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS User API Server DLL
- * FILE:            win32ss/user/winsrv/server.c
- * PURPOSE:         Server APIs
- * PROGRAMMERS:     Eric Kohl
- *                  Hermes Belusca-Maito (hermes.belusca@sfr.fr)
- */
-
-/* INCLUDES ******************************************************************/
-
-#include "winsrv.h"
-
-#define NDEBUG
-#include <debug.h>
-
-
-/* GLOBALS *******************************************************************/
-
-static BOOLEAN ServicesProcessIdValid = FALSE;
-static ULONG_PTR ServicesProcessId = 0;
-
-
-/* FUNCTIONS *****************************************************************/
-
-CSR_API(SrvRegisterServicesProcess)
-{
-    PCSRSS_REGISTER_SERVICES_PROCESS RegisterServicesProcessRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.RegisterServicesProcessRequest;
-
-    if (ServicesProcessIdValid == TRUE)
-    {
-        /* Only accept a single call */
-        return STATUS_INVALID_PARAMETER;
-    }
-    else
-    {
-        ServicesProcessId = RegisterServicesProcessRequest->ProcessId;
-        ServicesProcessIdValid = TRUE;
-        return STATUS_SUCCESS;
-    }
-}
-
-/* EOF */
index 27e4944..6a88d33 100644 (file)
@@ -6,7 +6,7 @@
  * PROGRAMMERS:
  */
 
-/* INCLUDES ******************************************************************/
+/* INCLUDES *******************************************************************/
 
 #include "winsrv.h"
 #include <sddl.h>
 #define NDEBUG
 #include <debug.h>
 
-
-static HWND LogonNotifyWindow = NULL;
-static ULONG_PTR LogonProcessId = 0;
-
-
-/* FUNCTIONS *****************************************************************/
-
-/*
-NTSTATUS FASTCALL
-Win32CsrEnumProcesses(CSRSS_ENUM_PROCESS_PROC EnumProc,
-                      PVOID Context)
-{
-    return CsrEnumProcesses(EnumProc, Context);
-}
-*/
-
-CSR_API(SrvRegisterLogonProcess)
-{
-    PCSRSS_REGISTER_LOGON_PROCESS RegisterLogonProcessRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.RegisterLogonProcessRequest;
-
-    if (RegisterLogonProcessRequest->Register)
-    {
-        if (LogonProcessId != 0)
-            return STATUS_LOGON_SESSION_EXISTS;
-
-        LogonProcessId = RegisterLogonProcessRequest->ProcessId;
-    }
-    else
-    {
-        if (ApiMessage->Header.ClientId.UniqueProcess != (HANDLE)LogonProcessId)
-        {
-            DPRINT1("Current logon process 0x%x, can't deregister from process 0x%x\n",
-                    LogonProcessId, ApiMessage->Header.ClientId.UniqueProcess);
-            return STATUS_NOT_LOGON_PROCESS;
-        }
-
-        LogonProcessId = 0;
-    }
-
-    return STATUS_SUCCESS;
-}
-
-/// HACK: ReactOS-specific
-CSR_API(RosSetLogonNotifyWindow)
-{
-    PCSRSS_SET_LOGON_NOTIFY_WINDOW SetLogonNotifyWindowRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.SetLogonNotifyWindowRequest;
-    DWORD WindowCreator;
-
-    if (0 == GetWindowThreadProcessId(SetLogonNotifyWindowRequest->LogonNotifyWindow,
-                                      &WindowCreator))
-    {
-        DPRINT1("Can't get window creator\n");
-        return STATUS_INVALID_HANDLE;
-    }
-    if (WindowCreator != LogonProcessId)
-    {
-        DPRINT1("Trying to register window not created by winlogon as notify window\n");
-        return STATUS_ACCESS_DENIED;
-    }
-
-    LogonNotifyWindow = SetLogonNotifyWindowRequest->LogonNotifyWindow;
-
-    return STATUS_SUCCESS;
-}
+/* GLOBALS ********************************************************************/
 
 typedef struct tagSHUTDOWN_SETTINGS
 {
@@ -114,6 +51,38 @@ typedef struct tagNOTIFY_CONTEXT
 #define QUERY_RESULT_ERROR    3
 #define QUERY_RESULT_FORCE    4
 
+typedef void (WINAPI *INITCOMMONCONTROLS_PROC)(void);
+
+typedef struct tagMESSAGE_CONTEXT
+{
+    HWND Wnd;
+    UINT Msg;
+    WPARAM wParam;
+    LPARAM lParam;
+    DWORD Timeout;
+} MESSAGE_CONTEXT, *PMESSAGE_CONTEXT;
+
+typedef struct tagPROCESS_ENUM_CONTEXT
+{
+    UINT ProcessCount;
+    PCSR_PROCESS *ProcessData;
+    TOKEN_ORIGIN TokenOrigin;
+    DWORD ShellProcess;
+    DWORD CsrssProcess;
+} PROCESS_ENUM_CONTEXT, *PPROCESS_ENUM_CONTEXT;
+
+
+/* FUNCTIONS ******************************************************************/
+
+/*
+NTSTATUS FASTCALL
+Win32CsrEnumProcesses(CSRSS_ENUM_PROCESS_PROC EnumProc,
+                      PVOID Context)
+{
+    return CsrEnumProcesses(EnumProc, Context);
+}
+*/
+
 static void FASTCALL
 UpdateProgressBar(HWND ProgressBar, PNOTIFY_CONTEXT NotifyContext)
 {
@@ -147,14 +116,14 @@ EndNowDlgProc(HWND Dlg, UINT Msg, WPARAM wParam, LPARAM lParam)
         TitleLength = SendMessageW(NotifyContext->WndClient, WM_GETTEXTLENGTH,
                                    0, 0) +
                       GetWindowTextLengthW(Dlg);
-        Title = HeapAlloc(UserSrvHeap, 0, (TitleLength + 1) * sizeof(WCHAR));
+        Title = HeapAlloc(UserServerHeap, 0, (TitleLength + 1) * sizeof(WCHAR));
         if (NULL != Title)
         {
             Len = GetWindowTextW(Dlg, Title, TitleLength + 1);
             SendMessageW(NotifyContext->WndClient, WM_GETTEXT,
                          TitleLength + 1 - Len, (LPARAM) (Title + Len));
             SetWindowTextW(Dlg, Title);
-            HeapFree(UserSrvHeap, 0, Title);
+            HeapFree(UserServerHeap, 0, Title);
         }
         ProgressBar = GetDlgItem(Dlg, IDC_PROGRESS);
         SendMessageW(ProgressBar, PBM_SETRANGE32, 0,
@@ -206,8 +175,6 @@ EndNowDlgProc(HWND Dlg, UINT Msg, WPARAM wParam, LPARAM lParam)
     return Result;
 }
 
-typedef void (WINAPI *INITCOMMONCONTROLS_PROC)(void);
-
 static void
 CallInitCommonControls()
 {
@@ -215,21 +182,13 @@ CallInitCommonControls()
     HMODULE Lib;
     INITCOMMONCONTROLS_PROC InitProc;
 
-    if (Initialized)
-    {
-        return;
-    }
+    if (Initialized) return;
 
     Lib = LoadLibraryW(L"COMCTL32.DLL");
-    if (NULL == Lib)
-    {
-        return;
-    }
+    if (NULL == Lib) return;
+
     InitProc = (INITCOMMONCONTROLS_PROC) GetProcAddress(Lib, "InitCommonControls");
-    if (NULL == InitProc)
-    {
-        return;
-    }
+    if (NULL == InitProc) return;
 
     (*InitProc)();
 
@@ -245,7 +204,7 @@ EndNowThreadProc(LPVOID Parameter)
     SetThreadDesktop(NotifyContext->Desktop);
     SwitchDesktop(NotifyContext->Desktop);
     CallInitCommonControls();
-    NotifyContext->Dlg = CreateDialogParam(UserSrvDllInstance,
+    NotifyContext->Dlg = CreateDialogParam(UserServerDllInstance,
                                            MAKEINTRESOURCE(IDD_END_NOW), NULL,
                                            EndNowDlgProc, (LPARAM) NotifyContext);
     if (NULL == NotifyContext->Dlg)
@@ -266,15 +225,6 @@ EndNowThreadProc(LPVOID Parameter)
     return Msg.wParam;
 }
 
-typedef struct tagMESSAGE_CONTEXT
-{
-    HWND Wnd;
-    UINT Msg;
-    WPARAM wParam;
-    LPARAM lParam;
-    DWORD Timeout;
-} MESSAGE_CONTEXT, *PMESSAGE_CONTEXT;
-
 static DWORD WINAPI
 SendQueryEndSession(LPVOID Parameter)
 {
@@ -487,7 +437,7 @@ DtbgIsDesktopVisible(VOID)
     return VisibleDesktopWindow != NULL;
 }
 
-/* TODO: Find another way to do it. */
+/* TODO: Find an other way to do it. */
 #if 0
 VOID FASTCALL
 ConioConsoleCtrlEventTimeout(DWORD Event, PCSR_PROCESS ProcessData, DWORD Timeout)
@@ -527,7 +477,7 @@ NotifyAndTerminateProcess(PCSR_PROCESS ProcessData,
 
     if (0 == (Flags & EWX_FORCE))
     {
-        // TODO: Find in an other way whether or not the process has a console.
+        // TODO: Find an other way whether or not the process has a console.
 #if 0
         if (NULL != ProcessData->Console)
         {
@@ -596,15 +546,6 @@ NotifyAndTerminateProcess(PCSR_PROCESS ProcessData,
     return TRUE;
 }
 
-typedef struct tagPROCESS_ENUM_CONTEXT
-{
-    UINT ProcessCount;
-    PCSR_PROCESS *ProcessData;
-    TOKEN_ORIGIN TokenOrigin;
-    DWORD ShellProcess;
-    DWORD CsrssProcess;
-} PROCESS_ENUM_CONTEXT, *PPROCESS_ENUM_CONTEXT;
-
 #if 0
 static NTSTATUS WINAPI
 ExitReactosProcessEnum(PCSR_PROCESS ProcessData, PVOID Data)
@@ -661,7 +602,7 @@ ExitReactosProcessEnum(PCSR_PROCESS ProcessData, PVOID Data)
         {
             ProcessData->ShutdownLevel = 0;
         }
-        NewData = HeapAlloc(UserSrvHeap, 0, (Context->ProcessCount + 1)
+        NewData = HeapAlloc(UserServerHeap, 0, (Context->ProcessCount + 1)
                             * sizeof(PCSR_PROCESS));
         if (NULL == NewData)
         {
@@ -671,7 +612,7 @@ ExitReactosProcessEnum(PCSR_PROCESS ProcessData, PVOID Data)
         {
             memcpy(NewData, Context->ProcessData,
                    Context->ProcessCount * sizeof(PCSR_PROCESS));
-            HeapFree(UserSrvHeap, 0, Context->ProcessData);
+            HeapFree(UserServerHeap, 0, Context->ProcessData);
         }
         Context->ProcessData = NewData;
         Context->ProcessData[Context->ProcessCount] = ProcessData;
@@ -709,7 +650,7 @@ ProcessDataCompare(const void *Elem1, const void *Elem2)
 }
 
 static DWORD FASTCALL
-GetShutdownSetting(HKEY DesktopKey, LPCWSTR ValueName, DWORD DefaultValue)
+GetShutdownSettings(HKEY DesktopKey, LPCWSTR ValueName, DWORD DefaultValue)
 {
     BYTE ValueBuffer[16];
     LONG ErrCode;
@@ -723,7 +664,7 @@ GetShutdownSetting(HKEY DesktopKey, LPCWSTR ValueName, DWORD DefaultValue)
                                &ValueSize);
     if (ERROR_SUCCESS != ErrCode)
     {
-        DPRINT("GetShutdownSetting for %S failed with error code %ld\n",
+        DPRINT("GetShutdownSettings for %S failed with error code %ld\n",
                ValueName, ErrCode);
         return DefaultValue;
     }
@@ -775,7 +716,7 @@ LoadShutdownSettings(PSID Sid, PSHUTDOWN_SETTINGS ShutdownSettings)
     }
     else
     {
-        KeyName = HeapAlloc(UserSrvHeap, 0,
+        KeyName = HeapAlloc(UserServerHeap, 0,
                             (wcslen(StringSid) + wcslen(Subkey) + 1) *
                             sizeof(WCHAR));
         if (NULL == KeyName)
@@ -791,7 +732,7 @@ LoadShutdownSettings(PSID Sid, PSHUTDOWN_SETTINGS ShutdownSettings)
     ErrCode = RegOpenKeyExW(HKEY_USERS, KeyName, 0, KEY_QUERY_VALUE, &DesktopKey);
     if (KeyName != InitialKeyName)
     {
-        HeapFree(UserSrvHeap, 0, KeyName);
+        HeapFree(UserServerHeap, 0, KeyName);
     }
     if (ERROR_SUCCESS != ErrCode)
     {
@@ -799,12 +740,12 @@ LoadShutdownSettings(PSID Sid, PSHUTDOWN_SETTINGS ShutdownSettings)
         return;
     }
 
-    ShutdownSettings->AutoEndTasks = (BOOL) GetShutdownSetting(DesktopKey, L"AutoEndTasks",
+    ShutdownSettings->AutoEndTasks = (BOOL) GetShutdownSettings(DesktopKey, L"AutoEndTasks",
                                      (DWORD) DEFAULT_AUTO_END_TASKS);
-    ShutdownSettings->HungAppTimeout = GetShutdownSetting(DesktopKey,
+    ShutdownSettings->HungAppTimeout = GetShutdownSettings(DesktopKey,
                                        L"HungAppTimeout",
                                        DEFAULT_HUNG_APP_TIMEOUT);
-    ShutdownSettings->WaitToKillAppTimeout = GetShutdownSetting(DesktopKey,
+    ShutdownSettings->WaitToKillAppTimeout = GetShutdownSettings(DesktopKey,
             L"WaitToKillAppTimeout",
             DEFAULT_WAIT_TO_KILL_APP_TIMEOUT);
 
@@ -862,7 +803,7 @@ InternalExitReactos(DWORD ProcessId, DWORD ThreadId, UINT Flags)
     {
         if (sizeof(FixedUserInfo) < ReturnLength)
         {
-            UserInfo = HeapAlloc(UserSrvHeap, 0, ReturnLength);
+            UserInfo = HeapAlloc(UserServerHeap, 0, ReturnLength);
             if (NULL == UserInfo)
             {
                 DPRINT1("Unable to allocate %u bytes for user info\n",
@@ -875,7 +816,7 @@ InternalExitReactos(DWORD ProcessId, DWORD ThreadId, UINT Flags)
             {
                 DPRINT1("GetTokenInformation failed with error %d\n",
                         GetLastError());
-                HeapFree(UserSrvHeap, 0, UserInfo);
+                HeapFree(UserServerHeap, 0, UserInfo);
                 CloseHandle(CallerToken);
                 return STATUS_UNSUCCESSFUL;
             }
@@ -895,7 +836,7 @@ InternalExitReactos(DWORD ProcessId, DWORD ThreadId, UINT Flags)
     LoadShutdownSettings(UserInfo->User.Sid, &ShutdownSettings);
     if (UserInfo != (TOKEN_USER *) FixedUserInfo)
     {
-        HeapFree(UserSrvHeap, 0, UserInfo);
+        HeapFree(UserServerHeap, 0, UserInfo);
     }
     Context.CsrssProcess = GetCurrentProcessId();
     ShellWnd = GetShellWindow();
@@ -917,7 +858,7 @@ InternalExitReactos(DWORD ProcessId, DWORD ThreadId, UINT Flags)
                 Status);
         if (NULL != Context.ProcessData)
         {
-            HeapFree(UserSrvHeap, 0, Context.ProcessData);
+            HeapFree(UserServerHeap, 0, Context.ProcessData);
         }
         return Status;
     }
@@ -942,7 +883,7 @@ InternalExitReactos(DWORD ProcessId, DWORD ThreadId, UINT Flags)
     /* Cleanup */
     if (NULL != Context.ProcessData)
     {
-        HeapFree(UserSrvHeap, 0, Context.ProcessData);
+        HeapFree(UserServerHeap, 0, Context.ProcessData);
     }
 
     return Status;
@@ -978,6 +919,9 @@ UserExitReactos(DWORD UserProcessId, UINT Flags)
     return Status;
 }
 
+
+/* PUBLIC SERVER APIS *********************************************************/
+
 CSR_API(SrvExitWindowsEx)
 {
     PCSRSS_EXIT_REACTOS ExitReactosRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.ExitReactosRequest;
index 0fad98b..7cec93a 100644 (file)
 #include <ndk/psfuncs.h>
 #include <ndk/rtlfuncs.h>
 
+/* PSEH for SEH Support */
+#include <pseh/pseh2.h>
+
 /* External Winlogon Header */
 #include <winlogon.h>
 
 /* CSRSS Header */
 #include <csr/csrsrv.h>
 
-/* PSEH for SEH Support */
-#include <pseh/pseh2.h>
-
 /* USER Headers */
 #include <win/winmsg.h>
-// #include <win/base.h>
-// #include <win/windows.h>
 
 /* Public Win32 Headers */
 #include <commctrl.h>
 #include "resource.h"
 
 
-extern HINSTANCE UserSrvDllInstance;
-extern HANDLE UserSrvHeap;
-// extern HANDLE BaseSrvSharedHeap;
-// extern PBASE_STATIC_SERVER_DATA BaseStaticServerData;
+extern HINSTANCE UserServerDllInstance;
+extern HANDLE UserServerHeap;
+
+extern HWND LogonNotifyWindow;
+extern ULONG_PTR LogonProcessId;
 
 /* init.c */
 BOOL WINAPI _UserSoundSentry(VOID);
 
 /* harderror.c */
-VOID
-WINAPI
-Win32CsrHardError(IN PCSR_THREAD ThreadData,
-                  IN PHARDERROR_MSG Message);
-
+VOID WINAPI UserServerHardError(IN PCSR_THREAD ThreadData,
+                                IN PHARDERROR_MSG Message);
 
-/* shutdown.c */
-CSR_API(SrvExitWindowsEx);
-// CSR_API(CsrRegisterSystemClasses);
+/* register.c */
 CSR_API(SrvRegisterServicesProcess);
 CSR_API(SrvRegisterLogonProcess);
-
 /// HACK: ReactOS-specific
 CSR_API(RosSetLogonNotifyWindow);
 
-
-/*****************************
-
-/\*
-typedef VOID (WINAPI *CSR_CLEANUP_OBJECT_PROC)(Object_t *Object);
-
-typedef struct tagCSRSS_OBJECT_DEFINITION
-{
-  LONG Type;
-  CSR_CLEANUP_OBJECT_PROC CsrCleanupObjectProc;
-} CSRSS_OBJECT_DEFINITION, *PCSRSS_OBJECT_DEFINITION;
-*\/
-
-
-
-*****************************/
+/* shutdown.c */
+CSR_API(SrvExitWindowsEx);
 
 #endif // __WINSRV_H__