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.

753 lines
14 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. baseobj.hxx
  5. Abstract:
  6. Basic Object Class IIS MetaBase.
  7. Author:
  8. Michael W. Thomas 20-May-96
  9. Revision History:
  10. --*/
  11. #ifndef _baseobj_
  12. #define _baseobj_
  13. class CMDBaseObject;
  14. class CChildNodeHashTable;
  15. #define SIZE_FOR_ON_STACK_BUFFER (MAX_PATH)
  16. // CMDKeyBuffer Class
  17. //
  18. // Subclasses BUFFER, keeping a real length of the data rather than
  19. // the length of the allocated buffer.
  20. class CMDKeyBuffer : public BUFFER
  21. {
  22. public:
  23. CMDKeyBuffer()
  24. : BUFFER(),
  25. m_cbUsed(0)
  26. {}
  27. CMDKeyBuffer( BYTE * pbInit, UINT cbInit)
  28. : BUFFER(pbInit,cbInit),
  29. m_cbUsed(0)
  30. {}
  31. UINT QuerySize() const
  32. { return m_cbUsed; }
  33. BOOL Resize(UINT cbNewSize)
  34. {
  35. BOOL fRet;
  36. fRet = BUFFER::Resize(cbNewSize);
  37. if (fRet)
  38. m_cbUsed = cbNewSize;
  39. return fRet;
  40. }
  41. BOOL Resize(UINT cbNewSize, UINT cbSlop)
  42. {
  43. BOOL fRet;
  44. fRet = BUFFER::Resize(cbNewSize, cbSlop);
  45. if (fRet)
  46. m_cbUsed = cbNewSize;
  47. return fRet;
  48. }
  49. VOID FreeMemory(VOID)
  50. {
  51. BUFFER::FreeMemory();
  52. m_cbUsed = 0;
  53. }
  54. void SyncSize(void)
  55. {
  56. m_cbUsed = BUFFER::QuerySize();
  57. }
  58. private:
  59. UINT m_cbUsed; // Actual amount of buffer in-use.
  60. };
  61. typedef struct _BASEOBJECT_CONTAINER {
  62. CMDBaseObject *pboMetaObject;
  63. struct _BASEOBJECT_CONTAINER *NextPtr;
  64. } BASEOBJECT_CONTAINER, *PBASEOBJECT_CONTAINER;
  65. typedef struct _DATA_CONTAINER {
  66. CMDBaseData *pbdDataObject;
  67. struct _DATA_CONTAINER *NextPtr;
  68. } DATA_CONTAINER, *PDATA_CONTAINER;
  69. class CMDBaseObject
  70. {
  71. friend class CChildNodeHashTable;
  72. public:
  73. CMDBaseObject(
  74. IN LPSTR strName,
  75. IN LPSTR strTag = NULL
  76. );
  77. CMDBaseObject(
  78. IN LPWSTR strName,
  79. IN LPWSTR strTag = NULL
  80. );
  81. ~CMDBaseObject();
  82. //
  83. // Basic Data
  84. //
  85. LPTSTR
  86. #ifdef UNICODE
  87. GetName(BOOL bUnicode = TRUE)
  88. #else
  89. GetName(BOOL bUnicode = FALSE)
  90. #endif
  91. /*++
  92. Routine Description:
  93. Gets the name of an object.
  94. Arguments:
  95. Return Value:
  96. LPTSTR - The name of the object.
  97. --*/
  98. {
  99. return m_strMDName.QueryStr(bUnicode);
  100. }
  101. BOOL
  102. SetName(
  103. IN LPSTR strName,
  104. IN BOOL bUnicode = FALSE
  105. );
  106. BOOL
  107. SetName(
  108. IN LPWSTR strName
  109. );
  110. BOOL IsNameUnicode(void)
  111. {
  112. return m_strMDName.IsCurrentUnicode();
  113. }
  114. CMDKeyBuffer* GetKey(void)
  115. {
  116. return &m_bufKey;
  117. }
  118. DWORD GetDataSetNumber()
  119. /*++
  120. Routine Description:
  121. Gets the Number associated with this data set.
  122. Arguments:
  123. Return Value:
  124. DWORD - The data set number.
  125. --*/
  126. {
  127. return m_dwDataSetNumber;
  128. };
  129. DWORD GetDescendantDataSetNumber()
  130. /*++
  131. Routine Description:
  132. Gets the Number of the data set associated with nonexistent descendant objects.
  133. Arguments:
  134. Return Value:
  135. DWORD - The data set number.
  136. --*/
  137. {
  138. if (m_dwNumNonInheritableData > 0) {
  139. return m_dwDataSetNumber + 1;
  140. }
  141. else {
  142. return m_dwDataSetNumber;
  143. }
  144. };
  145. CMDBaseObject *
  146. GetParent()
  147. /*++
  148. Routine Description:
  149. Gets the parent of the object.
  150. Arguments:
  151. Return Value:
  152. LPTSTR - The parent of the object.
  153. --*/
  154. {
  155. return m_pboParent;
  156. };
  157. VOID
  158. SetParent(
  159. IN CMDBaseObject *pboParent
  160. )
  161. /*++
  162. Routine Description:
  163. Gets the parent of the object.
  164. Arguments:
  165. Return Value:
  166. LPTSTR - The parent of the object.
  167. --*/
  168. {
  169. m_pboParent = pboParent;
  170. };
  171. DWORD
  172. GetObjectLevel();
  173. HRESULT
  174. InsertChildObject(
  175. IN CMDBaseObject *pboChild
  176. );
  177. HRESULT
  178. RemoveChildObject(
  179. IN LPTSTR strName,
  180. IN BOOL bUnicode = FALSE
  181. );
  182. HRESULT
  183. RemoveChildObject(
  184. IN CMDBaseObject *pboChild
  185. );
  186. CMDBaseObject *
  187. GetChildObject(
  188. IN OUT LPSTR &strName,
  189. OUT HRESULT *phresReturn,
  190. IN BOOL bUnicode = FALSE
  191. );
  192. CMDBaseObject *
  193. EnumChildObject(
  194. IN DWORD dwEnumObjectIndex
  195. );
  196. PBASEOBJECT_CONTAINER
  197. NextChildObject(
  198. IN PBASEOBJECT_CONTAINER pbocCurrent
  199. );
  200. //
  201. // All Data
  202. //
  203. HRESULT
  204. InsertDataObject(
  205. IN CMDBaseData *pbdInsert
  206. );
  207. HRESULT
  208. SetDataObject(
  209. IN PMETADATA_RECORD pmdrMDData,
  210. IN BOOL bUnicode = FALSE);
  211. HRESULT
  212. SetDataObject(
  213. IN CMDBaseData *pbdNew
  214. );
  215. HRESULT
  216. RemoveDataObject(
  217. IN CMDBaseData *pbdRemove,
  218. IN BOOL bDelete = TRUE
  219. );
  220. CMDBaseData *
  221. RemoveDataObject(
  222. IN DWORD dwIdentifier,
  223. IN DWORD dwDataType,
  224. IN BOOL bDelete = TRUE
  225. );
  226. CMDBaseData *
  227. GetDataObject(
  228. IN DWORD dwIdentifier,
  229. IN DWORD dwAttributes,
  230. IN DWORD dwDataType,
  231. CMDBaseObject **ppboAssociated = NULL
  232. );
  233. CMDBaseData *
  234. GetInheritableDataObject(
  235. IN DWORD dwIdentifier,
  236. IN DWORD dwDataType,
  237. CMDBaseObject **ppboAssociated = NULL
  238. );
  239. CMDBaseData *
  240. EnumDataObject(
  241. IN DWORD dwEnumDataIndex,
  242. IN DWORD dwAttributes,
  243. IN DWORD dwUserType = ALL_METADATA,
  244. IN DWORD dwDataType = ALL_METADATA,
  245. CMDBaseObject **ppboAssociated = NULL
  246. );
  247. CMDBaseData *
  248. EnumInheritableDataObject(
  249. DWORD &dwEnumDataIndex,
  250. DWORD dwUserType,
  251. DWORD dwDataType,
  252. CMDBaseObject **ppboAssociated = NULL
  253. );
  254. CMDBaseData *
  255. EnumInheritableDataObject(
  256. IN OUT DWORD &dwEnumDataIndex,
  257. IN DWORD dwUserType,
  258. IN DWORD dwDataType,
  259. IN OUT PVOID *ppvMainDataBuf,
  260. IN OUT DWORD &dwNumBufferEntries,
  261. CMDBaseObject **ppboAssociated = NULL
  262. );
  263. DWORD
  264. GetAllDataObjects(
  265. OUT PVOID *ppvMainDataBuf,
  266. IN DWORD dwAttributes,
  267. IN DWORD dwUserType,
  268. IN DWORD dwDataType,
  269. IN BOOL bInheritableOnly,
  270. IN BOOL bNonSecureOnly
  271. );
  272. HRESULT
  273. GetDataRecursive(IN OUT BUFFER *pbufMainDataBuf,
  274. IN DWORD dwMDIdentifier,
  275. IN DWORD dwMDDataType,
  276. IN OUT DWORD &rdwNumMetaObjects);
  277. VOID
  278. SetLastChangeTime(PFILETIME pftLastChangeTime = NULL);
  279. PFILETIME
  280. GetLastChangeTime();
  281. DWORD GetReadCounter()
  282. /*++
  283. Routine Description:
  284. Gets the Read Counter.
  285. Arguments:
  286. Return Value:
  287. DWORD - The number of read handles open to this object.
  288. --*/
  289. {
  290. return m_dwReadCounter;
  291. };
  292. VOID IncrementReadCounter()
  293. /*++
  294. Routine Description:
  295. Increments the Read Counter.
  296. Arguments:
  297. Return Value:
  298. --*/
  299. {
  300. m_dwReadCounter++;
  301. };
  302. VOID DecrementReadCounter()
  303. /*++
  304. Routine Description:
  305. Decrements the Read Counter.
  306. Arguments:
  307. Return Value:
  308. --*/
  309. {
  310. MD_REQUIRE(m_dwReadCounter-- > 0);
  311. };
  312. DWORD GetReadPathCounter()
  313. /*++
  314. Routine Description:
  315. Gets the Read Path Counter.
  316. Arguments:
  317. Return Value:
  318. DWORD - The number of read handles open to descendants of this object.
  319. --*/
  320. {
  321. return m_dwReadPathCounter;
  322. };
  323. VOID IncrementReadPathCounter()
  324. /*++
  325. Routine Description:
  326. Increments the Read Path Counter.
  327. Arguments:
  328. Return Value:
  329. --*/
  330. {
  331. m_dwReadPathCounter++;
  332. };
  333. VOID DecrementReadPathCounter()
  334. /*++
  335. Routine Description:
  336. Decrements the Read Path Counter.
  337. Arguments:
  338. Return Value:
  339. --*/
  340. {
  341. MD_REQUIRE(m_dwReadPathCounter-- > 0);
  342. };
  343. DWORD GetWriteCounter()
  344. /*++
  345. Routine Description:
  346. Gets the Write Counter.
  347. Arguments:
  348. Return Value:
  349. DWORD - The number of write handles open to this object.
  350. --*/
  351. {
  352. return m_dwWriteCounter;
  353. };
  354. VOID IncrementWriteCounter()
  355. /*++
  356. Routine Description:
  357. Increments the Write Counter.
  358. Arguments:
  359. Return Value:
  360. --*/
  361. {
  362. m_dwWriteCounter++;
  363. };
  364. VOID DecrementWriteCounter()
  365. /*++
  366. Routine Description:
  367. Decrements the Write Counter.
  368. Arguments:
  369. Return Value:
  370. --*/
  371. {
  372. MD_REQUIRE(m_dwWriteCounter-- > 0);
  373. };
  374. DWORD GetWritePathCounter()
  375. /*++
  376. Routine Description:
  377. Gets the Write Path Counter.
  378. Arguments:
  379. Return Value:
  380. DWORD - The number of write handles open to descendants of this object.
  381. --*/
  382. {
  383. return m_dwWritePathCounter;
  384. };
  385. VOID IncrementWritePathCounter()
  386. /*++
  387. Routine Description:
  388. Increments the Write Path Counter.
  389. Arguments:
  390. Return Value:
  391. --*/
  392. {
  393. m_dwWritePathCounter++;
  394. };
  395. VOID DecrementWritePathCounter()
  396. /*++
  397. Routine Description:
  398. Decrements the Write Path Counter.
  399. Arguments:
  400. Return Value:
  401. --*/
  402. {
  403. MD_REQUIRE(m_dwWritePathCounter-- > 0);
  404. };
  405. BOOL
  406. IsValid()
  407. {
  408. return m_strMDName.IsValid();
  409. };
  410. HRESULT
  411. AddChildObjectToHash(
  412. IN CMDBaseObject *pboChild,
  413. IN BASEOBJECT_CONTAINER* pbocChild = NULL
  414. );
  415. VOID
  416. RemoveChildObjectFromHash(
  417. IN CMDBaseObject *pboChild
  418. );
  419. VOID
  420. CascadingDataCleanup();
  421. private:
  422. enum
  423. {
  424. cboCreateHashThreashold = 50, // Create hashtable when this many children
  425. cboDeleteHashThreashold = 25 // Delete hashtable when this many children
  426. };
  427. STRAU m_strMDName;
  428. CMDKeyBuffer m_bufKey; // Key for comparison and hashing
  429. CMDBaseObject* m_pboParent;
  430. PBASEOBJECT_CONTAINER m_pbocChildHead;
  431. PBASEOBJECT_CONTAINER m_pbocChildTail; // Ignored if head is NULL.
  432. DWORD m_cbo;
  433. CChildNodeHashTable* m_phtChildren; // NULL if no hash table.
  434. PDATA_CONTAINER m_pdcarrayDataHead[INVALID_END_METADATA];
  435. DWORD m_dwReadCounter;
  436. DWORD m_dwReadPathCounter;
  437. DWORD m_dwWriteCounter;
  438. DWORD m_dwWritePathCounter;
  439. DWORD m_dwDataSetNumber;
  440. DWORD_PTR m_dwNumNonInheritableData;
  441. FILETIME m_ftLastChangeTime;
  442. bool
  443. GenerateKey();
  444. static bool
  445. GenerateBufFromStr(
  446. IN const char * str,
  447. IN int cch,
  448. IN BOOL fUnicode,
  449. OUT CMDKeyBuffer* pbuf);
  450. static bool
  451. FCompareKeys(
  452. IN CMDKeyBuffer* pbuf1,
  453. IN CMDKeyBuffer* pbuf2)
  454. {
  455. UINT cb;
  456. return ((cb = pbuf1->QuerySize()) == pbuf2->QuerySize()) ?
  457. memcmp(pbuf1->QueryPtr(), pbuf2->QueryPtr(), cb) == 0 :
  458. FALSE;
  459. }
  460. CMDBaseData *
  461. GetDataObjectByType(
  462. IN DWORD dwIdentifier,
  463. IN DWORD dwDataType
  464. );
  465. CMDBaseData *
  466. EnumDataObjectByType(
  467. IN DWORD &dwEnumDataIndex,
  468. IN DWORD dwUserType,
  469. IN DWORD dwDataType
  470. );
  471. CMDBaseData *
  472. EnumInheritableDataObjectByType(
  473. IN DWORD &dwEnumDataIndex,
  474. IN DWORD dwUserType,
  475. IN DWORD dwDataType,
  476. IN OUT PVOID *ppvMainDataBuf,
  477. IN OUT DWORD &dwNumBufferEntries);
  478. VOID
  479. CopyDataObjectsToBufferByType(
  480. IN DWORD dwUserType,
  481. IN DWORD dwDataType,
  482. OUT PVOID *ppvMainDataBuf,
  483. IN OUT DWORD &dwNumBufferEntries,
  484. IN BOOL bInheritableOnly,
  485. IN BOOL bNonSecureOnly);
  486. VOID
  487. CopyDataObjectsToBuffer(
  488. IN DWORD dwUserType,
  489. IN DWORD dwDataType,
  490. OUT PVOID *ppvMainDataBuf,
  491. IN OUT DWORD &dwNumBufferEntries,
  492. IN BOOL bInheritableOnly,
  493. IN BOOL bNonSecureOnly);
  494. BOOL
  495. IsDataInBuffer(
  496. DWORD dwIdentifier,
  497. PVOID *ppvMainDataBuf);
  498. #if 0 // No longer used /SAB
  499. BOOL
  500. CompareDelimitedString(
  501. IN LPTSTR strNonDelimitedString,
  502. IN OUT LPTSTR &strDelimitedString,
  503. IN BOOL bUnicode = FALSE
  504. );
  505. #endif
  506. CMDBaseObject*
  507. FindChild(
  508. IN LPSTR szName,
  509. IN int cchName,
  510. IN BOOL fUnicode,
  511. OUT HRESULT* phresult,
  512. IN BOOL fUseHash = TRUE,
  513. OUT BASEOBJECT_CONTAINER** ppbocPrev = NULL
  514. );
  515. };
  516. class CChildNodeHashTable
  517. : public CTypedHashTable<CChildNodeHashTable, _BASEOBJECT_CONTAINER, CMDKeyBuffer *>
  518. {
  519. private:
  520. CChildNodeHashTable(const CChildNodeHashTable&);
  521. void operator =(const CChildNodeHashTable&);
  522. public:
  523. CChildNodeHashTable()
  524. : CTypedHashTable<CChildNodeHashTable, _BASEOBJECT_CONTAINER, CMDKeyBuffer *>(
  525. "MDBaseO",
  526. /* maxload */ (double) LK_DFLT_MAXLOAD,
  527. /* initsize */ LK_DFLT_INITSIZE,
  528. /* num_subtbls */ 1)
  529. {}
  530. static CMDKeyBuffer *
  531. ExtractKey(const _BASEOBJECT_CONTAINER* pboc)
  532. {
  533. return pboc->pboMetaObject->GetKey();
  534. }
  535. static DWORD
  536. CalcKeyHash(CMDKeyBuffer * pbuf)
  537. {
  538. return HashBlob(pbuf->QueryPtr(), pbuf->QuerySize());
  539. }
  540. static bool
  541. EqualKeys(CMDKeyBuffer * pbuf1, CMDKeyBuffer * pbuf2)
  542. {
  543. return CMDBaseObject::FCompareKeys(pbuf1, pbuf2);
  544. }
  545. static void
  546. AddRefRecord(_BASEOBJECT_CONTAINER*, int)
  547. {
  548. // Do nothing. Table is always locked externally.
  549. }
  550. };
  551. #endif //_baseobj_