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.

739 lines
18 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. role.cxx
  5. Abstract:
  6. Routines implementing the Role object
  7. Author:
  8. Cliff Van Dyke (cliffv) 11-Apr-2001
  9. --*/
  10. #include "pch.hxx"
  11. DWORD
  12. AzpRoleInit(
  13. IN PGENERIC_OBJECT ParentGenericObject,
  14. IN PGENERIC_OBJECT ChildGenericObject
  15. )
  16. /*++
  17. Routine Description:
  18. This routine is a worker routine for AzRoleCreate. 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. PAZP_ROLE Role = (PAZP_ROLE) ChildGenericObject;
  33. PAZP_AZSTORE AzAuthorizationStore = NULL;
  34. PAZP_APPLICATION Application = NULL;
  35. PAZP_SCOPE Scope = NULL;
  36. PGENERIC_OBJECT_HEAD ParentSids = NULL;
  37. //
  38. // Initialization
  39. //
  40. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  41. //
  42. // Behave differently depending on the object type of the parent object
  43. //
  44. // A role references SID objects that are siblings of itself.
  45. // That way, the back links on the SID object references just the roles
  46. // that are siblings of the SID object.
  47. //
  48. if ( ParentGenericObject->ObjectType == OBJECT_TYPE_APPLICATION ) {
  49. AzAuthorizationStore = ParentGenericObject->AzStoreObject;
  50. Application = (PAZP_APPLICATION) ParentGenericObject;
  51. } else if ( ParentGenericObject->ObjectType == OBJECT_TYPE_SCOPE ) {
  52. AzAuthorizationStore = ParentGenericObject->AzStoreObject;
  53. Application = (PAZP_APPLICATION) ParentOfChild( ParentGenericObject );
  54. Scope = (PAZP_SCOPE) ParentGenericObject;
  55. } else {
  56. ASSERT( FALSE );
  57. }
  58. ParentSids = &ParentGenericObject->AzpSids;
  59. //
  60. // Roles reference groups, operations, and tasks.
  61. // These other groups can be siblings of this group or siblings of our parents.
  62. //
  63. // Let the generic object manager know all of the lists we support
  64. //
  65. ChildGenericObject->GenericObjectLists = &Role->AppMembers,
  66. // List of Groups
  67. ObInitObjectList( &Role->AppMembers,
  68. &Role->Operations,
  69. FALSE, // Forward link
  70. 0, // No link pair id
  71. AZ_DIRTY_ROLE_APP_MEMBERS,
  72. &AzAuthorizationStore->Groups,
  73. &Application->Groups,
  74. Scope == NULL ? NULL : &Scope->Groups );
  75. // List of Operations
  76. ObInitObjectList( &Role->Operations,
  77. &Role->Tasks,
  78. FALSE, // Forward link
  79. 0, // No link pair id
  80. AZ_DIRTY_ROLE_OPERATIONS,
  81. &Application->Operations,
  82. NULL,
  83. NULL );
  84. // List of Tasks
  85. ObInitObjectList( &Role->Tasks,
  86. &Role->SidMembers,
  87. FALSE, // Forward link
  88. 0, // No link pair id
  89. AZ_DIRTY_ROLE_TASKS,
  90. &Application->Tasks,
  91. Scope == NULL ? NULL : &Scope->Tasks,
  92. NULL );
  93. // Role reference SID objects
  94. ObInitObjectList( &Role->SidMembers,
  95. NULL,
  96. FALSE, // Forward link
  97. 0, // No link pair id
  98. AZ_DIRTY_ROLE_MEMBERS,
  99. ParentSids,
  100. NULL,
  101. NULL );
  102. return NO_ERROR;
  103. }
  104. VOID
  105. AzpRoleFree(
  106. IN PGENERIC_OBJECT GenericObject
  107. )
  108. /*++
  109. Routine Description:
  110. This routine is a worker routine for Role object free. It does any object specific
  111. cleanup that needs to be done.
  112. On entry, AzGlResource must be locked exclusively.
  113. Arguments:
  114. GenericObject - Specifies a pointer to the object to be deleted.
  115. Return Value:
  116. None
  117. --*/
  118. {
  119. // PAZP_ROLE Role = (PAZP_ROLE) GenericObject;
  120. UNREFERENCED_PARAMETER( GenericObject );
  121. //
  122. // Initialization
  123. //
  124. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  125. //
  126. // Free any local strings
  127. //
  128. }
  129. DWORD
  130. AzpRoleNameConflict(
  131. IN PGENERIC_OBJECT ParentGenericObject,
  132. IN PAZP_STRING ChildObjectNameString
  133. )
  134. /*++
  135. Routine Description:
  136. This routine is a worker routine to determine if the specified ChildObjectNameString
  137. conflicts with the names of other objects that share a namespace with Roles
  138. On entry, AzGlResource must be locked exclusively.
  139. Arguments:
  140. ParentGenericObject - Specifies the parent object to add the child object onto.
  141. The reference count has been incremented on this object.
  142. ChildObjectNameString - Specifies the name of the child object.
  143. Return Value:
  144. NO_ERROR - The operation was successful
  145. ERROR_ALREADY_EXISTS - An object by that name already exists
  146. --*/
  147. {
  148. PAZP_APPLICATION Application = NULL;
  149. ULONG WinStatus;
  150. PGENERIC_OBJECT ConflictGenericObject;
  151. //
  152. // Initialization
  153. //
  154. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  155. //
  156. // Behave differently depending on the object type of the parent object
  157. //
  158. //
  159. // A role that is a child of an application
  160. // cannot have the same name as any roles that are children of any of the child scopes.
  161. //
  162. if ( ParentGenericObject->ObjectType == OBJECT_TYPE_APPLICATION ) {
  163. Application = (PAZP_APPLICATION) ParentGenericObject;
  164. //
  165. // Check roles that are children of child scopes.
  166. //
  167. WinStatus = ObCheckNameConflict( &Application->Scopes,
  168. ChildObjectNameString,
  169. offsetof(_AZP_SCOPE, Roles),
  170. 0,
  171. 0 );
  172. //
  173. // A role that is a child of a scope,
  174. // cannot have the same name as roles that are children of the application.
  175. //
  176. } else if ( ParentGenericObject->ObjectType == OBJECT_TYPE_SCOPE ) {
  177. Application = (PAZP_APPLICATION) ParentOfChild( ParentGenericObject );
  178. //
  179. // Check roles that are children of the application.
  180. //
  181. WinStatus = ObReferenceObjectByName( &Application->Roles,
  182. ChildObjectNameString,
  183. 0, // No special flags
  184. &ConflictGenericObject );
  185. if ( WinStatus == NO_ERROR ) {
  186. ObDereferenceObject( ConflictGenericObject );
  187. return ERROR_ALREADY_EXISTS;
  188. }
  189. WinStatus = NO_ERROR;
  190. } else {
  191. WinStatus = ERROR_INTERNAL_ERROR;
  192. ASSERT( FALSE );
  193. }
  194. return WinStatus;
  195. }
  196. DWORD
  197. AzpRoleGetProperty(
  198. IN PGENERIC_OBJECT GenericObject,
  199. IN ULONG Flags,
  200. IN ULONG PropertyId,
  201. OUT PVOID *PropertyValue
  202. )
  203. /*++
  204. Routine Description:
  205. This routine is the Role specific worker routine for AzGetProperty.
  206. It does any object specific property gets.
  207. On entry, AzGlResource must be locked shared.
  208. Arguments:
  209. GenericObject - Specifies a pointer to the object to be queried
  210. Flags - Specifies internal flags
  211. AZP_FLAGS_BY_GUID - name lists should be returned as GUID lists
  212. PropertyId - Specifies which property to return.
  213. PropertyValue - Specifies a pointer to return the property in.
  214. The returned pointer must be freed using AzFreeMemory.
  215. The returned value and type depends in PropertyId. The valid values are:
  216. AZ_PROP_ROLE_APP_MEMBERS AZ_STRING_ARRAY - Application groups that are members of this role
  217. AZ_PROP_ROLE_MEMBERS AZ_SID_ARRAY - NT Sids that are members of this role
  218. AZ_PROP_ROLE_OPERATIONS AZ_STRING_ARRAY - Operations that can be performed by this role
  219. AZ_PROP_ROLE_TASKS AZ_STRING_ARRAY - Tasks that can be performed by this role
  220. Return Value:
  221. Status of the operation
  222. --*/
  223. {
  224. DWORD WinStatus = NO_ERROR;
  225. PAZP_ROLE Role = (PAZP_ROLE) GenericObject;
  226. //
  227. // Initialization
  228. //
  229. ASSERT( AzpIsLockedShared( &AzGlResource ) );
  230. //
  231. // Return any object specific attribute
  232. //
  233. //
  234. switch ( PropertyId ) {
  235. // Return the set of app members to the caller
  236. case AZ_PROP_ROLE_APP_MEMBERS:
  237. if ( Flags & AZP_FLAGS_BY_GUID )
  238. {
  239. *PropertyValue = ObGetPropertyItemGuids( &Role->AppMembers );
  240. }
  241. else
  242. {
  243. *PropertyValue = ObGetPropertyItems( &Role->AppMembers );
  244. }
  245. if ( *PropertyValue == NULL ) {
  246. WinStatus = ERROR_NOT_ENOUGH_MEMORY;
  247. }
  248. break;
  249. // Return the set of SID members to the caller
  250. case AZ_PROP_ROLE_MEMBERS:
  251. *PropertyValue = ObGetPropertyItems( &Role->SidMembers );
  252. if ( *PropertyValue == NULL ) {
  253. WinStatus = ERROR_NOT_ENOUGH_MEMORY;
  254. }
  255. break;
  256. // Return the set of operations to the caller
  257. case AZ_PROP_ROLE_OPERATIONS:
  258. if ( Flags & AZP_FLAGS_BY_GUID )
  259. {
  260. *PropertyValue = ObGetPropertyItemGuids( &Role->Operations );
  261. }
  262. else
  263. {
  264. *PropertyValue = ObGetPropertyItems( &Role->Operations );
  265. }
  266. if ( *PropertyValue == NULL ) {
  267. WinStatus = ERROR_NOT_ENOUGH_MEMORY;
  268. }
  269. break;
  270. // Return the set of tasks to the caller
  271. case AZ_PROP_ROLE_TASKS:
  272. if ( Flags & AZP_FLAGS_BY_GUID )
  273. {
  274. *PropertyValue = ObGetPropertyItemGuids( &Role->Tasks );
  275. }
  276. else
  277. {
  278. *PropertyValue = ObGetPropertyItems( &Role->Tasks );
  279. }
  280. if ( *PropertyValue == NULL ) {
  281. WinStatus = ERROR_NOT_ENOUGH_MEMORY;
  282. }
  283. break;
  284. default:
  285. AzPrint(( AZD_INVPARM, "AzpRoleGetProperty: invalid prop id %ld\n", PropertyId ));
  286. WinStatus = ERROR_INVALID_PARAMETER;
  287. break;
  288. }
  289. return WinStatus;
  290. }
  291. DWORD
  292. AzpRoleGetGenericChildHead(
  293. IN AZ_HANDLE ParentHandle,
  294. OUT PULONG ObjectType,
  295. OUT PGENERIC_OBJECT_HEAD *GenericChildHead
  296. )
  297. /*++
  298. Routine Description:
  299. This routine determines whether ParentHandle supports Role objects as
  300. children.
  301. Arguments:
  302. ParentHandle - Specifies a handle to the object that is the parent of the role.
  303. This may be an Application Handle or a Scope handle.
  304. ObjectType - Returns the object type of the ParentHandle.
  305. GenericChildHead - Returns a pointer to the head of the list of roles objects
  306. that are children of the object specified by ParentHandle. This in an unverified
  307. pointer. The pointer is only valid after ParentHandle has been validated.
  308. Return Value:
  309. Status of the operation.
  310. --*/
  311. {
  312. DWORD WinStatus;
  313. //
  314. // Determine the type of the parent handle
  315. //
  316. WinStatus = ObGetHandleType( (PGENERIC_OBJECT)ParentHandle,
  317. FALSE, // ignore deleted objects
  318. ObjectType );
  319. if ( WinStatus != NO_ERROR ) {
  320. return WinStatus;
  321. }
  322. //
  323. // Verify that the specified handle support children roles.
  324. //
  325. switch ( *ObjectType ) {
  326. case OBJECT_TYPE_APPLICATION:
  327. *GenericChildHead = &(((PAZP_APPLICATION)ParentHandle)->Roles);
  328. break;
  329. case OBJECT_TYPE_SCOPE:
  330. *GenericChildHead = &(((PAZP_SCOPE)ParentHandle)->Roles);
  331. break;
  332. default:
  333. return ERROR_INVALID_HANDLE;
  334. }
  335. return NO_ERROR;
  336. }
  337. DWORD
  338. WINAPI
  339. AzRoleCreate(
  340. IN AZ_HANDLE ParentHandle,
  341. IN LPCWSTR RoleName,
  342. IN DWORD Reserved,
  343. OUT PAZ_HANDLE RoleHandle
  344. )
  345. /*++
  346. Routine Description:
  347. This routine adds a role into the scope of the specified parent object.
  348. Arguments:
  349. ParentHandle - Specifies a handle to the object that is the parent of the role.
  350. This may be an Application Handle or a Scope handle.
  351. RoleName - Specifies the name of the role to add.
  352. Reserved - Reserved. Must by zero.
  353. RoleHandle - Return a handle to the role.
  354. The caller must close this handle by calling AzCloseHandle.
  355. Return Value:
  356. NO_ERROR - The operation was successful
  357. ERROR_ALREADY_EXISTS - An object by that name already exists
  358. --*/
  359. {
  360. DWORD WinStatus;
  361. DWORD ObjectType;
  362. PGENERIC_OBJECT_HEAD GenericChildHead;
  363. //
  364. // Determine that the parent handle supports roles as children
  365. //
  366. WinStatus = AzpRoleGetGenericChildHead( ParentHandle,
  367. &ObjectType,
  368. &GenericChildHead );
  369. if ( WinStatus != NO_ERROR ) {
  370. return WinStatus;
  371. }
  372. //
  373. // Call the common routine to do most of the work
  374. //
  375. return ObCommonCreateObject(
  376. (PGENERIC_OBJECT) ParentHandle,
  377. ObjectType,
  378. GenericChildHead,
  379. OBJECT_TYPE_ROLE,
  380. RoleName,
  381. Reserved,
  382. (PGENERIC_OBJECT *) RoleHandle );
  383. }
  384. DWORD
  385. WINAPI
  386. AzRoleOpen(
  387. IN AZ_HANDLE ParentHandle,
  388. IN LPCWSTR RoleName,
  389. IN DWORD Reserved,
  390. OUT PAZ_HANDLE RoleHandle
  391. )
  392. /*++
  393. Routine Description:
  394. This routine opens a role into the scope of the specified parent object.
  395. Arguments:
  396. ParentHandle - Specifies a handle to the object that is the parent of the role.
  397. This may be an Application Handle or a Scope handle.
  398. RoleName - Specifies the name of the role to open
  399. Reserved - Reserved. Must by zero.
  400. RoleHandle - Return a handle to the role.
  401. The caller must close this handle by calling AzCloseHandle.
  402. Return Value:
  403. NO_ERROR - The operation was successful
  404. ERROR_NOT_FOUND - There is no role by that name
  405. --*/
  406. {
  407. DWORD WinStatus;
  408. DWORD ObjectType;
  409. PGENERIC_OBJECT_HEAD GenericChildHead;
  410. //
  411. // Determine that the parent handle supports roles as children
  412. //
  413. WinStatus = AzpRoleGetGenericChildHead( ParentHandle,
  414. &ObjectType,
  415. &GenericChildHead );
  416. if ( WinStatus != NO_ERROR ) {
  417. return WinStatus;
  418. }
  419. //
  420. // Call the common routine to do most of the work
  421. //
  422. return ObCommonOpenObject(
  423. (PGENERIC_OBJECT) ParentHandle,
  424. ObjectType,
  425. GenericChildHead,
  426. OBJECT_TYPE_ROLE,
  427. RoleName,
  428. Reserved,
  429. (PGENERIC_OBJECT *) RoleHandle );
  430. }
  431. DWORD
  432. WINAPI
  433. AzRoleEnum(
  434. IN AZ_HANDLE ParentHandle,
  435. IN DWORD Reserved,
  436. IN OUT PULONG EnumerationContext,
  437. OUT PAZ_HANDLE RoleHandle
  438. )
  439. /*++
  440. Routine Description:
  441. Enumerates all of the roles for the specified parent object.
  442. Arguments:
  443. ParentHandle - Specifies a handle to the object that is the parent of the role.
  444. This may be an Application Handle or a Scope handle.
  445. Reserved - Reserved. Must by zero.
  446. EnumerationContext - Specifies a context indicating the next role to return
  447. On input for the first call, should point to zero.
  448. On input for subsequent calls, should point to the value returned on the previous call.
  449. On output, returns a value to be passed on the next call.
  450. RoleHandle - Returns a handle to the next role object.
  451. The caller must close this handle by calling AzCloseHandle.
  452. Return Value:
  453. NO_ERROR - The operation was successful (a handle was returned)
  454. ERROR_NO_MORE_ITEMS - No more items were available for enumeration
  455. --*/
  456. {
  457. DWORD WinStatus;
  458. DWORD ObjectType;
  459. PGENERIC_OBJECT_HEAD GenericChildHead;
  460. //
  461. // Determine that the parent handle supports roles as children
  462. //
  463. WinStatus = AzpRoleGetGenericChildHead( ParentHandle,
  464. &ObjectType,
  465. &GenericChildHead );
  466. if ( WinStatus != NO_ERROR ) {
  467. return WinStatus;
  468. }
  469. //
  470. // Call the common routine to do most of the work
  471. //
  472. return ObCommonEnumObjects(
  473. (PGENERIC_OBJECT) ParentHandle,
  474. ObjectType,
  475. GenericChildHead,
  476. EnumerationContext,
  477. Reserved,
  478. (PGENERIC_OBJECT *) RoleHandle );
  479. }
  480. DWORD
  481. WINAPI
  482. AzRoleDelete(
  483. IN AZ_HANDLE ParentHandle,
  484. IN LPCWSTR RoleName,
  485. IN DWORD Reserved
  486. )
  487. /*++
  488. Routine Description:
  489. This routine deletes a role from the scope of the specified parent object.
  490. Also deletes any child objects of RoleName.
  491. Arguments:
  492. ParentHandle - Specifies a handle to the object that is the parent of the role.
  493. This may be an Application Handle or a Scope handle.
  494. RoleName - Specifies the name of the role to delete.
  495. Reserved - Reserved. Must by zero.
  496. Return Value:
  497. NO_ERROR - The operation was successful
  498. ERROR_NOT_FOUND - An object by that name cannot be found
  499. --*/
  500. {
  501. DWORD WinStatus;
  502. DWORD ObjectType;
  503. PGENERIC_OBJECT_HEAD GenericChildHead;
  504. //
  505. // Determine that the parent handle supports roles as children
  506. //
  507. WinStatus = AzpRoleGetGenericChildHead( ParentHandle,
  508. &ObjectType,
  509. &GenericChildHead );
  510. if ( WinStatus != NO_ERROR ) {
  511. return WinStatus;
  512. }
  513. //
  514. // Call the common routine to do most of the work
  515. //
  516. return ObCommonDeleteObject(
  517. (PGENERIC_OBJECT) ParentHandle,
  518. ObjectType,
  519. GenericChildHead,
  520. OBJECT_TYPE_ROLE,
  521. RoleName,
  522. Reserved );
  523. }