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.

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