ReactOS  0.4.15-dev-4927-gfe8f806
smclient.c File Reference
#include "precomp.h"
#include <sm/smmsg.h>
#include <debug.h>
Include dependency graph for smclient.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI SmExecPgm (IN HANDLE SmApiPort, IN PRTL_USER_PROCESS_INFORMATION ProcessInformation, IN BOOLEAN DebugFlag)
 
NTSTATUS NTAPI SmConnectToSm (IN PUNICODE_STRING SbApiPortName, IN HANDLE SbApiPort, IN ULONG ImageType, OUT PHANDLE SmApiPort)
 
NTSTATUS NTAPI SmSessionComplete (IN HANDLE SmApiPort, IN ULONG SessionId, IN NTSTATUS SessionStatus)
 
NTSTATUS NTAPI SmStartCsr (IN HANDLE SmApiPort, OUT PULONG pMuSessionId, IN PUNICODE_STRING CommandLine, OUT PHANDLE pWindowsSubSysProcessId, OUT PHANDLE pInitialCommandProcessId)
 
NTSTATUS NTAPI SmStopCsr (IN HANDLE SmApiPort, IN ULONG SessionId)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file smclient.c.

Function Documentation

◆ SmConnectToSm()

NTSTATUS NTAPI SmConnectToSm ( IN PUNICODE_STRING  SbApiPortName,
IN HANDLE  SbApiPort,
IN ULONG  ImageType,
OUT PHANDLE  SmApiPort 
)

Definition at line 68 of file smclient.c.

72 {
74  SB_CONNECTION_INFO ConnectInfo;
76  SECURITY_QUALITY_OF_SERVICE SecurityQos;
77  ULONG ConnectInfoLength = sizeof(ConnectInfo);
78 
79  /* Setup the QoS structure */
82  SecurityQos.EffectiveOnly = TRUE;
83 
84  /* Set the SM API port name */
85  RtlInitUnicodeString(&PortName, L"\\SmApiPort");
86 
87  /* Check if this is a client connecting to SMSS, or SMSS to itself */
88  if (SbApiPortName)
89  {
90  /* A client SB port as well as an image type must be present */
91  if (!(SbApiPort) || !(ImageType)) return STATUS_INVALID_PARAMETER_MIX;
92 
93  /* Copy the client port name, and NULL-terminate it */
94  RtlCopyMemory(ConnectInfo.SbApiPortName,
95  SbApiPortName->Buffer,
96  SbApiPortName->Length);
97  ConnectInfo.SbApiPortName[SbApiPortName->Length /
98  sizeof(WCHAR)] = UNICODE_NULL;
99 
100  /* Save the subsystem type */
101  ConnectInfo.SubsystemType = ImageType;
102  }
103  else
104  {
105  /* No client port, and the subsystem type is not set */
106  ConnectInfo.SbApiPortName[0] = UNICODE_NULL;
108  }
109 
110  /* Connect to SMSS and exchange connection information */
112  &PortName,
113  &SecurityQos,
114  NULL,
115  NULL,
116  NULL,
117  &ConnectInfo,
118  &ConnectInfoLength);
119  if (!NT_SUCCESS(Status))
120  {
121  DPRINT1("SmConnectToSm: Connect to Sm failed %lx\n", Status);
122  }
123  else
124  {
125  /* Treat a warning or informational status as success */
127  }
128 
129  /* Return if the connection was successful or not */
130  return Status;
131 }
ULONG SubsystemType
Definition: smmsg.h:193
HANDLE SmApiPort
Definition: smss.c:23
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_PARAMETER_MIX
Definition: ntstatus.h:285
SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode
Definition: lsa.idl:66
#define L(x)
Definition: ntvdm.h:50
#define UNICODE_NULL
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtConnectPort(OUT PHANDLE PortHandle, IN PUNICODE_STRING PortName, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos, IN OUT PPORT_VIEW ClientView OPTIONAL, IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL, OUT PULONG MaxMessageLength OPTIONAL, IN OUT PVOID ConnectionInformation OPTIONAL, IN OUT PULONG ConnectionInformationLength OPTIONAL)
Definition: connect.c:753
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IMAGE_SUBSYSTEM_UNKNOWN
Definition: ntimage.h:435
WCHAR SbApiPortName[120]
Definition: smmsg.h:194
#define SECURITY_DYNAMIC_TRACKING
Definition: setypes.h:103
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: lsa.idl:65
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
ImageType
Definition: gdiplusenums.h:192
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
IN PUNICODE_STRING PortName
Definition: conport.c:35

Referenced by CsrServerInitialization(), and SmpExecuteInitialCommand().

◆ SmExecPgm()

NTSTATUS NTAPI SmExecPgm ( IN HANDLE  SmApiPort,
IN PRTL_USER_PROCESS_INFORMATION  ProcessInformation,
IN BOOLEAN  DebugFlag 
)

