Leaked source code of windows server 2003
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.

212 lines
5.3 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. sbinit.c
  5. Abstract:
  6. This module contains the code to initialize the SbApiPort of the
  7. Server side of the Client-Server Runtime Subsystem.
  8. Author:
  9. Steve Wood (stevewo) 8-Oct-1990
  10. Environment:
  11. User Mode Only
  12. Revision History:
  13. --*/
  14. #include "csrsrv.h"
  15. NTSTATUS
  16. CsrCreateLocalSystemSD( PSECURITY_DESCRIPTOR *ppSD )
  17. {
  18. NTSTATUS Status;
  19. SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
  20. PSID pLocalSystemSid;
  21. ULONG Length;
  22. PSECURITY_DESCRIPTOR pSD = NULL;
  23. PACL pDacl;
  24. Status = RtlAllocateAndInitializeSid(
  25. &NtAuthority,
  26. 1,
  27. SECURITY_LOCAL_SYSTEM_RID,
  28. 0, 0, 0, 0, 0, 0, 0,
  29. &pLocalSystemSid
  30. );
  31. if (!NT_SUCCESS(Status)){
  32. pLocalSystemSid = NULL;
  33. goto CSR_CREATE_LOCAL_SYSTEM_SD_ERROR;
  34. }
  35. Length = SECURITY_DESCRIPTOR_MIN_LENGTH +
  36. (ULONG)sizeof(ACL) +
  37. (ULONG)sizeof(ACCESS_ALLOWED_ACE) +
  38. RtlLengthSid( pLocalSystemSid );
  39. pSD = RtlAllocateHeap( CsrHeap, MAKE_TAG( TMP_TAG ), Length);
  40. if (pSD == NULL) {
  41. Status = STATUS_NO_MEMORY;
  42. goto CSR_CREATE_LOCAL_SYSTEM_SD_ERROR;
  43. }
  44. pDacl = (PACL)((PCHAR)pSD + SECURITY_DESCRIPTOR_MIN_LENGTH);
  45. Status = RtlCreateSecurityDescriptor(
  46. pSD,
  47. SECURITY_DESCRIPTOR_REVISION
  48. );
  49. if (!NT_SUCCESS(Status)){
  50. goto CSR_CREATE_LOCAL_SYSTEM_SD_ERROR;
  51. }
  52. Status = RtlCreateAcl(
  53. pDacl,
  54. Length - SECURITY_DESCRIPTOR_MIN_LENGTH,
  55. ACL_REVISION2
  56. );
  57. if (!NT_SUCCESS(Status)){
  58. goto CSR_CREATE_LOCAL_SYSTEM_SD_ERROR;
  59. }
  60. Status = RtlAddAccessAllowedAce (
  61. pDacl,
  62. ACL_REVISION2,
  63. PORT_ALL_ACCESS,
  64. pLocalSystemSid
  65. );
  66. if (!NT_SUCCESS(Status)){
  67. goto CSR_CREATE_LOCAL_SYSTEM_SD_ERROR;
  68. }
  69. Status = RtlSetDaclSecurityDescriptor (
  70. pSD,
  71. TRUE,
  72. pDacl,
  73. FALSE
  74. );
  75. if (NT_SUCCESS(Status)){
  76. *ppSD = pSD;
  77. goto CSR_CREATE_LOCAL_SYSTEM_SD_EXIT;
  78. }
  79. CSR_CREATE_LOCAL_SYSTEM_SD_ERROR:
  80. if (pSD != NULL) {
  81. RtlFreeHeap( CsrHeap, 0, pSD );
  82. }
  83. CSR_CREATE_LOCAL_SYSTEM_SD_EXIT:
  84. if (pLocalSystemSid != NULL) {
  85. RtlFreeSid( pLocalSystemSid );
  86. }
  87. return Status;
  88. }
  89. NTSTATUS
  90. CsrSbApiPortInitialize( VOID )
  91. {
  92. NTSTATUS Status;
  93. OBJECT_ATTRIBUTES ObjectAttributes;
  94. HANDLE Thread;
  95. CLIENT_ID ClientId;
  96. ULONG n;
  97. PSECURITY_DESCRIPTOR pCsrSbApiPortSD;
  98. n = CsrDirectoryName.Length +
  99. sizeof( CSR_SBAPI_PORT_NAME ) +
  100. sizeof( OBJ_NAME_PATH_SEPARATOR );
  101. CsrSbApiPortName.Buffer = RtlAllocateHeap( CsrHeap, MAKE_TAG( INIT_TAG ), n );
  102. if (CsrSbApiPortName.Buffer == NULL) {
  103. return( STATUS_NO_MEMORY );
  104. }
  105. CsrSbApiPortName.Length = 0;
  106. CsrSbApiPortName.MaximumLength = (USHORT)n;
  107. RtlAppendUnicodeStringToString( &CsrSbApiPortName, &CsrDirectoryName );
  108. RtlAppendUnicodeToString( &CsrSbApiPortName, L"\\" );
  109. RtlAppendUnicodeToString( &CsrSbApiPortName, CSR_SBAPI_PORT_NAME );
  110. IF_CSR_DEBUG( LPC ) {
  111. DbgPrint( "CSRSS: Creating %wZ port and associated thread\n",
  112. &CsrSbApiPortName );
  113. }
  114. Status = CsrCreateLocalSystemSD( &pCsrSbApiPortSD );
  115. if (!NT_SUCCESS(Status)) {
  116. return Status;
  117. }
  118. InitializeObjectAttributes( &ObjectAttributes, &CsrSbApiPortName, 0,
  119. NULL, pCsrSbApiPortSD );
  120. Status = NtCreatePort( &CsrSbApiPort,
  121. &ObjectAttributes,
  122. sizeof( SBCONNECTINFO ),
  123. sizeof( SBAPIMSG ),
  124. sizeof( SBAPIMSG ) * 32
  125. );
  126. if (pCsrSbApiPortSD != NULL) {
  127. RtlFreeHeap( CsrHeap, 0, pCsrSbApiPortSD );
  128. }
  129. if (!NT_SUCCESS(Status)) {
  130. return Status;
  131. }
  132. Status = RtlCreateUserThread( NtCurrentProcess(),
  133. NULL,
  134. TRUE,
  135. 0,
  136. 0,
  137. 0,
  138. CsrSbApiRequestThread,
  139. NULL,
  140. &Thread,
  141. &ClientId
  142. );
  143. if (!NT_SUCCESS(Status)) {
  144. return Status;
  145. }
  146. CsrSbApiRequestThreadPtr = CsrAddStaticServerThread(Thread,&ClientId,0);
  147. Status = NtResumeThread( Thread, NULL );
  148. return( Status );
  149. }
  150. VOID
  151. CsrSbApiPortTerminate(
  152. NTSTATUS Status
  153. )
  154. {
  155. IF_CSR_DEBUG( LPC ) {
  156. DbgPrint( "CSRSS: Closing Sb port and associated thread\n" );
  157. }
  158. NtTerminateThread( CsrSbApiRequestThreadPtr->ThreadHandle,
  159. Status
  160. );
  161. NtClose( CsrSbApiPort );
  162. NtClose( CsrSmApiPort );
  163. }