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.

430 lines
9.6 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // File: SECDATA.hxx
  4. //
  5. // Contents: Structures for KDC global data mgmt
  6. //
  7. //
  8. // History:
  9. //
  10. //------------------------------------------------------------------------
  11. #ifndef INC__SECDATA_HXX
  12. #define INC__SECDATA_HXX
  13. // A bunch of include files that this file depends on...
  14. extern "C" {
  15. #include <nturtl.h>
  16. }
  17. #include "kdcsvr.hxx"
  18. //+---------------------------------------------------------------------------
  19. ///////////////////////////////////////////////////////////////
  20. //
  21. //
  22. // Constants and #define macros
  23. //
  24. //
  25. // Class: CSecurityData ()
  26. //
  27. // Purpose: Global data for KDC.
  28. //
  29. // Interface:
  30. // CSecurityData -- Constructor (need to call Init(), too)
  31. // ~CSecurityData -- Frees the strings.
  32. // Init -- Initializes the data.
  33. // NextJob -- Gets a job from the job queue.
  34. // AddJob -- Adds a job to the job queue.
  35. // GetJobEvent -- Gets a handle to an event that is
  36. // set when there's a job in the queue.
  37. // KdcRealm -- return the current realm.
  38. // KdcServiceName -- return "krbtgt"
  39. // KdcFullServiceName -- return "realm\krbtgt"
  40. // MachineName -- return machine name
  41. // KdcTgtTicketLifespan --
  42. // KdcTgsTicketLifespan --
  43. // KdcTicketRenewSpan --
  44. // KdcFlags --
  45. // DebugShowState --
  46. // DebugSetState --
  47. // DebugGetState --
  48. //
  49. // History: 4-02-93 WadeR Created
  50. //
  51. // Notes:
  52. //
  53. //----------------------------------------------------------------------------
  54. class CSecurityData {
  55. private:
  56. //
  57. // Private data
  58. //
  59. // Site constants
  60. KERB_REALM _KerbRealmName;
  61. KERB_REALM _KerbDnsRealmName;
  62. UNICODE_STRING _RealmName;
  63. UNICODE_STRING _DnsRealmName;
  64. UNICODE_STRING _KDC_Name;
  65. UNICODE_STRING _KDC_FullName;
  66. UNICODE_STRING _KDC_FullDnsName;
  67. UNICODE_STRING _KDC_FullKdcName;
  68. UNICODE_STRING _MachineName;
  69. UNICODE_STRING _MachineUpn;
  70. UNICODE_STRING _ForestRoot;
  71. PKERB_INTERNAL_NAME _KrbtgtServiceName;
  72. PKERB_INTERNAL_NAME _KpasswdServiceName;
  73. LARGE_INTEGER _KDC_TgsTicketLifespan;
  74. LARGE_INTEGER _KDC_TgtTicketLifespan;
  75. LARGE_INTEGER _KDC_TicketRenewSpan;
  76. LARGE_INTEGER _KDC_DomainPasswordReplSkew;
  77. LARGE_INTEGER _KDC_RestrictionLifetime; // how long after a ticket is issued do we need to start checking restrictions again
  78. DWORD _KDC_Flags;
  79. ULONG _KDC_AuditEvents;
  80. KDC_TICKET_INFO _KrbtgtTicketInfo;
  81. BOOLEAN _KrbtgtTicketInfoValid;
  82. BOOLEAN _KDC_CrossForestEnabled;
  83. BOOLEAN _KDC_IsForestRoot;
  84. LARGE_INTEGER _KrbtgtPasswordLastSet;
  85. // Locks
  86. RTL_CRITICAL_SECTION _Monitor;
  87. //
  88. // Private functions
  89. //
  90. public:
  91. //
  92. // Public functions
  93. //
  94. CSecurityData();
  95. ~CSecurityData(void);
  96. VOID Cleanup();
  97. NTSTATUS Init();
  98. NTSTATUS LoadParameters(SAM_HANDLE Domain);
  99. NTSTATUS ReloadPolicy(POLICY_NOTIFICATION_INFORMATION_CLASS Class);
  100. KERBERR GetKrbtgtTicketInfo(PKDC_TICKET_INFO TicketInfo);
  101. NTSTATUS UpdateKrbtgtTicketInfo();
  102. NTSTATUS SetForestRoot(PUNICODE_STRING NewForestRoot);
  103. // Site (domain) constants
  104. inline PUNICODE_STRING KdcRealmName();
  105. inline PUNICODE_STRING KdcDnsRealmName();
  106. inline KERB_REALM KdcKerbRealmName();
  107. inline KERB_REALM KdcKerbDnsRealmName();
  108. inline PUNICODE_STRING KdcServiceName();
  109. inline PUNICODE_STRING KdcFullServiceName();
  110. inline PUNICODE_STRING KdcFullServiceDnsName();
  111. inline PUNICODE_STRING KdcFullServiceKdcName();
  112. inline PUNICODE_STRING MachineName();
  113. inline PUNICODE_STRING MachineUpn();
  114. inline NTSTATUS GetKdcForestRoot(PUNICODE_STRING Temp);
  115. inline PKERB_INTERNAL_NAME KdcInternalName();
  116. inline PKERB_INTERNAL_NAME KpasswdInternalName();
  117. inline LARGE_INTEGER KdcTgtTicketLifespan();
  118. inline LARGE_INTEGER KdcTgsTicketLifespan();
  119. inline LARGE_INTEGER KdcTicketRenewSpan();
  120. inline LARGE_INTEGER KdcMaxPasswordAge();
  121. inline LARGE_INTEGER KdcDomainPasswordReplSkew();
  122. inline LARGE_INTEGER KdcRestrictionLifetime();
  123. inline DWORD KdcFlags();
  124. inline VOID SetCrossForestEnabled(BOOLEAN NewState);
  125. inline VOID ReadLock();
  126. inline VOID WriteLock();
  127. inline VOID Release();
  128. inline BOOLEAN AuditKdcEvent( ULONG EventToAudit );
  129. inline BOOLEAN IsCrossForestEnabled();
  130. inline BOOLEAN IsForestRoot( );
  131. inline VOID SetAuditEvents(ULONG AuditEvents);
  132. inline BOOLEAN IsOurRealm(PUNICODE_STRING Realm);
  133. inline BOOLEAN IsOurRealm(PKERB_REALM Realm);
  134. inline LARGE_INTEGER KrbtgtPasswordLastSet();
  135. #if DBG
  136. void DebugShowState(void);
  137. HRESULT DebugSetState(DWORD, LARGE_INTEGER, LARGE_INTEGER );
  138. HRESULT DebugGetState(DWORD *, LARGE_INTEGER *, LARGE_INTEGER * );
  139. #endif
  140. };
  141. //
  142. // Inline functions
  143. //
  144. inline PUNICODE_STRING
  145. CSecurityData::KdcServiceName()
  146. {
  147. return( &_KDC_Name);
  148. };
  149. inline PUNICODE_STRING
  150. CSecurityData::KdcFullServiceName()
  151. {
  152. return( &_KDC_FullName);
  153. };
  154. inline PUNICODE_STRING
  155. CSecurityData::KdcFullServiceDnsName()
  156. {
  157. return( &_KDC_FullDnsName);
  158. };
  159. inline NTSTATUS
  160. CSecurityData::GetKdcForestRoot(PUNICODE_STRING Output)
  161. {
  162. NTSTATUS Status = STATUS_POLICY_OBJECT_NOT_FOUND;
  163. ReadLock();
  164. if (_ForestRoot.Buffer != NULL)
  165. {
  166. Status = KerbDuplicateString(
  167. Output,
  168. &_ForestRoot
  169. );
  170. }
  171. Release();
  172. return ( Status );
  173. };
  174. inline BOOLEAN
  175. CSecurityData::IsCrossForestEnabled()
  176. {
  177. return( _KDC_CrossForestEnabled);
  178. };
  179. inline BOOLEAN
  180. CSecurityData::IsForestRoot()
  181. {
  182. return( _KDC_IsForestRoot);
  183. };
  184. inline VOID
  185. CSecurityData::SetCrossForestEnabled(BOOLEAN NewState)
  186. {
  187. WriteLock();
  188. _KDC_CrossForestEnabled = NewState;
  189. Release();
  190. }
  191. inline PUNICODE_STRING
  192. CSecurityData::KdcFullServiceKdcName()
  193. {
  194. return( &_KDC_FullKdcName);
  195. };
  196. inline PUNICODE_STRING
  197. CSecurityData::KdcRealmName()
  198. {
  199. return( &_RealmName );
  200. }
  201. inline PUNICODE_STRING
  202. CSecurityData::KdcDnsRealmName()
  203. {
  204. return( &_DnsRealmName );
  205. }
  206. inline KERB_REALM
  207. CSecurityData::KdcKerbRealmName()
  208. {
  209. return( _KerbRealmName );
  210. }
  211. inline KERB_REALM
  212. CSecurityData::KdcKerbDnsRealmName()
  213. {
  214. return( _KerbDnsRealmName );
  215. }
  216. inline PKERB_INTERNAL_NAME
  217. CSecurityData::KdcInternalName()
  218. {
  219. return( _KrbtgtServiceName );
  220. }
  221. inline PKERB_INTERNAL_NAME
  222. CSecurityData::KpasswdInternalName()
  223. {
  224. return( _KpasswdServiceName );
  225. }
  226. inline BOOLEAN
  227. CSecurityData::IsOurRealm(
  228. IN PKERB_REALM Realm
  229. )
  230. {
  231. return(KerbCompareRealmNames(
  232. Realm,
  233. &_KerbDnsRealmName
  234. ) ||
  235. KerbCompareRealmNames(
  236. Realm,
  237. &_KerbRealmName));
  238. }
  239. inline BOOLEAN
  240. CSecurityData::IsOurRealm(
  241. IN PUNICODE_STRING Realm
  242. )
  243. {
  244. return(KerbCompareUnicodeRealmNames(
  245. Realm,
  246. &_DnsRealmName
  247. ) ||
  248. KerbCompareUnicodeRealmNames(
  249. Realm,
  250. &_RealmName
  251. ));
  252. }
  253. inline PUNICODE_STRING
  254. CSecurityData::MachineName()
  255. {
  256. return( &_MachineName);
  257. };
  258. inline PUNICODE_STRING
  259. CSecurityData::MachineUpn()
  260. {
  261. return( &_MachineUpn);
  262. };
  263. inline LARGE_INTEGER
  264. CSecurityData::KdcTgtTicketLifespan()
  265. {
  266. LARGE_INTEGER Temp;
  267. ReadLock();
  268. Temp = _KDC_TgtTicketLifespan;
  269. Release();
  270. return(Temp);
  271. };
  272. inline LARGE_INTEGER
  273. CSecurityData::KdcTgsTicketLifespan()
  274. {
  275. LARGE_INTEGER Temp;
  276. ReadLock();
  277. Temp = _KDC_TgsTicketLifespan;
  278. Release();
  279. return(Temp);
  280. };
  281. inline LARGE_INTEGER
  282. CSecurityData::KdcTicketRenewSpan()
  283. {
  284. LARGE_INTEGER Temp;
  285. ReadLock();
  286. Temp = _KDC_TicketRenewSpan;
  287. Release();
  288. return( Temp );
  289. };
  290. inline LARGE_INTEGER
  291. CSecurityData::KdcDomainPasswordReplSkew()
  292. {
  293. LARGE_INTEGER Temp;
  294. ReadLock();
  295. Temp = _KDC_DomainPasswordReplSkew;
  296. Release();
  297. return( Temp );
  298. };
  299. inline LARGE_INTEGER
  300. CSecurityData::KdcRestrictionLifetime()
  301. {
  302. LARGE_INTEGER Temp;
  303. ReadLock();
  304. Temp = _KDC_RestrictionLifetime;
  305. Release();
  306. return( Temp );
  307. };
  308. inline DWORD
  309. CSecurityData::KdcFlags()
  310. {
  311. ULONG Temp;
  312. ReadLock();
  313. Temp = _KDC_Flags;
  314. Release();
  315. return( Temp );
  316. };
  317. inline BOOLEAN
  318. CSecurityData::AuditKdcEvent(
  319. IN ULONG AuditEvent
  320. )
  321. {
  322. return( ( (_KDC_AuditEvents & AuditEvent) != 0) ? TRUE : FALSE);
  323. };
  324. inline VOID
  325. CSecurityData::SetAuditEvents(
  326. IN ULONG AuditEvents
  327. )
  328. {
  329. _KDC_AuditEvents = AuditEvents;
  330. };
  331. inline VOID
  332. CSecurityData::ReadLock()
  333. {
  334. RtlEnterCriticalSection(&_Monitor);
  335. }
  336. inline VOID
  337. CSecurityData::WriteLock()
  338. {
  339. RtlEnterCriticalSection(&_Monitor);
  340. }
  341. inline VOID
  342. CSecurityData::Release()
  343. {
  344. RtlLeaveCriticalSection(&_Monitor);
  345. }
  346. inline LARGE_INTEGER
  347. CSecurityData::KrbtgtPasswordLastSet()
  348. {
  349. LARGE_INTEGER Temp = {0};
  350. ReadLock();
  351. if (_KrbtgtTicketInfoValid)
  352. {
  353. Temp = _KrbtgtPasswordLastSet;
  354. }
  355. Release();
  356. return( Temp );
  357. }
  358. #endif // INC__SECDATA_HXX