Definition at line 21 of file smclient.c.

24 {
26  SM_API_MSG SmApiMsg;
27 
28 #if 0 //def _WIN64 // You can take care of this Timo
29  /* 64-bit SMSS needs to talk to 32-bit processes so do the LPC conversion */
30  if (SmpIsWow64Process())
31  {
32  return SmpWow64ExecPgm(SmApiPort, ProcessInformation, DebugFlag);
33  }
34 #endif
35 
36  /* Initialize the generic LPC header */
37  SmApiMsg.h.u2.ZeroInit = 0;
38  SmApiMsg.h.u1.s1.DataLength = sizeof(SM_EXEC_PGM_MSG) + 8;
39  SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);
40 
41  /* Initialize this specific API's parameters */
42  SmApiMsg.ApiNumber = SmpExecPgmApi;
44  ProcessInformation,
45  sizeof(SmApiMsg.u.ExecPgm.ProcessInformation));
46  SmApiMsg.u.ExecPgm.DebugFlag = DebugFlag;
47 
48  /* Send the message to SMSS */
49  Status = NtRequestWaitReplyPort(SmApiPort, &SmApiMsg.h, &SmApiMsg.h);
50  if (!NT_SUCCESS(Status))
51  {
52  DPRINT1("SmExecPgm: NtRequestWaitReply Failed %lx\n", Status);
53  }
54  else
55  {
56  /* Upon success, we use the API's return value */
57  Status = SmApiMsg.ReturnValue;
58  }
59 
60  /* Close the handles that the parent passed in and return status */
61  NtClose(ProcessInformation->ProcessHandle);
62  NtClose(ProcessInformation->ThreadHandle);
63  return Status;
64 }
PORT_MESSAGE h
Definition: smmsg.h:92
SM_EXEC_PGM_MSG ExecPgm
Definition: smmsg.h:100
RTL_USER_PROCESS_INFORMATION ProcessInformation
Definition: smmsg.h:60
HANDLE SmApiPort
Definition: smss.c:23
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:695
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:24
SMSRV_API_NUMBER ApiNumber
Definition: smmsg.h:93
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
BOOLEAN DebugFlag
Definition: smmsg.h:61
ULONG DebugFlag
Definition: fxobject.cpp:44
#define DPRINT1
Definition: precomp.h:8
struct _SM_EXEC_PGM_MSG SM_EXEC_PGM_MSG
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
union _SM_API_MSG::@3474 u
NTSTATUS ReturnValue
Definition: smmsg.h:94

Referenced by SmpExecPgm(), and SmpExecuteInitialCommand().

◆ SmSessionComplete()

NTSTATUS NTAPI SmSessionComplete ( IN HANDLE  SmApiPort,
IN ULONG  SessionId,
IN NTSTATUS  SessionStatus 
)

Definition at line 135 of file smclient.c.

138 {
140  SM_API_MSG ApiMessage;
141  PSM_SESSION_COMPLETE_MSG SessionComplete = &ApiMessage.u.SessionComplete;
142 
143  /* Set the message data */
144  SessionComplete->SessionId = SessionId;
145  SessionComplete->SessionStatus = SessionStatus;
146 
147  /* Set the API Message Port Message header */
148  ApiMessage.ApiNumber = SmpSessionCompleteApi;
149  ApiMessage.h.u1.s1.DataLength = sizeof(SM_SESSION_COMPLETE_MSG) + 8;
150  ApiMessage.h.u1.s1.TotalLength = sizeof(SM_API_MSG);
151  ApiMessage.h.u2.ZeroInit = 0;
152 
153  /* Sent the message and wait for a reply */
155  &ApiMessage.h,
156  &ApiMessage.h);
157  if (NT_SUCCESS(Status))
158  {
159  /* Return the real status */
160  Status = ApiMessage.ReturnValue;
161  }
162  else
163  {
164  DPRINT1("SmCompleteSession: NtRequestWaitReply failed\n");
165  }
166 
167  /* Return status */
168  return Status;
169 }
PORT_MESSAGE h
Definition: smmsg.h:92
HANDLE SmApiPort
Definition: smss.c:23
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:695
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:24
SMSRV_API_NUMBER ApiNumber
Definition: smmsg.h:93
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _SM_API_MSG SM_API_MSG
struct _SM_SESSION_COMPLETE_MSG SM_SESSION_COMPLETE_MSG
#define DPRINT1
Definition: precomp.h:8
SM_SESSION_COMPLETE_MSG SessionComplete
Definition: smmsg.h:98
NTSTATUS SessionStatus
Definition: smmsg.h:50
union _SM_API_MSG::@3474 u
NTSTATUS ReturnValue
Definition: smmsg.h:94

Referenced by CsrDereferenceNtSession().

◆ SmStartCsr()

