Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensmclient.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Windows-Compatible Session Manager 00003 * LICENSE: BSD 2-Clause License 00004 * FILE: lib/smlib/smclient.c 00005 * PURPOSE: SMSS Client Library Stubs for calling SM APIs from a client 00006 * PROGRAMMERS: Alex Ionescu 00007 */ 00008 00009 /* INCLUDES *******************************************************************/ 00010 00011 #include "precomp.h" 00012 #include "sm/smmsg.h" // To go in precomp.h after 00013 #define NDEBUG 00014 #include "debug.h" 00015 00016 /* FUNCTIONS ******************************************************************/ 00017 00018 NTSTATUS 00019 NTAPI 00020 SmExecPgm(IN HANDLE SmApiPort, 00021 IN PRTL_USER_PROCESS_INFORMATION ProcessInformation, 00022 IN BOOLEAN DebugFlag) 00023 { 00024 NTSTATUS Status; 00025 SM_API_MSG SmApiMsg; 00026 00027 #if 0 //def _WIN64 // You can take care of this Timo 00028 /* 64-bit SMSS needs to talk to 32-bit processes so do the LPC conversion */ 00029 if (SmpIsWow64Process()) 00030 { 00031 return SmpWow64ExecPgm(SmApiPort, ProcessInformation, DebugFlag); 00032 } 00033 #endif 00034 00035 /* Initialize the generic LPC header */ 00036 SmApiMsg.h.u2.ZeroInit = 0; 00037 SmApiMsg.h.u1.s1.DataLength = sizeof(SM_EXEC_PGM_MSG) + 8; 00038 SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg); 00039 00040 /* Initalize this specific API's parameters */ 00041 SmApiMsg.ApiNumber = SmExecPgmApi; 00042 RtlCopyMemory(&SmApiMsg.u.ExecPgm.ProcessInformation, 00043 ProcessInformation, 00044 sizeof(SmApiMsg.u.ExecPgm.ProcessInformation)); 00045 SmApiMsg.u.ExecPgm.DebugFlag = DebugFlag; 00046 00047 /* Send the message to SMSS */ 00048 Status = NtRequestWaitReplyPort(SmApiPort, &SmApiMsg.h, &SmApiMsg.h); 00049 if (!NT_SUCCESS(Status)) 00050 { 00051 DPRINT1("SmExecPgm: NtRequestWaitReply Failed %lx\n", Status); 00052 } 00053 else 00054 { 00055 /* Upon success, we use the API's return value */ 00056 Status = SmApiMsg.ReturnValue; 00057 } 00058 00059 /* Close the handles that the parent passed in and return status */ 00060 NtClose(ProcessInformation->ProcessHandle); 00061 NtClose(ProcessInformation->ThreadHandle); 00062 return Status; 00063 } 00064 00065 NTSTATUS 00066 NTAPI 00067 SmConnectToSm(IN PUNICODE_STRING SbApiPortName, 00068 IN HANDLE SbApiPort, 00069 IN ULONG ImageType, 00070 IN HANDLE SmApiPort) 00071 { 00072 NTSTATUS Status; 00073 SB_CONNECTION_INFO ConnectInfo; 00074 UNICODE_STRING DestinationString; 00075 SECURITY_QUALITY_OF_SERVICE SecurityQos; 00076 ULONG ConnectInfoLength = sizeof(ConnectInfo); 00077 00078 /* Setup the QoS structure */ 00079 SecurityQos.ImpersonationLevel = SecurityIdentification; 00080 SecurityQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING; 00081 SecurityQos.EffectiveOnly = TRUE; 00082 00083 /* Set the SM API port name */ 00084 RtlInitUnicodeString(&DestinationString, L"\\SmApiPort2"); 00085 00086 /* Check if this is a client connecting to SMSS, or SMSS to itself */ 00087 if (SbApiPortName) 00088 { 00089 /* A client SB port as well as an image type must be present */ 00090 if (!(SbApiPort) || !(ImageType)) return STATUS_INVALID_PARAMETER_MIX; 00091 00092 /* Copy the client port name, and NULL-terminate it */ 00093 RtlCopyMemory(ConnectInfo.SbApiPortName, 00094 SbApiPortName->Buffer, 00095 SbApiPortName->Length); 00096 ConnectInfo.SbApiPortName[SbApiPortName->Length / 00097 sizeof(WCHAR)] = UNICODE_NULL; 00098 00099 /* Save the subsystem type */ 00100 ConnectInfo.SubsystemType = ImageType; 00101 } 00102 else 00103 { 00104 /* No client port, and the subsystem type is not set */ 00105 ConnectInfo.SbApiPortName[0] = UNICODE_NULL; 00106 ConnectInfo.SubsystemType = IMAGE_SUBSYSTEM_UNKNOWN; 00107 } 00108 00109 /* Connect to SMSS and exchange connection information */ 00110 Status = NtConnectPort(SmApiPort, 00111 &DestinationString, 00112 &SecurityQos, 00113 NULL, 00114 NULL, 00115 NULL, 00116 &ConnectInfo, 00117 &ConnectInfoLength); 00118 if (!NT_SUCCESS(Status)) 00119 { 00120 DPRINT1("SmConnectToSm: Connect to Sm failed %lx\n", Status); 00121 } 00122 else 00123 { 00124 /* Treat a warning or informational status as success */ 00125 Status = STATUS_SUCCESS; 00126 } 00127 00128 /* Return if the connection was successful or not */ 00129 return Status; 00130 } 00131 00132 NTSTATUS 00133 NTAPI 00134 SmSessionComplete(IN HANDLE SmApiPort, 00135 IN ULONG SessionId, 00136 IN NTSTATUS SessionStatus) 00137 { 00138 NTSTATUS Status; 00139 SM_API_MSG ApiMessage; 00140 PSM_SESSION_COMPLETE_MSG SessionComplete = &ApiMessage.u.SessionComplete; 00141 00142 /* Set the message data */ 00143 SessionComplete->SessionId = SessionId; 00144 SessionComplete->SessionStatus = SessionStatus; 00145 00146 /* Set the API Message Port Message header */ 00147 ApiMessage.ApiNumber = SmSessionCompleteApi; 00148 ApiMessage.h.u1.s1.DataLength = sizeof(SM_SESSION_COMPLETE_MSG) + 8; 00149 ApiMessage.h.u1.s1.TotalLength = sizeof(SM_API_MSG); 00150 ApiMessage.h.u2.ZeroInit = 0; 00151 00152 /* Sent the message and wait for a reply */ 00153 Status = NtRequestWaitReplyPort(SmApiPort, 00154 &ApiMessage.h, 00155 &ApiMessage.h); 00156 if (NT_SUCCESS(Status)) 00157 { 00158 /* Return the real status */ 00159 Status = ApiMessage.ReturnValue; 00160 } 00161 else 00162 { 00163 DPRINT1("SmCompleteSession: NtRequestWaitReply failed\n"); 00164 } 00165 00166 /* Return status */ 00167 return Status; 00168 } Generated on Sat May 26 2012 04:35:55 for ReactOS by
1.7.6.1
|