Fix invalid Object Attributes
[reactos.git] / reactos / subsys / smss / smapi.c
index b514546..6d2941a 100644 (file)
@@ -5,9 +5,7 @@
  * Reactos Session Manager
  *
  */
-
 #include "smss.h"
-#include <rosrtl/string.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -38,7 +36,7 @@ SM_PORT_API SmApi [] =
        SmQryInfo       /* smapyqry.c */
 };
 
-/* TODO: optimize this address computation (it should be done 
+/* TODO: optimize this address computation (it should be done
  * with a macro) */
 PSM_CONNECT_DATA FASTCALL SmpGetConnectData (PSM_PORT_MESSAGE Request)
 {
@@ -52,12 +50,13 @@ SmpHandleConnectionRequest (PSM_PORT_MESSAGE Request);
 #endif
 
 /**********************************************************************
- * SmpCallback/2
+ * SmpCallbackServer/2
  *
- * The SM calls back a previously connected subsystem process to
- * authorizes it to bootstrap (initialize). The SM connects to a
- * named LPC port which name was sent in the connection data by the
- * candidate subsystem server process.
+ * DESCRIPTION
+ *     The SM calls back a previously connected subsystem process to
+ *     authorize it to bootstrap (initialize). The SM connects to a
+ *     named LPC port which name was sent in the connection data by
+ *     the candidate subsystem server process.
  */
 static NTSTATUS
 SmpCallbackServer (PSM_PORT_MESSAGE Request,
@@ -69,10 +68,11 @@ SmpCallbackServer (PSM_PORT_MESSAGE Request,
        ULONG             CallbackPortNameLength = SM_SB_NAME_MAX_LENGTH; /* TODO: compute length */
        SB_CONNECT_DATA   SbConnectData;
        ULONG             SbConnectDataLength = sizeof SbConnectData;
-       
+
        DPRINT("SM: %s called\n", __FUNCTION__);
 
-       if(IMAGE_SUBSYSTEM_NATIVE == ConnectData->SubSystemId)
+       if (    (IMAGE_SUBSYSTEM_UNKNOWN == ConnectData->SubSystemId) ||
+               (IMAGE_SUBSYSTEM_NATIVE  == ConnectData->SubSystemId))
        {
                DPRINT("SM: %s: we do not need calling back SM!\n",
                                __FUNCTION__);
@@ -183,7 +183,7 @@ SmpHandleConnectionRequest (PSM_PORT_MESSAGE Request)
        HANDLE           hClientDataApiPortThread = (HANDLE) 0;
        PHANDLE          ClientDataApiPortThread = & hClientDataApiPortThread;
        PVOID            Context = NULL;
-       
+
        DPRINT("SM: %s called:\n  SubSystemID=%d\n  SbName=\"%S\"\n",
                        __FUNCTION__, ConnectData->SubSystemId, ConnectData->SbName);
 
@@ -210,12 +210,10 @@ SmpHandleConnectionRequest (PSM_PORT_MESSAGE Request)
                        {
                                DPRINT("SM: %s: id = %d\n", __FUNCTION__, ConnectData->SubSystemId);
                                /*
-                                * SmCreateClient/2 is called here explicitly to *fail*.
-                                * If it succeeds, there is something wrong in the
-                                * connection request. An environment subsystem *never*
-                                * registers twice. (security issue)
+                                * SmBeginClientInitialization/2 will succeed only if there
+                                * is a candidate client ready.
                                 */
-                               Status = SmCreateClient (Request, & ClientData);
+                               Status = SmBeginClientInitialization (Request, & ClientData);
                                if(STATUS_SUCCESS == Status)
                                {
                                        DPRINT("SM: %s: ClientData = 0x%08lx\n",
@@ -228,7 +226,7 @@ SmpHandleConnectionRequest (PSM_PORT_MESSAGE Request)
                                        ClientDataApiPortThread = & ClientData->ApiPortThread;
                                        /*
                                         * Call back the candidate environment subsystem
-                                        * server (use the port name sent in in the 
+                                        * server (use the port name sent in in the
                                         * connection request message).
                                         */
                                        Status = SmpCallbackServer (Request, ClientData);
@@ -284,8 +282,8 @@ SmpHandleConnectionRequest (PSM_PORT_MESSAGE Request)
                                             NULL,
                                             FALSE,
                                             0,
-                                            NULL,
-                                            NULL,
+                                            0,
+                                            0,
                                             (PTHREAD_START_ROUTINE) SmpApiConnectedThread,
                                             ClientDataApiPort,
                                             ClientDataApiPortThread,
@@ -310,10 +308,10 @@ SmpHandleConnectionRequest (PSM_PORT_MESSAGE Request)
  *
  * DECRIPTION
  *     Due to differences in LPC implementation between NT and ROS,
- *     we need a thread to listen for connection request that
+ *     we need a thread to listen to for connection request that
  *     creates a new thread for each connected port. This is not
  *     necessary in NT LPC, because server side connected ports are
- *     never used to receive requests. 
+ *     never used to receive requests.
  */
 VOID STDCALL
 SmpApiThread (HANDLE ListeningPort)
@@ -322,7 +320,7 @@ SmpApiThread (HANDLE ListeningPort)
        LPC_MAX_MESSAGE Request = {{0}};
 
        DPRINT("SM: %s called\n", __FUNCTION__);
-    
+
        while (TRUE)
        {
                Status = NtListenPort (ListeningPort, & Request.Header);
@@ -359,14 +357,12 @@ NTSTATUS
 SmCreateApiPort(VOID)
 {
   OBJECT_ATTRIBUTES  ObjectAttributes = {0};
-  UNICODE_STRING     UnicodeString = {0};
+  UNICODE_STRING     UnicodeString = RTL_CONSTANT_STRING(L"\\SmApiPort");
   NTSTATUS           Status = STATUS_SUCCESS;
 
-  RtlRosInitUnicodeStringFromLiteral(&UnicodeString,
-                      L"\\SmApiPort");
   InitializeObjectAttributes(&ObjectAttributes,
                             &UnicodeString,
-                            PORT_ALL_ACCESS,
+                            0,
                             NULL,
                             NULL);
 
@@ -387,8 +383,8 @@ SmCreateApiPort(VOID)
                      NULL,
                      FALSE,
                      0,
-                     NULL,
-                     NULL,
+                     0,
+                     0,
                      (PTHREAD_START_ROUTINE)SmpApiThread,
                      (PVOID)SmApiPort,
                      NULL,