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.

125 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. coninit.c
  5. Abstract:
  6. This module initialize the connection with the session console port
  7. Author:
  8. Avi Nathan (avin) 23-Jul-1991
  9. Revision History:
  10. Ellen Aycock-Wright (ellena) 15-Sept-1991 Modified for POSIX
  11. --*/
  12. #include <stdio.h>
  13. #include "psxdll.h"
  14. NTSTATUS
  15. PsxInitializeSessionPort(
  16. IN ULONG UniqueId
  17. )
  18. {
  19. PSXSESCONNECTINFO ConnectionInfoIn;
  20. ULONG ConnectionInfoInLength;
  21. CHAR SessionName[PSX_SES_BASE_PORT_NAME_LENGTH];
  22. STRING SessionPortName;
  23. UNICODE_STRING SessionPortName_U;
  24. STRING SessionDataName;
  25. UNICODE_STRING SessionDataName_U;
  26. NTSTATUS Status;
  27. SECURITY_QUALITY_OF_SERVICE DynamicQos;
  28. HANDLE SessionPortHandle;
  29. HANDLE SectionHandle;
  30. SIZE_T ViewSize = 0L;
  31. OBJECT_ATTRIBUTES ObjectAttributes;
  32. PVOID PsxSessionDataBaseAddress;
  33. ConnectionInfoInLength = sizeof(ConnectionInfoIn);
  34. CONSTRUCT_PSX_SES_NAME(SessionName, PSX_SES_BASE_PORT_PREFIX, UniqueId);
  35. RtlInitAnsiString(&SessionPortName, SessionName);
  36. RtlAnsiStringToUnicodeString(&SessionPortName_U, &SessionPortName, TRUE);
  37. DynamicQos.ImpersonationLevel = SecurityImpersonation;
  38. DynamicQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
  39. DynamicQos.EffectiveOnly = TRUE;
  40. //
  41. // get the session communication port handle. this handle will be used
  42. // to send console requests to psxses.exe for this session.
  43. //
  44. Status = NtConnectPort(&SessionPortHandle, &SessionPortName_U, &DynamicQos,
  45. NULL, NULL, NULL, NULL, NULL);
  46. RtlFreeUnicodeString(&SessionPortName_U);
  47. if (!NT_SUCCESS(Status)) {
  48. KdPrint(("PSXDLL: Unable to connect to %s - Status == %X\n",
  49. SessionPortName.Buffer, Status));
  50. return Status;
  51. }
  52. //
  53. // open the session data section and map it to this process
  54. //
  55. CONSTRUCT_PSX_SES_NAME(SessionName, PSX_SES_BASE_DATA_PREFIX, UniqueId);
  56. RtlInitAnsiString(&SessionDataName, SessionName);
  57. Status = RtlAnsiStringToUnicodeString(&SessionDataName_U, &SessionDataName,
  58. TRUE);
  59. ASSERT(NT_SUCCESS(Status));
  60. InitializeObjectAttributes(&ObjectAttributes, &SessionDataName_U, 0, NULL,
  61. NULL);
  62. Status = NtOpenSection(&SectionHandle, SECTION_MAP_WRITE,
  63. &ObjectAttributes);
  64. RtlFreeUnicodeString(&SessionDataName_U);
  65. if (!NT_SUCCESS(Status)) {
  66. return Status;
  67. }
  68. //
  69. // Let MM locate the view
  70. //
  71. PsxSessionDataBaseAddress = 0;
  72. Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(),
  73. &PsxSessionDataBaseAddress, 0L, 0L, NULL,
  74. &ViewSize, ViewUnmap, 0L, PAGE_READWRITE);
  75. if (!NT_SUCCESS(Status)) {
  76. return Status;
  77. }
  78. //
  79. // record the session port in the PEB.
  80. //
  81. {
  82. PPEB_PSX_DATA Peb;
  83. Peb = (PPEB_PSX_DATA)(NtCurrentPeb()->SubSystemData);
  84. Peb->SessionPortHandle = SessionPortHandle;
  85. Peb->SessionDataBaseAddress = PsxSessionDataBaseAddress;
  86. }
  87. // BUGBUG! find cleanup code and close the port, or let exit cleanup
  88. return Status;
  89. }