[CSRSRV]: The connection with SMSS(2) should be done after initialization, not before...
authorAlex Ionescu <aionescu@gmail.com>
Wed, 8 Feb 2012 21:56:23 +0000 (21:56 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Wed, 8 Feb 2012 21:56:23 +0000 (21:56 +0000)
[CSRSRV]: Fix many bugs in ServerSbApiPortThread. This function never worked as SMSS never actually connects to the SB API Port. Since SMSS2 does, a few bugs were discovered. Also, hack-plement the one SB API that is required for SMSS2 (SbpCreateSession). All we do is resume the thread we receive (Winlogon)... normally we'd also register a hard-error port, etc.
[CSRSRV]: If connecting with SMDLL to SMSS did not work (such as on my system where SMSS is no longer there), try using SMLIB and SMSS2 instead. This way CSRSS still works with both environments.
[CSRSRV]: Required rbuild/cmake changes to build with SMLIB.

svn path=/trunk/; revision=55500

reactos/subsystems/win32/csrss/csrsrv/CMakeLists.txt
reactos/subsystems/win32/csrss/csrsrv/api/wapi.c
reactos/subsystems/win32/csrss/csrsrv/csrsrv.rbuild
reactos/subsystems/win32/csrss/csrsrv/init.c
reactos/subsystems/win32/csrss/csrsrv/srv.h

index 6d96ca4..148f6e6 100644 (file)
@@ -15,7 +15,7 @@ list(APPEND SOURCE
 
 add_library(csrsrv SHARED ${SOURCE})
 
-target_link_libraries(csrsrv ${PSEH_LIB})
+target_link_libraries(csrsrv ${PSEH_LIB} smlib)
 
 set_module_type(csrsrv nativedll)
 
index e856b30..897f905 100644 (file)
@@ -767,7 +767,7 @@ DWORD WINAPI
 ServerSbApiPortThread (HANDLE hSbApiPortListen)
 {
     HANDLE          hConnectedPort = (HANDLE) 0;
-    PORT_MESSAGE    Request;
+    SB_API_MSG    Request;
     PVOID           Context = NULL;
     NTSTATUS        Status = STATUS_SUCCESS;
     PPORT_MESSAGE Reply = NULL;
@@ -775,7 +775,7 @@ ServerSbApiPortThread (HANDLE hSbApiPortListen)
     DPRINT("CSR: %s called\n", __FUNCTION__);
 
     RtlZeroMemory(&Request, sizeof(PORT_MESSAGE));
-    Status = NtListenPort (hSbApiPortListen, & Request);
+    Status = NtListenPort (hSbApiPortListen, & Request.h);
 
     if (!NT_SUCCESS(Status))
     {
@@ -785,7 +785,7 @@ ServerSbApiPortThread (HANDLE hSbApiPortListen)
         DPRINT("-- 1\n");
         Status = NtAcceptConnectPort(&hConnectedPort,
                                      NULL,
-                                     &Request,
+                                     &Request.h,
                                      TRUE,
                                      NULL,
                                      NULL);
@@ -819,7 +819,7 @@ ServerSbApiPortThread (HANDLE hSbApiPortListen)
                     Status = NtReplyWaitReceivePort(hConnectedPort,
                                                     Context,
                                                     Reply,
-                                                    &Request);
+                                                    &Request.h);
                     if(!NT_SUCCESS(Status))
                     {
                         DPRINT1("CSR: %s: NtReplyWaitReceivePort failed (Status=0x%08lx)\n",
@@ -827,12 +827,30 @@ ServerSbApiPortThread (HANDLE hSbApiPortListen)
                         break;
                     }
 
-                    switch (Request.u2.s2.Type) //fix .h PORT_MESSAGE_TYPE(Request))
+                    switch (Request.h.u2.s2.Type) //fix .h PORT_MESSAGE_TYPE(Request))
                     {
                         /* TODO */
+                        case LPC_PORT_CLOSED:
+                        case LPC_CLIENT_DIED:
+                            DPRINT1("CSR: SMSS died\n");
+                            Reply = NULL;
+                            break;
+                            
                         default:
                         DPRINT1("CSR: %s received message (type=%d)\n",
-                                __FUNCTION__, Request.u2.s2.Type);
+                                __FUNCTION__, Request.h.u2.s2.Type);
+
+                        if (Request.ApiNumber == SbpCreateSession)
+                        {
+                            DPRINT("Session create... legacy CSRSS resuming thread as minimum work done\n");
+                            Request.ReturnValue = NtResumeThread(Request.CreateSession.ProcessInfo.ThreadHandle, NULL);
+                        }
+                        else
+                        {
+                            DPRINT1("CSR: %d Not implemented in legacy CSRSS... faking success\n", Request.ApiNumber);
+                            Request.ReturnValue = STATUS_SUCCESS;
+                        }
+                        Reply = &Request.h;
                     }
                     DPRINT("-- 5\n");
                 }
index 987ed18..49ff4de 100644 (file)
@@ -9,6 +9,7 @@
        <library>ntdll</library>
        <library>pseh</library>
        <library>smdll</library>
+       <library>smlib</library>
        <directory name="api">
                <file>process.c</file>
                <file>user.c</file>
index fde310f..cf7b7a7 100644 (file)
@@ -383,9 +383,9 @@ CsrpCreateListenPort (IN     LPWSTR  Name,
                                    NULL);
        Status = NtCreatePort ( Port,
                                & PortAttributes,
-                               LPC_MAX_DATA_LENGTH, /* TODO: make caller set it*/
-                               LPC_MAX_MESSAGE_LENGTH, /* TODO: make caller set it*/
-                               0); /* TODO: make caller set it*/
+                               sizeof(SB_CONNECTION_INFO),
+                               sizeof(SB_API_MSG),
+                               32 * sizeof(SB_API_MSG));
        if(!NT_SUCCESS(Status))
        {
                DPRINT1("CSR: %s: NtCreatePort failed (Status=%08lx)\n",
@@ -540,6 +540,7 @@ CsrpCreateCallbackPort (int argc, char ** argv, char ** envp)
 /**********************************************************************
  * CsrpRegisterSubsystem/3
  */
+BOOLEAN g_ModernSm;
 static NTSTATUS
 CsrpRegisterSubsystem (int argc, char ** argv, char ** envp)
 {
@@ -579,6 +580,11 @@ CsrpRegisterSubsystem (int argc, char ** argv, char ** envp)
                                   hSbApiPort,
                                   IMAGE_SUBSYSTEM_WINDOWS_CUI,
                                   & hSmApiPort);
+    if (!NT_SUCCESS(Status))
+    {
+        Status = SmConnectToSm(&Name, hSbApiPort, IMAGE_SUBSYSTEM_WINDOWS_GUI, &hSmApiPort);
+        g_ModernSm = TRUE;
+    }
        if(!NT_SUCCESS(Status))
        {
                DPRINT("CSR: %s unable to connect to the SM (Status=0x%08lx)\n",
@@ -698,6 +704,7 @@ CsrpRunWinlogon (int argc, char ** argv, char ** envp)
 
 
        DPRINT("CSR: %s called\n", __FUNCTION__);
+    if (g_ModernSm) return STATUS_SUCCESS;
 
        /* initialize the process parameters */
        RtlInitUnicodeString (& ImagePath, L"\\SystemRoot\\system32\\winlogon.exe");
@@ -749,8 +756,6 @@ struct {
        PCHAR ErrorMessage;
 } InitRoutine [] = {
         {TRUE, CsrpCreateBNODirectory,   "create base named objects directory"},
-       {TRUE, CsrpCreateCallbackPort,   "create the callback port \\Windows\\SbApiPort"},
-       {TRUE, CsrpRegisterSubsystem,    "register with SM"},
        {TRUE, CsrpCreateHeap,           "create the CSR heap"},
        {TRUE, CsrpCreateApiPort,        "create the api port \\Windows\\ApiPort"},
     {TRUE, CsrpCreateHardErrorPort,  "create the hard error port"},
@@ -760,6 +765,8 @@ struct {
        {TRUE, CsrpApiRegisterDef,       "initialize api definitions"},
        {TRUE, CsrpCCTS,                 "connect client to server"},
        {TRUE, CsrpInitWin32Csr,         "load usermode dll"},
+       {TRUE, CsrpCreateCallbackPort,   "create the callback port \\Windows\\SbApiPort"},
+       {TRUE, CsrpRegisterSubsystem,    "register with SM"},
        {TRUE, CsrpRunWinlogon,          "run WinLogon"},
 };
 
index 204d4ea..981fdf8 100644 (file)
@@ -23,6 +23,7 @@
 
 /* Subsystem Manager Header */
 #include <sm/helper.h>
+#include <sm/smmsg.h>
 
 /* Internal CSRSS Headers */
 #include <api.h>