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.

595 lines
17 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. dsp.h
  5. Abstract:
  6. Private macros/definitions/prototypes for implementing a portion of the LSA store
  7. in the DS
  8. Author:
  9. Mac McLain (MacM) Jan 17, 1997
  10. Environment:
  11. User Mode
  12. Revision History:
  13. --*/
  14. #ifndef __DSP_H__
  15. #define __DSP_H__
  16. #include <filtypes.h>
  17. #include <attids.h>
  18. #include <dsattrs.h>
  19. #ifndef PDSNAME
  20. typedef DSNAME *PDSNAME;
  21. #endif
  22. #ifndef PATTR
  23. typedef ATTR *PATTR;
  24. #endif
  25. #ifndef PGUID
  26. typedef GUID *PGUID;
  27. #endif
  28. #define TENMEG 10485760
  29. //
  30. // Retuns the string name embedded in a DSNAME structure
  31. //
  32. #define LsapDsNameFromDsName(pdsname) \
  33. ((pdsname) == NULL ? NULL : (pdsname)->StringName)
  34. //
  35. // Returns the length of the string name embedded in a DSNAME structure
  36. //
  37. #define LsapDsNameLenFromDsName(pdsname) \
  38. ((pdsname) == NULL ? 0 : (pdsname)->NameLen)
  39. //
  40. // Returns the length of a unicode string buffer without the trailing NULL
  41. //
  42. #define LsapDsGetUnicodeStringLenNoNull(punicode) \
  43. (((PWSTR)(punicode)->Buffer)[(punicode)->Length / sizeof(WCHAR) - 1] == UNICODE_NULL ? \
  44. (punicode)->Length - sizeof(WCHAR) : \
  45. (punicode)->Length)
  46. #define LsapDsGetSelfRelativeUnicodeStringLenNoNull(punicode) \
  47. (((PWSTR)((PBYTE)(punicode) + sizeof(UNICODE_STRING_SR)))[(punicode)->Length / sizeof(WCHAR) - 1] == UNICODE_NULL ? \
  48. (punicode)->Length - sizeof(WCHAR) : \
  49. (punicode)->Length)
  50. #define LsapDsIsWriteDs( objhandle ) \
  51. ((((LSAP_DB_HANDLE)(objhandle))->fWriteDs && \
  52. (((LSAP_DB_HANDLE)(objhandle))->ObjectTypeId == TrustedDomainObject || \
  53. ((LSAP_DB_HANDLE)(objhandle))->ObjectTypeId == SecretObject)) ? TRUE : FALSE )
  54. #define LsapDsSetHandleWriteDs( objhandle ) (((LSAP_DB_HANDLE)(objhandle))->fWriteDs = TRUE)
  55. #define LsapDsWriteDs ( LsaDsStateInfo.UseDs )
  56. #define LSAPDS_ALLOC_AND_COPY_STRING_TO_UNICODE_ON_SUCCESS( status, dest, src, len )\
  57. if ( NT_SUCCESS( status ) ) { \
  58. \
  59. (dest)->MaximumLength = (USHORT)(len) + sizeof(WCHAR); \
  60. (dest)->Buffer = LsapAllocateLsaHeap( (dest)->MaximumLength ); \
  61. \
  62. if ( (dest)->Buffer == NULL ) { \
  63. \
  64. (status) = STATUS_INSUFFICIENT_RESOURCES; \
  65. \
  66. } else { \
  67. \
  68. (dest)->Length = (dest)->MaximumLength - sizeof( WCHAR ); \
  69. RtlCopyMemory( (dest)->Buffer, (src), (dest)->Length ); \
  70. ((WCHAR*)((dest)->Buffer))[(len)/sizeof(WCHAR)] = L'\0'; \
  71. } \
  72. }
  73. #define LSAPDS_ALLOC_AND_COPY_UNICODE_STRING_ON_SUCCESS( status, _dest_, _src_ ) \
  74. if ( NT_SUCCESS( status ) ) { \
  75. \
  76. ( _dest_ )->MaximumLength = ( _src_ )->MaximumLength; \
  77. ( _dest_ )->Buffer = LsapAllocateLsaHeap( (_dest_ )->MaximumLength ); \
  78. \
  79. if ( ( _dest_ )->Buffer == NULL ) { \
  80. \
  81. (status) = STATUS_INSUFFICIENT_RESOURCES; \
  82. \
  83. } else { \
  84. \
  85. RtlZeroMemory(( _dest_ )->Buffer, ( _dest_ )->MaximumLength ); \
  86. ( _dest_ )->Length = ( _src_ )->Length; \
  87. RtlCopyMemory( ( _dest_ )->Buffer, ( _src_ )->Buffer, ( _dest_ )->Length ); \
  88. } \
  89. }
  90. #define LSAPDS_ALLOC_AND_COPY_SID_ON_SUCCESS( status, dest, sid ) \
  91. if ( NT_SUCCESS( status ) ) { \
  92. \
  93. (dest) = LsapAllocateLsaHeap( RtlLengthSid( sid ) ); \
  94. if ( (dest) == NULL ) { \
  95. \
  96. (status) = STATUS_INSUFFICIENT_RESOURCES; \
  97. \
  98. } else { \
  99. \
  100. RtlCopyMemory( (dest), (sid), RtlLengthSid( sid ) ); \
  101. } \
  102. }
  103. #define LSAPDS_COPY_GUID_ON_SUCCESS( status, dest, src ) \
  104. if ( NT_SUCCESS( status ) ) { RtlCopyMemory((dest), (src), sizeof( GUID ) ); }
  105. #define LsapDsReturnSuccessIfNoDs \
  106. if ( !LsapDsWriteDs ) { \
  107. \
  108. return( STATUS_SUCCESS ); \
  109. }
  110. BOOL
  111. SampExistsDsTransaction(
  112. void
  113. );
  114. //
  115. // Determines whether a bit is on or not
  116. //
  117. #define FLAG_ON(flags,bit) ((flags) & (bit))
  118. #define LsapDsLengthAppendRdnLength( dsname, length ) \
  119. DSNameSizeFromLen( ( LsapDsNameLenFromDsName( dsname ) + 5 + ( ( ( length ) / sizeof( WCHAR ) * 2 ) ) ) )
  120. #define LsapDsSetDsaFlags( flag ) \
  121. SampSetDsa( flag ); \
  122. #define LsapDsInitializeAttrBlock( attrblock, attrs, count ) \
  123. { (attrblock)->attrCount = (count); \
  124. (attrblock)->pAttr = (attrs); }
  125. #define LSAP_DS_PARTITIONS_CONTAINER L"Partitions"
  126. #define LSAP_DS_SYSTEM_CONTAINER L"System"
  127. #define LSAP_DS_TRUSTED_DOMAIN L"trustedDomain"
  128. #define LSAP_DS_SECRET L"secret"
  129. #define LSAP_DS_SITES_CONTAINER L"CN=Sites"
  130. #define LSAP_DS_SUBNET_CONTAINER L"CN=Subnets," LSAP_DS_SITES_CONTAINER
  131. #define LSAP_DS_PATH_SEP L','
  132. #define LSAP_DS_PATH_SEP_AS_STRING L","
  133. #define LSAP_DS_CONTAINER_PREFIX L"CN="
  134. #define LSAP_DS_SECRET_POSTFIX L" Secret"
  135. #define LSAP_DS_SECRET_POSTFIX_LEN ((sizeof(LSAP_DS_SECRET_POSTFIX)/sizeof(WCHAR))-1)
  136. #define LSAP_DS_TRUSTED_DOMAIN_SECRET_PREFIX L"G$$"
  137. #define LSAP_DS_TRUSTED_DOMAIN_SECRET_PREFIX_SIZE \
  138. (sizeof( LSAP_DS_TRUSTED_DOMAIN_SECRET_PREFIX ) - sizeof( WCHAR ) )
  139. #define LSAP_DS_TRUSTED_DOMAIN_SECRET_PREFIX_LENGTH \
  140. (LSAP_DS_TRUSTED_DOMAIN_SECRET_PREFIX_SIZE/sizeof(WCHAR))
  141. #define LSAP_DS_INIT_ATTR(attr, type, cnt, vals) \
  142. { (attr).attrTyp = (type); \
  143. (attr).AttrVal.valCount = (cnt); \
  144. (attr).AttrVal.pAVal = (vals); }
  145. //
  146. // General flags to be used for all operations
  147. //
  148. #define LSAPDS_OP_NO_LOCK 0x00000001
  149. #define LSAPDS_OP_NO_TRANS 0x00000002
  150. //
  151. // Flags to use for search
  152. //
  153. #define LSAPDS_SEARCH_ROOT 0x00008000
  154. #define LSAPDS_SEARCH_ALL_NCS 0x00010000
  155. #define LSAPDS_SEARCH_LEVEL 0x00020000
  156. #define LSAPDS_SEARCH_TREE 0x00040000
  157. #define LSAPDS_SEARCH_OR 0x00100000
  158. #define LSAPDS_SEARCH_FLAGS 0x00168000
  159. //
  160. // Flags to use for Write
  161. //
  162. #define LSAPDS_REMOVE_ATTRIBUTE AT_CHOICE_REMOVE_ATT
  163. #define LSAPDS_REPLACE_ATTRIBUTE AT_CHOICE_REPLACE_ATT
  164. #define LSAPDS_WRITE_TYPES 0x00000FFF
  165. #define LSAPDS_REPL_CHANGE_URGENTLY 0x00002000
  166. #define LSAPDS_USE_PERMISSIVE_WRITE 0x00001000
  167. //
  168. // Flags to use for Read
  169. //
  170. #define LSAPDS_READ_NO_LOCK LSAPDS_OP_NO_LOCK
  171. #define LSAPDS_READ_DELETED 0x00002000
  172. #define LSAPDS_READ_RETURN_NOT_FOUND 0x10000000
  173. //
  174. // Flags to use for Create
  175. //
  176. #define LSAPDS_CREATE_TRUSTED 0x00002000
  177. #define LSAPDS_CREATE_WITH_SD 0x00004000
  178. NTSTATUS
  179. LsapDsMapDsReturnToStatus (
  180. ULONG DsStatus
  181. );
  182. NTSTATUS
  183. LsapDsMapDsReturnToStatusEx (
  184. IN COMMRES *pComRes
  185. );
  186. VOID
  187. LsapDsInitializeStdCommArg (
  188. IN COMMARG *pCommArg,
  189. IN ULONG Flags
  190. );
  191. NTSTATUS
  192. LsapAllocAndInitializeDsNameFromUnicode(
  193. IN PLSA_UNICODE_STRING pObjectName,
  194. OUT PDSNAME *pDsName
  195. );
  196. NTSTATUS
  197. LsapDsSearchUnique(
  198. IN ULONG Flags,
  199. IN PDSNAME pContainer,
  200. IN PATTR pAttrsToMatch,
  201. IN ULONG cAttrs,
  202. OUT PDSNAME *ppFoundName
  203. );
  204. NTSTATUS
  205. LsapDsSearchNonUnique(
  206. IN ULONG Flags,
  207. IN PDSNAME pContainer,
  208. IN PATTR pAttrToMatch,
  209. IN ULONG Attrs,
  210. OUT PDSNAME **pppFoundNames,
  211. OUT PULONG pcNames
  212. );
  213. NTSTATUS
  214. LsapDsFindUnique(
  215. IN ULONG Flags,
  216. IN PDSNAME NCName OPTIONAL,
  217. IN LSAP_DB_OBJECT_TYPE_ID ObjectTypeId,
  218. IN ATTRVAL *Attribute,
  219. IN ATTRTYP AttId,
  220. OUT PDSNAME *FoundObject
  221. );
  222. NTSTATUS
  223. LsapDsCreateAndSetObject(
  224. IN PLSA_UNICODE_STRING pObjectName,
  225. IN ULONG Flags,
  226. IN ULONG cItems,
  227. IN ATTRTYP *pAttrTypeList,
  228. IN ATTRVAL *pAttrValList
  229. );
  230. NTSTATUS
  231. LsapDsCreateObjectDs(
  232. IN PDSNAME ObjectName,
  233. IN ULONG Flags,
  234. IN ATTRBLOCK *AttrBlock
  235. );
  236. NTSTATUS
  237. LsapDsRead (
  238. IN PUNICODE_STRING pObject,
  239. IN ULONG fFlags,
  240. IN ATTRBLOCK *pAttributesToRead,
  241. OUT ATTRBLOCK *pAttributeValues
  242. );
  243. NTSTATUS
  244. LsapDsReadByDsName (
  245. IN PDSNAME DsName,
  246. IN ULONG fFlags,
  247. IN ATTRBLOCK *pAttributesToRead,
  248. OUT ATTRBLOCK *pAttributeValues
  249. );
  250. NTSTATUS
  251. LsapDsRemove (
  252. IN PDSNAME pObject
  253. );
  254. NTSTATUS
  255. LsapDsWrite(
  256. IN PUNICODE_STRING pObject,
  257. IN ULONG Flags,
  258. IN ATTRBLOCK *Attributes
  259. );
  260. NTSTATUS
  261. LsapDsWriteByDsName(
  262. IN PDSNAME DsName,
  263. IN ULONG Flags,
  264. IN ATTRBLOCK *Attributes
  265. );
  266. NTSTATUS
  267. LsapDsLsaAttributeToDsAttribute(
  268. IN PLSAP_DB_ATTRIBUTE LsaAttribute,
  269. OUT PATTR Attr
  270. );
  271. NTSTATUS
  272. LsapDsDsAttributeToLsaAttribute(
  273. IN ATTRVAL *AttVal,
  274. OUT PLSAP_DB_ATTRIBUTE LsaAttribute
  275. );
  276. NTSTATUS
  277. LsapDsIsSecretDsTrustedDomain(
  278. IN PUNICODE_STRING SecretName,
  279. IN PLSAP_DB_OBJECT_INFORMATION ObjectInformation,
  280. IN ULONG Options,
  281. IN ACCESS_MASK DesiredAccess,
  282. OUT PLSAPR_HANDLE TDObjHandle,
  283. OUT BOOLEAN *IsTrustedDomainSecret
  284. );
  285. NTSTATUS
  286. LsapDsIsHandleDsObjectTypeHandle(
  287. IN LSAP_DB_HANDLE Handle,
  288. IN LSAP_DB_OBJECT_TYPE_ID ObjectType,
  289. OUT BOOLEAN *IsObjectHandle
  290. );
  291. #define LsapDsIsHandleDsHandle( handle ) \
  292. (LsaDsStateInfo.UseDs && ((LSAP_DB_HANDLE) (handle))->PhysicalNameDs.Length != 0 )
  293. #define LsapDsIsFunctionTableValid() LsaDsStateInfo.FunctionTableInitialized
  294. NTSTATUS
  295. LsapDsTrustedDomainSidToLogicalName(
  296. IN PSID Sid,
  297. OUT PUNICODE_STRING LogicalNameU
  298. );
  299. NTSTATUS
  300. LsapDsInitAllocAsNeededEx(
  301. IN ULONG Options,
  302. IN LSAP_DB_OBJECT_TYPE_ID ObjectTypeId,
  303. OUT PBOOLEAN Reset
  304. );
  305. VOID
  306. LsapDsDeleteAllocAsNeededEx(
  307. IN ULONG Options,
  308. IN LSAP_DB_OBJECT_TYPE_ID ObjectTypeId,
  309. IN BOOLEAN Reset
  310. );
  311. VOID
  312. LsapDsDeleteAllocAsNeededEx2(
  313. IN ULONG Options,
  314. IN LSAP_DB_OBJECT_TYPE_ID ObjectTypeId,
  315. IN BOOLEAN Reset,
  316. IN BOOLEAN RollbackTransaction
  317. );
  318. NTSTATUS
  319. LsapDsCauseTransactionToCommitOrAbort (
  320. IN BOOLEAN Commit
  321. );
  322. NTSTATUS
  323. LsapDsGetListOfSystemContainerItems(
  324. IN ULONG ClassId,
  325. OUT PULONG Items,
  326. OUT PDSNAME **DsNames
  327. );
  328. //
  329. // Enumeration flags defined in dbp.h
  330. //
  331. NTSTATUS
  332. LsapDsEnumerateTrustedDomainsEx(
  333. IN PLSA_ENUMERATION_HANDLE EnumerationContext,
  334. IN TRUSTED_INFORMATION_CLASS InformationClass,
  335. OUT PLSAPR_TRUSTED_DOMAIN_INFO *TrustedDomainInformation,
  336. IN ULONG PreferedMaximumLength,
  337. IN OUT PULONG CountReturned,
  338. IN ULONG EnumerationFlags
  339. );
  340. NTSTATUS
  341. LsapDsGetTrustedDomainInfoEx(
  342. IN PDSNAME ObjectPath,
  343. IN ULONG ReadOptions,
  344. IN TRUSTED_INFORMATION_CLASS InformationClass,
  345. OUT PLSAPR_TRUSTED_DOMAIN_INFO TrustedDomainInformation,
  346. OUT PULONG Size OPTIONAL
  347. );
  348. NTSTATUS
  349. LsapDsBuildAuthInfoAttribute(
  350. IN LSAPR_HANDLE Handle,
  351. IN PLSAPR_TRUST_DOMAIN_AUTH_INFO_HALF NewAuthInfo,
  352. IN PLSAPR_TRUST_DOMAIN_AUTH_INFO_HALF PreviousAuthInfo,
  353. OUT PBYTE *Buffer,
  354. OUT PULONG Len
  355. );
  356. NTSTATUS
  357. LsapDsBuildAuthInfoFromAttribute(
  358. IN LSAPR_HANDLE Handle,
  359. IN PBYTE Buffer,
  360. IN ULONG Len,
  361. OUT PLSAPR_TRUST_DOMAIN_AUTH_INFO_HALF NewAuthInfo
  362. );
  363. NTSTATUS
  364. LsapDecryptAuthDataWithSessionKey(
  365. IN PLSAP_CR_CIPHER_KEY SessionKey,
  366. IN PLSAPR_TRUSTED_DOMAIN_AUTH_INFORMATION_INTERNAL AuthInformationInternal,
  367. IN PTRUSTED_DOMAIN_AUTH_INFORMATION AuthInfo
  368. );
  369. VOID
  370. LsapDsFreeUnmarshaledAuthInfo(
  371. IN ULONG Items,
  372. IN PLSAPR_AUTH_INFORMATION AuthInfo
  373. );
  374. VOID
  375. LsapDsFreeUnmarshalAuthInfoHalf(
  376. IN PLSAPR_TRUST_DOMAIN_AUTH_INFO_HALF AuthInfo
  377. );
  378. NTSTATUS
  379. LsapDsGetSecretOnTrustedDomainObject(
  380. IN LSAP_DB_HANDLE TrustedDomainHandle,
  381. IN OPTIONAL PLSAP_CR_CIPHER_KEY SessionKey OPTIONAL,
  382. OUT PLSAP_CR_CIPHER_VALUE *CipherCurrent OPTIONAL,
  383. OUT PLSAP_CR_CIPHER_VALUE *CipherOld OPTIONAL,
  384. OUT PLARGE_INTEGER CurrentValueSetTime OPTIONAL,
  385. OUT PLARGE_INTEGER OldValueSetTime OPTIONAL
  386. );
  387. NTSTATUS
  388. LsapDsSetSecretOnTrustedDomainObject(
  389. IN LSAP_DB_HANDLE TrustedDomainHandle,
  390. IN ULONG AuthDataType,
  391. IN PLSAP_CR_CLEAR_VALUE ClearCurrent,
  392. IN PLSAP_CR_CLEAR_VALUE ClearOld,
  393. IN PLARGE_INTEGER CurrentValueSetTime
  394. );
  395. NTSTATUS
  396. LsapDsAuthDataOnTrustedDomainObject(
  397. IN LSAP_DB_HANDLE TrustedDomainHandle,
  398. IN BOOLEAN Incoming,
  399. IN ULONG AuthDataType,
  400. IN PLSAP_CR_CLEAR_VALUE ClearCurrent,
  401. IN PLSAP_CR_CLEAR_VALUE ClearOld,
  402. IN PLARGE_INTEGER CurrentValueSetTime
  403. );
  404. NTSTATUS
  405. LsapDsEnumerateTrustedDomainsAsSecrets(
  406. IN OUT PLSAP_DB_NAME_ENUMERATION_BUFFER DbEnumerationBuffer
  407. );
  408. NTSTATUS
  409. LsapDsEnumerateSecrets(
  410. IN OUT PLSAP_DB_NAME_ENUMERATION_BUFFER EnumerationBuffer
  411. );
  412. NTSTATUS
  413. LsapDbOpenObjectDs(
  414. IN PLSAP_DB_OBJECT_INFORMATION ObjectInformation,
  415. IN PDSNAME DsName,
  416. IN ACCESS_MASK DesiredAccess,
  417. IN ULONG Options,
  418. OUT PLSAPR_HANDLE ObjectHandle
  419. );
  420. NTSTATUS
  421. LsapSceNotify(
  422. IN SECURITY_DB_DELTA_TYPE DeltaType,
  423. IN SECURITY_DB_OBJECT_TYPE ObjectType,
  424. IN PSID ObjectSid OPTIONAL
  425. );
  426. NTSTATUS
  427. LsapNetNotifyDelta (
  428. IN SECURITY_DB_TYPE DbType,
  429. IN LARGE_INTEGER SerialNumber,
  430. IN SECURITY_DB_DELTA_TYPE DeltaType,
  431. IN SECURITY_DB_OBJECT_TYPE ObjectType,
  432. IN ULONG ObjectRid,
  433. IN PSID ObjectSid,
  434. IN PUNICODE_STRING ObjectName,
  435. IN DWORD ReplicateImmediately,
  436. IN PSAM_DELTA_DATA MemberId
  437. );
  438. NTSTATUS
  439. LsapDsCopyDsNameLsa(
  440. OUT PDSNAME *Dest,
  441. IN PDSNAME Source
  442. );
  443. NTSTATUS
  444. LsapDsDomainUpgradeRegistryToDs(
  445. IN BOOLEAN DeleteOldValues
  446. );
  447. NTSTATUS
  448. LsapDsSecretUpgradeRegistryToDs(
  449. IN BOOLEAN DeleteOldValues
  450. );
  451. NTSTATUS
  452. LsapDsDomainUpgradeInterdomainTrustAccountsToDs(
  453. VOID
  454. );
  455. NTSTATUS
  456. LsapDsCreateInterdomainTrustAccount(
  457. IN LSAPR_HANDLE TrustedDomainObject
  458. );
  459. NTSTATUS
  460. LsapDsDeleteInterdomainTrustAccount(
  461. IN LSAPR_HANDLE TrustedDomainObject
  462. );
  463. NTSTATUS
  464. LsapDsCreateInterdomainTrustAccountByDsName(
  465. IN PDSNAME TrustedDomainPath,
  466. IN PUNICODE_STRING FlatName
  467. );
  468. NTSTATUS
  469. LsapDsFixupTrustedDomainObjectOnRestart(
  470. VOID
  471. );
  472. VOID
  473. LsapDsContinueTransaction(
  474. VOID
  475. );
  476. NTSTATUS
  477. LsapBuildForestTrustInfoLists(
  478. IN LSAPR_HANDLE PolicyHandle,
  479. IN PLIST_ENTRY TrustList
  480. );
  481. VOID
  482. LsapDsForestFreeTrustBlobList(
  483. IN PLIST_ENTRY TrustList
  484. );
  485. NTSTATUS
  486. LsapDsTrustedDomainObjectNameForDomain(
  487. IN PUNICODE_STRING TrustedDomainName,
  488. IN BOOLEAN NameAsFlatName,
  489. OUT PDSNAME *DsObjectName
  490. );
  491. BOOLEAN
  492. LsapNullUuid(
  493. IN const UUID *pUuid
  494. );
  495. #endif