NTSTATUS NTAPI SmStartCsr ( IN HANDLE  SmApiPort,
OUT PULONG  pMuSessionId,
IN PUNICODE_STRING  CommandLine,
OUT PHANDLE  pWindowsSubSysProcessId,
OUT PHANDLE  pInitialCommandProcessId 
)

Definition at line 173 of file smclient.c.

178 {
180  SM_API_MSG SmApiMsg;
181 
182  /* Initialize the generic LPC header */
183  RtlZeroMemory(&SmApiMsg, sizeof(SmApiMsg));
184  SmApiMsg.h.u1.s1.DataLength = sizeof(SM_EXEC_PGM_MSG) + 8;
185  SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);
186 
187  /* Initialize this specific API's parameters */
188  SmApiMsg.ApiNumber = SmpStartCsrApi;
189  if (CommandLine)
190  {
191  if (CommandLine->Length > ARRAYSIZE(SmApiMsg.u.StartCsr.Buffer))
192  {
193  DPRINT1("SmStartCsr: Command line too long\n");
195  }
196  RtlCopyMemory(SmApiMsg.u.StartCsr.Buffer, CommandLine->Buffer, CommandLine->Length);
197  SmApiMsg.u.StartCsr.Length = CommandLine->Length;
198  }
199 
200  /* Send the message to SMSS */
201  Status = NtRequestWaitReplyPort(SmApiPort, &SmApiMsg.h, &SmApiMsg.h);
202  if (!NT_SUCCESS(Status))
203  {
204  DPRINT1("SmStartCsr: NtRequestWaitReply Failed %lx\n", Status);
205  }
206  else
207  {
208  /* Upon success, we use the API's return value */
209  Status = SmApiMsg.ReturnValue;
210  }
211 
212  /* Give back informations to caller */
213  *pMuSessionId = SmApiMsg.u.StartCsr.MuSessionId;
214  *pWindowsSubSysProcessId = SmApiMsg.u.StartCsr.WindowsSubSysProcessId;
215  *pInitialCommandProcessId = SmApiMsg.u.StartCsr.SmpInitialCommandProcessId;
216 
217  return Status;
218 }
PORT_MESSAGE h
Definition: smmsg.h:92
HANDLE SmApiPort
Definition: smss.c:23
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:695
ULONG Length
Definition: smmsg.h:76
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
HANDLE WindowsSubSysProcessId
Definition: smmsg.h:78
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
WCHAR Buffer[128]
Definition: smmsg.h:77
Status
Definition: gdiplustypes.h:24
SMSRV_API_NUMBER ApiNumber
Definition: smmsg.h:93
ULONG MuSessionId
Definition: smmsg.h:75
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HANDLE SmpInitialCommandProcessId
Definition: smmsg.h:79
SM_START_CSR_MSG StartCsr
Definition: smmsg.h:102
#define DPRINT1
Definition: precomp.h:8
struct _SM_EXEC_PGM_MSG SM_EXEC_PGM_MSG
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
union _SM_API_MSG::@3474 u
NTSTATUS ReturnValue
Definition: smmsg.h:94

Referenced by SmpStartCsr().

◆ SmStopCsr()

NTSTATUS NTAPI SmStopCsr ( IN HANDLE  SmApiPort,
IN ULONG  SessionId 
)

Definition at line 222 of file smclient.c.

224 {
226  SM_API_MSG SmApiMsg;
227 
228  /* Initialize the generic LPC header */
229  RtlZeroMemory(&SmApiMsg, sizeof(SmApiMsg));
230  SmApiMsg.h.u1.s1.DataLength = sizeof(SM_EXEC_PGM_MSG) + 8;
231  SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);
232 
233  /* Initialize this specific API's parameters */
234  SmApiMsg.ApiNumber = SmpStopCsrApi;
235  SmApiMsg.u.StopCsr.MuSessionId = SessionId;
236 
237  /* Send the message to SMSS */
238  Status = NtRequestWaitReplyPort(SmApiPort, &SmApiMsg.h, &SmApiMsg.h);
239  if (!NT_SUCCESS(Status))
240  {
241  DPRINT1("SmStopCsr: NtRequestWaitReply Failed %lx\n", Status);
242  }
243  else
244  {
245  /* Upon success, we use the API's return value */
246  Status = SmApiMsg.ReturnValue;
247  }
248 
249  return Status;
250 }
PORT_MESSAGE h
Definition: smmsg.h:92
ULONG MuSessionId
Definition: smmsg.h:84
HANDLE SmApiPort
Definition: smss.c:23
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:695
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:24
SMSRV_API_NUMBER ApiNumber
Definition: smmsg.h:93
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
SM_STOP_CSR_MSG StopCsr
Definition: smmsg.h:103
#define DPRINT1
Definition: precomp.h:8
struct _SM_EXEC_PGM_MSG SM_EXEC_PGM_MSG
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
union _SM_API_MSG::@3474 u
NTSTATUS ReturnValue
Definition: smmsg.h:94