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.

452 lines
9.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. lsads.h
  5. Abstract:
  6. Private macros/definitions/prototypes for implementing portions of the LSA store
  7. in the DS and in the registry, simultaneously
  8. Author:
  9. Mac McLain (MacM) Jan 17, 1997
  10. Environment:
  11. User Mode
  12. Revision History:
  13. --*/
  14. #ifndef __LSADS_H__
  15. #define __LSADS_H__
  16. #include <ntdsa.h>
  17. #include <dsysdbg.h>
  18. #include <safelock.h>
  19. #if DBG == 1
  20. #ifdef ASSERT
  21. #undef ASSERT
  22. #endif
  23. #define ASSERT DsysAssert
  24. #define DEB_UPGRADE 0x10
  25. #define DEB_POLICY 0x20
  26. #define DEB_REPL 0x40
  27. #define DEB_FIXUP 0x80
  28. #define DEB_NOTIFY 0x100
  29. #define DEB_DSNOTIFY 0x200
  30. #define DEB_FTRACE 0x400
  31. #define DEB_LOOKUP 0x800
  32. #define DEB_HANDLE 0x1000
  33. #define DEB_FTINFO 0x2000
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif // __cplusplus
  37. DECLARE_DEBUG2( LsaDs )
  38. #ifdef __cplusplus
  39. }
  40. #endif // __cplusplus
  41. #define LsapDsDebugOut( args ) LsaDsDebugPrint args
  42. #define LsapEnterFunc( x ) \
  43. LsaDsDebugPrint( DEB_FTRACE, "0x%lx: Entering %s\n", GetCurrentThreadId(), x );
  44. #define LsapExitFunc( x, y ) \
  45. LsaDsDebugPrint( DEB_FTRACE, "0x%lx: Leaving %s: 0x%lx\n", GetCurrentThreadId(), x, y );
  46. #define LsapDsDebugDumpGuid( level, tag, pg ) \
  47. pg == NULL ? LsapDsDebugOut(( level, "%s: (NULL)\n", tag)) : \
  48. LsapDsDebugOut((level, \
  49. "%s: %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n", \
  50. tag,(pg)->Data1,(pg)->Data2,(pg)->Data3,(pg)->Data4[0], \
  51. (pg)->Data4[1],(pg)->Data4[2],(pg)->Data4[3],(pg)->Data4[4], \
  52. (pg)->Data4[5],(pg)->Data4[6],(pg)->Data4[7]))
  53. #define LSAP_TRACK_LOCK
  54. #else
  55. #define LsapDsDebugOut(args)
  56. #define LsapDsDebugDumpGuid(level, tag, pguid)
  57. #define LsapEnterFunc( x )
  58. #define LsapExitFunc( x, y )
  59. #endif // DBG
  60. //
  61. // These function prototypes control how the Ds transactioning is done. In
  62. // the Ds case, the pointers are initialized to routines that actually do
  63. // transactioning. In the non-Ds case, they point to dummy rountines that
  64. // do nothing.
  65. //
  66. typedef NTSTATUS ( *pfDsOpenTransaction ) ( ULONG );
  67. typedef NTSTATUS ( *pfDsApplyTransaction ) ( ULONG );
  68. typedef NTSTATUS ( *pfDsAbortTransaction ) ( ULONG );
  69. //
  70. // Ds functions that behave differently for the Ds and non-Ds case exist
  71. // in this function table.
  72. //
  73. typedef struct _LSADS_DS_FUNC_TABLE {
  74. pfDsOpenTransaction pOpenTransaction;
  75. pfDsApplyTransaction pApplyTransaction;
  76. pfDsAbortTransaction pAbortTransaction;
  77. } LSADS_DS_FUNC_TABLE, *PLSADS_DS_FUNC_TABLE;
  78. typedef struct _LSADS_DS_SYSTEM_CONTAINER_ITEMS {
  79. BOOLEAN NamesInitialized;
  80. PDSNAME TrustedDomainObject;
  81. PDSNAME SecretObject;
  82. } LSADS_DS_SYSTEM_CONTAINER_ITEMS, *PLSADS_DS_SYSTEM_CONTAINER_ITEMS;
  83. //
  84. // Basic LsaDs information structure
  85. //
  86. typedef struct _LSADS_DS_STATE_INFO {
  87. PDSNAME DsRoot; // DSNAME of the root of the Ds
  88. PDSNAME DsPartitionsContainer; // DSNAME of the partitions container
  89. PDSNAME DsSystemContainer; // DSNAME of the system container
  90. PDSNAME DsConfigurationContainer; // DSNAME of the configuration container
  91. ULONG DsDomainHandle; // DS Handle of the domain
  92. LSADS_DS_FUNC_TABLE DsFuncTable; // Function table for Ds specific
  93. // functions
  94. LSADS_DS_SYSTEM_CONTAINER_ITEMS SystemContainerItems;
  95. PVOID SavedThreadState; // Results from THSave
  96. BOOLEAN DsTransactionSave;
  97. BOOLEAN DsTHStateSave;
  98. BOOLEAN DsOperationSave;
  99. BOOLEAN WriteLocal; // Can we write to the registry?
  100. BOOLEAN UseDs; // Is the Ds active?
  101. BOOLEAN FunctionTableInitialized; // Is the function table initialized
  102. BOOLEAN DsInitializedAndRunning; // Has the Ds started
  103. BOOLEAN Nt4UpgradeInProgress; // Is this the case of an upgrade from NT4
  104. } LSADS_DS_STATE_INFO, *PLSADS_DS_STATE_INFO;
  105. typedef struct _LSADS_PER_THREAD_INFO {
  106. BOOLEAN SavedTransactionValid;
  107. ULONG UseCount;
  108. ULONG DsThreadStateUseCount;
  109. ULONG DsTransUseCount;
  110. ULONG DsOperationCount;
  111. PVOID SavedThreadState;
  112. PVOID InitialThreadState;
  113. ULONG OldTrustDirection;
  114. ULONG OldTrustType;
  115. } LSADS_PER_THREAD_INFO, *PLSADS_PER_THREAD_INFO;
  116. #if DBG
  117. typedef struct _LSADS_THREAD_INFO_NODE {
  118. PLSADS_PER_THREAD_INFO ThreadInfo;
  119. ULONG ThreadId;
  120. } LSADS_THREAD_INFO_NODE, *PLSADS_THREAD_INFO_NODE;
  121. #define LSAP_THREAD_INFO_LIST_MAX 15
  122. extern LSADS_THREAD_INFO_NODE LsapDsThreadInfoList[ LSAP_THREAD_INFO_LIST_MAX ];
  123. extern SAFE_RESOURCE LsapDsThreadInfoListResource;
  124. #endif
  125. //
  126. // Extern definitions
  127. //
  128. extern LSADS_DS_STATE_INFO LsaDsStateInfo;
  129. #ifdef __cplusplus
  130. extern "C" {
  131. #endif // __cplusplus
  132. extern DWORD LsapDsThreadState;
  133. #ifdef __cplusplus
  134. }
  135. #endif // __cplusplus
  136. //
  137. // Implemented as a macro for performance reasons
  138. //
  139. // PLSADS_PER_THREAD_INFO
  140. // LsapQueryThreadInfo(
  141. // VOID
  142. // );
  143. #define LsapQueryThreadInfo( ) TlsGetValue( LsapDsThreadState )
  144. VOID
  145. LsapDsDebugInitialize(
  146. VOID
  147. );
  148. //
  149. // Registry specific functions
  150. //
  151. NTSTATUS
  152. LsapRegReadObjectSD(
  153. IN LSAPR_HANDLE ObjectHandle,
  154. OUT PSECURITY_DESCRIPTOR *ppSD
  155. );
  156. NTSTATUS
  157. LsapRegGetPhysicalObjectName(
  158. IN PLSAP_DB_OBJECT_INFORMATION ObjectInformation,
  159. IN PUNICODE_STRING LogicalNameU,
  160. OUT OPTIONAL PUNICODE_STRING PhysicalNameU
  161. );
  162. NTSTATUS
  163. LsapRegOpenObject(
  164. IN LSAP_DB_HANDLE ObjectHandle,
  165. IN ULONG OpenMode,
  166. OUT PVOID *pvKey
  167. );
  168. NTSTATUS
  169. LsapRegOpenTransaction(
  170. );
  171. NTSTATUS
  172. LsapRegApplyTransaction(
  173. );
  174. NTSTATUS
  175. LsapRegAbortTransaction(
  176. );
  177. NTSTATUS
  178. LsapRegCreateObject(
  179. IN PUNICODE_STRING ObjectPath,
  180. IN LSAP_DB_OBJECT_TYPE_ID ObjectType
  181. );
  182. NTSTATUS
  183. LsapRegDeleteObject(
  184. IN PUNICODE_STRING ObjectPath
  185. );
  186. NTSTATUS
  187. LsapRegWriteAttribute(
  188. IN PUNICODE_STRING AttributePath,
  189. IN PVOID pvAttribute,
  190. IN ULONG AttributeLength
  191. );
  192. NTSTATUS
  193. LsapRegDeleteAttribute(
  194. IN PUNICODE_STRING AttributePath,
  195. IN BOOLEAN DeleteSecurely,
  196. IN ULONG AttributeLength
  197. );
  198. NTSTATUS
  199. LsapRegReadAttribute(
  200. IN LSAPR_HANDLE ObjectHandle,
  201. IN PUNICODE_STRING AttributeName,
  202. IN OPTIONAL PVOID AttributeValue,
  203. IN OUT PULONG AttributeValueLength
  204. );
  205. //
  206. // Counterpart Ds functions
  207. //
  208. NTSTATUS
  209. LsapDsReadObjectSD(
  210. IN LSAPR_HANDLE ObjectHandle,
  211. OUT PSECURITY_DESCRIPTOR *ppSD
  212. );
  213. NTSTATUS
  214. LsapDsGetPhysicalObjectName(
  215. IN PLSAP_DB_OBJECT_INFORMATION ObjectInformation,
  216. IN BOOLEAN DefaultName,
  217. IN PUNICODE_STRING LogicalNameU,
  218. OUT OPTIONAL PUNICODE_STRING PhysicalNameU
  219. );
  220. NTSTATUS
  221. LsapDsOpenObject(
  222. IN LSAP_DB_HANDLE ObjectHandle,
  223. IN ULONG OpenMode,
  224. OUT PVOID *pvKey
  225. );
  226. NTSTATUS
  227. LsapDsVerifyObjectExistenceByDsName(
  228. IN PDSNAME DsName
  229. );
  230. NTSTATUS
  231. LsapDsOpenTransaction(
  232. IN ULONG Options
  233. );
  234. //
  235. // Assert that there is a DS transaction open
  236. //
  237. #define LsapAssertDsTransactionOpen() \
  238. { \
  239. PLSADS_PER_THREAD_INFO CurrentThreadInfo; \
  240. CurrentThreadInfo = LsapQueryThreadInfo(); \
  241. \
  242. ASSERT( CurrentThreadInfo != NULL ); \
  243. if ( CurrentThreadInfo != NULL ) { \
  244. ASSERT( CurrentThreadInfo->DsTransUseCount > 0 ); \
  245. } \
  246. }
  247. NTSTATUS
  248. LsapDsOpenTransactionDummy(
  249. IN ULONG Options
  250. );
  251. NTSTATUS
  252. LsapDsApplyTransaction(
  253. IN ULONG Options
  254. );
  255. NTSTATUS
  256. LsapDsApplyTransactionDummy(
  257. IN ULONG Options
  258. );
  259. NTSTATUS
  260. LsapDsAbortTransaction(
  261. IN ULONG Options
  262. );
  263. NTSTATUS
  264. LsapDsAbortTransactionDummy(
  265. IN ULONG Options
  266. );
  267. NTSTATUS
  268. LsapDsCreateObject(
  269. IN PUNICODE_STRING ObjectPath,
  270. IN ULONG Flags,
  271. IN LSAP_DB_OBJECT_TYPE_ID ObjectType
  272. );
  273. NTSTATUS
  274. LsapDsDeleteObject(
  275. IN PUNICODE_STRING ObjectPath
  276. );
  277. NTSTATUS
  278. LsapDsWriteAttributes(
  279. IN PUNICODE_STRING ObjectPath,
  280. IN PLSAP_DB_ATTRIBUTE Attributes,
  281. IN ULONG AttributeCount,
  282. IN ULONG Options
  283. );
  284. NTSTATUS
  285. LsapDsWriteAttributesByDsName(
  286. IN PDSNAME ObjectPath,
  287. IN PLSAP_DB_ATTRIBUTE Attributes,
  288. IN ULONG AttributeCount,
  289. IN ULONG Options
  290. );
  291. NTSTATUS
  292. LsapDsReadAttributes(
  293. IN PUNICODE_STRING ObjectPath,
  294. IN ULONG Options,
  295. IN OUT PLSAP_DB_ATTRIBUTE Attributes,
  296. IN ULONG AttributeCount
  297. );
  298. NTSTATUS
  299. LsapDsReadAttributesByDsName(
  300. IN PDSNAME ObjectPath,
  301. IN ULONG Options,
  302. IN OUT PLSAP_DB_ATTRIBUTE Attributes,
  303. IN ULONG AttributeCount
  304. );
  305. NTSTATUS
  306. LsapDsRenameObject(
  307. IN PDSNAME OldObject,
  308. IN PDSNAME NewParent,
  309. IN ULONG AttrType,
  310. IN PUNICODE_STRING NewObject
  311. );
  312. NTSTATUS
  313. LsapDsDeleteAttributes(
  314. IN PUNICODE_STRING ObjectPath,
  315. IN OUT PLSAP_DB_ATTRIBUTE Attributes,
  316. IN ULONG AttributeCount
  317. );
  318. //
  319. // Interesting or global functions
  320. //
  321. PVOID
  322. LsapDsAlloc(
  323. IN DWORD dwLen
  324. );
  325. VOID
  326. LsapDsFree(
  327. IN PVOID pvMemory
  328. );
  329. NTSTATUS
  330. LsapDsPostDsInstallSetup(
  331. VOID
  332. );
  333. NTSTATUS
  334. LsapDsInitializePromoteInterface(
  335. VOID
  336. );
  337. BOOLEAN
  338. LsapDsIsValidSid(
  339. IN PSID Sid,
  340. IN BOOLEAN DsSid
  341. );
  342. NTSTATUS
  343. LsapDsTruncateNameToFitCN(
  344. IN PUNICODE_STRING OriginalName,
  345. OUT PUNICODE_STRING TruncatedName
  346. );
  347. BOOLEAN
  348. LsapDsIsNtStatusResourceError(
  349. NTSTATUS NtStatus
  350. );
  351. //
  352. // Exported for the DsSetup functions
  353. //
  354. NTSTATUS
  355. LsapDsRemoveDuplicateTrustObjects(
  356. IN LSAPR_HANDLE PolicyHandle
  357. );
  358. #endif