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.

2017 lines
50 KiB

  1. /*++
  2. Copyright (c) 1991-1996 Microsoft Corporation
  3. Module Name:
  4. ssiinit.h
  5. Abstract:
  6. Private global variables, defines, and routine declarations used for
  7. to implement SSI.
  8. Author:
  9. Cliff Van Dyke (cliffv) 25-Jul-1991
  10. Environment:
  11. User mode only.
  12. Contains NT-specific code.
  13. Requires ANSI C extensions: slash-slash comments, long external names.
  14. Revision History:
  15. 02-Jan-1992 (madana)
  16. added support for builtin/multidomain replication.
  17. 04-10-1992 (madana)
  18. added support for LSA replication.
  19. --*/
  20. // general purpose mainfests
  21. //
  22. // Define UserAccountControl bit to indicate an NT 5.0 interdomain trust.
  23. //
  24. // This is not really a SAM account. But UserAccountControl is used for all
  25. // other trust types.
  26. //
  27. // Pick a bit that will never be used in the future to indicate a different
  28. // account type.
  29. //
  30. #define USER_DNS_DOMAIN_TRUST_ACCOUNT USER_ACCOUNT_AUTO_LOCKED
  31. //
  32. // Maximum time we'll wait during full sync in an attempt to decrease
  33. // wan link utilization.
  34. //
  35. #define MAX_SYNC_SLEEP_TIME (60*60*1000) // 1 hour
  36. //
  37. // How big a buffer we request on a SAM delta or a SAM sync.
  38. //
  39. #define SAM_DELTA_BUFFER_SIZE (128*1024)
  40. //
  41. // The size of the largest mailslot message.
  42. //
  43. // All mailslot messages we receive are broadcast. The Win32 spec says
  44. // the limit on broadcast mailslot is 400 bytes. Really it is
  45. // 444 bytes (512 minus SMB header etc) - size of the mailslot name.
  46. // I'll use 444 to ensure this size is the largest I'll ever need.
  47. //
  48. // The NETLOGON_SAM_LOGON_RESPONSE_EX structure isn't packed into a mailslot
  49. // packet so it may be larger.
  50. //
  51. #define NETLOGON_MAX_MS_SIZE max(444, sizeof(NETLOGON_SAM_LOGON_RESPONSE_EX))
  52. //
  53. // Structure describing a transport supported by redir/server and browser.
  54. //
  55. typedef struct _NL_TRANSPORT {
  56. //
  57. // List of all transports headed by NlTransportListHead.
  58. // (Serialized by NlTransportCritSect)
  59. //
  60. LIST_ENTRY Next;
  61. //
  62. // True if the transport is currently enabled.
  63. // We never delete a transport in order to avoid maintaining a reference count.
  64. //
  65. BOOLEAN TransportEnabled;
  66. //
  67. // True if transport is an IP transport.
  68. //
  69. BOOLEAN IsIpTransport;
  70. //
  71. // True if transport is direct host IPX transport
  72. //
  73. BOOLEAN DirectHostIpx;
  74. //
  75. // IP Address for this transport.
  76. // Zero if not IP or none yet assigned.
  77. //
  78. ULONG IpAddress;
  79. //
  80. // Handle to the transport device
  81. //
  82. HANDLE DeviceHandle;
  83. //
  84. // Name of the transport.
  85. //
  86. WCHAR TransportName[1];
  87. } NL_TRANSPORT, *PNL_TRANSPORT;
  88. /////////////////////////////////////////////////////////////////////////////
  89. //
  90. // Client Session definitions
  91. //
  92. /////////////////////////////////////////////////////////////////////////////
  93. //
  94. // An internal timer used to schedule a periodic event.
  95. //
  96. typedef struct _TIMER {
  97. LARGE_INTEGER StartTime; // Start of period (NT absolute time)
  98. DWORD Period; // length of period (miliseconds)
  99. #define TIMER_MAX_PERIOD (MAILSLOT_WAIT_FOREVER - 1)
  100. } TIMER, *PTIMER;
  101. #define NL_MILLISECONDS_PER_SECOND (1000)
  102. #define NL_MILLISECONDS_PER_MINUTE (60 * NL_MILLISECONDS_PER_SECOND)
  103. #define NL_MILLISECONDS_PER_HOUR (60 * NL_MILLISECONDS_PER_MINUTE)
  104. #define NL_MILLISECONDS_PER_DAY (24 * NL_MILLISECONDS_PER_HOUR)
  105. //
  106. // Structure the describes an API call over the secure channel
  107. //
  108. typedef struct _CLIENT_API {
  109. //
  110. // Each API call made across this secure channel is timed by this timer.
  111. // If the timer expires, the session to the server is forcefully
  112. // terminated to ensure the client doesn't hang for a dead server.
  113. //
  114. // Access serialized by DomainInfo->DomTrustListCritSect.
  115. //
  116. TIMER CaApiTimer;
  117. #define SHORT_API_CALL_PERIOD (45*1000) // Logon API lasts 45 seconds
  118. #define LONG_API_CALL_PERIOD (15*60*1000) // Replication API 15 minute
  119. #define BINDING_CACHE_PERIOD (3*60*1000) // Cache RPC handle for 3 minutes
  120. #define WRITER_WAIT_PERIOD NlGlobalParameters.ShortApiCallPeriod // Max time to wait to become writer
  121. #define IsApiActive( _ClientApi ) ((_ClientApi)->CaApiTimer.Period != MAILSLOT_WAIT_FOREVER )
  122. //
  123. // Handle to the thread doing the API.
  124. //
  125. // Access serialized by DomainInfo->DomTrustListCritSect.
  126. //
  127. HANDLE CaThreadHandle;
  128. //
  129. // Access serialized by DomainInfo->DomTrustListCritSect.
  130. //
  131. DWORD CaFlags;
  132. #define CA_BINDING_CACHED 0x1 // Set if the binding handle is cached
  133. #define CA_TCP_BINDING 0x2 // Set if the cached binding handle is TCP/IP
  134. #define CA_BINDING_AUTHENTICATED 0x4 // Set if the binding handle is marked authenticated
  135. #define CA_ENTRY_IN_USE 0x8 // Entry is in use by a thread
  136. //
  137. // Rpc context handle for this call.
  138. //
  139. // Access serialized by DomainInfo->DomTrustListCritSect.
  140. //
  141. handle_t CaRpcHandle;
  142. //
  143. // When an api is in progress,
  144. // this is the CsSessionCount at the start of the API call.
  145. //
  146. // Access serialized by CsWriterSemaphore.
  147. //
  148. DWORD CaSessionCount;
  149. } CLIENT_API, * PCLIENT_API;
  150. //
  151. // Client session.
  152. //
  153. // Structure to define the client side of a session to a DC.
  154. //
  155. typedef struct _CLIENT_SESSION {
  156. //
  157. // Each client session entry is in a doubly linked list defined by
  158. // DomTrustList.
  159. //
  160. // Access serialized by DomTrustListCritSect.
  161. //
  162. LIST_ENTRY CsNext;
  163. //
  164. // Time when the last authentication attempt was made.
  165. //
  166. // When the CsState is CS_AUTHENTICATED, this field is the time the
  167. // secure channel was setup.
  168. //
  169. // When the CsState is CS_IDLE, this field is the time of the last
  170. // failed discovery or session setup. Or it may be zero, to indicate
  171. // that it is OK to do another discovery at any time.
  172. //
  173. // When the CsState is CS_DC_PICKED, this field is zero indicating it is
  174. // OK to do the session setup at any time. Or it may be the time of the
  175. // last failed session setup if different threads did the setup/discovery.
  176. //
  177. // Access serialized by NlGlobalDcDiscoveryCritSect
  178. //
  179. LARGE_INTEGER CsLastAuthenticationTry;
  180. //
  181. // Time when the last discovery attempt was made.
  182. //
  183. // The time is the time of completion of the last discovery attempt regardless
  184. // of the success or failure of that attempt or the discovery type (with or without account)
  185. //
  186. // Access serialized by NlGlobalDcDiscoveryCritSect
  187. //
  188. LARGE_INTEGER CsLastDiscoveryTime;
  189. //
  190. // Time when the last discovery attempt with account was made
  191. // regardless of the success or failure of that attempt
  192. //
  193. LARGE_INTEGER CsLastDiscoveryWithAccountTime;
  194. //
  195. // Time when the session was refreshed last time
  196. //
  197. LARGE_INTEGER CsLastRefreshTime;
  198. //
  199. // WorkItem for Async discovery
  200. //
  201. WORKER_ITEM CsAsyncDiscoveryWorkItem;
  202. //
  203. // Name/Guid of the domain this connection is to
  204. //
  205. // Access serialized by DomTrustListCritSect.
  206. //
  207. GUID CsDomainGuidBuffer;
  208. UNICODE_STRING CsNetbiosDomainName;
  209. CHAR CsOemNetbiosDomainName[DNLEN+1];
  210. ULONG CsOemNetbiosDomainNameLength;
  211. UNICODE_STRING CsDnsDomainName;
  212. LPSTR CsUtf8DnsDomainName;
  213. GUID *CsDomainGuid; // NULL if domain has no GUID.
  214. // Either the Netbios or Dns Domain name.
  215. // Suitable for debug. Suitable for Eventlog messages.
  216. LPWSTR CsDebugDomainName;
  217. //
  218. // Name of the local trusted domain object.
  219. //
  220. PUNICODE_STRING CsTrustName;
  221. //
  222. // Name of the account on the server.
  223. // For NT 5.0 interdomain trust, this is the dns name of this domain.
  224. //
  225. LPWSTR CsAccountName;
  226. //
  227. // Domain ID of the domain this connection is to
  228. //
  229. // Access serialized by either DomTrustListCritSect or CsWriter.
  230. // Modifications must lock both.
  231. PSID CsDomainId;
  232. //
  233. // Hosted domain this session is for
  234. //
  235. PDOMAIN_INFO CsDomainInfo;
  236. //
  237. // Type of CsAccountName
  238. //
  239. NETLOGON_SECURE_CHANNEL_TYPE CsSecureChannelType;
  240. //
  241. // State of the connection to the server.
  242. //
  243. // Access serialized by NlGlobalDcDiscoveryCritSect
  244. // This field can be read without the crit sect locked if
  245. // the answer will only be used as a hint.
  246. //
  247. DWORD CsState;
  248. #define CS_IDLE 0 // No session is currently active
  249. #define CS_DC_PICKED 1 // The session has picked a DC for session
  250. #define CS_AUTHENTICATED 2 // The session is currently active
  251. //
  252. // Status of latest attempt to contact the server.
  253. //
  254. // When the CsState is CS_AUTHENTICATED, this field is STATUS_SUCCESS.
  255. //
  256. // When the CsState is CS_IDLE, this field is a non-successful status.
  257. //
  258. // When the CsState is CS_DC_PICKED, this field is the same non-successful
  259. // status from when the CsState was last CS_IDLE.
  260. //
  261. // Access serialized by NlGlobalDcDiscoveryCritSect
  262. // This field can be read without the crit sect locked if
  263. // the answer will only be used as a hint.
  264. //
  265. NTSTATUS CsConnectionStatus;
  266. //
  267. // Access serialized by DomTrustListCritSect or
  268. // by the writer lock if so indicated
  269. //
  270. DWORD CsFlags;
  271. #define CS_UPDATE_PASSWORD 0x01 // Set if the password has already
  272. // been changed on the client and
  273. // needs changing on the server.
  274. #define CS_PASSWORD_REFUSED 0x02 // Set if DC refused a password change.
  275. #define CS_NT5_DOMAIN_TRUST 0x04 // Trust is to an NT 5 domain.
  276. #define CS_WRITER 0x08 // Entry is being modified
  277. #define CS_DIRECT_TRUST 0x10 // We have a direct trust to the specified
  278. // domain.
  279. #define CS_CHECK_PASSWORD 0x20 // Set if we need to check the password
  280. #define CS_PICK_DC 0x40 // Set if we need to Pick a DC
  281. #define CS_REDISCOVER_DC 0x80 // Set when we need to Rediscover a DC
  282. #define CS_HANDLE_API_TIMER 0x400 // Set if we need to handle API timer expiration
  283. #define CS_NOT_IN_LSA 0x800 // Flag to delete this entry if it's
  284. // not later proved to be in the LSA.
  285. #define CS_ZERO_LAST_AUTH 0x2000 // Set if we need to zero CsLastAuthenticationTry
  286. #define CS_DOMAIN_IN_FOREST 0x4000 // Set if trusted domain is in same forest as this domain.
  287. #define CS_NEW_TRUST 0x8000 // Set on a newly allocated trusted domain
  288. // until async discovery has been tried
  289. #define CS_DC_PICKED_ONCE 0x10000 // Set if DC was picked at least once.
  290. // Access serialized by writer lock
  291. //
  292. // Trust attributes for the trusted domain object
  293. //
  294. ULONG CsTrustAttributes;
  295. //
  296. // Pointer to client session that represents the direct trust that's
  297. // the closest route to the domain of this client session.
  298. //
  299. // The pointed to client session will always be marked CS_DIRECT_TRUST.
  300. //
  301. // If this is a CS_DIRECT_TRUST session,
  302. // this field will point to this client session.
  303. //
  304. struct _CLIENT_SESSION *CsDirectClientSession;
  305. //
  306. // Flags describing capabilities of both client and server.
  307. //
  308. ULONG CsNegotiatedFlags;
  309. //
  310. // Time Number of authentication attempts since last success.
  311. //
  312. // Access serialized by CsWriterSemaphore.
  313. //
  314. DWORD CsAuthAlertCount;
  315. //
  316. // Number of times the secure channel has been dropped.
  317. //
  318. // Access serialized by CsWriterSemaphore.
  319. //
  320. DWORD CsSessionCount;
  321. //
  322. // Number of threads referencing this entry.
  323. //
  324. // Access serialized by DomTrustListCritSect.
  325. //
  326. DWORD CsReferenceCount;
  327. //
  328. // Writer semaphore.
  329. //
  330. // This semaphore is locked whenever there is a writer modifying
  331. // fields in this client session.
  332. //
  333. HANDLE CsWriterSemaphore;
  334. #ifdef _DC_NETLOGON
  335. //
  336. // The following fields are used by the NlDiscoverDc to keep track
  337. // of discovery state.
  338. //
  339. // Access serialized by NlGlobalDcDiscoveryCritSect
  340. //
  341. DWORD CsDiscoveryFlags;
  342. #define CS_DISCOVERY_DEAD_DOMAIN 0x001 // This is a dead domain disocvery
  343. #define CS_DISCOVERY_ASYNCHRONOUS 0x002 // Discovery being processed in worker thread
  344. #define CS_DISCOVERY_HAS_DS 0x004 // Discovered DS has a DS
  345. #define CS_DISCOVERY_IS_CLOSE 0x008 // Discovered DS is in a close site
  346. #define CS_DISCOVERY_HAS_IP 0x010 // Discovered DC has IP address
  347. #define CS_DISCOVERY_USE_MAILSLOT 0x020 // Discovered DC should be pinged using mailslot mechanism
  348. #define CS_DISCOVERY_USE_LDAP 0x040 // Discovered DC should be pinged using LDAP mechanism
  349. #define CS_DISCOVERY_HAS_TIMESERV 0x080 // Discovered DC runs the Windows Time Service
  350. #define CS_DISCOVERY_DNS_SERVER 0x100 // Discovered DC name is DNS (if off, the name is Netbios)
  351. //
  352. // The next 2 password/trust monitor bits are protected by the writer lock
  353. //
  354. #define CS_DISCOVERY_NO_PWD_MONITOR 0x200 // Discovered DC cannot process NetrServerTrustPasswordsGet
  355. #define CS_DISCOVERY_NO_PWD_ATTR_MONITOR 0x400 // Discovered DC cannot process NetrServerTrustPasswordsAndAttribGet
  356. //
  357. // This event is set to indicate that discovery is not in progress on this
  358. // client session.
  359. //
  360. HANDLE CsDiscoveryEvent;
  361. #endif // _DC_NETLOGON
  362. //
  363. // API timout count. After each logon/logoff API call made to the
  364. // server this count is incremented if the time taken to execute the
  365. // this API is more than MAX_DC_API_TIMEOUT.
  366. //
  367. // The count is decremented each time there are FAST_DC_API_THRESHOLD calls
  368. // that execute in FAST_DC_API_TIMEOUT seconds.
  369. //
  370. //
  371. // Access serialized by CsWriterSemaphore.
  372. //
  373. DWORD CsTimeoutCount;
  374. #define MAX_DC_TIMEOUT_COUNT 2 // drop the session after this
  375. // many timeouts and when it is
  376. // time to reauthenticate.
  377. #define MAX_DC_API_TIMEOUT (long) (15L*1000L) // 15 seconds
  378. #define MAX_DC_REAUTHENTICATION_WAIT (long) (5L*60L*1000L) // 5 mins
  379. #define MAX_DC_REFRESH_TIMEOUT (45 * 60 * 1000) // 45 minutes
  380. #define FAST_DC_API_THRESHOLD 5 // Number of fast calls needed before
  381. // we decrement timeout count
  382. #define FAST_DC_API_TIMEOUT (1000) // 1 second
  383. //
  384. // Count of Fast Calls
  385. //
  386. // Access serialized by CsWriterSemaphore.
  387. //
  388. DWORD CsFastCallCount;
  389. //
  390. // Authentication information.
  391. //
  392. // Access serialized by CsWriterSemaphore.
  393. //
  394. NETLOGON_CREDENTIAL CsAuthenticationSeed;
  395. NETLOGON_SESSION_KEY CsSessionKey;
  396. PVOID ClientAuthData;
  397. CredHandle CsCredHandle;
  398. #ifdef _DC_NETLOGON
  399. //
  400. // Transport the server was discovered on.
  401. //
  402. PNL_TRANSPORT CsTransport;
  403. #endif // _DC_NETLOGON
  404. //
  405. // Rid of the account used to contact server
  406. //
  407. ULONG CsAccountRid;
  408. //
  409. // Know good password for this secure channel.
  410. //
  411. // After secure channel setup, it is the password used to setup the channel.
  412. // After a password change, it is the password successfully set on the DC.
  413. //
  414. NT_OWF_PASSWORD CsNtOwfPassword;
  415. //
  416. // Name of the server this connection is to (may be DNS or Netbios) and its
  417. // IP address (if any).
  418. //
  419. // Access serialized by CsWriterSemaphore or NlGlobalDcDiscoveryCritSect.
  420. // Modification from Null to non-null serialized by
  421. // NlGlobalDcDiscoveryCritSect
  422. // (Modification from non-null to null requires both to be locked.)
  423. //
  424. LPWSTR CsUncServerName;
  425. SOCKET_ADDRESS CsServerSockAddr;
  426. SOCKADDR_IN CsServerSockAddrIn;
  427. //
  428. // API semaphore.
  429. //
  430. // This semaphore has one reference for each slot in CsClientApi.
  431. // (Except the zeroth slot which is special.)
  432. //
  433. HANDLE CsApiSemaphore;
  434. //
  435. // List of API calls outstanding on this session
  436. //
  437. // Access serialized by DomainInfo->DomTrustListCritSect.
  438. //
  439. CLIENT_API CsClientApi[1];
  440. #define ClientApiIndex( _ClientSession, _ClientApi ) \
  441. ((LONG) ((_ClientApi)-&((_ClientSession)->CsClientApi[0])) )
  442. #define UseConcurrentRpc( _ClientSession, _ClientApi ) \
  443. (ClientApiIndex( _ClientSession, _ClientApi ) != 0 )
  444. } CLIENT_SESSION, * PCLIENT_SESSION;
  445. #define LOCK_TRUST_LIST(_DI) EnterCriticalSection( &(_DI)->DomTrustListCritSect )
  446. #define UNLOCK_TRUST_LIST(_DI) LeaveCriticalSection( &(_DI)->DomTrustListCritSect )
  447. //
  448. // For member workstations,
  449. // maintain a list of domains trusted by our primary domain.
  450. //
  451. // Access serialized by NlGlobalDcDiscoveryCritSect
  452. //
  453. typedef struct {
  454. WCHAR UnicodeNetbiosDomainName[DNLEN+1];
  455. LPSTR Utf8DnsDomainName;
  456. } TRUSTED_DOMAIN, *PTRUSTED_DOMAIN;
  457. #ifdef _DC_NETLOGON
  458. /////////////////////////////////////////////////////////////////////////////
  459. //
  460. // Server Session definitions
  461. //
  462. /////////////////////////////////////////////////////////////////////////////
  463. //
  464. // Sam Sync Context.
  465. //
  466. // A Sam sync context is maintained on the PDC for each BDC/member currently
  467. // doing a full sync.
  468. //
  469. typedef struct _SAM_SYNC_CONTEXT {
  470. //
  471. // The Sync state indicates tracks the progression of the sync.
  472. //
  473. SYNC_STATE SyncState;
  474. //
  475. // A serial number indicating the number of times the BDC/member
  476. // has called us. We use this as a resume handle.
  477. //
  478. ULONG SyncSerial;
  479. //
  480. // The current Sam Enumeration information
  481. //
  482. SAM_ENUMERATE_HANDLE SamEnumHandle; // Current Sam Enum Handle
  483. PSAMPR_ENUMERATION_BUFFER SamEnum; // Sam returned buffer
  484. PULONG RidArray; // Array of enumerated Rids
  485. ULONG Index; // Index to current entry
  486. ULONG Count; // Total Number of entries
  487. BOOL SamAllDone; // True, if Sam has completed
  488. } SAM_SYNC_CONTEXT, *PSAM_SYNC_CONTEXT;
  489. #define SAM_SYNC_PREF_MAX 1024 // Preferred max for Sam Sync
  490. //
  491. // Lsa Sync Context.
  492. //
  493. // A Lsa sync context is maintained on the PDC for each BDC/member
  494. // currently doing a full sync.
  495. //
  496. typedef struct _LSA_SYNC_CONTEXT {
  497. //
  498. // The Sync state indicates tracks the progression of the sync.
  499. //
  500. enum {
  501. AccountState,
  502. TDomainState,
  503. SecretState,
  504. LsaDoneState
  505. } SyncState;
  506. //
  507. // A serial number indicating the number of times the BDC/member
  508. // has called us. We use this as a resume handle.
  509. //
  510. ULONG SyncSerial;
  511. //
  512. // The current Lsa Enumeration information
  513. //
  514. LSA_ENUMERATION_HANDLE LsaEnumHandle; // Current Lsa Enum Handle
  515. enum {
  516. AccountEnumBuffer,
  517. TDomainEnumBuffer,
  518. SecretEnumBuffer,
  519. EmptyEnumBuffer
  520. } LsaEnumBufferType;
  521. union {
  522. LSAPR_ACCOUNT_ENUM_BUFFER Account;
  523. LSAPR_TRUSTED_ENUM_BUFFER TDomain;
  524. PVOID Secret;
  525. } LsaEnum; // Lsa returned buffer
  526. ULONG Index; // Index to current entry
  527. ULONG Count; // Total Number of entries
  528. BOOL LsaAllDone; // True, if Lsa has completed
  529. } LSA_SYNC_CONTEXT, *PLSA_SYNC_CONTEXT;
  530. //
  531. // union of lsa and sam context
  532. //
  533. typedef struct _SYNC_CONTEXT {
  534. enum {
  535. LsaDBContextType,
  536. SamDBContextType
  537. } DBContextType;
  538. union {
  539. LSA_SYNC_CONTEXT Lsa;
  540. SAM_SYNC_CONTEXT Sam;
  541. } DBContext;
  542. } SYNC_CONTEXT, *PSYNC_CONTEXT;
  543. //
  544. // Macro used to free any resources allocated by SAM.
  545. //
  546. // ?? check LsaIFree_LSAPR_* call parameters.
  547. //
  548. #define CLEAN_SYNC_CONTEXT( _Sync ) { \
  549. if ( (_Sync)->DBContextType == LsaDBContextType ) { \
  550. if ( (_Sync)->DBContext.Lsa.LsaEnumBufferType != \
  551. EmptyEnumBuffer) { \
  552. if ( (_Sync)->DBContext.Lsa.LsaEnumBufferType == \
  553. AccountEnumBuffer) { \
  554. LsaIFree_LSAPR_ACCOUNT_ENUM_BUFFER( \
  555. &((_Sync)->DBContext.Lsa.LsaEnum.Account) ); \
  556. } \
  557. else if ( (_Sync)->DBContext.Lsa.LsaEnumBufferType == \
  558. TDomainEnumBuffer) { \
  559. LsaIFree_LSAPR_TRUSTED_ENUM_BUFFER( \
  560. &((_Sync)->DBContext.Lsa.LsaEnum.TDomain) ); \
  561. } \
  562. else { \
  563. LsaIFree_LSAI_SECRET_ENUM_BUFFER ( \
  564. (_Sync)->DBContext.Lsa.LsaEnum.Secret, \
  565. (_Sync)->DBContext.Lsa.Count ); \
  566. (_Sync)->DBContext.Lsa.LsaEnum.Secret = NULL; \
  567. } \
  568. (_Sync)->DBContext.Lsa.LsaEnumBufferType = \
  569. EmptyEnumBuffer; \
  570. } \
  571. } else { \
  572. if ( (_Sync)->DBContext.Sam.SamEnum != NULL ) { \
  573. SamIFree_SAMPR_ENUMERATION_BUFFER( \
  574. (_Sync)->DBContext.Sam.SamEnum ); \
  575. (_Sync)->DBContext.Sam.SamEnum = NULL; \
  576. } \
  577. if ( (_Sync)->DBContext.Sam.RidArray != NULL ) { \
  578. MIDL_user_free( (_Sync)->DBContext.Sam.RidArray );\
  579. (_Sync)->DBContext.Sam.RidArray = NULL; \
  580. } \
  581. } \
  582. }
  583. //
  584. // Macro to initialize Sync Context
  585. //
  586. #define INIT_SYNC_CONTEXT( _Sync, _ContextType ) { \
  587. RtlZeroMemory( (_Sync), sizeof( *(_Sync) ) ) ; \
  588. (_Sync)->DBContextType = (_ContextType) ; \
  589. }
  590. //
  591. // Server Session structure
  592. //
  593. // This structure represents the server side of a connection to a DC.
  594. //
  595. // ISSUE-2000/09/15-CliffV: This structure could be made smaller by using SsSecureChannelType
  596. // as a discriminator. Many fields are specific to a BDC server session entry. Others
  597. // are specific to a domain server session entry. However, most entries are member workstation
  598. // server session entries that don't use either of the fields.
  599. //
  600. typedef struct _SERVER_SESSION {
  601. //
  602. // Each server session entry is in a doubly linked list for each hash bucket.
  603. // Indexed by SsComputerName
  604. //
  605. LIST_ENTRY SsHashList;
  606. //
  607. // Each server session entry is in a doubly linked list defined by
  608. // DomainInfo->DomServerSessionTable.
  609. //
  610. LIST_ENTRY SsSeqList;
  611. //
  612. // List of all BDCs headed by NlGlobalBdcServerSessionList.
  613. //
  614. // (The field is set only on BDC server session entries)
  615. //
  616. // Access serialized by NlGlobalServerSessionTableCritSect.
  617. //
  618. LIST_ENTRY SsBdcList;
  619. //
  620. // List of BDC's which have a pulse pending.
  621. //
  622. LIST_ENTRY SsPendingBdcList;
  623. //
  624. // Time when the last pulse was sent to this machine
  625. //
  626. // (The field is set only on BDC server session entries)
  627. //
  628. LARGE_INTEGER SsLastPulseTime;
  629. //
  630. // Current serial numbers of each database on the BDC.
  631. //
  632. // (The field is set only on BDC server session entries)
  633. //
  634. LARGE_INTEGER SsBdcDbSerialNumber[NUM_DBS];
  635. //
  636. // The computername uniquely identifies this server session entry.
  637. //
  638. NETLOGON_SECURE_CHANNEL_TYPE SsSecureChannelType;
  639. CHAR SsComputerName[CNLEN+1];
  640. //
  641. // Rid of the account to authenticate with
  642. //
  643. ULONG SsAccountRid;
  644. //
  645. // The number of times there has been no response to a pulse.
  646. //
  647. USHORT SsPulseTimeoutCount;
  648. //
  649. // Hosted domain for this server session.
  650. //
  651. PDOMAIN_INFO SsDomainInfo;
  652. //
  653. // The number of times this entry has been scavanged.
  654. //
  655. USHORT SsCheck;
  656. //
  657. // Flags describing the state of the current entry.
  658. // See the SS_ defines below.
  659. //
  660. USHORT SsFlags;
  661. #define SS_BDC_FORCE_DELETE 0x0001 // Unless set, BDC server session won't be deleted
  662. #define SS_AUTHENTICATED 0x0002 // Remote side has been authenticated
  663. #define SS_LOCKED 0x0004 // Delay deletion requests for this entry
  664. // While set, SsSessionKey may be referenced
  665. #define SS_DELETE_ON_UNLOCK 0x0008 // Delete entry when it is unlocked
  666. #define SS_BDC 0x0010 // BDC account exists for this Client
  667. #define SS_FOREST_TRANSITIVE 0x0020 // TDO has TRUST_ATTRIBUTE_FOREST_TRANSITIVE set
  668. #define SS_PENDING_BDC 0x0040 // BDC is on pending BDC list.
  669. #define SS_FORCE_PULSE 0x0200 // Force a pulse message to this BDC.
  670. #define SS_PULSE_SENT 0x0400 // Pulse has been sent but has not
  671. // been responded to yet
  672. #define SS_LSA_REPL_NEEDED 0x2000 // BDC needs LSA DB replicated
  673. #define SS_ACCOUNT_REPL_NEEDED 0x4000 // BDC needs SAM Account DB replicated
  674. #define SS_BUILTIN_REPL_NEEDED 0x8000 // BDC needs SAM Builtin DB replicated
  675. #define SS_REPL_MASK 0xE000 // BDC needs replication mask
  676. #define SS_REPL_LSA_MASK 0x2000 // BDC needs LSA replication mask
  677. #define SS_REPL_SAM_MASK 0xC000 // BDC needs SAM replication mask
  678. // Don't clear these on session setup
  679. #define SS_PERMANENT_FLAGS \
  680. ( SS_BDC | SS_PENDING_BDC | SS_FORCE_PULSE | SS_REPL_MASK )
  681. //
  682. // Flags describing capabilities of both client and server.
  683. //
  684. ULONG SsNegotiatedFlags;
  685. //
  686. // Transport the client connected over.
  687. //
  688. PNL_TRANSPORT SsTransport;
  689. //
  690. // This is the ClientCredential (after authentication is complete).
  691. //
  692. NETLOGON_CREDENTIAL SsAuthenticationSeed;
  693. //
  694. // This is the ServerChallenge (during the challenge phase) and later
  695. // the SessionKey (after authentication is complete).
  696. //
  697. NETLOGON_SESSION_KEY SsSessionKey;
  698. //
  699. // A pointer to the Sync context.
  700. //
  701. // (The field is set only on BDC server session entries)
  702. //
  703. PSYNC_CONTEXT SsSync;
  704. //
  705. // Each server session entry is in a doubly linked list for each hash bucket.
  706. // Indexed by SsTdoName
  707. //
  708. // (This field is set only on *uplevel* interdomain trust entries.)
  709. //
  710. LIST_ENTRY SsTdoNameHashList;
  711. UNICODE_STRING SsTdoName;
  712. } SERVER_SESSION, *PSERVER_SESSION;
  713. #endif // _DC_NETLOGON
  714. //
  715. // Structure shared by all PDC and BDC sync routines.
  716. // (And other users of secure channels.)
  717. //
  718. typedef struct _SESSION_INFO {
  719. //
  720. // Session Key shared by both client and server.
  721. //
  722. NETLOGON_SESSION_KEY SessionKey;
  723. //
  724. // Flags describing capabilities of both client and server.
  725. //
  726. ULONG NegotiatedFlags;
  727. } SESSION_INFO, *PSESSION_INFO;
  728. //
  729. // Macro for tranlating the negotiated database replication flags to the mask of
  730. // which databases to replicate/
  731. //
  732. #define NlMaxReplMask( _NegotiatedFlags ) \
  733. ((((_NegotiatedFlags) & NETLOGON_SUPPORTS_AVOID_SAM_REPL) ? 0 : SS_REPL_SAM_MASK ) | \
  734. (((_NegotiatedFlags) & NETLOGON_SUPPORTS_AVOID_LSA_REPL) ? 0 : SS_REPL_LSA_MASK ) )
  735. /////////////////////////////////////////////////////////////////////////////
  736. //
  737. // Structures and variables describing the database info.
  738. //
  739. /////////////////////////////////////////////////////////////////////////////
  740. typedef struct _DB_Info {
  741. LARGE_INTEGER CreationTime; // database creation time
  742. DWORD DBIndex; // index of Database table
  743. SAM_HANDLE DBHandle; // database handle to access
  744. LPWSTR DBName; // Name of the database
  745. DWORD DBSessionFlag; // SS_ Flag representing this database
  746. } DB_INFO, *PDB_INFO;
  747. /////////////////////////////////////////////////////////////////////////////
  748. //
  749. // Replication timing macros
  750. //
  751. /////////////////////////////////////////////////////////////////////////////
  752. #if NETLOGONDBG
  753. ///////////////////////////////////////////////////////////////////////////////
  754. #define DEFPACKTIMER DWORD PackTimer, PackTimerTicks
  755. #define INITPACKTIMER PackTimer = 0;
  756. #define STARTPACKTIMER \
  757. IF_NL_DEBUG( REPL_OBJ_TIME ) { \
  758. PackTimerTicks = GetTickCount(); \
  759. }
  760. #define STOPPACKTIMER \
  761. IF_NL_DEBUG( REPL_OBJ_TIME ) { \
  762. PackTimer += GetTickCount() - PackTimerTicks; \
  763. }
  764. #define PRINTPACKTIMER \
  765. IF_NL_DEBUG( REPL_OBJ_TIME ) { \
  766. NlPrint((NL_REPL_OBJ_TIME,"\tTime Taken to PACK this object = %d msecs\n", \
  767. PackTimer )); \
  768. }
  769. ///////////////////////////////////////////////////////////////////////////////
  770. #define DEFSAMTIMER DWORD SamTimer, SamTimerTicks
  771. #define INITSAMTIMER SamTimer = 0;
  772. #define STARTSAMTIMER \
  773. IF_NL_DEBUG( REPL_OBJ_TIME ) { \
  774. SamTimerTicks = GetTickCount(); \
  775. }
  776. #define STOPSAMTIMER \
  777. IF_NL_DEBUG( REPL_OBJ_TIME ) { \
  778. SamTimer += GetTickCount() - SamTimerTicks; \
  779. }
  780. #define PRINTSAMTIMER \
  781. IF_NL_DEBUG( REPL_OBJ_TIME ) { \
  782. NlPrint((NL_REPL_OBJ_TIME, \
  783. "\tTime spent in SAM calls = %d msecs\n", \
  784. SamTimer )); \
  785. }
  786. ///////////////////////////////////////////////////////////////////////////////
  787. #define DEFLSATIMER DWORD LsaTimer, LsaTimerTicks
  788. #define INITLSATIMER LsaTimer = 0;
  789. #define STARTLSATIMER \
  790. IF_NL_DEBUG( REPL_OBJ_TIME ) { \
  791. LsaTimerTicks = GetTickCount(); \
  792. }
  793. #define STOPLSATIMER \
  794. IF_NL_DEBUG( REPL_OBJ_TIME ) { \
  795. LsaTimer += GetTickCount() - LsaTimerTicks; \
  796. }
  797. #define PRINTLSATIMER \
  798. IF_NL_DEBUG( REPL_OBJ_TIME ) { \
  799. NlPrint((NL_REPL_OBJ_TIME, \
  800. "\tTime spent in LSA calls = %d msecs\n", \
  801. LsaTimer )); \
  802. }
  803. ///////////////////////////////////////////////////////////////////////////////
  804. #define DEFSSIAPITIMER DWORD SsiApiTimer, SsiApiTimerTicks
  805. #define INITSSIAPITIMER SsiApiTimer = 0;
  806. #define STARTSSIAPITIMER \
  807. IF_NL_DEBUG( REPL_TIME ) { \
  808. SsiApiTimerTicks = GetTickCount(); \
  809. }
  810. #define STOPSSIAPITIMER \
  811. IF_NL_DEBUG( REPL_TIME ) { \
  812. SsiApiTimer += GetTickCount() - \
  813. SsiApiTimerTicks; \
  814. }
  815. #define PRINTSSIAPITIMER \
  816. IF_NL_DEBUG( REPL_TIME ) { \
  817. NlPrint((NL_REPL_TIME, \
  818. "\tTime Taken by this SSIAPI call = %d msecs\n", \
  819. SsiApiTimer )); \
  820. }
  821. #else // NETLOGONDBG
  822. #define DEFPACKTIMER
  823. #define INITPACKTIMER
  824. #define STARTPACKTIMER
  825. #define STOPPACKTIMER
  826. #define PRINTPACKTIMER
  827. #define DEFSAMTIMER
  828. #define INITSAMTIMER
  829. #define STARTSAMTIMER
  830. #define STOPSAMTIMER
  831. #define PRINTSAMTIMER
  832. #define DEFLSATIMER
  833. #define INITLSATIMER
  834. #define STARTLSATIMER
  835. #define STOPLSATIMER
  836. #define PRINTLSATIMER
  837. #define DEFSSIAPITIMER
  838. #define INITSSIAPITIMER
  839. #define STARTSSIAPITIMER
  840. #define STOPSSIAPITIMER
  841. #define PRINTSSIAPITIMER
  842. #endif // NETLOGONDBG
  843. //
  844. // macros used in pack and unpack routines
  845. //
  846. #define SECURITYINFORMATION OWNER_SECURITY_INFORMATION | \
  847. GROUP_SECURITY_INFORMATION | \
  848. SACL_SECURITY_INFORMATION | \
  849. DACL_SECURITY_INFORMATION
  850. #define INIT_PLACE_HOLDER(_x) \
  851. RtlInitString( (PSTRING) &(_x)->DummyString1, NULL ); \
  852. RtlInitString( (PSTRING) &(_x)->DummyString2, NULL ); \
  853. RtlInitString( (PSTRING) &(_x)->DummyString3, NULL ); \
  854. RtlInitString( (PSTRING) &(_x)->DummyString4, NULL ); \
  855. (_x)->DummyLong1 = 0; \
  856. (_x)->DummyLong2 = 0; \
  857. (_x)->DummyLong3 = 0; \
  858. (_x)->DummyLong4 = 0;
  859. #define QUERY_LSA_SECOBJ_INFO(_x) \
  860. STARTLSATIMER; \
  861. Status = LsarQuerySecurityObject( \
  862. (_x), \
  863. SECURITYINFORMATION, \
  864. &SecurityDescriptor );\
  865. STOPLSATIMER; \
  866. \
  867. if (!NT_SUCCESS(Status)) { \
  868. SecurityDescriptor = NULL; \
  869. goto Cleanup; \
  870. }
  871. #define QUERY_SAM_SECOBJ_INFO(_x) \
  872. STARTSAMTIMER; \
  873. Status = SamrQuerySecurityObject( \
  874. (_x), \
  875. SECURITYINFORMATION, \
  876. &SecurityDescriptor );\
  877. STOPSAMTIMER; \
  878. \
  879. if (!NT_SUCCESS(Status)) { \
  880. SecurityDescriptor = NULL; \
  881. goto Cleanup; \
  882. }
  883. #define SET_LSA_SECOBJ_INFO(_x, _y) \
  884. SecurityDescriptor.Length = (_x)->SecuritySize; \
  885. SecurityDescriptor.SecurityDescriptor = (_x)->SecurityDescriptor; \
  886. \
  887. STARTLSATIMER; \
  888. Status = LsarSetSecurityObject( \
  889. (_y), \
  890. (_x)->SecurityInformation, \
  891. &SecurityDescriptor ); \
  892. STOPLSATIMER; \
  893. \
  894. if (!NT_SUCCESS(Status)) { \
  895. NlPrint((NL_CRITICAL, \
  896. "LsarSetSecurityObject failed (%lx)\n", \
  897. Status )); \
  898. goto Cleanup; \
  899. }
  900. #define SET_SAM_SECOBJ_INFO(_x, _y) \
  901. SecurityDescriptor.Length = (_x)->SecuritySize; \
  902. SecurityDescriptor.SecurityDescriptor = (_x)->SecurityDescriptor; \
  903. \
  904. STARTSAMTIMER; \
  905. Status = SamrSetSecurityObject( \
  906. (_y), \
  907. (_x)->SecurityInformation, \
  908. &SecurityDescriptor ); \
  909. STOPSAMTIMER; \
  910. \
  911. if (!NT_SUCCESS(Status)) { \
  912. NlPrint((NL_CRITICAL, \
  913. "SamrSetSecurityObject failed (%lx)\n", \
  914. Status )); \
  915. goto Cleanup; \
  916. }
  917. #define DELTA_SECOBJ_INFO(_x) \
  918. (_x)->SecurityInformation = SECURITYINFORMATION;\
  919. (_x)->SecuritySize = SecurityDescriptor->Length;\
  920. \
  921. *BufferSize += NlCopyData( \
  922. (LPBYTE *)&SecurityDescriptor->SecurityDescriptor, \
  923. (LPBYTE *)&(_x)->SecurityDescriptor, \
  924. SecurityDescriptor->Length );
  925. //
  926. // Values of WorkstationFlags field of NETLOGON_WORKSTATION_INFO
  927. //
  928. #define NL_NEED_BIDIRECTIONAL_TRUSTS 0x0001 // Client wants inbound trusts, too
  929. #define NL_CLIENT_HANDLES_SPN 0x0002 // Client handles updating SPN
  930. #define NL_GET_DOMAIN_INFO_SUPPORTED 0x0003 // Mask of all bits supported
  931. //
  932. // Structure describing failed user logon.
  933. // We keep a small cache of failed use logons
  934. // with bad password.
  935. //
  936. typedef struct _NL_FAILED_USER_LOGON {
  937. //
  938. // Link to next entry in the list of failed forwarded logons
  939. // (Serialized by DomainInfo->DomTrustListCritSect)
  940. //
  941. LIST_ENTRY FuNext;
  942. //
  943. // Last time we forwarded the logon to the PDC
  944. //
  945. ULONG FuLastTimeSentToPdc;
  946. //
  947. // Count of failed local logons
  948. //
  949. ULONG FuBadLogonCount;
  950. //
  951. // The user name (must be lat field in struct)
  952. //
  953. WCHAR FuUserName[ANYSIZE_ARRAY];
  954. } NL_FAILED_USER_LOGON, *PNL_FAILED_USER_LOGON;
  955. //
  956. // The number of failed user logons we keep per domain.
  957. // (The maximum number of negative cache entries we keep
  958. // before throwing the least recently used one.)
  959. //
  960. #define NL_MAX_FAILED_USER_LOGONS 50
  961. //
  962. // Number of failed logons for a given user after which we refrain from
  963. // forwarding subsequent user logons to the PDC for some period of time
  964. //
  965. #define NL_FAILED_USER_MAX_LOGON_COUNT 10
  966. //
  967. // Time period during which we refrain from forwarding a given
  968. // user logon to the PDC once number of failed user logons
  969. // reaches the above limit
  970. //
  971. #define NL_FAILED_USER_FORWARD_LOGON_TIMEOUT 300000 // 5 minutes
  972. ///////////////////////////////////////////////////////////////////////////////
  973. //
  974. // Procedure forwards.
  975. //
  976. ///////////////////////////////////////////////////////////////////////////////
  977. #ifdef _DC_NETLOGON
  978. //
  979. // srvsess.c
  980. //
  981. NET_API_STATUS
  982. NlTransportOpen(
  983. VOID
  984. );
  985. BOOL
  986. NlTransportAddTransportName(
  987. IN LPWSTR TransportName,
  988. OUT PBOOLEAN IpTransportChanged
  989. );
  990. BOOLEAN
  991. NlTransportDisableTransportName(
  992. IN LPWSTR TransportName
  993. );
  994. PNL_TRANSPORT
  995. NlTransportLookupTransportName(
  996. IN LPWSTR TransportName
  997. );
  998. PNL_TRANSPORT
  999. NlTransportLookup(
  1000. IN LPWSTR ClientName
  1001. );
  1002. VOID
  1003. NlTransportClose(
  1004. VOID
  1005. );
  1006. ULONG
  1007. NlTransportGetIpAddresses(
  1008. IN ULONG HeaderSize,
  1009. IN BOOLEAN ReturnOffsets,
  1010. OUT PSOCKET_ADDRESS *RetIpAddresses,
  1011. OUT PULONG RetIpAddressSize
  1012. );
  1013. BOOLEAN
  1014. NlHandleWsaPnp(
  1015. VOID
  1016. );
  1017. PSERVER_SESSION
  1018. NlFindNamedServerSession(
  1019. IN PDOMAIN_INFO DomainInfo,
  1020. IN LPWSTR ComputerName
  1021. );
  1022. VOID
  1023. NlSetServerSessionAttributesByTdoName(
  1024. IN PDOMAIN_INFO DomainInfo,
  1025. IN PUNICODE_STRING TdoName,
  1026. IN ULONG TrustAttributes
  1027. );
  1028. NTSTATUS
  1029. NlInsertServerSession(
  1030. IN PDOMAIN_INFO DomainInfo,
  1031. IN LPWSTR ComputerName,
  1032. IN LPWSTR TdoName OPTIONAL,
  1033. IN NETLOGON_SECURE_CHANNEL_TYPE SecureChannelType,
  1034. IN DWORD Flags,
  1035. IN ULONG AccountRid,
  1036. IN ULONG NegotiatedFlags,
  1037. IN PNL_TRANSPORT Transport OPTIONAL,
  1038. IN PNETLOGON_SESSION_KEY SessionKey OPTIONAL,
  1039. IN PNETLOGON_CREDENTIAL AuthenticationSeed OPTIONAL
  1040. );
  1041. NTSTATUS
  1042. NlCheckServerSession(
  1043. IN ULONG ServerRid,
  1044. IN PUNICODE_STRING AccountName OPTIONAL,
  1045. IN NETLOGON_SECURE_CHANNEL_TYPE SecureChannelType
  1046. );
  1047. NTSTATUS
  1048. NlBuildNtBdcList(
  1049. PDOMAIN_INFO DomainInfo
  1050. );
  1051. NTSTATUS
  1052. NlBuildLmBdcList(
  1053. PDOMAIN_INFO DomainInfo
  1054. );
  1055. BOOLEAN
  1056. NlFreeServerSession(
  1057. IN PSERVER_SESSION ServerSession
  1058. );
  1059. VOID
  1060. NlUnlockServerSession(
  1061. IN PSERVER_SESSION ServerSession
  1062. );
  1063. VOID
  1064. NlFreeNamedServerSession(
  1065. IN PDOMAIN_INFO DomainInfo,
  1066. IN LPWSTR ComputerName,
  1067. IN BOOLEAN AccountBeingDeleted
  1068. );
  1069. VOID
  1070. NlFreeServerSessionForAccount(
  1071. IN PUNICODE_STRING AccountName
  1072. );
  1073. VOID
  1074. NlServerSessionScavenger(
  1075. IN PDOMAIN_INFO DomainInfo
  1076. );
  1077. #endif // _DC_NETLOGON
  1078. //
  1079. // ssiauth.c
  1080. //
  1081. NTSTATUS
  1082. NlMakeSessionKey(
  1083. IN ULONG NegotiatedFlags,
  1084. IN PNT_OWF_PASSWORD CryptKey,
  1085. IN PNETLOGON_CREDENTIAL ClientChallenge,
  1086. IN PNETLOGON_CREDENTIAL ServerChallenge,
  1087. OUT PNETLOGON_SESSION_KEY SessionKey
  1088. );
  1089. #ifdef _DC_NETLOGON
  1090. NTSTATUS
  1091. NlCheckAuthenticator(
  1092. IN OUT PSERVER_SESSION ServerServerSession,
  1093. IN PNETLOGON_AUTHENTICATOR Authenticator,
  1094. OUT PNETLOGON_AUTHENTICATOR ReturnAuthenticator
  1095. );
  1096. #endif _DC_NETLOGON
  1097. VOID
  1098. NlComputeCredentials(
  1099. IN PNETLOGON_CREDENTIAL Challenge,
  1100. OUT PNETLOGON_CREDENTIAL Credential,
  1101. IN PNETLOGON_SESSION_KEY SessionKey
  1102. );
  1103. VOID
  1104. NlComputeChallenge(
  1105. OUT PNETLOGON_CREDENTIAL Challenge
  1106. );
  1107. VOID
  1108. NlBuildAuthenticator(
  1109. IN OUT PNETLOGON_CREDENTIAL AuthenticationSeed,
  1110. IN PNETLOGON_SESSION_KEY SessionKey,
  1111. OUT PNETLOGON_AUTHENTICATOR Authenticator
  1112. );
  1113. BOOL
  1114. NlUpdateSeed(
  1115. IN OUT PNETLOGON_CREDENTIAL AuthenticationSeed,
  1116. IN PNETLOGON_CREDENTIAL TargetCredential,
  1117. IN PNETLOGON_SESSION_KEY SessionKey
  1118. );
  1119. VOID
  1120. NlEncryptRC4(
  1121. IN OUT PVOID Buffer,
  1122. IN ULONG BufferSize,
  1123. IN PSESSION_INFO SessionInfo
  1124. );
  1125. VOID
  1126. NlDecryptRC4(
  1127. IN OUT PVOID Buffer,
  1128. IN ULONG BufferSize,
  1129. IN PSESSION_INFO SessionInfo
  1130. );
  1131. VOID
  1132. NlPrintTrustedDomain(
  1133. PDS_DOMAIN_TRUSTSW TrustedDomain,
  1134. IN BOOLEAN VerbosePrint,
  1135. IN BOOLEAN AnsiOutput
  1136. );
  1137. //
  1138. // trustutl.c
  1139. //
  1140. //
  1141. // Extended trust information passed via I_NetLogonGetDomainInfo
  1142. //
  1143. typedef struct _NL_TRUST_EXTENSION {
  1144. ULONG Flags;
  1145. ULONG ParentIndex;
  1146. ULONG TrustType;
  1147. ULONG TrustAttributes;
  1148. } NL_TRUST_EXTENSION, *PNL_TRUST_EXTENSION;
  1149. PCLIENT_SESSION
  1150. NlFindNamedClientSession(
  1151. IN PDOMAIN_INFO DomainInfo,
  1152. IN PUNICODE_STRING DomainName,
  1153. IN ULONG Flags,
  1154. OUT PBOOLEAN TransitiveUsed OPTIONAL
  1155. );
  1156. PCLIENT_SESSION
  1157. NlAllocateClientSession(
  1158. IN PDOMAIN_INFO DomainInfo,
  1159. IN PUNICODE_STRING DomainName,
  1160. IN PUNICODE_STRING DnsDomainName OPTIONAL,
  1161. IN PSID DomainId,
  1162. IN GUID *DomainGuid OPTIONAL,
  1163. IN ULONG Flags,
  1164. IN NETLOGON_SECURE_CHANNEL_TYPE SecureChannelType,
  1165. IN ULONG TrustAttributes
  1166. );
  1167. VOID
  1168. NlFreeClientSession(
  1169. IN PCLIENT_SESSION ClientSession
  1170. );
  1171. VOID
  1172. NlRefClientSession(
  1173. IN PCLIENT_SESSION ClientSession
  1174. );
  1175. VOID
  1176. NlUnrefClientSession(
  1177. IN PCLIENT_SESSION ClientSession
  1178. );
  1179. PCLIENT_API
  1180. NlAllocateClientApi(
  1181. IN PCLIENT_SESSION ClientSession,
  1182. IN DWORD Timeout
  1183. );
  1184. VOID
  1185. NlFreeClientApi(
  1186. IN PCLIENT_SESSION ClientSession,
  1187. IN PCLIENT_API ClientApi
  1188. );
  1189. BOOL
  1190. NlTimeoutSetWriterClientSession(
  1191. IN PCLIENT_SESSION ClientSession,
  1192. IN DWORD Timeout
  1193. );
  1194. VOID
  1195. NlResetWriterClientSession(
  1196. IN PCLIENT_SESSION ClientSession
  1197. );
  1198. NTSTATUS
  1199. NlCaptureServerClientSession (
  1200. IN PCLIENT_SESSION ClientSession,
  1201. OUT LPWSTR *UncServerName,
  1202. OUT DWORD *DiscoveryFlags OPTIONAL
  1203. );
  1204. NTSTATUS
  1205. NlCaptureNetbiosServerClientSession (
  1206. IN PCLIENT_SESSION ClientSession,
  1207. OUT WCHAR NetbiosUncServerName[UNCLEN+1]
  1208. );
  1209. BOOL
  1210. NlSetNamesClientSession(
  1211. IN PCLIENT_SESSION ClientSession,
  1212. IN PUNICODE_STRING DomainName OPTIONAL,
  1213. IN PUNICODE_STRING DnsDomainName OPTIONAL,
  1214. IN PSID DomainId OPTIONAL,
  1215. IN GUID *DomainGuid OPTIONAL
  1216. );
  1217. VOID
  1218. NlSetStatusClientSession(
  1219. IN PCLIENT_SESSION ClientSession,
  1220. IN NTSTATUS CsConnectionStatus
  1221. );
  1222. #ifdef _DC_NETLOGON
  1223. NTSTATUS
  1224. NlInitTrustList(
  1225. IN PDOMAIN_INFO DomainInfo
  1226. );
  1227. VOID
  1228. NlPickTrustedDcForEntireTrustList(
  1229. IN PDOMAIN_INFO DomainInfo,
  1230. IN BOOLEAN OnlyDoNewTrusts
  1231. );
  1232. #endif // _DC_NETLOGON
  1233. NTSTATUS
  1234. NlUpdatePrimaryDomainInfo(
  1235. IN LSAPR_HANDLE PolicyHandle,
  1236. IN PUNICODE_STRING NetbiosDomainName,
  1237. IN PUNICODE_STRING DnsDomainName,
  1238. IN PUNICODE_STRING DnsForestName,
  1239. IN GUID *DomainGuid
  1240. );
  1241. VOID
  1242. NlSetForestTrustList (
  1243. IN PDOMAIN_INFO DomainInfo,
  1244. IN OUT PDS_DOMAIN_TRUSTSW *ForestTrustList,
  1245. IN ULONG ForestTrustListSize,
  1246. IN ULONG ForestTrustListCount
  1247. );
  1248. NET_API_STATUS
  1249. NlReadRegTrustedDomainList (
  1250. IN PDOMAIN_INFO DomainInfo,
  1251. IN BOOL DeleteName,
  1252. OUT PDS_DOMAIN_TRUSTSW *RetForestTrustList,
  1253. OUT PULONG RetForestTrustListSize,
  1254. OUT PULONG RetForestTrustListCount
  1255. );
  1256. NET_API_STATUS
  1257. NlReadFileTrustedDomainList (
  1258. IN PDOMAIN_INFO DomainInfo,
  1259. IN LPWSTR FileSuffix,
  1260. IN BOOL DeleteName,
  1261. IN ULONG Flags,
  1262. OUT PDS_DOMAIN_TRUSTSW *RetForestTrustList,
  1263. OUT PULONG RetForestTrustListSize,
  1264. OUT PULONG RetForestTrustListCount
  1265. );
  1266. NET_API_STATUS
  1267. NlpEnumerateDomainTrusts (
  1268. IN PDOMAIN_INFO DomainInfo,
  1269. IN ULONG Flags,
  1270. OUT PULONG RetForestTrustListCount,
  1271. OUT PDS_DOMAIN_TRUSTSW *RetForestTrustList
  1272. );
  1273. BOOLEAN
  1274. NlIsDomainTrusted (
  1275. IN PUNICODE_STRING DomainName
  1276. );
  1277. NET_API_STATUS
  1278. NlGetTrustedDomainNames (
  1279. IN PDOMAIN_INFO DomainInfo,
  1280. IN LPWSTR DomainName,
  1281. OUT LPWSTR *TrustedDnsDomainName,
  1282. OUT LPWSTR *TrustedNetbiosDomainName
  1283. );
  1284. typedef enum _DISCOVERY_TYPE {
  1285. #ifdef _DC_NETLOGON
  1286. DT_DeadDomain,
  1287. DT_Asynchronous,
  1288. #endif // _DC_NETLOGON
  1289. DT_Synchronous
  1290. } DISCOVERY_TYPE;
  1291. NET_API_STATUS
  1292. NlSetServerClientSession(
  1293. IN OUT PCLIENT_SESSION ClientSession,
  1294. IN PNL_DC_CACHE_ENTRY NlDcCacheEntry,
  1295. IN BOOL DcDiscoveredWithAccount,
  1296. IN BOOL SessionRefresh
  1297. );
  1298. NTSTATUS
  1299. NlDiscoverDc (
  1300. IN OUT PCLIENT_SESSION ClientSession,
  1301. IN DISCOVERY_TYPE DiscoveryType,
  1302. IN BOOLEAN InDiscoveryThread,
  1303. IN BOOLEAN DiscoverWithAccount
  1304. );
  1305. VOID
  1306. NlFlushCacheOnPnp (
  1307. VOID
  1308. );
  1309. BOOL
  1310. NlReadSamLogonResponse (
  1311. IN HANDLE ResponseMailslotHandle,
  1312. IN LPWSTR AccountName,
  1313. OUT LPDWORD Opcode,
  1314. OUT LPWSTR *LogonServer,
  1315. OUT PNL_DC_CACHE_ENTRY *NlDcCacheEntry OPTIONAL
  1316. );
  1317. #ifdef _DC_NETLOGON
  1318. NTSTATUS
  1319. NlPickDomainWithAccount (
  1320. IN PDOMAIN_INFO DomainInfo,
  1321. IN PUNICODE_STRING InAccountNameString,
  1322. IN PUNICODE_STRING InDomainNameString OPTIONAL,
  1323. IN ULONG AllowableAccountControlBits,
  1324. IN NETLOGON_SECURE_CHANNEL_TYPE SecureChannelType,
  1325. IN BOOLEAN ExpediteToRoot,
  1326. IN BOOLEAN CrossForestHop,
  1327. OUT LPWSTR *RealSamAccountName,
  1328. OUT LPWSTR *RealDomainName,
  1329. OUT PULONG RealExtraFlags
  1330. );
  1331. #endif // _DC_NETLOGON
  1332. #ifdef _NETLOGON_SERVER
  1333. NTSTATUS
  1334. NlGetConfigurationName(
  1335. DWORD which,
  1336. DWORD *pcbName,
  1337. DSNAME *pName );
  1338. NTSTATUS
  1339. NlGetConfigurationNamesList(
  1340. DWORD which,
  1341. DWORD dwFlags,
  1342. ULONG * pcbNames,
  1343. DSNAME ** padsNames );
  1344. NTSTATUS
  1345. NlGetDnsRootAlias(
  1346. WCHAR * pDnsRootAlias,
  1347. WCHAR * pRootDnsRootAlias);
  1348. DWORD
  1349. NlDsGetServersAndSitesForNetLogon(
  1350. WCHAR * pNDNC,
  1351. SERVERSITEPAIR ** ppaRes);
  1352. VOID
  1353. NlDsFreeServersAndSitesForNetLogon(
  1354. SERVERSITEPAIR * paServerSites
  1355. );
  1356. NTSTATUS
  1357. NlCrackSingleName(
  1358. DWORD formatOffered, // one of DS_NAME_FORMAT in ntdsapi.h
  1359. BOOL fPerformAtGC, // whether to go to GC or not
  1360. WCHAR *pNameIn, // name to crack
  1361. DWORD formatDesired, // one of DS_NAME_FORMAT in ntdsapi.h
  1362. DWORD *pccDnsDomain, // char count of following argument
  1363. WCHAR *pDnsDomain, // buffer for DNS domain name
  1364. DWORD *pccNameOut, // char count of following argument
  1365. WCHAR *pNameOut, // buffer for formatted name
  1366. DWORD *pErr); // one of DS_NAME_ERROR in ntdsapi.h
  1367. #endif // _NETLOGON_SERVER
  1368. //
  1369. // Macros to wrap all API calls over the secure channel.
  1370. //
  1371. // Here's a sample calling sequence"
  1372. //
  1373. // NL_API_START( Status, ClientSession, TRUE ) {
  1374. //
  1375. // Status = /* Call the secure channel API */
  1376. //
  1377. // } NL_API_ELSE ( Status, ClientSession, FALSE ) {
  1378. //
  1379. // /* Do whatever you'd do if the secure channel was timed out */
  1380. //
  1381. // } NL_API_END;
  1382. // Loop through each of the appropriate RPC bindings for this ClientSession.
  1383. // Avoid the real API call altogether if we can't bind.
  1384. #define NL_API_START_EX( _NtStatus, _ClientSession, _QuickApiCall, _ClientApi ) \
  1385. { \
  1386. ULONG _BindingLoopCount; \
  1387. \
  1388. _NtStatus = RPC_NT_PROTSEQ_NOT_SUPPORTED; \
  1389. for ( _BindingLoopCount=0; _BindingLoopCount<2; _BindingLoopCount++ ) { \
  1390. _NtStatus = NlStartApiClientSession( (_ClientSession), (_QuickApiCall), _BindingLoopCount, _NtStatus, _ClientApi ); \
  1391. \
  1392. if ( NT_SUCCESS(_NtStatus) ) {
  1393. #define NL_API_START( _NtStatus, _ClientSession, _QuickApiCall ) \
  1394. NL_API_START_EX( _NtStatus, _ClientSession, _QuickApiCall, &(_ClientSession)->CsClientApi[0] )
  1395. // If the real API indicates the endpoint isn't registered,
  1396. // fall back to another binding.
  1397. //
  1398. // EPT_NT_NOT_REGISTERED: from NlStartApiClientSession
  1399. // RPC_NT_SERVER_UNAVAILABLE: From server if TCP not configured at all
  1400. // RPC_NT_PROTSEQ_NOT_SUPPORTED: From client or server if TCP/IP not supported
  1401. //
  1402. #define NL_API_ELSE_EX( _NtStatus, _ClientSession, _OkToKillSession, _AmWriter, _ClientApi ) \
  1403. \
  1404. } \
  1405. \
  1406. if ( _NtStatus == EPT_NT_NOT_REGISTERED || \
  1407. _NtStatus == RPC_NT_SERVER_UNAVAILABLE || \
  1408. _NtStatus == RPC_NT_PROTSEQ_NOT_SUPPORTED ) { \
  1409. continue; \
  1410. } \
  1411. \
  1412. break; \
  1413. \
  1414. } \
  1415. \
  1416. if ( !NlFinishApiClientSession( (_ClientSession), (_OkToKillSession), (_AmWriter), (_ClientApi) ) ) {
  1417. #define NL_API_ELSE( _NtStatus, _ClientSession, _OkToKillSession ) \
  1418. NL_API_ELSE_EX( _NtStatus, _ClientSession, _OkToKillSession, TRUE, &(_ClientSession)->CsClientApi[0] ) \
  1419. #define NL_API_END \
  1420. } \
  1421. } \
  1422. NTSTATUS
  1423. NlStartApiClientSession(
  1424. IN PCLIENT_SESSION ClientSession,
  1425. IN BOOLEAN QuickApiCall,
  1426. IN ULONG RetryIndex,
  1427. IN NTSTATUS DefaultStatus,
  1428. IN PCLIENT_API ClientApi
  1429. );
  1430. BOOLEAN
  1431. NlFinishApiClientSession(
  1432. IN PCLIENT_SESSION ClientSession,
  1433. IN BOOLEAN OkToKillSession,
  1434. IN BOOLEAN AmWriter,
  1435. IN PCLIENT_API ClientApi
  1436. );
  1437. VOID
  1438. NlTimeoutApiClientSession(
  1439. IN PDOMAIN_INFO DomainInfo
  1440. );
  1441. typedef
  1442. DWORD
  1443. (*PDsBindW)(
  1444. LPCWSTR DomainControllerName, // in, optional
  1445. LPCWSTR DnsDomainName, // in, optional
  1446. HANDLE *phDS);
  1447. typedef
  1448. DWORD
  1449. (*PDsUnBindW)(
  1450. HANDLE *phDS); // in
  1451. typedef NTSTATUS
  1452. (*PCrackSingleName)(
  1453. DWORD formatOffered,
  1454. DWORD dwFlags,
  1455. WCHAR *pNameIn,
  1456. DWORD formatDesired,
  1457. DWORD *pccDnsDomain,
  1458. WCHAR *pDnsDomain,
  1459. DWORD *pccNameOut,
  1460. WCHAR *pNameOut,
  1461. DWORD *pErr);
  1462. typedef NTSTATUS
  1463. (*PGetConfigurationName)(
  1464. DWORD which,
  1465. DWORD *pcbName,
  1466. DSNAME *pName);
  1467. typedef NTSTATUS
  1468. (*PGetConfigurationNamesList)(
  1469. DWORD which,
  1470. DWORD dwFlags,
  1471. ULONG * pcbNames,
  1472. DSNAME ** padsNames);
  1473. typedef NTSTATUS
  1474. (*PGetDnsRootAlias)(
  1475. WCHAR * pDnsRootAlias,
  1476. WCHAR * pRootDnsRootAlias);
  1477. typedef DWORD
  1478. (*PDsGetServersAndSitesForNetLogon)(
  1479. WCHAR * pNDNC,
  1480. SERVERSITEPAIR ** ppaRes);
  1481. typedef VOID
  1482. (*PDsFreeServersAndSitesForNetLogon)(
  1483. SERVERSITEPAIR * paServerSites);
  1484. NTSTATUS
  1485. NlLoadNtdsaDll(
  1486. VOID
  1487. );
  1488. //
  1489. // secpkg.c
  1490. //
  1491. PVOID
  1492. NlBuildAuthData(
  1493. PCLIENT_SESSION ClientSession
  1494. );
  1495. BOOL
  1496. NlStartNetlogonCall(
  1497. VOID
  1498. );
  1499. VOID
  1500. NlEndNetlogonCall(
  1501. VOID
  1502. );
  1503. //
  1504. // ssiapi.c
  1505. //
  1506. NTSTATUS
  1507. NlGetAnyDCName (
  1508. IN PCLIENT_SESSION ClientSession,
  1509. IN BOOL RequireIp,
  1510. IN BOOL DoDiscoveryWithAccount,
  1511. OUT PNL_DC_CACHE_ENTRY *NlDcCacheEntry,
  1512. OUT PBOOLEAN DcRediscovered
  1513. );
  1514. NET_API_STATUS
  1515. NlSetDsSPN(
  1516. IN BOOLEAN Synchronous,
  1517. IN BOOLEAN SetSpn,
  1518. IN BOOLEAN SetDnsHostName,
  1519. IN PDOMAIN_INFO DomainInfo,
  1520. IN LPWSTR UncDcName,
  1521. IN LPWSTR ComputerName,
  1522. IN LPWSTR DnsHostName
  1523. );
  1524. NET_API_STATUS
  1525. NlPingDcName (
  1526. IN PCLIENT_SESSION ClientSession,
  1527. IN ULONG DcNamePingFlags,
  1528. IN BOOL CachePingedDc,
  1529. IN BOOL RequireIp,
  1530. IN BOOL DoPingWithAccount,
  1531. IN BOOL RefreshClientSession,
  1532. IN LPWSTR DcName OPTIONAL,
  1533. OUT PNL_DC_CACHE_ENTRY *NlDcCacheEntry OPTIONAL
  1534. );
  1535. VOID
  1536. NlFreePingContext(
  1537. IN PNL_GETDC_CONTEXT PingContext
  1538. );
  1539. VOID
  1540. NlScavengeOldChallenges(
  1541. VOID
  1542. );
  1543. VOID
  1544. NlRemoveChallenge(
  1545. IN LPWSTR ClientName OPTIONAL,
  1546. IN LPWSTR AccountName OPTIONAL,
  1547. IN BOOL InterdomainTrustAccount
  1548. );
  1549. //
  1550. // logonapi.c
  1551. //
  1552. NTSTATUS
  1553. NlpUserValidateHigher (
  1554. IN PCLIENT_SESSION ClientSession,
  1555. IN BOOLEAN DoingIndirectTrust,
  1556. IN NETLOGON_LOGON_INFO_CLASS LogonLevel,
  1557. IN LPBYTE LogonInformation,
  1558. IN NETLOGON_VALIDATION_INFO_CLASS ValidationLevel,
  1559. OUT LPBYTE * ValidationInformation,
  1560. OUT PBOOLEAN Authoritative,
  1561. IN OUT PULONG ExtraFlags
  1562. );
  1563. VOID
  1564. NlScavengeOldFailedLogons(
  1565. IN PDOMAIN_INFO DomainInfo
  1566. );
  1567. //
  1568. // ftinfo.c
  1569. //
  1570. NTSTATUS
  1571. NlpGetForestTrustInfoHigher(
  1572. IN PCLIENT_SESSION ClientSession,
  1573. IN DWORD Flags,
  1574. IN BOOLEAN ImpersonateCaller,
  1575. OUT PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo
  1576. );