Create a branch for header work.

svn path=/branches/header-work/; revision=45691
This commit is contained in:
Timo Kreuzer 2010-02-26 22:57:55 +00:00
parent 14fe274b1c
commit 9ea495ba33
19538 changed files with 0 additions and 1063950 deletions

61
lib/smlib/compses.c Normal file
View file

@ -0,0 +1,61 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/smlib/compses.c
* PURPOSE: Call SM API SM_API_COMPLETE_SESSION
*/
#include "precomp.h"
#define NDEBUG
#include <debug.h>
/**********************************************************************
* NAME EXPORTED
* SmCompleteSession/3
*
* DESCRIPTION
* This function is called by an environment subsystem server to
* tell the SM it finished initialization phase and is ready to
* manage processes it registered for (SmConnectApiPort).
*
* ARGUMENTS
* hSmApiPort: port handle returned by SmConnectApiPort;
* hSbApiPort: call back API port of the subsystem (handle);
* hApiPort : API port of the subsystem (handle).
*
* RETURN VALUE
* Success status as handed by the SM reply; otherwise a failure
* status code.
*/
NTSTATUS WINAPI
SmCompleteSession (IN HANDLE hSmApiPort,
IN HANDLE hSbApiPort,
IN HANDLE hApiPort)
{
NTSTATUS Status;
SM_PORT_MESSAGE SmReqMsg;
DPRINT("SMLIB: %s called\n", __FUNCTION__);
/* Marshal Ses in the LPC message */
SmReqMsg.Request.CompSes.hApiPort = hApiPort;
SmReqMsg.Request.CompSes.hSbApiPort = hSbApiPort;
/* SM API to invoke */
SmReqMsg.SmHeader.ApiIndex = SM_API_COMPLETE_SESSION;
/* Port message */
SmReqMsg.Header.u2.s2.Type = LPC_NEW_MESSAGE;
SmReqMsg.Header.u1.s1.DataLength = SM_PORT_DATA_SIZE(SmReqMsg.Request);
SmReqMsg.Header.u1.s1.TotalLength = SM_PORT_MESSAGE_SIZE;
Status = NtRequestWaitReplyPort (hSmApiPort, (PPORT_MESSAGE) & SmReqMsg, (PPORT_MESSAGE) & SmReqMsg);
if (NT_SUCCESS(Status))
{
return SmReqMsg.SmHeader.Status;
}
DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
return Status;
}
/* EOF */

104
lib/smlib/connect.c Normal file
View file

@ -0,0 +1,104 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: reactos/lib/smlib/connect.c
* PURPOSE: Connect to the API LPC port exposed by the SM
*/
#include "precomp.h"
#define NDEBUG
#include <debug.h>
/**********************************************************************
* NAME EXPORTED
* SmConnectApiPort/4
*
* DESCRIPTION
* Connect to SM API port and register a session "begin" port (Sb)
* or to issue API requests to SmApiPort.
*
* ARGUMENTS
* pSbApiPortName: name of the Sb port the calling subsystem
* server already created in the system name space;
* hSbApiPort: LPC port handle (checked, but not used: the
* subsystem is required to have already created
* the callback port before it connects to the SM);
* wSubsystem: a valid IMAGE_SUBSYSTEM_xxx value;
* phSmApiPort: a pointer to a HANDLE, which will be
* filled with a valid client-side LPC comm port.
*
* There should be only two ways to call this API:
* a) subsystems willing to register with SM will use it
* with full parameters (the function checks them);
* b) regular SM clients, will set to 0 the 1st, the 2nd,
* and the 3rd parameter.
*
* RETURN VALUE
* If all three optional values are omitted, an LPC status.
* STATUS_INVALID_PARAMETER_MIX if PortName is defined and
* both hSbApiPort and wSubsystem are 0.
*/
NTSTATUS WINAPI
SmConnectApiPort (IN PUNICODE_STRING pSbApiPortName OPTIONAL,
IN HANDLE hSbApiPort OPTIONAL,
IN WORD wSubSystemId OPTIONAL,
IN OUT PHANDLE phSmApiPort)
{
UNICODE_STRING SmApiPortName;
SECURITY_QUALITY_OF_SERVICE SecurityQos;
NTSTATUS Status = STATUS_SUCCESS;
SM_CONNECT_DATA ConnectData = {0,0,{0}};
ULONG ConnectDataLength = 0;
DPRINT("SMLIB: %s called\n", __FUNCTION__);
if (pSbApiPortName)
{
if (pSbApiPortName->Length > (sizeof pSbApiPortName->Buffer[0] * SM_SB_NAME_MAX_LENGTH))
{
return STATUS_INVALID_PARAMETER_1;
}
if (NULL == hSbApiPort || IMAGE_SUBSYSTEM_UNKNOWN == wSubSystemId)
{
return STATUS_INVALID_PARAMETER_MIX;
}
RtlZeroMemory (& ConnectData, sizeof ConnectData);
ConnectData.Unused = 0;
ConnectData.SubSystemId = wSubSystemId;
if (pSbApiPortName->Length > 0)
{
RtlCopyMemory (& ConnectData.SbName,
pSbApiPortName->Buffer,
pSbApiPortName->Length);
}
}
ConnectDataLength = sizeof ConnectData;
SecurityQos.Length = sizeof (SecurityQos);
SecurityQos.ImpersonationLevel = SecurityIdentification;
SecurityQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
SecurityQos.EffectiveOnly = TRUE;
RtlInitUnicodeString (& SmApiPortName, SM_API_PORT_NAME);
Status = NtConnectPort (
phSmApiPort,
& SmApiPortName,
& SecurityQos,
NULL,
NULL,
NULL,
& ConnectData,
& ConnectDataLength
);
if (NT_SUCCESS(Status))
{
return STATUS_SUCCESS;
}
DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
return Status;
}
/* EOF */

