SMDLL + SMLIB (static code in SMSS.EXE)
SM now self registers for IMAGE_SUBSYSTEM_NATIVE.
Modified: trunk/reactos/Makefile
Modified: trunk/reactos/include/sm/helper.h
Deleted: trunk/reactos/lib/smdll/compses.c
Deleted: trunk/reactos/lib/smdll/connect.c
Deleted: trunk/reactos/lib/smdll/execpgm.c
Modified: trunk/reactos/lib/smdll/makefile
Added: trunk/reactos/lib/smdll/query.c
Modified: trunk/reactos/lib/smdll/smdll.def
Added: trunk/reactos/lib/smlib/
Added: trunk/reactos/lib/smlib/compses.c
Added: trunk/reactos/lib/smlib/connect.c
Added: trunk/reactos/lib/smlib/execpgm.c
Added: trunk/reactos/lib/smlib/makefile
Modified: trunk/reactos/subsys/smss/initss.c
Modified: trunk/reactos/subsys/smss/makefile

Modified: trunk/reactos/Makefile
--- trunk/reactos/Makefile	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/Makefile	2005-03-14 22:38:12 UTC (rev 14080)
@@ -61,8 +61,8 @@
 DLLS = acledit aclui advapi32 advpack cabinet cards comctl32 crtdll comdlg32 d3d8thk dbghelp expat fmifs freetype \
 	gdi32 gdiplus glu32 hid imagehlp imm32 iphlpapi kernel32 lzexpand mesa32 midimap mmdrv mpr msacm msafd \
 	msgina msi msimg32 msvcrt20 msvideo mswsock netapi32 ntdll ole32 oleaut32 oledlg olepro32 opengl32 \
-	packet psapi riched20 richedit rpcrt4 samlib secur32 setupapi shell32 shlwapi smdll snmpapi syssetup \
-	twain user32 userenv version wininet winmm winspool ws2help ws2_32 wsock32 wshirda dnsapi \
+	packet psapi riched20 richedit rpcrt4 samlib secur32 setupapi shell32 shlwapi smlib smdll snmpapi \
+	syssetup twain user32 userenv version wininet winmm winspool ws2help ws2_32 wsock32 wshirda dnsapi \
 	urlmon shdocvw dinput dinput8 dxdiagn devenum dsound lsasrv $(DLLS_KBD) $(DLLS_CPL) $(DLLS_SHELLEXT)
 
 SUBSYS = smss win32k csrss ntvdm

Modified: trunk/reactos/include/sm/helper.h
--- trunk/reactos/include/sm/helper.h	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/include/sm/helper.h	2005-03-14 22:38:12 UTC (rev 14080)
@@ -3,21 +3,31 @@
 
 /* $Id$ */
 
-/* smdll/connect.c */
+/* smlib/connect.c */
 NTSTATUS STDCALL
 SmConnectApiPort (IN      PUNICODE_STRING  pSbApiPortName  OPTIONAL,
 		  IN      HANDLE           hSbApiPort      OPTIONAL,
 		  IN      DWORD            dwSubsystem     OPTIONAL, /* pe.h */
 		  IN OUT  PHANDLE          phSmApiPort);
-/* smdll/compses.c */
+/* smlib/compses.c */
 NTSTATUS STDCALL
 SmCompleteSession (IN     HANDLE  hSmApiPort,
 		   IN     HANDLE  hSbApiPort,
 		   IN     HANDLE  hApiPort);
-/* smdll/execpgm.c */
+/* smlib/execpgm.c */
 NTSTATUS STDCALL
 SmExecuteProgram (IN     HANDLE           hSmApiPort,
 		  IN     PUNICODE_STRING  Pgm
 		  );
+/* smdll/query.c */
+typedef enum {
+	SM_BASE_INFORMATION
+} SM_INFORMATION_CLASS, *PSM_INFORMATION_CLASS;
 
+NTSTATUS STDCALL
+SmQuery (IN      HANDLE                SmApiPort,
+	 IN      SM_INFORMATION_CLASS  SmInformationClass,
+	 IN OUT  PVOID                 Data,
+	 IN OUT  PULONG                DataLength);
+
 #endif /* ndef INCLUDE_SM_HELPER_H */

