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.

565 lines
14 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. genobj.h
  5. Abstract:
  6. Definitions for the generic object implementation.
  7. AZ roles has so many objects that need creation, enumeration, etc
  8. that it seems prudent to have a single body of code for doing those operations.
  9. Author:
  10. Cliff Van Dyke (cliffv) 11-Apr-2001
  11. --*/
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. //
  17. // Structure definitions
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. //
  21. // A generic object list head.
  22. //
  23. // This structure represent the head of a linked list of objects. The linked
  24. // list of objects are considered to be "children" of this structure.
  25. //
  26. typedef struct _GENERIC_OBJECT_HEAD {
  27. //
  28. // Head of the linked list of objects
  29. //
  30. LIST_ENTRY Head;
  31. //
  32. // Back pointer to the GenericObject containing this structure
  33. //
  34. struct _GENERIC_OBJECT *ParentGenericObject;
  35. //
  36. // Each of the list heads that are rooted on a single object are linked
  37. // together. That list is headed by GENERIC_OBJECT->ChildGenericObjectHead.
  38. // This field is a pointer to the next entry in the list.
  39. //
  40. struct _GENERIC_OBJECT_HEAD *SiblingGenericObjectHead;
  41. //
  42. // This is a circular list of all the GENERIC_OBJECT_HEAD structures of
  43. // objects that share a namespace. For instance, an AzOperation and AzTask object
  44. // may not have the same name.
  45. //
  46. LIST_ENTRY SharedNamespace;
  47. //
  48. // The next sequence number to give out.
  49. //
  50. ULONG NextSequenceNumber;
  51. //
  52. // Object type of objects in this list
  53. //
  54. ULONG ObjectType;
  55. //
  56. // The order of the defines below must match the tables at the top of genobj.cxx
  57. //
  58. #define OBJECT_TYPE_ROOT 0
  59. #define OBJECT_TYPE_ADMIN_MANAGER 1
  60. #define OBJECT_TYPE_APPLICATION 2
  61. #define OBJECT_TYPE_OPERATION 3
  62. #define OBJECT_TYPE_TASK 4
  63. #define OBJECT_TYPE_SCOPE 5
  64. #define OBJECT_TYPE_GROUP 6
  65. #define OBJECT_TYPE_ROLE 7
  66. #define OBJECT_TYPE_JUNCTION_POINT 8
  67. #define OBJECT_TYPE_SID 9
  68. #define OBJECT_TYPE_CLIENT_CONTEXT 10
  69. #define OBJECT_TYPE_MAXIMUM 11
  70. } GENERIC_OBJECT_HEAD, *PGENERIC_OBJECT_HEAD;
  71. //
  72. // A generic object
  73. //
  74. typedef struct _GENERIC_OBJECT {
  75. //
  76. // Link to the next instance of an object of this type for the same parent object
  77. //
  78. LIST_ENTRY Next;
  79. //
  80. // Back pointer to the head of the list this object is in
  81. //
  82. PGENERIC_OBJECT_HEAD ParentGenericObjectHead;
  83. //
  84. // Pointer to the list heads for children of this object
  85. // This is a static list of the various GENERIC_OBJECT_HEAD structures
  86. // that exist in the object type specific portion of this object.
  87. // The list allows the generic object code to have insight into the
  88. // children of this object.
  89. //
  90. PGENERIC_OBJECT_HEAD ChildGenericObjectHead;
  91. //
  92. // Pointer to the list heads of pointers to other objects
  93. // This is a static list of the various GENERIC_OBJECT_LIST structures
  94. // that exist in the object type specific portion of this object.
  95. // The list allows the generic object code to have insight into the
  96. // other types of objects pointed to by this object.
  97. //
  98. struct _GENERIC_OBJECT_LIST *GenericObjectLists;
  99. //
  100. // Pointer to the generic object at the root of all generic objects
  101. // (Pointer to an AdminManager object)
  102. //
  103. struct _AZP_ADMIN_MANAGER *AdminManagerObject;
  104. //
  105. // Name of the object
  106. //
  107. AZP_STRING ObjectName;
  108. //
  109. // Description of the object
  110. //
  111. AZP_STRING Description;
  112. //
  113. // GUID of the object
  114. // The Guid of the object is assigned by the persistence provider.
  115. // The GUID is needed to make the object rename safe.
  116. //
  117. GUID PersistenceGuid;
  118. //
  119. // Number of references to this instance of the object
  120. // These are references from within our code.
  121. //
  122. LONG ReferenceCount;
  123. //
  124. // Number of references to this instance of the object
  125. // These are references represented by handles passed back to our caller.
  126. //
  127. LONG HandleReferenceCount;
  128. //
  129. // Sequence number of this object.
  130. // The list specified in Next is maintained in SequenceNumber order.
  131. // New entries are added to the tail end.
  132. // Enumerations are returned in SequenceNumber order.
  133. // SequenceNumber is returned to the caller as the EnumerationContext.
  134. //
  135. // This mechanism allows insertions and deletions to be handled seemlessly.
  136. //
  137. ULONG SequenceNumber;
  138. //
  139. // Specific object type represented by this generic object
  140. //
  141. ULONG ObjectType;
  142. //
  143. // Flags describing attributes of the generic object
  144. //
  145. ULONG Flags;
  146. #define GENOBJ_FLAGS_DELETED 0x01 // Object has been deleted
  147. #define GENOBJ_FLAGS_DIRTY 0x02 // Object has been modified
  148. #define GENOBJ_FLAGS_REFRESH_ME 0x04 // Object needs to be refreshed from cache
  149. } GENERIC_OBJECT, *PGENERIC_OBJECT;
  150. //
  151. // Object List
  152. //
  153. // Some objects have lists of references to other objects. These lists are
  154. // not parent/child relationships. Rather they represent memberships, etc.
  155. //
  156. // This structure represents the head of such a list.
  157. //
  158. // Both the pointed-from and pointed-to object have a generic object list. The
  159. // "forward" link represents the list that is managed via external API. The
  160. // "backward" link is provided to allow fixup of references when an object is deleted.
  161. // The "backward" link is also provided for cases where internal routines need to
  162. // traverse the link relationship in the opposite direction of the external API.
  163. // By convention, GENERIC_OBJECT_LIST instances in the forward direction are named
  164. // simply by the name of the object to point to. For instance, an object list that points
  165. // to AZ_OPERATION objects might be called "Operations". By convention, GENERIC_OBJECT_LIST
  166. // instances in the backward direction are prefixed by the name "back". For instance,
  167. // "backTasks".
  168. //
  169. // Note, there really isn't any reason why we couldn't expose "AddPropertyItem" and
  170. // "RemovePropertyItem" APIs for the "back" lists. See the IsBackLink and LinkPairId
  171. // definition.
  172. //
  173. typedef struct _GENERIC_OBJECT_LIST {
  174. //
  175. // Each of the object lists that are rooted on a single object are linked
  176. // together. That list is headed by GENERIC_OBJECT->GenericObjectLists.
  177. // This field is a pointer to the next entry in the list.
  178. //
  179. struct _GENERIC_OBJECT_LIST *NextGenericObjectList;
  180. //
  181. // Since an object list is a list of other objects, we want to be able to
  182. // generically find the other objects. The array below is an array of pointers
  183. // to the head of the lists that contain the other objects.
  184. //
  185. //
  186. // Unused elements in this array are set to NULL.
  187. //
  188. // These pointers are always pointers to a field in a "parent" structure.
  189. // Therefore, reference counts aren't needed. Instead, the "child" structure
  190. // containing the pointer to the parent will be deleted before the parent structure.
  191. //
  192. #define GEN_OBJECT_HEAD_COUNT 3
  193. PGENERIC_OBJECT_HEAD GenericObjectHeads[GEN_OBJECT_HEAD_COUNT];
  194. //
  195. // List identifier.
  196. //
  197. // The code maintains the link and the backlink. To do that, the code needs to
  198. // find one the "other" generic object list from this one. That algorithm uses
  199. // the IsBackLink and LinkPairId field.
  200. //
  201. // One object list has IsBackLink set TRUE and the other set FALSE. This handles
  202. // the case where an object contain both a forward an backward object list. For
  203. // instance, the AZ_GROUP object contains the AppMembers and backAppMembers fields.
  204. // This field differentiates between the two.
  205. //
  206. // There are cases where an object has multiple links between the same object types.
  207. // For instance, the AZ_GROUP object has both AppMembers and AppNonMembers links.
  208. // In those cases, the LinkPairId is set to a unique value to identify the pair.
  209. // In most cases, the value is simply zero.
  210. //
  211. BOOL IsBackLink;
  212. ULONG LinkPairId;
  213. #define AZP_LINKPAIR_MEMBERS 1
  214. #define AZP_LINKPAIR_NON_MEMBERS 2
  215. #define AZP_LINKPAIR_SID_MEMBERS 3
  216. #define AZP_LINKPAIR_SID_NON_MEMBERS 4
  217. //
  218. // The array of pointers to the generic objects.
  219. //
  220. // Being in this list does not increment the ReferenceCount on the pointed-to
  221. // generic object.
  222. //
  223. AZP_PTR_ARRAY GenericObjects;
  224. } GENERIC_OBJECT_LIST, *PGENERIC_OBJECT_LIST;
  225. /////////////////////////////////////////////////////////////////////////////
  226. //
  227. // Macro definitions
  228. //
  229. /////////////////////////////////////////////////////////////////////////////
  230. //
  231. // Macro to determine if a GENERIC_OBJECT_LIST is a list of sids
  232. //
  233. #define AzpIsSidList( _gol ) \
  234. ((_gol)->GenericObjectHeads[0] != NULL && \
  235. (_gol)->GenericObjectHeads[0]->ObjectType == OBJECT_TYPE_SID )
  236. /////////////////////////////////////////////////////////////////////////////
  237. //
  238. // Procedure definitions
  239. //
  240. /////////////////////////////////////////////////////////////////////////////
  241. VOID
  242. ObInitGenericHead(
  243. IN PGENERIC_OBJECT_HEAD GenericObjectHead,
  244. IN ULONG ObjectType,
  245. IN PGENERIC_OBJECT ParentGenericObject,
  246. IN PGENERIC_OBJECT_HEAD SiblingGenericObjectHead OPTIONAL,
  247. IN PGENERIC_OBJECT_HEAD SharedNamespace OPTIONAL
  248. );
  249. PGENERIC_OBJECT
  250. ObAllocateGenericObject(
  251. IN ULONG ObjectType
  252. );
  253. VOID
  254. ObFreeGenericObject(
  255. IN PGENERIC_OBJECT GenericObject,
  256. IN BOOLEAN JustRefresh
  257. );
  258. VOID
  259. ObInsertGenericObject(
  260. IN PGENERIC_OBJECT_HEAD GenericObjectHead,
  261. IN PGENERIC_OBJECT GenericObject
  262. );
  263. VOID
  264. ObIncrHandleRefCount(
  265. IN PGENERIC_OBJECT GenericObject
  266. );
  267. VOID
  268. ObDecrHandleRefCount(
  269. IN PGENERIC_OBJECT GenericObject
  270. );
  271. DWORD
  272. ObGetHandleType(
  273. IN PGENERIC_OBJECT Handle,
  274. IN BOOL AllowDeletedObjects,
  275. OUT PULONG ObjectType
  276. );
  277. DWORD
  278. ObReferenceObjectByHandle(
  279. IN PGENERIC_OBJECT Handle,
  280. IN BOOL AllowDeletedObjects,
  281. IN BOOLEAN RefreshCache,
  282. IN ULONG ObjectType
  283. );
  284. VOID
  285. ObDereferenceObject(
  286. IN PGENERIC_OBJECT GenericObject
  287. );
  288. typedef DWORD
  289. (OBJECT_INIT_ROUTINE)(
  290. IN PGENERIC_OBJECT ParentGenericObject,
  291. IN PGENERIC_OBJECT ChildGenericObject
  292. );
  293. typedef VOID
  294. (OBJECT_FREE_ROUTINE)(
  295. IN PGENERIC_OBJECT GenericObject
  296. );
  297. typedef DWORD
  298. (OBJECT_GET_PROPERTY_ROUTINE)(
  299. IN PGENERIC_OBJECT GenericObject,
  300. IN ULONG PropertyId,
  301. OUT PVOID *PropertyValue
  302. );
  303. typedef DWORD
  304. (OBJECT_SET_PROPERTY_ROUTINE)(
  305. IN PGENERIC_OBJECT GenericObject,
  306. IN ULONG PropertyId,
  307. IN PVOID PropertyValue
  308. );
  309. typedef DWORD
  310. (OBJECT_ADD_PROPERTY_ITEM_ROUTINE)(
  311. IN PGENERIC_OBJECT GenericObject,
  312. IN PGENERIC_OBJECT_LIST GenericObjectList,
  313. IN PGENERIC_OBJECT LinkedToObject
  314. );
  315. DWORD
  316. ObCreateObject(
  317. IN PGENERIC_OBJECT ParentGenericObject,
  318. IN PGENERIC_OBJECT_HEAD GenericChildHead,
  319. IN ULONG ChildObjectType,
  320. IN PAZP_STRING ChildObjectNameString,
  321. OUT PGENERIC_OBJECT *RetChildGenericObject
  322. );
  323. DWORD
  324. ObCommonCreateObject(
  325. IN PGENERIC_OBJECT ParentGenericObject,
  326. IN ULONG ParentObjectType,
  327. IN PGENERIC_OBJECT_HEAD GenericChildHead,
  328. IN ULONG ChildObjectType,
  329. IN LPCWSTR ChildObjectName,
  330. IN DWORD Reserved,
  331. OUT PGENERIC_OBJECT *RetChildGenericObject
  332. );
  333. DWORD
  334. ObCommonOpenObject(
  335. IN PGENERIC_OBJECT ParentGenericObject,
  336. IN ULONG ParentObjectType,
  337. IN PGENERIC_OBJECT_HEAD GenericChildHead,
  338. IN ULONG ChildObjectType,
  339. IN LPCWSTR ChildObjectName,
  340. IN DWORD Reserved,
  341. OUT PGENERIC_OBJECT *RetChildGenericObject
  342. );
  343. DWORD
  344. ObEnumObjects(
  345. IN PGENERIC_OBJECT_HEAD GenericChildHead,
  346. IN BOOL EnumerateDeletedObjects,
  347. IN BOOL RefreshCache,
  348. IN OUT PULONG EnumerationContext,
  349. OUT PGENERIC_OBJECT *RetChildGenericObject
  350. );
  351. DWORD
  352. ObCommonEnumObjects(
  353. IN PGENERIC_OBJECT ParentGenericObject,
  354. IN ULONG ParentObjectType,
  355. IN PGENERIC_OBJECT_HEAD GenericChildHead,
  356. IN OUT PULONG EnumerationContext,
  357. IN DWORD Reserved,
  358. OUT PGENERIC_OBJECT *RetChildGenericObject
  359. );
  360. DWORD
  361. ObCommonGetProperty(
  362. IN PGENERIC_OBJECT GenericObject,
  363. IN ULONG ObjectType,
  364. IN ULONG PropertyId,
  365. IN DWORD Reserved,
  366. OUT PVOID *PropertyValue
  367. );
  368. DWORD
  369. ObCommonSetProperty(
  370. IN PGENERIC_OBJECT GenericObject,
  371. IN ULONG ObjectType,
  372. IN ULONG PropertyId,
  373. IN DWORD Reserved,
  374. IN PVOID PropertyValue
  375. );
  376. VOID
  377. ObMarkObjectDeleted(
  378. IN PGENERIC_OBJECT GenericObject
  379. );
  380. DWORD
  381. ObCommonDeleteObject(
  382. IN PGENERIC_OBJECT ParentGenericObject,
  383. IN ULONG ParentObjectType,
  384. IN PGENERIC_OBJECT_HEAD GenericChildHead,
  385. IN ULONG ChildObjectType,
  386. IN LPCWSTR ChildObjectName,
  387. IN DWORD Reserved
  388. );
  389. VOID
  390. ObInitObjectList(
  391. IN OUT PGENERIC_OBJECT_LIST GenericObjectList,
  392. IN PGENERIC_OBJECT_LIST NextGenericObjectList OPTIONAL,
  393. IN BOOL IsBackLink,
  394. IN ULONG LinkPairId,
  395. IN PGENERIC_OBJECT_HEAD GenericObjectHead0 OPTIONAL,
  396. IN PGENERIC_OBJECT_HEAD GenericObjectHead1 OPTIONAL,
  397. IN PGENERIC_OBJECT_HEAD GenericObjectHead2 OPTIONAL
  398. );
  399. DWORD
  400. ObAddPropertyItem(
  401. IN PGENERIC_OBJECT GenericObject,
  402. IN PGENERIC_OBJECT_LIST GenericObjectList,
  403. IN PAZP_STRING ObjectName
  404. );
  405. DWORD
  406. ObCommonAddPropertyItem(
  407. IN PGENERIC_OBJECT GenericObject,
  408. IN ULONG ObjectType,
  409. IN PGENERIC_OBJECT_LIST GenericObjectList,
  410. IN DWORD Reserved,
  411. IN LPWSTR ObjectName
  412. );
  413. DWORD
  414. ObLookupPropertyItem(
  415. IN PGENERIC_OBJECT_LIST GenericObjectList,
  416. IN AZP_STRING ObjectName,
  417. OUT PULONG InsertionPoint OPTIONAL
  418. );
  419. DWORD
  420. ObRemovePropertyItem(
  421. IN PGENERIC_OBJECT GenericObject,
  422. IN PGENERIC_OBJECT_LIST GenericObjectList,
  423. IN PAZP_STRING ObjectName
  424. );
  425. DWORD
  426. ObCommonRemovePropertyItem(
  427. IN PGENERIC_OBJECT GenericObject,
  428. IN ULONG ObjectType,
  429. IN PGENERIC_OBJECT_LIST GenericObjectList,
  430. IN DWORD Reserved,
  431. IN LPWSTR ObjectName
  432. );
  433. PAZ_STRING_ARRAY
  434. ObGetPropertyItems(
  435. IN PGENERIC_OBJECT_LIST GenericObjectList
  436. );
  437. VOID
  438. ObRemoveObjectListLinks(
  439. IN PGENERIC_OBJECT GenericObject,
  440. IN BOOLEAN BackwardLinksToo
  441. );
  442. VOID
  443. ObFreeObjectList(
  444. IN OUT PGENERIC_OBJECT_LIST GenericObjectList
  445. );
  446. #ifdef __cplusplus
  447. }
  448. #endif