Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

572 lines
12 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. smsrvp.h
  5. Abstract:
  6. Session Manager Private Types and Prototypes
  7. Author:
  8. Mark Lucovsky (markl) 04-Oct-1989
  9. Revision History:
  10. --*/
  11. #ifndef _SMSRVP_
  12. #define _SMSRVP_
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <ntsm.h>
  17. #define NOEXTAPI
  18. #include <wdbgexts.h>
  19. #include <ntdbg.h>
  20. #include <stdlib.h>
  21. #if defined(REMOTE_BOOT)
  22. #include <remboot.h>
  23. #endif // defined(REMOTE_BOOT)
  24. #include "sm.h"
  25. #pragma warning(3:4101) // Unreferenced local variable
  26. #define SMP_SHOW_REGISTRY_DATA 0
  27. //
  28. // VOID
  29. // SmpSetDaclDefaulted(
  30. // IN POBJECT_ATTRIBUTES ObjectAttributes,
  31. // OUT PSECURITY_DESCRIPTOR_CONTROL CurrentSdControl
  32. // )
  33. //
  34. // Description:
  35. //
  36. // This routine will set the DaclDefaulted flag of the DACL passed
  37. // via the ObjectAttributes parameter. If the ObjectAttributes do
  38. // not include a SecurityDescriptor, then no action is taken.
  39. //
  40. // Parameters:
  41. //
  42. // ObjectAttributes - The object attributes whose security descriptor is
  43. // to have its DaclDefaulted flag set.
  44. //
  45. // CurrentSdControl - Receives the current value of the security descriptor's
  46. // control flags. This may be used in a subsequent call to
  47. // SmpRestoreDaclDefaulted() to restore the flag to its original state.
  48. //
  49. #define SmpSetDaclDefaulted( OA, SDC ) \
  50. if( (OA)->SecurityDescriptor != NULL) { \
  51. (*SDC) = ((PISECURITY_DESCRIPTOR)((OA)->SecurityDescriptor))->Control & \
  52. SE_DACL_DEFAULTED; \
  53. ((PISECURITY_DESCRIPTOR)((OA)->SecurityDescriptor))->Control |= \
  54. SE_DACL_DEFAULTED; \
  55. }
  56. //
  57. // VOID
  58. // SmpRestoreDaclDefaulted(
  59. // IN POBJECT_ATTRIBUTES ObjectAttributes,
  60. // IN SECURITY_DESCRIPTOR_CONTROL OriginalSdControl
  61. // )
  62. //
  63. // Description:
  64. //
  65. // This routine will set the DaclDefaulted flag of the DACL back to
  66. // a prior state (indicated by the value in OriginalSdControl).
  67. //
  68. // Parameters:
  69. //
  70. // ObjectAttributes - The object attributes whose security descriptor is
  71. // to have its DaclDefaulted flag restored. If the object attributes
  72. // have no security descriptor, then no action is taken.
  73. //
  74. // OriginalSdControl - The original value of the security descriptor's
  75. // control flags. This typically is obtained via a prior call to
  76. // SmpSetDaclDefaulted().
  77. //
  78. #define SmpRestoreDaclDefaulted( OA, SDC ) \
  79. if( (OA)->SecurityDescriptor != NULL) { \
  80. ((PISECURITY_DESCRIPTOR)((OA)->SecurityDescriptor))->Control = \
  81. (((PISECURITY_DESCRIPTOR)((OA)->SecurityDescriptor))->Control & \
  82. ~SE_DACL_DEFAULTED) | \
  83. (SDC & SE_DACL_DEFAULTED); \
  84. }
  85. //
  86. // VOID
  87. // SmpReferenceKnownSubSys(
  88. // IN PSMPKNOWNSUBSYS KnownSubSys
  89. // )
  90. //
  91. // Description:
  92. //
  93. // This routine Increments the Refcount for a KnownSubSys
  94. // to prevent him from being deleted while still in use.
  95. // The KnownSubSystem lock must be held while using thie macro
  96. //
  97. // Parameters:
  98. //
  99. // KnownSubSys - The SMPKNOWNSUBSYS structure to referemce.
  100. //
  101. #define SmpReferenceKnownSubSys( KS ) KS->RefCount++
  102. //
  103. // VOID
  104. // SmpDereferenceKnownSubSys(
  105. // IN PSMPKNOWNSUBSYS KnownSubSys
  106. // )
  107. //
  108. // Description:
  109. //
  110. // This routine decrements the Refcount for a KnownSubSys
  111. // If the KnownSubSys is bein deleted and refcount goes to
  112. // Zero, then cleanup is done and KnownSubSys is freed.
  113. // The KnownSubSystem lock must be held while using thie macro
  114. //
  115. // Parameters:
  116. //
  117. // KnownSubSys - The SMPKNOWNSUBSYS structure to dereference.
  118. //
  119. #define SmpDeferenceKnownSubSys( KS ) \
  120. if ((--KS->RefCount) == 0 && KS->Deleting) { \
  121. if (KS->Active) {NtClose(KS->Active);} \
  122. if (KS->Process) {NtClose(KS->Process);} \
  123. if (KS->SbApiCommunicationPort) {NtClose(KS->SbApiCommunicationPort);} \
  124. RtlFreeHeap(SmpHeap, 0, KS); \
  125. }
  126. //
  127. // Types
  128. //
  129. typedef struct _SMP_REGISTRY_VALUE {
  130. LIST_ENTRY Entry;
  131. UNICODE_STRING Name;
  132. UNICODE_STRING Value;
  133. LPSTR AnsiValue;
  134. } SMP_REGISTRY_VALUE, *PSMP_REGISTRY_VALUE;
  135. typedef struct _SMPKNOWNSUBSYS {
  136. LIST_ENTRY Links;
  137. HANDLE Active;
  138. HANDLE Process;
  139. ULONG ImageType;
  140. HANDLE SmApiCommunicationPort;
  141. HANDLE SbApiCommunicationPort;
  142. CLIENT_ID InitialClientId;
  143. ULONG MuSessionId;
  144. BOOLEAN Deleting;
  145. ULONG RefCount;
  146. } SMPKNOWNSUBSYS, *PSMPKNOWNSUBSYS;
  147. typedef enum {
  148. UNKNOWN_CONTEXT,
  149. NONSYSTEM_CONTEXT,
  150. SYSTEM_CONTEXT
  151. } ENUMSECURITYCONTEXT;
  152. typedef struct _SMP_CLIENT_CONTEXT {
  153. struct _SMP_CLIENT_CONTEXT * Link;
  154. PSMPKNOWNSUBSYS KnownSubSys;
  155. HANDLE ClientProcessHandle;
  156. HANDLE ServerPortHandle;
  157. ENUMSECURITYCONTEXT SecurityContext;
  158. } SMP_CLIENT_CONTEXT, *PSMP_CLIENT_CONTEXT;
  159. typedef struct _SMPSESSION {
  160. LIST_ENTRY SortedSessionIdListLinks;
  161. ULONG SessionId;
  162. PSMPKNOWNSUBSYS OwningSubsystem;
  163. PSMPKNOWNSUBSYS CreatorSubsystem;
  164. } SMPSESSION, *PSMPSESSION;
  165. typedef struct _SMPPROCESS {
  166. LIST_ENTRY Links;
  167. CLIENT_ID DebugUiClientId;
  168. CLIENT_ID ConnectionKey;
  169. } SMPPROCESS, *PSMPPROCESS;
  170. //
  171. // Define structure for an on-disk master boot record. (pulled from
  172. // private\windows\setup\textmode\kernel\sppartit.h)
  173. //
  174. typedef struct _ON_DISK_PTE {
  175. UCHAR ActiveFlag;
  176. UCHAR StartHead;
  177. UCHAR StartSector;
  178. UCHAR StartCylinder;
  179. UCHAR SystemId;
  180. UCHAR EndHead;
  181. UCHAR EndSector;
  182. UCHAR EndCylinder;
  183. UCHAR RelativeSectors[4];
  184. UCHAR SectorCount[4];
  185. } ON_DISK_PTE, *PON_DISK_PTE;
  186. typedef struct _ON_DISK_MBR {
  187. UCHAR BootCode[440];
  188. UCHAR NTFTSignature[4];
  189. UCHAR Filler[2];
  190. ON_DISK_PTE PartitionTable[4];
  191. UCHAR AA55Signature[2];
  192. } ON_DISK_MBR, *PON_DISK_MBR;
  193. //
  194. // Global Data
  195. //
  196. RTL_CRITICAL_SECTION SmpKnownSubSysLock;
  197. LIST_ENTRY SmpKnownSubSysHead;
  198. LIST_ENTRY NativeProcessList;
  199. RTL_CRITICAL_SECTION SmpSessionListLock;
  200. LIST_ENTRY SmpSessionListHead;
  201. ULONG SmpNextSessionId;
  202. BOOLEAN SmpNextSessionIdScanMode;
  203. ULONG SmpDebug;
  204. HANDLE SmpDebugPort;
  205. BOOLEAN SmpDbgSsLoaded;
  206. PDBGSS_INITIALIZE_ROUTINE SmpDbgInitRoutine;
  207. PDBGSS_HANDLE_MSG_ROUTINE SmpDbgHandleMsgRoutine;
  208. UNICODE_STRING SmpSubsystemName;
  209. UNICODE_STRING SmpKnownDllPath;
  210. HANDLE SmpDosDevicesObjectDirectory;
  211. HANDLE SmpSessionsObjectDirectory;
  212. PVOID SmpHeap;
  213. LUID SmpTcbPrivilege;
  214. PVOID SmpDefaultEnvironment;
  215. PTOKEN_OWNER SmpSmOwnerSid;
  216. ULONG SmpSmOwnerSidLength;
  217. UNICODE_STRING SmpDefaultLibPath;
  218. WCHAR *SmpDefaultLibPathBuffer;
  219. UNICODE_STRING SmpSystemRoot;
  220. WCHAR *SmpSystemRootBuffer;
  221. #define VALUE_BUFFER_SIZE (sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 256 * sizeof(WCHAR))
  222. #if defined(REMOTE_BOOT)
  223. #define MAX_HAL_NAME_LENGTH 30 // Keep in sync with definition in setupblk.h
  224. extern BOOLEAN SmpAutoFormat;
  225. extern BOOLEAN SmpRepin;
  226. extern BOOLEAN SmpNetboot;
  227. extern BOOLEAN SmpNetbootDisconnected;
  228. extern CHAR SmpHalName[MAX_HAL_NAME_LENGTH + 1];
  229. #endif // defined(REMOTE_BOOT)
  230. extern ULONG AttachedSessionId;
  231. //
  232. // Session Manager Apis
  233. //
  234. typedef
  235. NTSTATUS
  236. (* PSMAPI)(
  237. IN PSMAPIMSG SmApiMsg,
  238. IN PSMP_CLIENT_CONTEXT CallingClient,
  239. IN HANDLE CallPort
  240. );
  241. NTSTATUS
  242. SmpCreateForeignSession(
  243. IN PSMAPIMSG SmApiMsg,
  244. IN PSMP_CLIENT_CONTEXT CallingClient,
  245. IN HANDLE CallPort
  246. );
  247. NTSTATUS
  248. SmpSessionComplete(
  249. IN PSMAPIMSG SmApiMsg,
  250. IN PSMP_CLIENT_CONTEXT CallingClient,
  251. IN HANDLE CallPort
  252. );
  253. NTSTATUS
  254. SmpTerminateForeignSession(
  255. IN PSMAPIMSG SmApiMsg,
  256. IN PSMP_CLIENT_CONTEXT CallingClient,
  257. IN HANDLE CallPort
  258. );
  259. NTSTATUS
  260. SmpExecPgm( // Temporary Hack
  261. IN PSMAPIMSG SmApiMsg,
  262. IN PSMP_CLIENT_CONTEXT CallingClient,
  263. IN HANDLE CallPort
  264. );
  265. NTSTATUS
  266. SmpLoadDeferedSubsystem(
  267. IN PSMAPIMSG SmApiMsg,
  268. IN PSMP_CLIENT_CONTEXT CallingClient,
  269. IN HANDLE CallPort
  270. );
  271. NTSTATUS
  272. SmpStartCsr(
  273. IN PSMAPIMSG SmApiMsg,
  274. IN PSMP_CLIENT_CONTEXT CallingClient,
  275. IN HANDLE CallPort
  276. );
  277. NTSTATUS
  278. SmpStopCsr(
  279. IN PSMAPIMSG SmApiMsg,
  280. IN PSMP_CLIENT_CONTEXT CallingClient,
  281. IN HANDLE CallPort
  282. );
  283. ENUMSECURITYCONTEXT
  284. SmpClientSecurityContext (
  285. IN PPORT_MESSAGE Message,
  286. IN HANDLE ServerPortHandle
  287. );
  288. //
  289. // Private Prototypes
  290. //
  291. NTSTATUS
  292. SmpExecuteInitialCommand(
  293. IN ULONG MuSessionId,
  294. IN PUNICODE_STRING InitialCommand,
  295. OUT PHANDLE InitialCommandProcess,
  296. OUT PULONG_PTR InitialCommandProcessId
  297. );
  298. NTSTATUS
  299. SmpApiLoop (
  300. IN PVOID ThreadParameter
  301. );
  302. NTSTATUS
  303. SmpInit(
  304. OUT PUNICODE_STRING InitialCommand,
  305. OUT PHANDLE WindowsSubSystem
  306. );
  307. NTSTATUS
  308. SmpExecuteImage(
  309. IN PUNICODE_STRING ImageFileName,
  310. IN PUNICODE_STRING CurrentDirectory,
  311. IN PUNICODE_STRING CommandLine,
  312. IN ULONG MuSessionId,
  313. IN ULONG Flags,
  314. IN OUT PRTL_USER_PROCESS_INFORMATION ProcessInformation OPTIONAL
  315. );
  316. NTSTATUS
  317. SmpLoadDbgSs(
  318. IN PUNICODE_STRING DbgSsName
  319. );
  320. PSMPKNOWNSUBSYS
  321. SmpLocateKnownSubSysByCid(
  322. IN PCLIENT_ID ClientId
  323. );
  324. PSMPKNOWNSUBSYS
  325. SmpLocateKnownSubSysByType(
  326. IN ULONG MuSessionId,
  327. IN ULONG ImageType
  328. );
  329. ULONG
  330. SmpAllocateSessionId(
  331. IN PSMPKNOWNSUBSYS OwningSubsystem,
  332. IN PSMPKNOWNSUBSYS CreatorSubsystem OPTIONAL
  333. );
  334. PSMPSESSION
  335. SmpSessionIdToSession(
  336. IN ULONG SessionId
  337. );
  338. VOID
  339. SmpDeleteSession(
  340. IN ULONG SessionId
  341. );
  342. HANDLE
  343. SmpOpenDir(
  344. BOOLEAN IsDosName,
  345. BOOLEAN IsSynchronous,
  346. PWSTR DirName
  347. );
  348. NTSTATUS
  349. SmpCopyFile(
  350. HANDLE SrcDirHandle,
  351. HANDLE DstDirHandle,
  352. PUNICODE_STRING FileName
  353. );
  354. NTSTATUS
  355. SmpDeleteFile(
  356. IN PUNICODE_STRING pFile
  357. );
  358. #if SMP_SHOW_REGISTRY_DATA
  359. VOID
  360. SmpDumpQuery(
  361. IN PWSTR ModId,
  362. IN PCHAR RoutineName,
  363. IN PWSTR ValueName,
  364. IN ULONG ValueType,
  365. IN PVOID ValueData,
  366. IN ULONG ValueLength
  367. );
  368. #endif
  369. #define ALIGN(p,val) (PVOID)((((ULONG_PTR)(p) + (val) - 1)) & (~((val) - 1)))
  370. #define U_USHORT(p) (*(USHORT UNALIGNED *)(p))
  371. #define U_ULONG(p) (*(ULONG UNALIGNED *)(p))
  372. #if defined(REMOTE_BOOT)
  373. VOID
  374. SmpGetHarddiskBootPartition(
  375. OUT PULONG DiskNumber,
  376. OUT PULONG PartitionNumber
  377. );
  378. VOID
  379. SmpPartitionDisk(
  380. IN ULONG DiskNumber,
  381. OUT PULONG PartitionNumber
  382. );
  383. VOID
  384. SmpFindCSCPartition(
  385. IN ULONG DiskNumber,
  386. OUT PULONG PartitionNumber
  387. );
  388. #endif // defined(REMOTE_BOOT)
  389. //
  390. // Stubs for Hydra specific API's
  391. //
  392. NTSTATUS
  393. SmpLoadSubSystemsForMuSession(
  394. OUT PULONG pMuSessionId,
  395. OUT PULONG_PTR WindowsSubSysProcessId,
  396. IN OUT PUNICODE_STRING InitialCommand );
  397. NTSTATUS
  398. SmpGetProcessMuSessionId(
  399. IN HANDLE Process,
  400. OUT PULONG pMuSessionId );
  401. NTSTATUS
  402. SmpSetProcessMuSessionId(
  403. IN HANDLE Process,
  404. IN ULONG MuSessionId );
  405. BOOLEAN
  406. SmpCheckDuplicateMuSessionId(
  407. IN ULONG MuSessionId );
  408. //
  409. // Stubs for Sb APIs
  410. //
  411. NTSTATUS
  412. SmpSbCreateSession (
  413. IN PSMPSESSION SourceSession OPTIONAL,
  414. IN PSMPKNOWNSUBSYS CreatorSubsystem OPTIONAL,
  415. IN PRTL_USER_PROCESS_INFORMATION ProcessInformation,
  416. IN ULONG DebugSession OPTIONAL,
  417. IN PCLIENT_ID DebugUiClientId OPTIONAL
  418. );
  419. ULONG SmBaseTag;
  420. #define MAKE_TAG( t ) (RTL_HEAP_MAKE_TAG( SmBaseTag, t ))
  421. #define INIT_TAG 0
  422. #define DBG_TAG 1
  423. #define SM_TAG 2
  424. //
  425. // Utility Routines (smutil.c)
  426. //
  427. NTSTATUS
  428. SmpSaveRegistryValue(
  429. IN OUT PLIST_ENTRY ListHead,
  430. IN PWSTR Name,
  431. IN PWSTR Value OPTIONAL,
  432. IN BOOLEAN CheckForDuplicate
  433. );
  434. PSMP_REGISTRY_VALUE
  435. SmpFindRegistryValue(
  436. IN PLIST_ENTRY ListHead,
  437. IN PWSTR Name
  438. );
  439. NTSTATUS
  440. SmpAcquirePrivilege(
  441. ULONG Privilege,
  442. PVOID *ReturnedState
  443. );
  444. VOID
  445. SmpReleasePrivilege(
  446. PVOID StatePointer
  447. );
  448. //
  449. // String parsing routine from sminit.c
  450. //
  451. NTSTATUS
  452. SmpParseCommandLine(
  453. IN PUNICODE_STRING CommandLine,
  454. OUT PULONG Flags,
  455. OUT PUNICODE_STRING ImageFileName,
  456. OUT PUNICODE_STRING ImageFileDirectory OPTIONAL,
  457. OUT PUNICODE_STRING Arguments
  458. );
  459. //
  460. // Crashdump routines from smcrash.c
  461. //
  462. BOOLEAN
  463. SmpCheckForCrashDump(
  464. IN PUNICODE_STRING PageFileName
  465. );
  466. #endif // _SMSRVP_