Deleted: trunk/reactos/lib/smdll/compses.c
--- trunk/reactos/lib/smdll/compses.c	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/lib/smdll/compses.c	2005-03-14 22:38:12 UTC (rev 14080)
@@ -1,64 +0,0 @@
-/* $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
- */
-#define NTOS_MODE_USER
-#include <ntos.h>
-#include <sm/api.h>
-#include <sm/helper.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 STDCALL
-SmCompleteSession (IN HANDLE hSmApiPort,
-		   IN HANDLE hSbApiPort,
-		   IN HANDLE hApiPort)
-{
-  NTSTATUS         Status;
-  SM_PORT_MESSAGE  SmReqMsg;
-    
-  DPRINT("SMDLL: %s called\n", __FUNCTION__);
-
-  /* Marshal Ses in the LPC message */
-  SmReqMsg.CompSes.hApiPort   = hApiPort;
-  SmReqMsg.CompSes.hSbApiPort = hSbApiPort;
-
-  /* SM API to invoke */
-  SmReqMsg.ApiIndex = SM_API_COMPLETE_SESSION;
-
-  /* Port message */
-  SmReqMsg.Header.MessageType = LPC_NEW_MESSAGE;
-  SmReqMsg.Header.DataSize    = SM_PORT_DATA_SIZE(SmReqMsg.CompSes);
-  SmReqMsg.Header.MessageSize = SM_PORT_MESSAGE_SIZE;
-  Status = NtRequestWaitReplyPort (hSmApiPort, (PLPC_MESSAGE) & SmReqMsg, (PLPC_MESSAGE) & SmReqMsg);
-  if (NT_SUCCESS(Status))
-  {
-    return SmReqMsg.Status;
-  }
-  DPRINT("SMDLL: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
-  return Status;
-}
-
-/* EOF */

Deleted: trunk/reactos/lib/smdll/connect.c
--- trunk/reactos/lib/smdll/connect.c	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/lib/smdll/connect.c	2005-03-14 22:38:12 UTC (rev 14080)
@@ -1,98 +0,0 @@
-/* $Id$
- *
- * COPYRIGHT:  See COPYING in the top level directory
- * PROJECT:    ReactOS system libraries
- * FILE:       reactos/lib/smdll/connect.c
- * PURPOSE:    Connect to the API LPC port exposed by the SM
- */
-#define NTOS_MODE_USER
-#include <ntos.h>
-#include <sm/api.h>
-#include <sm/helper.h>
-#include <pe.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);
- *	dwSubsystem: a valid IMAGE_SUBSYSTEM_xxx value;
- *	phSmApiPort: a pointer to a HANDLE, which will be
- *		filled with a valid client-side LPC comm port.
- *	
- * RETURN VALUE
- * 	If all three optional values are omitted, an LPC status.
- * 	STATUS_INVALID_PARAMETER_MIX if PortName is defined and
- * 	both hSbApiPort and dwSubsystem are 0.
- */
-NTSTATUS STDCALL
-SmConnectApiPort (IN      PUNICODE_STRING  pSbApiPortName  OPTIONAL,
-		  IN      HANDLE           hSbApiPort      OPTIONAL,
-		  IN      DWORD            dwSubsystem     OPTIONAL,
-		  IN OUT  PHANDLE          phSmApiPort)
-{
-  UNICODE_STRING              SmApiPortName;
-  SECURITY_QUALITY_OF_SERVICE SecurityQos;
-  NTSTATUS                    Status = STATUS_SUCCESS;
-  SM_CONNECT_DATA             ConnectData = {0,{0}};
-  ULONG                       ConnectDataLength = 0;
-
-  DPRINT("SMDLL: %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 == dwSubsystem)
-    {
-      return STATUS_INVALID_PARAMETER_MIX;
-    }
-    RtlZeroMemory (& ConnectData, sizeof ConnectData);
-    ConnectData.Subsystem = dwSubsystem;
-    if (pSbApiPortName->Length > 0)
-    {
-      RtlCopyMemory (& ConnectData.SbName,
-		     pSbApiPortName->Buffer,
-		     pSbApiPortName->Length);
-    }
-  }
-  ConnectDataLength = sizeof ConnectData;
-
-  SecurityQos.Length              = sizeof (SecurityQos);
-  SecurityQos.ImpersonationLevel  = SecurityIdentification;
-  SecurityQos.ContextTrackingMode = TRUE;
-  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("SMDLL: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
-  return Status;
-}
-
-/* EOF */

Deleted: trunk/reactos/lib/smdll/execpgm.c
--- trunk/reactos/lib/smdll/execpgm.c	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/lib/smdll/execpgm.c	2005-03-14 22:38:12 UTC (rev 14080)
@@ -1,76 +0,0 @@
-/* $Id$
- *
- * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS system libraries
- * FILE:            lib/smdll/execpgm.c
- * PURPOSE:         Call SM API SM_API_EXECPGM
- */
-#define NTOS_MODE_USER
-#include <ntos.h>
-#include <sm/api.h>
-#include <sm/helper.h>
-#include <string.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 STDCALL
-SmExecuteProgram (IN HANDLE          hSmApiPort,
-		  IN PUNICODE_STRING Pgm)
-{
-  NTSTATUS         Status;
-  SM_PORT_MESSAGE  SmReqMsg;
-
-
-  DPRINT("SMDLL: %s called\n", __FUNCTION__);
-
-  /* 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.ExecPgm.NameLength = Pgm->Length;
-  RtlCopyMemory (SmReqMsg.ExecPgm.Name,
-		 Pgm->Buffer,
-		 Pgm->Length);
-		
-  /* SM API to invoke */
-  SmReqMsg.ApiIndex = SM_API_EXECUTE_PROGRAMME;
-
-  /* LPC message */
-  SmReqMsg.Header.MessageType = LPC_NEW_MESSAGE;
-  SmReqMsg.Header.DataSize    = SM_PORT_DATA_SIZE(SmReqMsg.ExecPgm);
-  SmReqMsg.Header.MessageSize = SM_PORT_MESSAGE_SIZE;
-
-  /* Call SM and wait for a reply */
-  Status = NtRequestWaitReplyPort (hSmApiPort, (PLPC_MESSAGE) & SmReqMsg, (PLPC_MESSAGE) & SmReqMsg);
-  if (NT_SUCCESS(Status))
-  {
-    return SmReqMsg.Status;
-  }
-  DPRINT("SMDLL: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
-  return Status;
-}
-
-/* EOF */

Modified: trunk/reactos/lib/smdll/makefile
--- trunk/reactos/lib/smdll/makefile	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/lib/smdll/makefile	2005-03-14 22:38:12 UTC (rev 14080)
@@ -6,7 +6,7 @@
 
 TARGET_NAME = smdll
 
-TARGET_SDKLIBS = ntdll.a
+TARGET_SDKLIBS = smlib.a ntdll.a
 
 TARGET_CFLAGS = -I./include -Wall -Werror
 
@@ -19,9 +19,7 @@
 
 TARGET_OBJECTS = \
 	dllmain.o \
-	connect.o \
-	execpgm.o \
-	compses.o
+	query.o
 	
 DEP_OBJECTS = $(TARGET_OBJECTS)
 

Added: trunk/reactos/lib/smdll/query.c
--- trunk/reactos/lib/smdll/query.c	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/lib/smdll/query.c	2005-03-14 22:38:12 UTC (rev 14080)
@@ -0,0 +1,39 @@
+/* $Id: compses.c 13731 2005-02-23 23:37:06Z ea $
+ *
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS system libraries
+ * FILE:            lib/smdll/query.c
+ * PURPOSE:         Call SM API SM_API_QUERY (not in NT)
+ */
+#define NTOS_MODE_USER
+#include <ntos.h>
+#include <sm/api.h>
+#include <sm/helper.h>
+
+#define NDEBUG
+#include <debug.h>
+
+/**********************************************************************
+ * NAME							EXPORTED
+ *	SmQuery/4
+ *
+ * DESCRIPTION
+ *
+ * ARGUMENTS
+ *
+ * RETURN VALUE
+ */
+NTSTATUS STDCALL
+SmQuery (IN      HANDLE                SmApiPort,
+	 IN      SM_INFORMATION_CLASS  SmInformationClass,
+	 IN OUT  PVOID                 Data,
+	 IN OUT  PULONG                DataLength)
+{
+	/* TODO */
+	if(NULL != DataLength)
+	{
+		*DataLength = 0;
+	}
+	return STATUS_SUCCESS;	
+}
+/* EOF */

Modified: trunk/reactos/lib/smdll/smdll.def
--- trunk/reactos/lib/smdll/smdll.def	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/lib/smdll/smdll.def	2005-03-14 22:38:12 UTC (rev 14080)
@@ -3,3 +3,4 @@
 SmCompleteSession@12
 SmConnectApiPort@16
 SmExecuteProgram@8
+SmQuery@16

Added: trunk/reactos/lib/smlib/compses.c
--- trunk/reactos/lib/smlib/compses.c	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/lib/smlib/compses.c	2005-03-14 22:38:12 UTC (rev 14080)
@@ -0,0 +1,64 @@
+/* $Id: compses.c 13731 2005-02-23 23:37:06Z ea $
+ *
+ * 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
+ */
+#define NTOS_MODE_USER
+#include <ntos.h>
+#include <sm/api.h>
+#include <sm/helper.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 STDCALL
+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.CompSes.hApiPort   = hApiPort;
+  SmReqMsg.CompSes.hSbApiPort = hSbApiPort;
+
+  /* SM API to invoke */
+  SmReqMsg.ApiIndex = SM_API_COMPLETE_SESSION;
+
+  /* Port message */
+  SmReqMsg.Header.MessageType = LPC_NEW_MESSAGE;
+  SmReqMsg.Header.DataSize    = SM_PORT_DATA_SIZE(SmReqMsg.CompSes);
+  SmReqMsg.Header.MessageSize = SM_PORT_MESSAGE_SIZE;
+  Status = NtRequestWaitReplyPort (hSmApiPort, (PLPC_MESSAGE) & SmReqMsg, (PLPC_MESSAGE) & SmReqMsg);
+  if (NT_SUCCESS(Status))
+  {
+    return SmReqMsg.Status;
+  }
+  DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
+  return Status;
+}
+
+/* EOF */

Added: trunk/reactos/lib/smlib/connect.c
--- trunk/reactos/lib/smlib/connect.c	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/lib/smlib/connect.c	2005-03-14 22:38:12 UTC (rev 14080)
@@ -0,0 +1,98 @@
+/* $Id: connect.c 14015 2005-03-13 17:00:19Z ea $
+ *
+ * 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
+ */
+#define NTOS_MODE_USER
+#include <ntos.h>
+#include <sm/api.h>
+#include <sm/helper.h>
+#include <pe.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);
+ *	dwSubsystem: a valid IMAGE_SUBSYSTEM_xxx value;
+ *	phSmApiPort: a pointer to a HANDLE, which will be
+ *		filled with a valid client-side LPC comm port.
+ *	
+ * RETURN VALUE
+ * 	If all three optional values are omitted, an LPC status.
+ * 	STATUS_INVALID_PARAMETER_MIX if PortName is defined and
+ * 	both hSbApiPort and dwSubsystem are 0.
+ */
+NTSTATUS STDCALL
+SmConnectApiPort (IN      PUNICODE_STRING  pSbApiPortName  OPTIONAL,
+		  IN      HANDLE           hSbApiPort      OPTIONAL,
+		  IN      DWORD            dwSubsystem     OPTIONAL,
+		  IN OUT  PHANDLE          phSmApiPort)
+{
+  UNICODE_STRING              SmApiPortName;
+  SECURITY_QUALITY_OF_SERVICE SecurityQos;
+  NTSTATUS                    Status = STATUS_SUCCESS;
+  SM_CONNECT_DATA             ConnectData = {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 == dwSubsystem)
+    {
+      return STATUS_INVALID_PARAMETER_MIX;
+    }
+    RtlZeroMemory (& ConnectData, sizeof ConnectData);
+    ConnectData.Subsystem = dwSubsystem;
+    if (pSbApiPortName->Length > 0)
+    {
+      RtlCopyMemory (& ConnectData.SbName,
+		     pSbApiPortName->Buffer,
+		     pSbApiPortName->Length);
+    }
+  }
+  ConnectDataLength = sizeof ConnectData;
+
+  SecurityQos.Length              = sizeof (SecurityQos);
+  SecurityQos.ImpersonationLevel  = SecurityIdentification;
+  SecurityQos.ContextTrackingMode = TRUE;
+  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 */

Added: trunk/reactos/lib/smlib/execpgm.c
--- trunk/reactos/lib/smlib/execpgm.c	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/lib/smlib/execpgm.c	2005-03-14 22:38:12 UTC (rev 14080)
@@ -0,0 +1,76 @@
+/* $Id: execpgm.c 13731 2005-02-23 23:37:06Z ea $
+ *
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS system libraries
+ * FILE:            lib/smlib/execpgm.c
+ * PURPOSE:         Call SM API SM_API_EXECPGM
+ */
+#define NTOS_MODE_USER
+#include <ntos.h>
+#include <sm/api.h>
+#include <sm/helper.h>
+#include <string.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 STDCALL
+SmExecuteProgram (IN HANDLE          hSmApiPort,
+		  IN PUNICODE_STRING Pgm)
+{
+  NTSTATUS         Status;
+  SM_PORT_MESSAGE  SmReqMsg;
+
+
+  DPRINT("SMLIB: %s called\n", __FUNCTION__);
+
+  /* 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.ExecPgm.NameLength = Pgm->Length;
+  RtlCopyMemory (SmReqMsg.ExecPgm.Name,
+		 Pgm->Buffer,
+		 Pgm->Length);
+		
+  /* SM API to invoke */
+  SmReqMsg.ApiIndex = SM_API_EXECUTE_PROGRAMME;
+
+  /* LPC message */
+  SmReqMsg.Header.MessageType = LPC_NEW_MESSAGE;
+  SmReqMsg.Header.DataSize    = SM_PORT_DATA_SIZE(SmReqMsg.ExecPgm);
+  SmReqMsg.Header.MessageSize = SM_PORT_MESSAGE_SIZE;
+
+  /* Call SM and wait for a reply */
+  Status = NtRequestWaitReplyPort (hSmApiPort, (PLPC_MESSAGE) & SmReqMsg, (PLPC_MESSAGE) & SmReqMsg);
+  if (NT_SUCCESS(Status))
+  {
+    return SmReqMsg.Status;
+  }
+  DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
+  return Status;
+}
+
+/* EOF */

Added: trunk/reactos/lib/smlib/makefile
--- trunk/reactos/lib/smlib/makefile	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/lib/smlib/makefile	2005-03-14 22:38:12 UTC (rev 14080)
@@ -0,0 +1,35 @@
+
+PATH_TO_TOP = ../..
+
+TARGET_TYPE = library
+
+TARGET_NAME = smlib
+
+include $(PATH_TO_TOP)/config
+
+TARGET_CFLAGS = -Wall -Werror -ffreestanding
+
+# require os code to explicitly request A/W version of structs/functions
+TARGET_CFLAGS += -D_DISABLE_TIDENTS
+
+ifneq ($(DBG), 0)
+TARGET_CFLAGS += -DDBG
+endif
+
+TARGET_OBJECTS = \
+	connect.o \
+	execpgm.o \
+	compses.o
+
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+DEP_OBJECTS := $(TARGET_OBJECTS)
+
+TARGET_CLEAN = $(DEP_FILES)
+
+include $(PATH_TO_TOP)/tools/depend.mk
+
+# EOF

Modified: trunk/reactos/subsys/smss/initss.c
--- trunk/reactos/subsys/smss/initss.c	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/subsys/smss/initss.c	2005-03-14 22:38:12 UTC (rev 14080)
@@ -60,7 +60,7 @@
  *	(programmatically). This also open hSmApiPort to be used
  *	in loading required subsystems.
  */
-#if 0
+
 static NTSTATUS
 SmpRegisterSmss(VOID)
 {
@@ -68,7 +68,8 @@
 	UNICODE_STRING SbApiPortName = {0,0,NULL};
 
 	DPRINT("SM: %s called\n",__FUNCTION__);
-	
+
+	RtlInitUnicodeString (& SbApiPortName, L"");	
 	Status = SmConnectApiPort(& SbApiPortName,
 				  (HANDLE) 0,
 				  IMAGE_SUBSYSTEM_NATIVE,
@@ -79,6 +80,7 @@
 			__FUNCTION__,Status);
 		return Status;
 	}
+	DPRINT("SM self registered\n");
 	/*
 	 * Note that you don't need to call complete session
 	 * because connection handling code autocompletes
@@ -86,8 +88,8 @@
 	 */
 	return Status;
 }
-#endif
 
+
 /**********************************************************************
  */
 NTSTATUS
@@ -103,13 +105,12 @@
 	DPRINT("SM: loading subsystems\n");
 
 	/* SM self registers */
-#if 0
 	Status = SmpRegisterSmss();
 	if(!NT_SUCCESS(Status))
 	{
 		DPRINT1("SM: SM failed to self register: system is not secure!\n");
 	}
-#endif
+
 	/* Load Kmode subsystem (aka win32k.sys) */
 	Status = SmLookupSubsystem (L"Kmode",
 				    Data,
@@ -136,7 +137,7 @@
 	}
 	/* TODO: load Required subsystems (Debug Windows) */
 #if 0
-	Status = SmExecuteProgram(L"DEBUG");
+	Status = SmExecuteProgram (hSmApiPort, L"DEBUG");
 	if(!NT_SUCCESS(Status))
 	{
 		DPRINT1("SM: DBSS failed to initialize!\n");

Modified: trunk/reactos/subsys/smss/makefile
--- trunk/reactos/subsys/smss/makefile	2005-03-14 22:28:58 UTC (rev 14079)
+++ trunk/reactos/subsys/smss/makefile	2005-03-14 22:38:12 UTC (rev 14080)
@@ -6,7 +6,7 @@
 
 TARGET_APPTYPE = native
 
-TARGET_SDKLIBS = ntdll.a smdll.a
+TARGET_SDKLIBS = smlib.a ntdll.a
 
 TARGET_NAME = smss