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.

634 lines
15 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. scope.cxx
  5. Abstract:
  6. Routines implementing the Scope object
  7. Author:
  8. Cliff Van Dyke (cliffv) 11-Apr-2001
  9. --*/
  10. #include "pch.hxx"
  11. DWORD
  12. AzpScopeInit(
  13. IN PGENERIC_OBJECT ParentGenericObject,
  14. IN PGENERIC_OBJECT ChildGenericObject
  15. )
  16. /*++
  17. Routine Description:
  18. This routine is a worker routine for AzScopeCreate. It does any object specific
  19. initialization that needs to be done.
  20. On entry, AzGlResource must be locked exclusively.
  21. Arguments:
  22. ParentGenericObject - Specifies the parent object to add the child object onto.
  23. The reference count has been incremented on this object.
  24. ChildGenericObject - Specifies the newly allocated child object.
  25. The reference count has been incremented on this object.
  26. Return Value:
  27. NO_ERROR - The operation was successful
  28. ERROR_NOT_ENOUGH_MEMORY - not enough memory
  29. Other exception status codes
  30. --*/
  31. {
  32. DWORD WinStatus = NO_ERROR;
  33. PAZP_SCOPE Scope = (PAZP_SCOPE) ChildGenericObject;
  34. //
  35. // Initialization
  36. //
  37. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  38. //
  39. // Sanity check the parent
  40. //
  41. ASSERT( ParentGenericObject->ObjectType == OBJECT_TYPE_APPLICATION );
  42. UNREFERENCED_PARAMETER( ParentGenericObject );
  43. //
  44. // Initialize the lists of child objects
  45. // Let the generic object manager know all of the types of children we support
  46. //
  47. ChildGenericObject->ChildGenericObjectHead = &Scope->Tasks;
  48. // List of child Tasks
  49. ObInitGenericHead( &Scope->Tasks,
  50. OBJECT_TYPE_TASK,
  51. ChildGenericObject,
  52. &Scope->Groups );
  53. // List of child groups
  54. ObInitGenericHead( &Scope->Groups,
  55. OBJECT_TYPE_GROUP,
  56. ChildGenericObject,
  57. &Scope->Roles );
  58. // List of child roles
  59. ObInitGenericHead( &Scope->Roles,
  60. OBJECT_TYPE_ROLE,
  61. ChildGenericObject,
  62. &ChildGenericObject->AzpSids );
  63. // List of child AzpSids
  64. ObInitGenericHead( &ChildGenericObject->AzpSids,
  65. OBJECT_TYPE_SID,
  66. ChildGenericObject,
  67. NULL );
  68. //
  69. // If the parent application object's parent AzAuthorizationStore object supports delegation,
  70. // then the scope object supports the following options:
  71. // . AZPE_OPTIONS_SUPPORTS_DACL
  72. // . AZPE_OPTIONS_SUPPORTS_SACL
  73. //
  74. if ( CHECK_DELEGATION_SUPPORT( (PGENERIC_OBJECT) ParentGenericObject->AzStoreObject ) ==
  75. NO_ERROR ) {
  76. ChildGenericObject->IsAclSupported = TRUE;
  77. ChildGenericObject->IsSACLSupported = TRUE;
  78. }
  79. //
  80. // If the provider does not support Lazy load, set the AreChildrenLoaded to
  81. // TRUE. Else leave it as FALSE. This will be set to true during the call
  82. // to AzPersistUpdateChildrenCache
  83. //
  84. if ( !(ParentGenericObject->AzStoreObject)->ChildLazyLoadSupported ) {
  85. ChildGenericObject->AreChildrenLoaded = TRUE;
  86. } else {
  87. ChildGenericObject->AreChildrenLoaded = FALSE;
  88. }
  89. return WinStatus;
  90. }
  91. VOID
  92. AzpScopeFree(
  93. IN PGENERIC_OBJECT GenericObject
  94. )
  95. /*++
  96. Routine Description:
  97. This routine is a worker routine for Scope object free. It does any object specific
  98. cleanup that needs to be done.
  99. On entry, AzGlResource must be locked exclusively.
  100. Arguments:
  101. GenericObject - Specifies a pointer to the object to be deleted.
  102. Return Value:
  103. None
  104. --*/
  105. {
  106. // PAZP_SCOPE Scope = (PAZP_SCOPE) GenericObject;
  107. UNREFERENCED_PARAMETER( GenericObject );
  108. //
  109. // Initialization
  110. //
  111. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  112. //
  113. // Free any local strings
  114. //
  115. }
  116. DWORD
  117. WINAPI
  118. AzScopeCreate(
  119. IN AZ_HANDLE ApplicationHandle,
  120. IN LPCWSTR ScopeName,
  121. IN DWORD Reserved,
  122. OUT PAZ_HANDLE ScopeHandle
  123. )
  124. /*++
  125. Routine Description:
  126. This routine adds a scope into the scope of the specified application. It also sets
  127. Scope object specific optional characteristics using the parent Application object's
  128. parent AzAuthorizationStore object.
  129. Arguments:
  130. ApplicationHandle - Specifies a handle to the application.
  131. ScopeName - Specifies the name of the scope to add.
  132. Reserved - Reserved. Must by zero.
  133. ScopeHandle - Return a handle to the scope.
  134. The caller must close this handle by calling AzCloseHandle.
  135. Return Value:
  136. NO_ERROR - The operation was successful
  137. ERROR_ALREADY_EXISTS - An object by that name already exists
  138. --*/
  139. {
  140. //
  141. // Call the common routine to do most of the work
  142. //
  143. return ObCommonCreateObject(
  144. (PGENERIC_OBJECT) ApplicationHandle,
  145. OBJECT_TYPE_APPLICATION,
  146. &(((PAZP_APPLICATION)ApplicationHandle)->Scopes),
  147. OBJECT_TYPE_SCOPE,
  148. ScopeName,
  149. Reserved,
  150. (PGENERIC_OBJECT *) ScopeHandle );
  151. }
  152. DWORD
  153. WINAPI
  154. AzScopeOpen(
  155. IN AZ_HANDLE ApplicationHandle,
  156. IN LPCWSTR ScopeName,
  157. IN DWORD Reserved,
  158. OUT PAZ_HANDLE ScopeHandle
  159. )
  160. /*++
  161. Routine Description:
  162. This routine opens a scope into the scope of the specified application.
  163. Arguments:
  164. ApplicationHandle - Specifies a handle to the application.
  165. ScopeName - Specifies the name of the scope to open
  166. Reserved - Reserved. Must by zero.
  167. ScopeHandle - Return a handle to the scope.
  168. The caller must close this handle by calling AzCloseHandle.
  169. Return Value:
  170. NO_ERROR - The operation was successful
  171. ERROR_NOT_FOUND - There is no scope by that name
  172. --*/
  173. {
  174. DWORD WinStatus = 0;
  175. //
  176. // Call the common routine to do most of the work
  177. //
  178. WinStatus = ObCommonOpenObject(
  179. (PGENERIC_OBJECT) ApplicationHandle,
  180. OBJECT_TYPE_APPLICATION,
  181. &(((PAZP_APPLICATION)ApplicationHandle)->Scopes),
  182. OBJECT_TYPE_SCOPE,
  183. ScopeName,
  184. Reserved,
  185. (PGENERIC_OBJECT *) ScopeHandle );
  186. if ( WinStatus == NO_ERROR ) {
  187. //
  188. // Load the children if the Scope object has already been submitted to
  189. // the store
  190. //
  191. if ( !((PGENERIC_OBJECT) *ScopeHandle)->AreChildrenLoaded ) {
  192. //
  193. // Grab the global resource lock
  194. //
  195. AzpLockResourceExclusive( &AzGlResource );
  196. WinStatus = AzPersistUpdateChildrenCache(
  197. (PGENERIC_OBJECT) *ScopeHandle
  198. );
  199. AzpUnlockResource( &AzGlResource );
  200. if ( WinStatus != NO_ERROR ) {
  201. //
  202. // Derefence the scope handle and return nothing to the caller
  203. //
  204. AzCloseHandle( (PGENERIC_OBJECT)*ScopeHandle, 0 );
  205. *ScopeHandle = NULL;
  206. }
  207. }
  208. }
  209. return WinStatus;
  210. }
  211. DWORD
  212. WINAPI
  213. AzScopeEnum(
  214. IN AZ_HANDLE ApplicationHandle,
  215. IN DWORD Reserved,
  216. IN OUT PULONG EnumerationContext,
  217. OUT PAZ_HANDLE ScopeHandle
  218. )
  219. /*++
  220. Routine Description:
  221. Enumerates all of the scopes for the specified application.
  222. Arguments:
  223. ApplicationHandle - Specifies a handle to the application.
  224. Reserved - Reserved. Must by zero.
  225. EnumerationContext - Specifies a context indicating the next scope to return
  226. On input for the first call, should point to zero.
  227. On input for subsequent calls, should point to the value returned on the previous call.
  228. On output, returns a value to be passed on the next call.
  229. ScopeHandle - Returns a handle to the next scope object.
  230. The caller must close this handle by calling AzCloseHandle.
  231. Return Value:
  232. NO_ERROR - The operation was successful (a handle was returned)
  233. ERROR_NO_MORE_ITEMS - No more items were available for enumeration
  234. --*/
  235. {
  236. //
  237. // Call the common routine to do most of the work
  238. //
  239. return ObCommonEnumObjects(
  240. (PGENERIC_OBJECT) ApplicationHandle,
  241. OBJECT_TYPE_APPLICATION,
  242. &(((PAZP_APPLICATION)ApplicationHandle)->Scopes),
  243. EnumerationContext,
  244. Reserved,
  245. (PGENERIC_OBJECT *) ScopeHandle );
  246. }
  247. DWORD
  248. WINAPI
  249. AzScopeDelete(
  250. IN AZ_HANDLE ApplicationHandle,
  251. IN LPCWSTR ScopeName,
  252. IN DWORD Reserved
  253. )
  254. /*++
  255. Routine Description:
  256. This routine deletes a scope from the scope of the specified application.
  257. Also deletes any child objects of ScopeName.
  258. Arguments:
  259. ApplicationHandle - Specifies a handle to the application.
  260. ScopeName - Specifies the name of the scope to delete.
  261. Reserved - Reserved. Must by zero.
  262. Return Value:
  263. NO_ERROR - The operation was successful
  264. ERROR_NOT_FOUND - An object by that name cannot be found
  265. --*/
  266. {
  267. //
  268. // Call the common routine to do most of the work
  269. //
  270. return ObCommonDeleteObject(
  271. (PGENERIC_OBJECT) ApplicationHandle,
  272. OBJECT_TYPE_APPLICATION,
  273. &(((PAZP_APPLICATION)ApplicationHandle)->Scopes),
  274. OBJECT_TYPE_SCOPE,
  275. ScopeName,
  276. Reserved );
  277. }
  278. DWORD
  279. AzpScopeGetProperty(
  280. IN PGENERIC_OBJECT GenericObject,
  281. IN ULONG Flags,
  282. IN ULONG PropertyId,
  283. OUT PVOID *PropertyValue
  284. )
  285. /*++
  286. Routine Description:
  287. This routine is the Scope specific worker routine for AzGetProperty.
  288. It does any object specific property gets.
  289. On entry, AzGlResource must be locked shared.
  290. Arguments:
  291. GenericObject - Specifies a pointer to the object to be queried
  292. Flags - ignored
  293. PropertyId - Specifies which property to return.
  294. PropertyValue - Specifies a pointer to return the property in.
  295. The returned pointer must be freed using AzFreeMemory.
  296. The returned value and type depends in PropertyId.
  297. Return Value:
  298. Status of the operation
  299. --*/
  300. {
  301. DWORD WinStatus = NO_ERROR;
  302. UNREFERENCED_PARAMETER(Flags); //ignore
  303. *PropertyValue = NULL;
  304. //
  305. // Initialization
  306. //
  307. ASSERT( AzpIsLockedShared( &AzGlResource ) );
  308. //
  309. // Return any object specific attribute
  310. //
  311. switch ( PropertyId ) {
  312. //
  313. // if the scope can be deleted (already has bizrule defined)
  314. //
  315. case AZ_PROP_SCOPE_CAN_BE_DELEGATED:
  316. if ( AzpScopeCanBeDelegated(GenericObject, TRUE) == ERROR_SUCCESS ) {
  317. *PropertyValue = AzpGetUlongProperty( 1 );
  318. } else {
  319. *PropertyValue = AzpGetUlongProperty( 0 );
  320. }
  321. break;
  322. //
  323. // if bizrule attributes under the scope can be created/modified
  324. //
  325. case AZ_PROP_SCOPE_BIZRULES_WRITABLE:
  326. if ( GenericObject->IsWritable &&
  327. GenericObject->PolicyAdmins.GenericObjects.UsedCount == 0 ) {
  328. //
  329. // scope has not been delegated and is writable.
  330. // for XML store that doesn't support delegation, PolicyAdmins should be empty
  331. //
  332. *PropertyValue = AzpGetUlongProperty( 1);
  333. } else {
  334. //
  335. // scope is not writable, or already been delegated
  336. //
  337. *PropertyValue = AzpGetUlongProperty(0);
  338. }
  339. break;
  340. default:
  341. AzPrint(( AZD_INVPARM, "AzScopeGetProperty: invalid prop id %ld\n", PropertyId ));
  342. WinStatus = ERROR_INVALID_PARAMETER;
  343. }
  344. return WinStatus;
  345. }
  346. DWORD
  347. AzpScopeCanBeDelegated(
  348. IN PGENERIC_OBJECT GenericObject,
  349. IN BOOL bLockedShared
  350. )
  351. /*
  352. Routine Description:
  353. This routine determines if the scope passed in can be delegated. The logic here
  354. is to check if there is any task object under the scope that has bizrules defined.
  355. If there is task with bizrule, the scope cannot be delegated; otherwise, it can.
  356. Note that the scope may not be loaded in cache yet (with the lazy bit set), in which
  357. case, this routine will load the scope first then perform the check.
  358. Arguments
  359. GenericObject - pointer to the scope object
  360. bLockedShared - TRUE if the global resource is shared
  361. Return
  362. ERROR_SUCCESS if the scope can be delegated
  363. ERROR_NOT_SUPPORTED if the scope cannot be delegated
  364. other error if cannot determine
  365. */
  366. {
  367. DWORD WinStatus = NO_ERROR;
  368. //
  369. // check input
  370. //
  371. if ( GenericObject == NULL ||
  372. GenericObject->ObjectType != OBJECT_TYPE_SCOPE ) {
  373. WinStatus = ERROR_INVALID_PARAMETER;
  374. goto Cleanup;
  375. }
  376. if ( GenericObject->PolicyAdmins.GenericObjects.UsedCount != 0 ) {
  377. //
  378. // this scope is already delegated
  379. //
  380. WinStatus = ERROR_SUCCESS;
  381. goto Cleanup;
  382. }
  383. PAZP_SCOPE Scope = (PAZP_SCOPE)GenericObject;
  384. //
  385. // check if we need to load the scope first
  386. //
  387. if ( !(GenericObject->AreChildrenLoaded) ) {
  388. if ( bLockedShared ) {
  389. //
  390. // Grab the resource exclusively
  391. //
  392. AzpLockResourceSharedToExclusive( &AzGlResource );
  393. }
  394. WinStatus = AzPersistUpdateChildrenCache(
  395. GenericObject
  396. );
  397. if ( bLockedShared ) {
  398. AzpLockResourceExclusiveToShared( &AzGlResource );
  399. }
  400. if ( WinStatus != NO_ERROR ) {
  401. goto Cleanup;
  402. }
  403. }
  404. PLIST_ENTRY ListEntry;
  405. BOOL BizRuleTaskFound = FALSE;
  406. for ( ListEntry = Scope->Tasks.Head.Flink ;
  407. ListEntry != &(Scope->Tasks.Head) ;
  408. ListEntry = ListEntry->Flink ) {
  409. PGENERIC_OBJECT MyGO;
  410. //
  411. // Grab a pointer to the next task to process
  412. //
  413. MyGO = CONTAINING_RECORD( ListEntry,
  414. GENERIC_OBJECT,
  415. Next );
  416. ASSERT( MyGO->ObjectType == OBJECT_TYPE_TASK );
  417. //
  418. // check if there is bizrule defined in this task
  419. //
  420. PAZP_TASK Task = (PAZP_TASK)MyGO;
  421. if ( Task->BizRule.String != NULL ||
  422. Task->BizRuleLanguage.String != NULL ||
  423. Task->BizRuleImportedPath.String != NULL ) {
  424. BizRuleTaskFound = TRUE;
  425. break;
  426. }
  427. }
  428. if ( BizRuleTaskFound ) {
  429. //
  430. // there are bizrule defined.
  431. //
  432. WinStatus = ERROR_NOT_SUPPORTED;
  433. }
  434. Cleanup:
  435. return WinStatus;
  436. }