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.

467 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. // The RID of the computer account for DC.
  94. // Will be set to zero for workstations.
  95. //
  96. ULONG DomDcComputerAccountRid;
  97. //
  98. // Handle to SAM database
  99. //
  100. SAMPR_HANDLE DomSamServerHandle;
  101. SAMPR_HANDLE DomSamAccountDomainHandle;
  102. SAMPR_HANDLE DomSamBuiltinDomainHandle;
  103. //
  104. // Handle to LSA database
  105. //
  106. LSAPR_HANDLE DomLsaPolicyHandle;
  107. #endif // _DC_NETLOGON
  108. //
  109. // To serialize access to DomTrustList and DomClientSession
  110. //
  111. CRITICAL_SECTION DomTrustListCritSect;
  112. #ifdef _DC_NETLOGON
  113. //
  114. // The list of domains trusted by this domain.
  115. //
  116. LIST_ENTRY DomTrustList;
  117. DWORD DomTrustListLength; // Number of entries in DomTrustList
  118. //
  119. // The list of all trusted domains in the forest.
  120. // (Serialized by DomTrustListCritSect)
  121. //
  122. PDS_DOMAIN_TRUSTSW DomForestTrustList;
  123. DWORD DomForestTrustListSize;
  124. ULONG DomForestTrustListCount;
  125. //
  126. // On BDC, our secure channel to PDC of the domain.
  127. // On workstations, our secure channel to a DC in the domain.
  128. // (Serialized by DomTrustListCritSect)
  129. //
  130. struct _CLIENT_SESSION *DomClientSession;
  131. //
  132. // On a DC, our secure channel to our 'parent' domain.
  133. // NULL: if we have no parent.
  134. // (Serialized by DomTrustListCritSect)
  135. //
  136. struct _CLIENT_SESSION *DomParentClientSession;
  137. //
  138. // Table of all Server Sessions
  139. // The size of the hash table must be a power-of-2.
  140. //
  141. #define SERVER_SESSION_HASH_TABLE_SIZE 128
  142. #define SERVER_SESSION_TDO_NAME_HASH_TABLE_SIZE 128
  143. #define LOCK_SERVER_SESSION_TABLE(_DI) \
  144. EnterCriticalSection( &(_DI)->DomServerSessionTableCritSect )
  145. #define UNLOCK_SERVER_SESSION_TABLE(_DI) \
  146. LeaveCriticalSection( &(_DI)->DomServerSessionTableCritSect )
  147. CRITICAL_SECTION DomServerSessionTableCritSect;
  148. PLIST_ENTRY DomServerSessionHashTable;
  149. PLIST_ENTRY DomServerSessionTdoNameHashTable;
  150. LIST_ENTRY DomServerSessionTable;
  151. #endif // _DC_NETLOGON
  152. //
  153. // Number of outstanding pointers to the domain structure.
  154. // (Serialized by NlGlobalDomainCritSect)
  155. //
  156. DWORD ReferenceCount;
  157. //
  158. // Role: (PDC, BDC, or workstation) of this machine in the hosted domain
  159. //
  160. NETLOGON_ROLE DomRole;
  161. #ifdef _DC_NETLOGON
  162. //
  163. // Misc flags.
  164. // (Serialized by NlGlobalDomainCritSect)
  165. //
  166. DWORD DomFlags;
  167. #define DOM_CREATION_NEEDED 0x00000001 // TRUE if async phase 2 create needed
  168. #define DOM_ROLE_UPDATE_NEEDED 0x00000002 // TRUE if role of the machine needs update
  169. #define DOM_TRUST_UPDATE_NEEDED 0x00000004 // TRUE if trust list needs to be updated
  170. #define DOM_PROMOTED_BEFORE 0x00000010 // TRUE if this machine has been promoted to PDC before.
  171. #define DOM_THREAD_RUNNING 0x00000020 // TRUE if domain worker thread is queued or running
  172. #define DOM_THREAD_TERMINATE 0x00000040 // TRUE if domain worker thread should be terminated
  173. #define DOM_DELETED 0x00000080 // TRUE if domain is being deleted.
  174. #define DOM_ADDED_1B_NAME 0x00000100 // True if Domain<1B> name has been added
  175. #define DOM_ADD_1B_NAME_EVENT_LOGGED 0x00000200 // True if Domain<1B> name add failed at least once
  176. #define DOM_RENAMED_1B_NAME 0x00000400 // True if Domain<1B> name should be renamed
  177. #define DOM_DOMAIN_REFRESH_PENDING 0x00000800 // True if this Domain needs refreshing
  178. #define DOM_PRIMARY_DOMAIN 0x00001000 // True if this is the primary domain of the machine
  179. #define DOM_REAL_DOMAIN 0x00002000 // This is a real domain (as opposed to NDNC or forest)
  180. #define DOM_NON_DOMAIN_NC 0x00004000 // This is NDNC
  181. #define DOM_FOREST 0x00008000 // This is a forest entry (not currently used)
  182. #define DOM_FOREST_ROOT 0x00010000 // This domain is at the root of the forest.
  183. #define DOM_API_TIMEOUT_NEEDED 0x00040000 // TRUE if client session API timeout is needed
  184. #define DOM_PRIMARY_ANNOUNCE_NEEDED 0x00080000 // Primary announcement is needed
  185. #define DOM_PRIMARY_ANNOUNCE_CONTINUE 0x00100000 // Continuation of Primary announcement is needed
  186. #define DOM_PRIMARY_ANNOUNCE_IMMEDIATE 0x00200000 // Immediate Primary announcement is needed
  187. #define DOM_PRIMARY_ANNOUNCE_FLAGS ( \
  188. DOM_PRIMARY_ANNOUNCE_NEEDED | \
  189. DOM_PRIMARY_ANNOUNCE_CONTINUE | \
  190. DOM_PRIMARY_ANNOUNCE_IMMEDIATE )
  191. //
  192. // The lists of covered sites. Both lists protected by NlGlobalSiteCritSect.
  193. //
  194. // If this is a real domain, CoveredSites is a list of sites we cover as a DC.
  195. // If this is a non-domain NC, CoveredSites is a list of sites we cover as an NDNC.
  196. //
  197. struct _NL_COVERED_SITE *CoveredSites;
  198. ULONG CoveredSitesCount;
  199. //
  200. // If this is a real (primary) domain, GcCoveredSites is a list of sites we cover as a GC
  201. // in the forest which the primary domain belongs to. Otherwise, GcCoveredSites is NULL.
  202. //
  203. // ??: When we go multihosted, we will have a separate DOMAIN_INFO entry for each of the
  204. // hosted forests, so only one list of covered sites will be associated with DOMAIN_INFO
  205. // corresponding to the role we play in a given domain/forest/NDNC.
  206. //
  207. struct _NL_COVERED_SITE *GcCoveredSites;
  208. ULONG GcCoveredSitesCount;
  209. //
  210. // List of failed user logons with bad password.
  211. // Used on BDC to maintain the list of bad password
  212. // logons forwarded to the PDC.
  213. //
  214. LIST_ENTRY DomFailedUserLogonList;
  215. #endif // _DC_NETLOGON
  216. } DOMAIN_INFO, *PDOMAIN_INFO;
  217. #ifdef _DC_NETLOGON
  218. #define IsPrimaryDomain( _DomainInfo ) \
  219. (((_DomainInfo)->DomFlags & DOM_PRIMARY_DOMAIN) != 0 )
  220. #else // _DC_NETLOGON
  221. #define IsPrimaryDomain( _DomainInfo ) TRUE
  222. #endif // _DC_NETLOGON
  223. //
  224. // The DOMAIN_ENUM_CALLBACK is a callback for NlEnumerateDomains.
  225. //
  226. // It defines a routine that takes two parameters, the first is a DomainInfo
  227. // structure, the second is a context for that Domain.
  228. //
  229. typedef
  230. NET_API_STATUS
  231. (*PDOMAIN_ENUM_CALLBACK)(
  232. PDOMAIN_INFO DomainInfo,
  233. PVOID Context
  234. );
  235. //
  236. // domain.c procedure forwards.
  237. //
  238. NET_API_STATUS
  239. NlGetDomainName(
  240. OUT LPWSTR *DomainName,
  241. OUT LPWSTR *DnsDomainName,
  242. OUT PSID *AccountDomainSid,
  243. OUT PSID *PrimaryDomainSid,
  244. OUT GUID **PrimaryDomainGuid,
  245. OUT PBOOLEAN DnsForestNameChanged OPTIONAL
  246. );
  247. NET_API_STATUS
  248. NlInitializeDomains(
  249. VOID
  250. );
  251. NET_API_STATUS
  252. NlCreateDomainPhase1(
  253. IN LPWSTR DomainName OPTIONAL,
  254. IN LPWSTR DnsDomainName OPTIONAL,
  255. IN PSID DomainSid OPTIONAL,
  256. IN GUID *DomainGuid OPTIONAL,
  257. IN LPWSTR ComputerName,
  258. IN LPWSTR DnsHostName OPTIONAL,
  259. IN BOOLEAN CallNlExitOnFailure,
  260. IN ULONG DomainFlags,
  261. OUT PDOMAIN_INFO *ReturnedDomainInfo
  262. );
  263. #ifdef _DC_NETLOGON
  264. NET_API_STATUS
  265. NlCreateDomainPhase2(
  266. IN PDOMAIN_INFO DomainInfo,
  267. IN BOOLEAN CallNlExitOnFailure
  268. );
  269. #endif // _DC_NETLOGON
  270. PDOMAIN_INFO
  271. NlFindDomain(
  272. LPCWSTR DomainName OPTIONAL,
  273. GUID *DomainGuid OPTIONAL,
  274. BOOLEAN DefaultToPrimary
  275. );
  276. PDOMAIN_INFO
  277. NlFindNetbiosDomain(
  278. LPCWSTR DomainName,
  279. BOOLEAN DefaultToPrimary
  280. );
  281. PDOMAIN_INFO
  282. NlFindDnsDomain(
  283. IN LPCSTR DnsDomainName OPTIONAL,
  284. IN GUID *DomainGuid OPTIONAL,
  285. IN BOOLEAN DefaultToNdnc,
  286. IN BOOLEAN CheckAliasName,
  287. OUT PBOOLEAN AliasNameMatched OPTIONAL
  288. );
  289. #ifdef _DC_NETLOGON
  290. NET_API_STATUS
  291. NlStartDomainThread(
  292. PDOMAIN_INFO DomainInfo,
  293. PDWORD DomFlags
  294. );
  295. NET_API_STATUS
  296. NlUpdateRole(
  297. IN PDOMAIN_INFO DomainInfo
  298. );
  299. NET_API_STATUS
  300. NlUpdateServicedNdncs(
  301. IN LPWSTR ComputerName,
  302. IN LPWSTR DnsHostName,
  303. IN BOOLEAN CallNlExitOnFailure,
  304. OUT PBOOLEAN ServicedNdncChanged OPTIONAL
  305. );
  306. NTSTATUS
  307. NlUpdateDnsRootAlias(
  308. IN PDOMAIN_INFO DomainInfo,
  309. OUT PBOOL AliasNamesChanged OPTIONAL
  310. );
  311. #endif // _DC_NETLOGON
  312. struct _CLIENT_SESSION *
  313. NlRefDomClientSession(
  314. IN PDOMAIN_INFO DomainInfo
  315. );
  316. struct _CLIENT_SESSION *
  317. NlRefDomParentClientSession(
  318. IN PDOMAIN_INFO DomainInfo
  319. );
  320. VOID
  321. NlDeleteDomClientSession(
  322. IN PDOMAIN_INFO DomainInfo
  323. );
  324. PDOMAIN_INFO
  325. NlFindDomainByServerName(
  326. LPWSTR ServerName
  327. );
  328. NET_API_STATUS
  329. NlEnumerateDomains(
  330. IN BOOLEAN EnumerateNdncsToo,
  331. PDOMAIN_ENUM_CALLBACK Callback,
  332. PVOID Context
  333. );
  334. NET_API_STATUS
  335. NlSetDomainForestRoot(
  336. IN PDOMAIN_INFO DomainInfo,
  337. IN PVOID Context
  338. );
  339. GUID *
  340. NlCaptureDomainInfo (
  341. IN PDOMAIN_INFO DomainInfo,
  342. OUT WCHAR DnsDomainName[NL_MAX_DNS_LENGTH+1] OPTIONAL,
  343. OUT GUID *DomainGuid OPTIONAL
  344. );
  345. NET_API_STATUS
  346. NlSetDomainNameInDomainInfo(
  347. IN PDOMAIN_INFO DomainInfo,
  348. IN LPWSTR DnsDomainName OPTIONAL,
  349. IN LPWSTR NetbiosDomainName OPTIONAL,
  350. IN GUID *DomainGuid OPTIONAL,
  351. OUT PBOOLEAN DnsDomainNameChanged OPTIONAL,
  352. OUT PBOOLEAN NetbiosDomainNameChanged OPTIONAL,
  353. OUT PBOOLEAN DomainGuidChanged OPTIONAL
  354. );
  355. VOID
  356. NlDereferenceDomain(
  357. IN PDOMAIN_INFO DomainInfo
  358. );
  359. VOID
  360. NlDeleteDomain(
  361. IN PDOMAIN_INFO DomainInfo
  362. );
  363. VOID
  364. NlUninitializeDomains(
  365. VOID
  366. );