84
lib/smlib/execpgm.c Normal file
View file

@ -0,0 +1,84 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/smlib/execpgm.c
* PURPOSE: Call SM API SM_API_EXECPGM
*/
#include "precomp.h"
#define NDEBUG
#include <debug.h>
/**********************************************************************
* NAME EXPORTED
* SmExecuteProgram/2
*
* DESCRIPTION
* This function is used to make the SM start an environment
* subsystem server process.
*
* ARGUMENTS
* hSmApiPort: port handle returned by SmConnectApiPort;
* Pgm : name of the subsystem (to be used by the SM to
* lookup the image name from the registry).
* Valid names are: DEBUG, WINDOWS, POSIX, OS2,
* and VMS.
*
* RETURN VALUE
* Success status as handed by the SM reply; otherwise a failure
* status code.
*/
NTSTATUS WINAPI
SmExecuteProgram (IN HANDLE hSmApiPort,
IN PUNICODE_STRING Pgm)
{
NTSTATUS Status;
SM_PORT_MESSAGE SmReqMsg;
DPRINT("SMLIB: %s(%08lx,'%S') called\n",
__FUNCTION__, hSmApiPort, Pgm->Buffer);
/* Check Pgm's length */
if (Pgm->Length > (sizeof (Pgm->Buffer[0]) * SM_EXEXPGM_MAX_LENGTH))
{
return STATUS_INVALID_PARAMETER;
}
/* Marshal Pgm in the LPC message */
RtlZeroMemory (& SmReqMsg, sizeof SmReqMsg);
SmReqMsg.Request.ExecPgm.NameLength = Pgm->Length;
RtlCopyMemory (SmReqMsg.Request.ExecPgm.Name,
Pgm->Buffer,
Pgm->Length);
/* SM API to invoke */
SmReqMsg.SmHeader.ApiIndex = SM_API_EXECUTE_PROGRAMME;
/* LPC message */
SmReqMsg.Header.u2.s2.Type = LPC_NEW_MESSAGE;
SmReqMsg.Header.u1.s1.DataLength = SM_PORT_DATA_SIZE(SmReqMsg.Request);
SmReqMsg.Header.u1.s1.TotalLength = SM_PORT_MESSAGE_SIZE;
DPRINT("SMLIB: %s:\n"
" u2.s2.Type = %d\n"
" u1.s1.DataLength = %d\n"
" u1.s1.TotalLength = %d\n"
" sizeof(PORT_MESSAGE)==%d\n",
__FUNCTION__,
SmReqMsg.Header.u2.s2.Type,
SmReqMsg.Header.u1.s1.DataLength,
SmReqMsg.Header.u1.s1.TotalLength,
sizeof(PORT_MESSAGE));
/* Call SM and wait for a reply */
Status = NtRequestWaitReplyPort (hSmApiPort, (PPORT_MESSAGE) & SmReqMsg, (PPORT_MESSAGE) & SmReqMsg);
if (NT_SUCCESS(Status))
{
return SmReqMsg.SmHeader.Status;
}
DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
return Status;
}
/* EOF */

153
lib/smlib/lookupss.c Normal file
View file

