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.

256 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. cache.hxx
  5. Abstract:
  6. cache
  7. Author:
  8. Larry Zhu (LZhu) December 1, 2001
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #ifndef CACHE_HXX
  14. #define CACHE_HXX
  15. //
  16. // CACHE_PASSWORDS - passwords are stored (in secret storage) as two encrypted
  17. // one way function (OWF) passwords concatenated together. They must be fixed
  18. // length
  19. //
  20. typedef struct _CACHE_PASSWORDS {
  21. USER_INTERNAL1_INFORMATION SecretPasswords;
  22. } CACHE_PASSWORDS, *PCACHE_PASSWORDS;
  23. //
  24. // LOGON_CACHE_ENTRY - this is what we store in the cache. We don't need to
  25. // cache all the fields from the NETLOGON_VALIDATION_SAM_INFO - just the ones
  26. // we can't easily invent.
  27. //
  28. // There is additional data following the end of the structure: There are
  29. // <GroupCount> GROUP_MEMBERSHIP structures, followed by a SID which is the
  30. // LogonDomainId. The rest of the data in the entry is the buffer areas for
  31. // the UNICODE_STRING fields
  32. //
  33. typedef struct _LOGON_CACHE_ENTRY {
  34. USHORT UserNameLength;
  35. USHORT DomainNameLength;
  36. USHORT EffectiveNameLength;
  37. USHORT FullNameLength;
  38. USHORT LogonScriptLength;
  39. USHORT ProfilePathLength;
  40. USHORT HomeDirectoryLength;
  41. USHORT HomeDirectoryDriveLength;
  42. ULONG UserId;
  43. ULONG PrimaryGroupId;
  44. ULONG GroupCount;
  45. USHORT LogonDomainNameLength;
  46. //
  47. // The following fields are present in NT1.0A release and later
  48. // systems.
  49. //
  50. USHORT LogonDomainIdLength; // was Unused1
  51. LARGE_INTEGER Time;
  52. ULONG Revision;
  53. ULONG SidCount; // was Unused2
  54. BOOLEAN Valid;
  55. //
  56. // The following fields are present for NT 3.51 since build 622
  57. //
  58. CHAR Unused[3];
  59. ULONG SidLength;
  60. //
  61. // The following fields have been present (but zero) since NT 3.51.
  62. // We started filling it in in NT 5.0
  63. //
  64. ULONG LogonPackage; // The RPC ID of the package doing the logon.
  65. USHORT DnsDomainNameLength;
  66. USHORT UpnLength;
  67. //
  68. // The following fields were added for NT5.0 build 2053.
  69. //
  70. //
  71. // define a 128bit random key for this cache entry. This is used
  72. // in conjunction with a per-machine LSA secret to derive an encryption
  73. // key used to encrypt CachePasswords & Opaque data.
  74. //
  75. CHAR RandomKey[ 16 ];
  76. CHAR MAC[ 16 ]; // encrypted data integrity check.
  77. //
  78. // store the CACHE_PASSWORDS with the cache entry, encrypted using
  79. // the RandomKey & per-machine LSA secret.
  80. // this improves performance and eliminates problems with storing data
  81. // in 2 locations.
  82. //
  83. // note: data from this point forward is encrypted and protected from
  84. // tampering via HMAC. This includes the data marshalled beyond the
  85. // structure.
  86. //
  87. CACHE_PASSWORDS CachePasswords;
  88. //
  89. // Length of opaque supplemental cache data.
  90. //
  91. ULONG SupplementalCacheDataLength;
  92. //
  93. // offset from LOGON_CACHE_ENTRY to SupplementalCacheData.
  94. //
  95. ULONG SupplementalCacheDataOffset;
  96. //
  97. // Used for special cache properties, e.g. MIT cached logon.
  98. //
  99. ULONG CacheFlags;
  100. //
  101. // LogonServer that satisfied the logon.
  102. //
  103. ULONG LogonServerLength; // was Spare2
  104. //
  105. // spare slots for future data, to potentially avoid revising the structure
  106. //
  107. ULONG Spare3;
  108. ULONG Spare4;
  109. ULONG Spare5;
  110. ULONG Spare6;
  111. } LOGON_CACHE_ENTRY, *PLOGON_CACHE_ENTRY;
  112. //
  113. // This data structure is a single cache table entry (CTE)
  114. // Each entry in the cache has a corresponding CTE.
  115. //
  116. typedef struct _NLP_CTE {
  117. //
  118. // CTEs are linked on either an invalid list (in any order)
  119. // or on a valid list (in ascending order of time).
  120. // This makes it easy to figure out which entry is to be
  121. // flushed when adding to the cache.
  122. //
  123. LIST_ENTRY Link;
  124. //
  125. // Time the cache entry was established.
  126. // This is used to determine which cache
  127. // entry is the oldest, and therefore will
  128. // be flushed from the cache first to make
  129. // room for new entries.
  130. //
  131. LARGE_INTEGER Time;
  132. //
  133. // This field contains the index of the CTE within the
  134. // CTE table. This index is used to generate the names
  135. // of the entrie's secret key and cache key in the registry.
  136. // This field is valid even if the entry is marked Inactive.
  137. //
  138. ULONG Index;
  139. //
  140. // Normally, we walk the active and inactive lists
  141. // to find entries. When growing or shrinking the
  142. // cache, however, it is nice to be able to walk the
  143. // table using indexes. In this case, it is nice to
  144. // have a local way of determining whether an entry
  145. // is on the active or inactive list. This field
  146. // provides that capability.
  147. //
  148. // TRUE ==> on active list
  149. // FALSE ==> not on active list
  150. //
  151. BOOLEAN Active;
  152. } NLP_CTE, *PNLP_CTE;
  153. #define NLP_DEFAULT_LOGON_CACHE_COUNT (10)
  154. #define NLP_MAX_LOGON_CACHE_COUNT (50)
  155. #define NLP_CACHE_REVISION_NT_1_0 (0x00010000) // NT 3.0
  156. #define NLP_CACHE_REVISION_NT_1_0B (0x00010002) // NT 3.5
  157. #define NLP_CACHE_REVISION_NT_4_SP4 (0x00010003) // NT 4.0 SP 4 to save passwords as salted.
  158. #define NLP_CACHE_REVISION_NT_5_0 (0x00010004) // NT 5.0 to support opaque cache data and single location data storage.
  159. #define NLP_CACHE_REVISION (NLP_CACHE_REVISION_NT_5_0)
  160. #define CACHE_NAME L"\\Registry\\Machine\\Security\\Cache"
  161. #define CACHE_NAME_SIZE (sizeof(CACHE_NAME) - sizeof(L""))
  162. #define CACHE_TITLE_INDEX 100 // ?
  163. #define NLP_CACHE_ENCRYPTION_KEY_LEN (64)
  164. NTSTATUS
  165. NlpReadCacheEntryByIndex(
  166. IN ULONG Index,
  167. OUT PLOGON_CACHE_ENTRY* ppCacheEntry,
  168. OUT PULONG pcbEntrySize
  169. );
  170. NTSTATUS
  171. NlpOpenCache(
  172. OUT HANDLE* phNlpCache
  173. );
  174. NTSTATUS
  175. NlpMakeCacheEntryName(
  176. IN ULONG EntryIndex,
  177. OUT UNICODE_STRING* pName
  178. );
  179. NTSTATUS
  180. EnumerateNlpCacheEntries(
  181. IN CHAR NlpCacheEncryptionKey[NLP_CACHE_ENCRYPTION_KEY_LEN],
  182. IN LIST_ENTRY* pNlpActiveCtes
  183. );
  184. NTSTATUS
  185. NlpDecryptCacheEntry(
  186. IN CHAR NlpCacheEncryptionKey[NLP_CACHE_ENCRYPTION_KEY_LEN],
  187. IN ULONG EntrySize,
  188. IN OUT PLOGON_CACHE_ENTRY pCacheEntry
  189. );
  190. #endif // #ifndef CACHE_HXX