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.

285 lines
8.5 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992
  5. //
  6. // File: chinst.cxx
  7. //
  8. // Contents: DocFile child instance management code
  9. //
  10. // History: 19-Nov-91 DrewB Created
  11. //
  12. //---------------------------------------------------------------
  13. #include <dfhead.cxx>
  14. #pragma hdrstop
  15. // Permissions checked in the less-restrictive rule
  16. #define TCANTSET DF_READ
  17. #define DCANTSET (DF_READ | DF_WRITE)
  18. #define CANTCLEAR (DF_DENYREAD | DF_DENYWRITE)
  19. //+--------------------------------------------------------------
  20. //
  21. // Method: CChildInstanceList::Add, private
  22. //
  23. // Synopsis: Registers an instance of a child
  24. //
  25. // Arguments: [prv] - Child
  26. //
  27. // History: 17-Oct-91 DrewB Created
  28. //
  29. //---------------------------------------------------------------
  30. #ifdef CODESEGMENTS
  31. #pragma code_seg(SEG_CChildInstanceList_Add)
  32. #endif
  33. void CChildInstanceList::Add(PRevertable *prv)
  34. {
  35. olDebugOut((DEB_ITRACE, "In CChildInstanceList::Add(%p)\n", prv));
  36. prv->_prvNext = _prvHead;
  37. _prvHead = P_TO_BP(CBasedRevertablePtr, prv);
  38. olDebugOut((DEB_ITRACE, "Out CChildInstanceList::Add\n"));
  39. }
  40. //+---------------------------------------------------------------------------
  41. //
  42. // Member: CChildInstanceList::FindByName, private
  43. //
  44. // Synopsis: Finds a child instance by name
  45. //
  46. // Arguments: [pdfn] - Name
  47. //
  48. // Returns: Pointer to instance or NULL
  49. //
  50. // History: 12-Nov-92 DrewB Created
  51. //
  52. //----------------------------------------------------------------------------
  53. #ifdef CODESEGMENTS
  54. #pragma code_seg(SEG_CChildInstanceList_FindByName)
  55. #endif
  56. PRevertable *CChildInstanceList::FindByName(CDfName const *pdfn)
  57. {
  58. PRevertable *prv;
  59. olDebugOut((DEB_ITRACE, "In CChildInstanceList::FindByName:%p(%ws)\n",
  60. this, pdfn->GetBuffer()));
  61. for (prv = BP_TO_P(PRevertable *, _prvHead);
  62. prv;
  63. prv = BP_TO_P(PRevertable *, prv->_prvNext))
  64. {
  65. if (prv->_dfn.IsEqual(pdfn))
  66. return prv;
  67. }
  68. olDebugOut((DEB_ITRACE, "Out CChildInstanceList::FindByName\n"));
  69. return NULL;
  70. }
  71. //+---------------------------------------------------------------------------
  72. //
  73. // Member: CChildInstanceList::FlushBufferedData, private
  74. //
  75. // Synopsis: Calls each child, instructing it to flush property data.
  76. //
  77. // Arguments: [recursionlevel] -- current level in hierachy below initial
  78. // entry point.
  79. //
  80. // Returns: SCODE
  81. //
  82. // History: 5-May-1995 BillMo Created
  83. //
  84. //----------------------------------------------------------------------------
  85. #ifdef NEWPROPS
  86. #ifdef CODESEGMENTS
  87. #pragma code_seg(SEG_CChildInstanceList_FindByName)
  88. #endif
  89. SCODE CChildInstanceList::FlushBufferedData(int recursionlevel)
  90. {
  91. PRevertable *prv;
  92. SCODE sc = S_OK;
  93. olDebugOut((DEB_ITRACE, "In CChildInstanceList::FlushBufferedData:%p\n",
  94. this));
  95. for (prv = BP_TO_P(PRevertable *, _prvHead);
  96. prv && sc == S_OK;
  97. prv = BP_TO_P(PRevertable *, prv->_prvNext))
  98. {
  99. sc = prv->FlushBufferedData(recursionlevel + 1);
  100. }
  101. olDebugOut((DEB_ITRACE, "Out CChildInstanceList::FlushBufferedData\n"));
  102. return sc;
  103. }
  104. #endif
  105. //+--------------------------------------------------------------
  106. //
  107. // Method: CChildInstanceList::DeleteByName, private
  108. //
  109. // Synopsis: Removes an instance from the instance list
  110. // and reverts it
  111. //
  112. // Arguments: [pdfn] - Name or NULL
  113. //
  114. // History: 17-Oct-91 DrewB Created
  115. //
  116. // Notes: The entry does not have to exist
  117. // There can be multiple entries
  118. // If name is NULL, all entries match
  119. //
  120. //---------------------------------------------------------------
  121. #ifdef CODESEGMENTS
  122. #pragma code_seg(SEG_CChildInstanceList_DeleteByName)
  123. #endif
  124. void CChildInstanceList::DeleteByName(CDfName const *pdfn)
  125. {
  126. CBasedRevertablePtr *pprv;
  127. olDebugOut((DEB_ITRACE, "In CChildInstanceList::DeleteByName(%ws)\n",
  128. pdfn->GetBuffer()));
  129. for (pprv = &_prvHead; *pprv; )
  130. if (NULL == pdfn || (*pprv)->_dfn.IsEqual(pdfn))
  131. {
  132. (*pprv)->RevertFromAbove();
  133. *pprv = (*pprv)->_prvNext;
  134. }
  135. else
  136. pprv = &(*pprv)->_prvNext;
  137. olDebugOut((DEB_ITRACE, "Out CChildInstanceList::DeleteByName\n"));
  138. }
  139. //+--------------------------------------------------------------
  140. //
  141. // Method: CChildInstanceList::RemoveRv, private
  142. //
  143. // Synopsis: Removes a specific instance from the instance list
  144. //
  145. // Arguments: [prv] - Instance
  146. //
  147. // History: 17-Oct-91 DrewB Created
  148. //
  149. // Notes: The entry does not have to exist
  150. //
  151. //---------------------------------------------------------------
  152. #ifdef CODESEGMENTS
  153. #pragma code_seg(SEG_CChildInstanceList_RemoveRv)
  154. #endif
  155. void CChildInstanceList::RemoveRv(PRevertable *prvRv)
  156. {
  157. CBasedRevertablePtr *prv;
  158. olDebugOut((DEB_ITRACE, "In CChildInstanceList::RemoveRv(%p)\n", prvRv));
  159. for (prv = &_prvHead; *prv; prv = &(*prv)->_prvNext)
  160. if (*prv == prvRv)
  161. {
  162. *prv = (*prv)->_prvNext;
  163. break;
  164. }
  165. olDebugOut((DEB_ITRACE, "Out CChildInstanceList::RemoveRv\n"));
  166. }
  167. //+--------------------------------------------------------------
  168. //
  169. // Method: CChildInstanceList::IsDenied, private
  170. //
  171. // Synopsis: Checks the parent instantiation list for a previous
  172. // instance of the given child with DENY flags on
  173. // Also determines whether child mode flags are
  174. // less restrictive than the parent's
  175. //
  176. // Arguments: [pdfn] - Instance name
  177. // [dfCheck] - Access modes to check for denial
  178. // [dfAgainst] - Access modes to check against
  179. //
  180. // Returns: Appropriate status code
  181. //
  182. // History: 17-Oct-91 DrewB Created
  183. // 28-Oct-92 AlexT Converted to names
  184. //
  185. // Notes: The instance doesn't have to be in the list.
  186. // If it isn't, it's not denied
  187. //
  188. //---------------------------------------------------------------
  189. #ifdef CODESEGMENTS
  190. #pragma code_seg(SEG_CChildInstanceList_IsDenied)
  191. #endif
  192. SCODE CChildInstanceList::IsDenied(CDfName const *pdfn,
  193. DFLAGS const dfCheck,
  194. DFLAGS const dfAgainst)
  195. {
  196. PRevertable *prv;
  197. SCODE sc = S_OK;
  198. olDebugOut((DEB_ITRACE, "In CChildInstanceList::IsDenied("
  199. "%p, %lX, %lX)\n", pdfn, dfCheck, dfAgainst));
  200. olAssert(pdfn != NULL && aMsg("IsDenied, null name"));
  201. // Check to see if permissions are less restrictive than
  202. // parent permissions
  203. // This checks to see that a child isn't specifying
  204. // a permission that its parent doesn't
  205. // For example, giving read permission when the parent
  206. // doesn't
  207. if ((~dfAgainst & dfCheck &
  208. (P_TRANSACTED(dfAgainst) ? TCANTSET : DCANTSET)) ||
  209. (dfAgainst & ~dfCheck & CANTCLEAR))
  210. olErr(EH_Err, STG_E_INVALIDFLAG);
  211. // Check for DENY_*
  212. olAssert((DF_DENYALL >> DF_DENIALSHIFT) == DF_READWRITE);
  213. for (prv = BP_TO_P(PRevertable *, _prvHead);
  214. prv != NULL; prv = prv->GetNext())
  215. {
  216. if (prv->_dfn.IsEqual(pdfn))
  217. {
  218. // Check for existing instance with DENY_* mode
  219. if ((((prv->GetDFlags() & DF_DENYALL) >> DF_DENIALSHIFT) &
  220. dfCheck) != 0 ||
  221. // Check for instance with permission already given that
  222. // new instance wants to deny
  223. (((dfCheck & DF_DENYALL) >> DF_DENIALSHIFT) &
  224. prv->GetDFlags()) != 0)
  225. {
  226. sc = STG_E_ACCESSDENIED;
  227. break;
  228. }
  229. }
  230. }
  231. olDebugOut((DEB_ITRACE, "Out CChildInstanceList::IsDenied\n"));
  232. // Fall through
  233. EH_Err:
  234. return sc;
  235. }
  236. //+--------------------------------------------------------------
  237. //
  238. // Member: CChildInstanceList::EmptyCache, public
  239. //
  240. // Synopsis: empties the stream caches
  241. //
  242. // History: 22-Jun-99 HenryLee Created
  243. //
  244. //---------------------------------------------------------------
  245. void CChildInstanceList::EmptyCache ()
  246. {
  247. for (PRevertable *prv = BP_TO_P(PRevertable *, _prvHead);
  248. prv != NULL; prv = prv->GetNext())
  249. {
  250. prv->EmptyCache();
  251. }
  252. }