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.

253 lines
6.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // statinfo.c
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines and initializes global variables containing static configuration
  12. // information.
  13. //
  14. // MODIFICATION HISTORY
  15. //
  16. // 08/15/1998 Original version.
  17. // 03/24/1999 Convert domain names to upper case.
  18. //
  19. ///////////////////////////////////////////////////////////////////////////////
  20. #include <nt.h>
  21. #include <ntrtl.h>
  22. #include <nturtl.h>
  23. #include <ntlsa.h>
  24. #include <windows.h>
  25. #include <statinfo.h>
  26. #include <iastrace.h>
  27. //////////
  28. // Domain names.
  29. //////////
  30. WCHAR theAccountDomain [DNLEN + 1]; // Local account domain.
  31. WCHAR theRegistryDomain[DNLEN + 1]; // Registry override for default domain.
  32. //////////
  33. // SID's
  34. //////////
  35. PSID theAccountDomainSid;
  36. PSID theBuiltinDomainSid;
  37. //////////
  38. // UNC name of the local computer.
  39. //////////
  40. WCHAR theLocalServer[CNLEN + 3];
  41. //////////
  42. // Product type for the local machine.
  43. //////////
  44. IAS_PRODUCT_TYPE ourProductType;
  45. //////////
  46. // Object Attributes -- no need to have more than one.
  47. //////////
  48. SECURITY_QUALITY_OF_SERVICE QOS =
  49. {
  50. sizeof(SECURITY_QUALITY_OF_SERVICE), // Length
  51. SecurityImpersonation, // ImpersonationLevel
  52. SECURITY_DYNAMIC_TRACKING, // ContextTrackingMode
  53. FALSE // EffectiveOnly
  54. };
  55. OBJECT_ATTRIBUTES theObjectAttributes =
  56. {
  57. sizeof(OBJECT_ATTRIBUTES), // Length
  58. NULL, // RootDirectory
  59. NULL, // ObjectName
  60. 0, // Attributes
  61. NULL, // SecurityDescriptor
  62. &QOS // SecurityQualityOfService
  63. };
  64. //////////
  65. // Buffers containing the SID's defined above.
  66. //////////
  67. BYTE theAccountDomainSidBuffer[24];
  68. BYTE theBuiltinDomainSidBuffer[16];
  69. //////////
  70. // Location of default domain parameter in the registry.
  71. //////////
  72. CONST
  73. WCHAR
  74. RAS_KEYPATH_BUILTIN[] = L"SYSTEM\\CurrentControlSet\\Services\\RasMan"
  75. L"\\ppp\\ControlProtocols\\BuiltIn";
  76. CONST
  77. WCHAR
  78. RAS_VALUENAME_DEFAULT_DOMAIN[] = L"DefaultDomain";
  79. ///////////////////////////////////////////////////////////////////////////////
  80. //
  81. // FUNCTION
  82. //
  83. // IASStaticInfoInitialize
  84. //
  85. // DESCRIPTION
  86. //
  87. // Initializes the static data defined above.
  88. //
  89. ///////////////////////////////////////////////////////////////////////////////
  90. DWORD
  91. WINAPI
  92. IASStaticInfoInitialize( VOID )
  93. {
  94. DWORD cbData, status, type;
  95. LSA_HANDLE hLsa;
  96. PPOLICY_ACCOUNT_DOMAIN_INFO padi;
  97. SID_IDENTIFIER_AUTHORITY sia = SECURITY_NT_AUTHORITY;
  98. NT_PRODUCT_TYPE ntProductType;
  99. HKEY hKey;
  100. //////////
  101. // The local host is always the server for the local domain.
  102. //////////
  103. wcscpy(theLocalServer, L"\\\\");
  104. cbData = CNLEN + 1;
  105. if (!GetComputerNameW(theLocalServer + 2, &cbData))
  106. { return GetLastError(); }
  107. IASTracePrintf("Local server: %S", theLocalServer);
  108. //////////
  109. // Open a handle to the LSA.
  110. //////////
  111. status = LsaOpenPolicy(
  112. NULL,
  113. &theObjectAttributes,
  114. POLICY_VIEW_LOCAL_INFORMATION,
  115. &hLsa
  116. );
  117. if (!NT_SUCCESS(status)) { goto error; }
  118. //////////
  119. // Get the account domain information.
  120. //////////
  121. status = LsaQueryInformationPolicy(
  122. hLsa,
  123. PolicyAccountDomainInformation,
  124. (PVOID*)&padi
  125. );
  126. LsaClose(hLsa);
  127. if (!NT_SUCCESS(status)) { goto error; }
  128. // Save the domain name.
  129. wcsncpy(theAccountDomain, padi->DomainName.Buffer, DNLEN);
  130. _wcsupr(theAccountDomain);
  131. IASTracePrintf("Local account domain: %S", theAccountDomain);
  132. // Save the domain SID.
  133. theAccountDomainSid = (PSID)theAccountDomainSidBuffer;
  134. RtlCopySid(
  135. sizeof(theAccountDomainSidBuffer),
  136. theAccountDomainSid,
  137. padi->DomainSid
  138. );
  139. // We have what we need, so free the memory.
  140. LsaFreeMemory(padi);
  141. //////////
  142. // Form the SID for the Built-in domain.
  143. //////////
  144. theBuiltinDomainSid = (PSID)theBuiltinDomainSidBuffer;
  145. RtlInitializeSid(
  146. theBuiltinDomainSid,
  147. &sia,
  148. 1
  149. );
  150. *RtlSubAuthoritySid(theBuiltinDomainSid, 0) = SECURITY_BUILTIN_DOMAIN_RID;
  151. /////////
  152. // Determine our product type.
  153. //////////
  154. RtlGetNtProductType(&ntProductType);
  155. if (ntProductType == NtProductWinNt)
  156. {
  157. ourProductType = IAS_PRODUCT_WORKSTATION;
  158. IASTraceString("Product Type: Workstation");
  159. }
  160. else
  161. {
  162. ourProductType = IAS_PRODUCT_SERVER;
  163. IASTraceString("Product Type: Server");
  164. }
  165. //////////
  166. // Read the default domain (if any) from the registry.
  167. //////////
  168. // Open the registry key.
  169. status = RegOpenKeyW(
  170. HKEY_LOCAL_MACHINE,
  171. RAS_KEYPATH_BUILTIN,
  172. &hKey
  173. );
  174. if (status == NO_ERROR)
  175. {
  176. // Query the default domain value.
  177. cbData = sizeof(theRegistryDomain);
  178. status = RegQueryValueExW(
  179. hKey,
  180. RAS_VALUENAME_DEFAULT_DOMAIN,
  181. NULL,
  182. &type,
  183. (LPBYTE)theRegistryDomain,
  184. &cbData
  185. );
  186. RegCloseKey(hKey);
  187. }
  188. // If we didn't successfully read a string, null it out.
  189. if (status != NO_ERROR || type != REG_SZ)
  190. {
  191. theRegistryDomain[0] = L'\0';
  192. }
  193. _wcsupr(theRegistryDomain);
  194. IASTracePrintf("Registry override: %S", theRegistryDomain);
  195. // Ignore any registry errors since the override is optional.
  196. return NO_ERROR;
  197. error:
  198. return RtlNtStatusToDosError(status);
  199. }
  200. ///////////////////////////////////////////////////////////////////////////////
  201. //
  202. // FUNCTION
  203. //
  204. // IASStaticInfoShutdown
  205. //
  206. // DESCRIPTION
  207. //
  208. // Currently just a placeholder.
  209. //
  210. ///////////////////////////////////////////////////////////////////////////////
  211. VOID
  212. WINAPI
  213. IASStaticInfoShutdown( VOID )
  214. {
  215. }