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.

460 lines
12 KiB

  1. /*++
  2. Copyright (c) 1995-1996 Microsoft Corporation
  3. Module Name:
  4. domain.h
  5. Abstract:
  6. Header file for Code to manage multiple domains hosted on a DC.
  7. Author:
  8. Cliff Van Dyke (CliffV) 20-Feb-1995
  9. Revision History:
  10. --*/
  11. //
  12. // Role that a particular domain is playing
  13. //
  14. typedef enum _NETLOGON_ROLE {
  15. RoleInvalid = 0,
  16. RolePrimary,
  17. RoleBackup,
  18. RoleMemberWorkstation,
  19. RoleNdnc
  20. } NETLOGON_ROLE, * PNETLOGON_ROLE;
  21. /////////////////////////////////////////////////////////////////////////////
  22. //
  23. // Description of a single hosted domain. (size of this struct is 0x164)
  24. //
  25. /////////////////////////////////////////////////////////////////////////////
  26. typedef struct _DOMAIN_INFO {
  27. //
  28. // Link to next domain in 'NlGlobalServicedDomains'
  29. // (Serialized by NlGlobalDomainCritSect)
  30. //
  31. LIST_ENTRY DomNext;
  32. //
  33. // DomainThread WorkItem
  34. // (Serialized by NlGlobalDomainCritSect)
  35. //
  36. WORKER_ITEM DomThreadWorkItem;
  37. //
  38. // Name of the domain being handled
  39. //
  40. // On a Workstation, this is the Domain the workstation is a member of.
  41. //
  42. UNICODE_STRING DomUnicodeDomainNameString;
  43. WCHAR DomUnicodeDomainName[DNLEN+1];
  44. CHAR DomOemDomainName[DNLEN+1];
  45. DWORD DomOemDomainNameLength;
  46. //
  47. // DNS domain name of the domain being handled.
  48. // These fields will be null if there is no DNS domain name for the
  49. // domain.
  50. //
  51. // Access serialized by either NlGlobalDomainCritSect or DomTrustListCritSect
  52. // Modifications must lock both.
  53. //
  54. UNICODE_STRING DomUnicodeDnsDomainNameString;
  55. LPWSTR DomUnicodeDnsDomainName;
  56. LPSTR DomUtf8DnsDomainName;
  57. //
  58. // DNS domain name alias of the domain being handled.
  59. // Access serialized by NlGlobalDomainCritSect
  60. //
  61. LPSTR DomUtf8DnsDomainNameAlias;
  62. //
  63. // Name of the "Account Domain" of the current machine.
  64. // On a DC, this is the same as above.
  65. // On a workstation, this is the name of the workstation.
  66. UNICODE_STRING DomUnicodeAccountDomainNameString;
  67. //
  68. // Domain SID of the domain being handled.
  69. //
  70. // On a Workstation, this is the DomainId of the workstation SAM itself.
  71. //
  72. PSID DomAccountDomainId;
  73. //
  74. // Instance GUID of the domain object representing this hosted domain.
  75. //
  76. // Access serialized by either NlGlobalDomainCritSect or DomTrustListCritSect
  77. // Modifications must lock both.
  78. GUID DomDomainGuidBuffer;
  79. GUID *DomDomainGuid; // NULL if there is no GUID
  80. //
  81. // Computer name of this computer in this domain.
  82. //
  83. WCHAR DomUncUnicodeComputerName[UNCLEN+1];
  84. UNICODE_STRING DomUnicodeComputerNameString;
  85. UNICODE_STRING DomUnicodeDnsHostNameString;
  86. LPSTR DomUtf8DnsHostName;
  87. CHAR DomOemComputerName[CNLEN+1];
  88. DWORD DomOemComputerNameLength;
  89. LPSTR DomUtf8ComputerName;
  90. DWORD DomUtf8ComputerNameLength; // length in bytes
  91. #ifdef _DC_NETLOGON
  92. //
  93. // Handle to SAM database
  94. //
  95. SAMPR_HANDLE DomSamServerHandle;
  96. SAMPR_HANDLE DomSamAccountDomainHandle;
  97. SAMPR_HANDLE DomSamBuiltinDomainHandle;
  98. //
  99. // Handle to LSA database
  100. //
  101. LSAPR_HANDLE DomLsaPolicyHandle;
  102. #endif // _DC_NETLOGON
  103. //
  104. // To serialize access to DomTrustList and DomClientSession
  105. //
  106. CRITICAL_SECTION DomTrustListCritSect;
  107. #ifdef _DC_NETLOGON
  108. //
  109. // The list of domains trusted by this domain.
  110. //
  111. LIST_ENTRY DomTrustList;
  112. DWORD DomTrustListLength; // Number of entries in DomTrustList
  113. //
  114. // The list of all trusted domains in the forest.
  115. // (Serialized by DomTrustListCritSect)
  116. //
  117. PDS_DOMAIN_TRUSTSW DomForestTrustList;
  118. DWORD DomForestTrustListSize;
  119. ULONG DomForestTrustListCount;
  120. //
  121. // On BDC, our secure channel to PDC of the domain.
  122. // On workstations, our secure channel to a DC in the domain.
  123. // (Serialized by DomTrustListCritSect)
  124. //
  125. struct _CLIENT_SESSION *DomClientSession;
  126. //
  127. // On a DC, our secure channel to our 'parent' domain.
  128. // NULL: if we have no parent.
  129. // (Serialized by DomTrustListCritSect)
  130. //
  131. struct _CLIENT_SESSION *DomParentClientSession;
  132. //
  133. // Table of all Server Sessions
  134. // The size of the hash table must be a power-of-2.
  135. //
  136. #define SERVER_SESSION_HASH_TABLE_SIZE 128
  137. #define SERVER_SESSION_TDO_NAME_HASH_TABLE_SIZE 128
  138. #define LOCK_SERVER_SESSION_TABLE(_DI) \
  139. EnterCriticalSection( &(_DI)->DomServerSessionTableCritSect )
  140. #define UNLOCK_SERVER_SESSION_TABLE(_DI) \
  141. LeaveCriticalSection( &(_DI)->DomServerSessionTableCritSect )
  142. CRITICAL_SECTION DomServerSessionTableCritSect;
  143. PLIST_ENTRY DomServerSessionHashTable;
  144. PLIST_ENTRY DomServerSessionTdoNameHashTable;
  145. LIST_ENTRY DomServerSessionTable;
  146. #endif // _DC_NETLOGON
  147. //
  148. // Number of outstanding pointers to the domain structure.
  149. // (Serialized by NlGlobalDomainCritSect)
  150. //
  151. DWORD ReferenceCount;
  152. //
  153. // Role: (PDC, BDC, or workstation) of this machine in the hosted domain
  154. //
  155. NETLOGON_ROLE DomRole;
  156. #ifdef _DC_NETLOGON
  157. //
  158. // Misc flags.
  159. // (Serialized by NlGlobalDomainCritSect)
  160. //
  161. DWORD DomFlags;
  162. #define DOM_CREATION_NEEDED 0x00000001 // TRUE if async phase 2 create needed
  163. #define DOM_ROLE_UPDATE_NEEDED 0x00000002 // TRUE if role of the machine needs update
  164. #define DOM_TRUST_UPDATE_NEEDED 0x00000004 // TRUE if trust list needs to be updated
  165. #define DOM_DNSPNP_UPDATE_NEEDED 0x00000008 // TRUE if DNS records need to be updated
  166. #define DOM_PROMOTED_BEFORE 0x00000010 // TRUE if this machine has been promoted to PDC before.
  167. #define DOM_THREAD_RUNNING 0x00000020 // TRUE if domain worker thread is queued or running
  168. #define DOM_THREAD_TERMINATE 0x00000040 // TRUE if domain worker thread should be terminated
  169. #define DOM_DELETED 0x00000080 // TRUE if domain is being deleted.
  170. #define DOM_ADDED_1B_NAME 0x00000100 // True if Domain<1B> name has been added
  171. #define DOM_ADD_1B_NAME_EVENT_LOGGED 0x00000200 // True if Domain<1B> name add failed at least once
  172. #define DOM_RENAMED_1B_NAME 0x00000400 // True if Domain<1B> name should be renamed
  173. #define DOM_DOMAIN_REFRESH_PENDING 0x00000800 // True if this Domain needs refreshing
  174. #define DOM_PRIMARY_DOMAIN 0x00001000 // True if this is the primary domain of the machine
  175. #define DOM_REAL_DOMAIN 0x00002000 // This is a real domain (as opposed to NDNC or forest)
  176. #define DOM_NON_DOMAIN_NC 0x00004000 // This is NDNC
  177. #define DOM_FOREST 0x00008000 // This is a forest entry (not currently used)
  178. #define DOM_FOREST_ROOT 0x00010000 // This domain is at the root of the forest.
  179. #define DOM_DNSPNPREREG_UPDATE_NEEDED 0x00020000 // TRUE if all (including already registered) DNS
  180. // records need to be updated
  181. #define DOM_API_TIMEOUT_NEEDED 0x00040000 // TRUE if client session API timeout is needed
  182. //
  183. // The lists of covered sites. Both lists protected by NlGlobalSiteCritSect.
  184. //
  185. // If this is a real domain, CoveredSites is a list of sites we cover as a DC.
  186. // If this is a non-domain NC, CoveredSites is a list of sites we cover as an NDNC.
  187. //
  188. struct _NL_COVERED_SITE *CoveredSites;
  189. ULONG CoveredSitesCount;
  190. //
  191. // If this is a real (primary) domain, GcCoveredSites is a list of sites we cover as a GC
  192. // in the forest which the primary domain belongs to. Otherwise, GcCoveredSites is NULL.
  193. //
  194. // ??: When we go multihosted, we will have a separate DOMAIN_INFO entry for each of the
  195. // hosted forests, so only one list of covered sites will be associated with DOMAIN_INFO
  196. // corresponding to the role we play in a given domain/forest/NDNC.
  197. //
  198. struct _NL_COVERED_SITE *GcCoveredSites;
  199. ULONG GcCoveredSitesCount;
  200. //
  201. // List of failed user logons with bad password.
  202. // Used on BDC to maintain the list of bad password
  203. // logons forwarded to the PDC.
  204. //
  205. LIST_ENTRY DomFailedUserLogonList;
  206. CRITICAL_SECTION DomDnsRegisterCritSect;
  207. #endif // _DC_NETLOGON
  208. } DOMAIN_INFO, *PDOMAIN_INFO;
  209. #ifdef _DC_NETLOGON
  210. #define IsPrimaryDomain( _DomainInfo ) \
  211. (((_DomainInfo)->DomFlags & DOM_PRIMARY_DOMAIN) != 0 )
  212. #else // _DC_NETLOGON
  213. #define IsPrimaryDomain( _DomainInfo ) TRUE
  214. #endif // _DC_NETLOGON
  215. //
  216. // The DOMAIN_ENUM_CALLBACK is a callback for NlEnumerateDomains.
  217. //
  218. // It defines a routine that takes two parameters, the first is a DomainInfo
  219. // structure, the second is a context for that Domain.
  220. //
  221. typedef
  222. NET_API_STATUS
  223. (*PDOMAIN_ENUM_CALLBACK)(
  224. PDOMAIN_INFO DomainInfo,
  225. PVOID Context
  226. );
  227. //
  228. // domain.c procedure forwards.
  229. //
  230. NET_API_STATUS
  231. NlGetDomainName(
  232. OUT LPWSTR *DomainName,
  233. OUT LPWSTR *DnsDomainName,
  234. OUT PSID *AccountDomainSid,
  235. OUT PSID *PrimaryDomainSid,
  236. OUT GUID **PrimaryDomainGuid,
  237. OUT PBOOLEAN DnsForestNameChanged OPTIONAL
  238. );
  239. NET_API_STATUS
  240. NlInitializeDomains(
  241. VOID
  242. );
  243. NET_API_STATUS
  244. NlCreateDomainPhase1(
  245. IN LPWSTR DomainName OPTIONAL,
  246. IN LPWSTR DnsDomainName OPTIONAL,
  247. IN PSID DomainSid OPTIONAL,
  248. IN GUID *DomainGuid OPTIONAL,
  249. IN LPWSTR ComputerName,
  250. IN LPWSTR DnsHostName OPTIONAL,
  251. IN BOOLEAN CallNlExitOnFailure,
  252. IN ULONG DomainFlags,
  253. OUT PDOMAIN_INFO *ReturnedDomainInfo
  254. );
  255. #ifdef _DC_NETLOGON
  256. NET_API_STATUS
  257. NlCreateDomainPhase2(
  258. IN PDOMAIN_INFO DomainInfo,
  259. IN BOOLEAN CallNlExitOnFailure
  260. );
  261. #endif // _DC_NETLOGON
  262. PDOMAIN_INFO
  263. NlFindDomain(
  264. LPCWSTR DomainName OPTIONAL,
  265. GUID *DomainGuid OPTIONAL,
  266. BOOLEAN DefaultToPrimary
  267. );
  268. PDOMAIN_INFO
  269. NlFindNetbiosDomain(
  270. LPCWSTR DomainName,
  271. BOOLEAN DefaultToPrimary
  272. );
  273. PDOMAIN_INFO
  274. NlFindDnsDomain(
  275. IN LPCSTR DnsDomainName OPTIONAL,
  276. IN GUID *DomainGuid OPTIONAL,
  277. IN BOOLEAN DefaultToNdnc,
  278. IN BOOLEAN CheckAliasName,
  279. OUT PBOOLEAN AliasNameMatched OPTIONAL
  280. );
  281. #ifdef _DC_NETLOGON
  282. NET_API_STATUS
  283. NlStartDomainThread(
  284. PDOMAIN_INFO DomainInfo,
  285. PDWORD DomFlags
  286. );
  287. NET_API_STATUS
  288. NlUpdateRole(
  289. IN PDOMAIN_INFO DomainInfo
  290. );
  291. NET_API_STATUS
  292. NlUpdateServicedNdncs(
  293. IN LPWSTR ComputerName,
  294. IN LPWSTR DnsHostName,
  295. IN BOOLEAN CallNlExitOnFailure,
  296. OUT PBOOLEAN ServicedNdncChanged OPTIONAL
  297. );
  298. NTSTATUS
  299. NlUpdateDnsRootAlias(
  300. IN PDOMAIN_INFO DomainInfo,
  301. OUT PBOOL AliasNamesChanged OPTIONAL
  302. );
  303. #endif // _DC_NETLOGON
  304. struct _CLIENT_SESSION *
  305. NlRefDomClientSession(
  306. IN PDOMAIN_INFO DomainInfo
  307. );
  308. struct _CLIENT_SESSION *
  309. NlRefDomParentClientSession(
  310. IN PDOMAIN_INFO DomainInfo
  311. );
  312. VOID
  313. NlDeleteDomClientSession(
  314. IN PDOMAIN_INFO DomainInfo
  315. );
  316. PDOMAIN_INFO
  317. NlFindDomainByServerName(
  318. LPWSTR ServerName
  319. );
  320. NET_API_STATUS
  321. NlEnumerateDomains(
  322. IN BOOLEAN EnumerateNdncsToo,
  323. PDOMAIN_ENUM_CALLBACK Callback,
  324. PVOID Context
  325. );
  326. NET_API_STATUS
  327. NlSetDomainForestRoot(
  328. IN PDOMAIN_INFO DomainInfo,
  329. IN PVOID Context
  330. );
  331. GUID *
  332. NlCaptureDomainInfo (
  333. IN PDOMAIN_INFO DomainInfo,
  334. OUT WCHAR DnsDomainName[NL_MAX_DNS_LENGTH+1] OPTIONAL,
  335. OUT GUID *DomainGuid OPTIONAL
  336. );
  337. NET_API_STATUS
  338. NlSetDomainNameInDomainInfo(
  339. IN PDOMAIN_INFO DomainInfo,
  340. IN LPWSTR DnsDomainName OPTIONAL,
  341. IN LPWSTR NetbiosDomainName OPTIONAL,
  342. IN GUID *DomainGuid OPTIONAL,
  343. OUT PBOOLEAN DnsDomainNameChanged OPTIONAL,
  344. OUT PBOOLEAN NetbiosDomainNameChanged OPTIONAL,
  345. OUT PBOOLEAN DomainGuidChanged OPTIONAL
  346. );
  347. VOID
  348. NlDereferenceDomain(
  349. IN PDOMAIN_INFO DomainInfo
  350. );
  351. VOID
  352. NlDeleteDomain(
  353. IN PDOMAIN_INFO DomainInfo
  354. );
  355. VOID
  356. NlUninitializeDomains(
  357. VOID
  358. );