2008-09-23 10:47:10 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Session Manager
|
|
|
|
* LICENSE: GPL v2 or later - See COPYING in the top level directory
|
|
|
|
* FILE: base/system/smss/print.c
|
|
|
|
* PURPOSE: \SmApiPort LPC port message management.
|
|
|
|
* PROGRAMMERS: ReactOS Development Team
|
1999-12-01 15:18:54 +00:00
|
|
|
*/
|
2008-09-23 10:47:10 +00:00
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
1999-12-01 15:18:54 +00:00
|
|
|
#include "smss.h"
|
|
|
|
|
2005-02-24 22:20:43 +00:00
|
|
|
#define NDEBUG
|
2005-02-13 22:55:28 +00:00
|
|
|
#include <debug.h>
|
1999-12-01 15:18:54 +00:00
|
|
|
|
2002-05-24 07:52:09 +00:00
|
|
|
/* GLOBAL VARIABLES *********************************************************/
|
|
|
|
|
|
|
|
static HANDLE SmApiPort = INVALID_HANDLE_VALUE;
|
|
|
|
|
2005-02-12 09:08:52 +00:00
|
|
|
/* SM API *******************************************************************/
|
2005-02-06 21:55:07 +00:00
|
|
|
|
|
|
|
SMAPI(SmInvalid)
|
|
|
|
{
|
2009-06-29 21:10:40 +00:00
|
|
|
DPRINT("SM: %s called\n",__FUNCTION__);
|
|
|
|
Request->SmHeader.Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
return STATUS_SUCCESS;
|
2005-02-06 21:55:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SM API Table */
|
|
|
|
typedef NTSTATUS (FASTCALL * SM_PORT_API)(PSM_PORT_MESSAGE);
|
|
|
|
|
|
|
|
SM_PORT_API SmApi [] =
|
|
|
|
{
|
2009-06-29 21:10:40 +00:00
|
|
|
SmInvalid, /* unused */
|
|
|
|
SmCompSes, /* smapicomp.c */
|
|
|
|
SmInvalid, /* obsolete */
|
|
|
|
SmInvalid, /* unknown */
|
|
|
|
SmExecPgm, /* smapiexec.c */
|
|
|
|
SmQryInfo /* smapyqry.c */
|
2005-02-06 21:55:07 +00:00
|
|
|
};
|
|
|
|
|
2005-05-08 04:07:56 +00:00
|
|
|
/* TODO: optimize this address computation (it should be done
|
2005-03-20 22:55:05 +00:00
|
|
|
* with a macro) */
|
|
|
|
PSM_CONNECT_DATA FASTCALL SmpGetConnectData (PSM_PORT_MESSAGE Request)
|
|
|
|
{
|
2009-06-29 21:10:40 +00:00
|
|
|
PPORT_MESSAGE PortMessage = (PPORT_MESSAGE) Request;
|
|
|
|
return (PSM_CONNECT_DATA)(PortMessage + 1);
|
2005-03-20 22:55:05 +00:00
|
|
|
}
|
|
|
|
|
2008-11-30 11:16:55 +00:00
|
|
|
NTSTATUS NTAPI
|
2005-02-19 22:58:18 +00:00
|
|
|
SmpHandleConnectionRequest (PSM_PORT_MESSAGE Request);
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
/**********************************************************************
|
2005-05-22 15:54:15 +00:00
|
|
|
* SmpCallbackServer/2
|
2005-03-20 22:55:05 +00:00
|
|
|
*
|
2005-05-22 15:54:15 +00:00
|
|
|
* 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.
|
2005-03-20 22:55:05 +00:00
|
|
|
*/
|
|
|
|
static NTSTATUS
|
|
|
|
SmpCallbackServer (PSM_PORT_MESSAGE Request,
|
2009-06-29 21:10:40 +00:00
|
|
|
PSM_CLIENT_DATA ClientData)
|
2005-03-20 22:55:05 +00:00
|
|
|
{
|
2009-06-29 21:10:40 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
PSM_CONNECT_DATA ConnectData = SmpGetConnectData (Request);
|
|
|
|
UNICODE_STRING CallbackPortName;
|
|
|
|
ULONG CallbackPortNameLength = SM_SB_NAME_MAX_LENGTH; /* TODO: compute length */
|
|
|
|
SB_CONNECT_DATA SbConnectData;
|
|
|
|
ULONG SbConnectDataLength = sizeof SbConnectData;
|
|
|
|
SECURITY_QUALITY_OF_SERVICE SecurityQos;
|
|
|
|
|
|
|
|
DPRINT("SM: %s called\n", __FUNCTION__);
|
|
|
|
|
|
|
|
if ( ((USHORT)-1 == ConnectData->SubSystemId) ||
|
|
|
|
(IMAGE_SUBSYSTEM_NATIVE == ConnectData->SubSystemId))
|
|
|
|
{
|
|
|
|
DPRINT("SM: %s: we do not need calling back SM!\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
RtlCopyMemory (ClientData->SbApiPortName,
|
|
|
|
ConnectData->SbName,
|
|
|
|
CallbackPortNameLength);
|
|
|
|
RtlInitUnicodeString (& CallbackPortName,
|
|
|
|
ClientData->SbApiPortName);
|
2005-04-10 19:08:23 +00:00
|
|
|
|
2006-10-30 14:17:37 +00:00
|
|
|
SecurityQos.Length = sizeof (SecurityQos);
|
|
|
|
SecurityQos.ImpersonationLevel = SecurityIdentification;
|
|
|
|
SecurityQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
|
|
|
|
SecurityQos.EffectiveOnly = TRUE;
|
|
|
|
|
2009-06-29 21:10:40 +00:00
|
|
|
SbConnectData.SmApiMax = (sizeof SmApi / sizeof SmApi[0]);
|
|
|
|
Status = NtConnectPort (& ClientData->SbApiPort,
|
|
|
|
& CallbackPortName,
|
|
|
|
&SecurityQos,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
& SbConnectData,
|
|
|
|
& SbConnectDataLength);
|
|
|
|
return Status;
|
2005-03-20 22:55:05 +00:00
|
|
|
}
|
2005-02-19 22:58:18 +00:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* NAME
|
|
|
|
* SmpApiConnectedThread/1
|
|
|
|
*
|
|
|
|
* DESCRIPTION
|
|
|
|
* Entry point for the listener thread of LPC port "\SmApiPort".
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
VOID NTAPI
|
2005-03-13 17:01:59 +00:00
|
|
|
SmpApiConnectedThread(PVOID pConnectedPort)
|
2005-02-19 22:58:18 +00:00
|
|
|
{
|
2009-06-29 21:10:40 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
PPORT_MESSAGE Reply = NULL;
|
|
|
|
SM_PORT_MESSAGE Request;
|
|
|
|
HANDLE ConnectedPort = * (PHANDLE) pConnectedPort;
|
|
|
|
|
|
|
|
DPRINT("SM: %s called\n", __FUNCTION__);
|
|
|
|
RtlZeroMemory(&Request, sizeof(SM_PORT_MESSAGE));
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
DPRINT("SM: %s: waiting for message\n",__FUNCTION__);
|
|
|
|
|
|
|
|
Status = NtReplyWaitReceivePort(ConnectedPort,
|
|
|
|
NULL,
|
|
|
|
Reply,
|
|
|
|
(PPORT_MESSAGE) & Request);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT("SM: %s: message received (type=%d)\n",
|
|
|
|
__FUNCTION__,
|
|
|
|
Request.Header.u2.s2.Type);
|
|
|
|
|
|
|
|
switch (Request.Header.u2.s2.Type)
|
|
|
|
{
|
|
|
|
case LPC_CONNECTION_REQUEST:
|
|
|
|
SmpHandleConnectionRequest (&Request);
|
|
|
|
Reply = NULL;
|
|
|
|
break;
|
|
|
|
case LPC_DEBUG_EVENT:
|
2005-02-19 22:58:18 +00:00
|
|
|
// DbgSsHandleKmApiMsg (&Request, 0);
|
2009-06-29 21:10:40 +00:00
|
|
|
Reply = NULL;
|
|
|
|
break;
|
|
|
|
case LPC_PORT_CLOSED:
|
|
|
|
Reply = NULL;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
if ((Request.SmHeader.ApiIndex) &&
|
|
|
|
(Request.SmHeader.ApiIndex < (sizeof SmApi / sizeof SmApi[0])))
|
|
|
|
{
|
|
|
|
Status = SmApi[Request.SmHeader.ApiIndex](&Request);
|
|
|
|
Reply = (PPORT_MESSAGE) & Request;
|
|
|
|
} else {
|
|
|
|
Request.SmHeader.Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
Reply = (PPORT_MESSAGE) & Request;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* LPC failed */
|
|
|
|
DPRINT1("SM: %s: NtReplyWaitReceivePort() failed (Status=0x%08lx)\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NtClose (ConnectedPort);
|
|
|
|
DPRINT("SM: %s done\n", __FUNCTION__);
|
|
|
|
NtTerminateThread (NtCurrentThread(), Status);
|
2005-02-19 22:58:18 +00:00
|
|
|
}
|
2002-05-24 07:52:09 +00:00
|
|
|
|
2005-02-06 21:55:07 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* NAME
|
2005-02-19 22:58:18 +00:00
|
|
|
* SmpHandleConnectionRequest/1
|
|
|
|
*
|
|
|
|
* ARGUMENTS
|
|
|
|
* Request: LPC connection request message
|
2005-02-06 21:55:07 +00:00
|
|
|
*
|
|
|
|
* REMARKS
|
|
|
|
* Quoted in http://support.microsoft.com/kb/258060/EN-US/
|
|
|
|
*/
|
2008-11-30 11:16:55 +00:00
|
|
|
NTSTATUS NTAPI
|
2005-02-19 22:58:18 +00:00
|
|
|
SmpHandleConnectionRequest (PSM_PORT_MESSAGE Request)
|
2005-02-06 21:55:07 +00:00
|
|
|
{
|
2009-06-29 21:10:40 +00:00
|
|
|
PSM_CONNECT_DATA ConnectData = SmpGetConnectData (Request);
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
BOOL Accept = FALSE;
|
|
|
|
PSM_CLIENT_DATA ClientData = NULL;
|
|
|
|
HANDLE hClientDataApiPort = (HANDLE) 0;
|
|
|
|
PHANDLE ClientDataApiPort = & hClientDataApiPort;
|
|
|
|
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);
|
|
|
|
|
|
|
|
if(sizeof (SM_CONNECT_DATA) == Request->Header.u1.s1.DataLength)
|
|
|
|
{
|
|
|
|
if(IMAGE_SUBSYSTEM_UNKNOWN == ConnectData->SubSystemId)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This is not a call to register an image set,
|
|
|
|
* but a simple connection request from a process
|
|
|
|
* that will use the SM API.
|
|
|
|
*/
|
|
|
|
DPRINT("SM: %s: simple request\n", __FUNCTION__);
|
|
|
|
ClientDataApiPort = & hClientDataApiPort;
|
|
|
|
ClientDataApiPortThread = & hClientDataApiPortThread;
|
|
|
|
Accept = TRUE;
|
|
|
|
} else {
|
|
|
|
DPRINT("SM: %s: request to register an image set\n", __FUNCTION__);
|
|
|
|
/*
|
|
|
|
* Reject GUIs classes: only odd subsystem IDs are
|
|
|
|
* allowed to register here (tty mode images).
|
|
|
|
*/
|
|
|
|
if(1 == (ConnectData->SubSystemId % 2))
|
|
|
|
{
|
|
|
|
DPRINT("SM: %s: id = %d\n", __FUNCTION__, ConnectData->SubSystemId);
|
|
|
|
/*
|
|
|
|
* SmBeginClientInitialization/2 will succeed only if there
|
|
|
|
* is a candidate client ready.
|
|
|
|
*/
|
|
|
|
Status = SmBeginClientInitialization (Request, & ClientData);
|
|
|
|
if(STATUS_SUCCESS == Status)
|
|
|
|
{
|
|
|
|
DPRINT("SM: %s: ClientData = %p\n",
|
|
|
|
__FUNCTION__, ClientData);
|
|
|
|
/*
|
|
|
|
* OK: the client is an environment subsystem
|
|
|
|
* willing to manage a free image type.
|
|
|
|
*/
|
|
|
|
ClientDataApiPort = & ClientData->ApiPort;
|
|
|
|
ClientDataApiPortThread = & ClientData->ApiPortThread;
|
|
|
|
/*
|
|
|
|
* Call back the candidate environment subsystem
|
|
|
|
* server (use the port name sent in in the
|
|
|
|
* connection request message).
|
|
|
|
*/
|
|
|
|
Status = SmpCallbackServer (Request, ClientData);
|
|
|
|
if(NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT("SM: %s: SmpCallbackServer OK\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
Accept = TRUE;
|
|
|
|
} else {
|
|
|
|
DPRINT("SM: %s: SmpCallbackServer failed (Status=%08lx)\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
Status = SmDestroyClient (ConnectData->SubSystemId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DPRINT("SM: %s: before NtAcceptConnectPort\n", __FUNCTION__);
|
|
|
|
|
|
|
|
Status = NtAcceptConnectPort (ClientDataApiPort,
|
|
|
|
Context,
|
|
|
|
(PPORT_MESSAGE) Request,
|
|
|
|
Accept,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if(Accept)
|
|
|
|
{
|
|
|
|
if(!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("SM: %s: NtAcceptConnectPort() failed (Status=0x%08lx)\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
return Status;
|
|
|
|
} else {
|
|
|
|
DPRINT("SM: %s: completing connection request\n", __FUNCTION__);
|
|
|
|
Status = NtCompleteConnectPort (*ClientDataApiPort);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("SM: %s: NtCompleteConnectPort() failed (Status=0x%08lx)\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
DPRINT("SM: %s done\n", __FUNCTION__);
|
|
|
|
return Status;
|
2005-02-06 21:55:07 +00:00
|
|
|
}
|
1999-12-01 15:18:54 +00:00
|
|
|
|
2005-02-12 09:08:52 +00:00
|
|
|
|
|
|
|
/* LPC PORT INITIALIZATION **************************************************/
|
|
|
|
|
|
|
|
|
2005-02-06 21:55:07 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* NAME
|
2005-02-12 09:08:52 +00:00
|
|
|
* SmCreateApiPort/0
|
2005-02-06 21:55:07 +00:00
|
|
|
*
|
|
|
|
* DECRIPTION
|
|
|
|
*/
|
2002-05-24 07:52:09 +00:00
|
|
|
NTSTATUS
|
2005-02-12 09:08:52 +00:00
|
|
|
SmCreateApiPort(VOID)
|
2002-05-24 07:52:09 +00:00
|
|
|
{
|
2005-02-19 22:58:18 +00:00
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes = {0};
|
2009-05-23 15:02:19 +00:00
|
|
|
UNICODE_STRING UnicodeString = RTL_CONSTANT_STRING(SM_API_PORT_NAME);
|
2005-02-19 22:58:18 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2002-05-24 07:52:09 +00:00
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
2009-06-29 21:10:40 +00:00
|
|
|
&UnicodeString,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2002-05-24 07:52:09 +00:00
|
|
|
|
|
|
|
Status = NtCreatePort(&SmApiPort,
|
2009-06-29 21:10:40 +00:00
|
|
|
&ObjectAttributes,
|
|
|
|
sizeof(SM_CONNECT_DATA),
|
|
|
|
sizeof(SM_PORT_MESSAGE),
|
|
|
|
0);
|
2002-05-24 07:52:09 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return(Status);
|
1999-12-01 15:18:54 +00:00
|
|
|
}
|
2009-06-22 11:33:19 +00:00
|
|
|
|
2005-02-19 22:58:18 +00:00
|
|
|
/*
|
|
|
|
* Create one thread for the named LPC
|
|
|
|
* port \SmApiPort
|
|
|
|
*/
|
2002-05-24 07:52:09 +00:00
|
|
|
RtlCreateUserThread(NtCurrentProcess(),
|
2009-06-29 21:10:40 +00:00
|
|
|
NULL,
|
|
|
|
FALSE,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
(PTHREAD_START_ROUTINE)SmpApiConnectedThread,
|
|
|
|
&SmApiPort,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On NT LPC, we need a second thread to handle incoming connections
|
|
|
|
* generated by incoming requests, otherwise the thread handling
|
|
|
|
* the request will be busy sending the LPC message, without any other
|
|
|
|
* thread being busy to receive the LPC message.
|
|
|
|
*/
|
2006-10-30 14:17:37 +00:00
|
|
|
Status = RtlCreateUserThread(NtCurrentProcess(),
|
|
|
|
NULL,
|
|
|
|
FALSE,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
(PTHREAD_START_ROUTINE)SmpApiConnectedThread,
|
|
|
|
&SmApiPort,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
2002-05-24 07:52:09 +00:00
|
|
|
return(Status);
|
1999-12-01 15:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|