@ -0,0 +1,153 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/smlib/lookupss.c
*/
#include "precomp.h"
#define NDEBUG
#include <debug.h>
/**********************************************************************
* NAME EXPORTED
* SmLookupSubsystem/6
*
* DESCRIPTION
* Read from the registry key
* \Registry\SYSTEM\CurrentControlSet\Control\Session Manager\Subsystems
* the value which name is Name.
*
* ARGUMENTS
* Name: name of the program to run, that is a value's name in
* the SM registry key Subsystems;
* Data: what the registry gave back for Name;
* DataLength: how much Data the registry returns;
* DataType: what is Data?
* Environment: set it if you want this function to use it
* to possibly expand Data before giving it back; if set
* to NULL, no expansion will be performed.
*/
NTSTATUS WINAPI
SmLookupSubsystem (IN PWSTR Name,
IN OUT PWSTR Data,
IN OUT PULONG DataLength,
IN OUT PULONG DataType,
IN PVOID Environment OPTIONAL)
{
NTSTATUS Status = STATUS_SUCCESS;
UNICODE_STRING usKeyName = { 0, 0, NULL };
OBJECT_ATTRIBUTES Oa = {0};
HANDLE hKey = (HANDLE) 0;
DPRINT("SM: %s(Name='%S') called\n", __FUNCTION__, Name);
/*
* Prepare the key name to scan and
* related object attributes.
*/
RtlInitUnicodeString (& usKeyName,
L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\SubSystems");
InitializeObjectAttributes (& Oa,
& usKeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
/*
* Open the key. This MUST NOT fail, if the
* request is for a legitimate subsystem.
*/
Status = NtOpenKey (& hKey,
MAXIMUM_ALLOWED,
& Oa);
if(NT_SUCCESS(Status))
{
UNICODE_STRING usValueName = { 0, 0, NULL };
PWCHAR KeyValueInformation = NULL;
ULONG KeyValueInformationLength = 1024;
ULONG ResultLength = 0L;
PKEY_VALUE_PARTIAL_INFORMATION kvpi = NULL;
KeyValueInformation = RtlAllocateHeap (RtlGetProcessHeap(),
0,
KeyValueInformationLength);
if (NULL == KeyValueInformation)
{
return STATUS_NO_MEMORY;
}
kvpi = (PKEY_VALUE_PARTIAL_INFORMATION) KeyValueInformation;
RtlInitUnicodeString (& usValueName, Name);
Status = NtQueryValueKey (hKey,
& usValueName,
KeyValuePartialInformation,
KeyValueInformation,
KeyValueInformationLength,
& ResultLength);
if(NT_SUCCESS(Status))
{
DPRINT("nkvpi.TitleIndex = %ld\n", kvpi->TitleIndex);
DPRINT("kvpi.Type = %ld\n", kvpi->Type);
DPRINT("kvpi.DataLength = %ld\n", kvpi->DataLength);
if((NULL != Data) && (NULL != DataLength) && (NULL != DataType))
{
*DataType = kvpi->Type;
if((NULL != Environment) && (REG_EXPAND_SZ == *DataType))
{
UNICODE_STRING Source;
PWCHAR DestinationBuffer = NULL;
UNICODE_STRING Destination;
ULONG Length = 0;
DPRINT("SM: %s: value will be expanded\n", __FUNCTION__);
DestinationBuffer = RtlAllocateHeap (RtlGetProcessHeap(),
0,
(2 * KeyValueInformationLength));
if (NULL == DestinationBuffer)
{
Status = STATUS_NO_MEMORY;
}
else
{
Source.Length = kvpi->DataLength;
Source.MaximumLength = kvpi->DataLength;
Source.Buffer = (PWCHAR) & kvpi->Data;
Destination.Length = 0;
Destination.MaximumLength = (2 * KeyValueInformationLength);
Destination.Buffer = DestinationBuffer;
Status = RtlExpandEnvironmentStrings_U (Environment,
& Source,
& Destination,
& Length);
if(NT_SUCCESS(Status))
{
*DataLength = min(*DataLength, Destination.Length);
RtlCopyMemory (Data, Destination.Buffer, *DataLength);
}
RtlFreeHeap (RtlGetProcessHeap(), 0, DestinationBuffer);
}
}else{
DPRINT("SM: %s: value won't be expanded\n", __FUNCTION__);
*DataLength = min(*DataLength, kvpi->DataLength);
RtlCopyMemory (Data, & kvpi->Data, *DataLength);
}
*DataType = kvpi->Type;
}else{
DPRINT1("SM: %s: Data or DataLength or DataType is NULL!\n", __FUNCTION__);
Status = STATUS_INVALID_PARAMETER;
}
}else{
DPRINT1("%s: NtQueryValueKey failed (Status=0x%08lx)\n", __FUNCTION__, Status);
}
RtlFreeHeap (RtlGetProcessHeap(), 0, KeyValueInformation);
NtClose (hKey);
}else{
DPRINT1("%s: NtOpenKey failed (Status=0x%08lx)\n", __FUNCTION__, Status);
}
return Status;
}
/* EOF */

18
lib/smlib/precomp.h Normal file
View file

@ -0,0 +1,18 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS System Libraries
* FILE: lib/smlib/precomp.h
* PURPOSE: SMLIB Library Header
* PROGRAMMER: Alex Ionescu (alex@relsoft.net)
*/
/* INCLUDES ******************************************************************/
/* SDK/DDK/NDK Headers. */
#define WIN32_NO_STATUS
#include <windows.h>
#define NTOS_MODE_USER
#include <ndk/ntndk.h>
#include <sm/helper.h>

11
lib/smlib/smlib.rbuild Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "../../tools/rbuild/project.dtd">
<module name="smlib" type="staticlibrary">
<include base="smlib">.</include>
<include base="ReactOS">include/reactos/subsys</include>
<file>connect.c</file>
<file>execpgm.c</file>
<file>compses.c</file>
<file>lookupss.c</file>
<pch>precomp.h</pch>
</module>