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.

509 lines
11 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. bizrule.h
  5. Abstract:
  6. Header for data associated with Client Contexts.
  7. Include routines implementing Business Rules and the Operation Cache.
  8. Author:
  9. IActiveScript sample code taken from http://support.microsoft.com/support/kb/articles/Q183/6/98.ASP
  10. Cliff Van Dyke (cliffv) 18-July-2001
  11. --*/
  12. /////////////////////////////////////////////////////////////////////////////
  13. //
  14. // Structure definitions
  15. //
  16. /////////////////////////////////////////////////////////////////////////////
  17. //
  18. // For a particular role or task, define the operations or tasks that apply.
  19. //
  20. typedef struct _AZ_OPS_AND_TASKS {
  21. //
  22. // Applicable operations
  23. // An array of operations that are applicable for this access check.
  24. // Each element is an index into the OpInfo array.
  25. //
  26. ULONG OpCount;
  27. PULONG OpIndexes;
  28. //
  29. // Applicable task
  30. // An array of operations that are applicable for this access check.
  31. // Each element is an index into the TaskInfo array.
  32. //
  33. ULONG TaskCount;
  34. PULONG TaskIndexes;
  35. #define AZ_INVALID_INDEX 0xFFFFFFFF
  36. } AZ_OPS_AND_TASKS, *PAZ_OPS_AND_TASKS;
  37. //
  38. // Define all the information associated with a role and
  39. // that has a lifetime of an AccessCheck operation
  40. //
  41. typedef struct _AZ_ROLE_INFO {
  42. //
  43. // A pointer to the role object.
  44. // The reference count is held on this role object.
  45. //
  46. PAZP_ROLE Role;
  47. //
  48. // Operations and tasks that apply to this role
  49. //
  50. AZ_OPS_AND_TASKS OpsAndTasks;
  51. //
  52. // Computed group membership of this role
  53. // NOT_YET_DONE: Status has not yet been computed.
  54. //
  55. ULONG ResultStatus;
  56. //
  57. // Boolean indicating that this role has been processed and no further processing
  58. // is required for the lifetime of the AccessCheck.
  59. //
  60. BOOLEAN RoleProcessed;
  61. //
  62. // Boolean indicating that the Sid membership of the role has been computed
  63. //
  64. BOOLEAN SidsProcessed;
  65. } AZ_ROLE_INFO, *PAZ_ROLE_INFO;
  66. //
  67. // Define all the information associated with a task and
  68. // that has a lifetime of an AccessCheck operation
  69. //
  70. typedef struct _AZ_TASK_INFO {
  71. //
  72. // A pointer to the task object.
  73. // The reference count is held on this task object.
  74. //
  75. PAZP_TASK Task;
  76. //
  77. // Operations and tasks that apply to this task
  78. //
  79. AZ_OPS_AND_TASKS OpsAndTasks;
  80. //
  81. // Boolean indicating that this task has been processed and no further processing
  82. // is required for the lifetime of the AccessCheck.
  83. //
  84. BOOLEAN TaskProcessed;
  85. //
  86. // Boolean indicating that the BizRule for this task has been processed and that the
  87. // result of the BizRule is in BizRuleResult.
  88. //
  89. BOOLEAN BizRuleProcessed;
  90. BOOLEAN BizRuleResult;
  91. } AZ_TASK_INFO, *PAZ_TASK_INFO;
  92. //
  93. // Define a context that describe an access check operation in progress
  94. //
  95. typedef struct _ACCESS_CHECK_CONTEXT {
  96. //
  97. // Client context of the caller
  98. //
  99. PAZP_CLIENT_CONTEXT ClientContext;
  100. //
  101. // Application doing the access check
  102. //
  103. PAZP_APPLICATION Application;
  104. //
  105. // Object being accessed
  106. //
  107. AZP_STRING ObjectNameString;
  108. //
  109. // The BusinessRuleString returned from the various bizrules
  110. //
  111. AZP_STRING BusinessRuleString;
  112. //
  113. // Operations that the caller wants to check and the Result access granted for that operation.
  114. //
  115. ULONG OperationCount;
  116. PAZP_OPERATION *OperationObjects;
  117. PULONG Results;
  118. // Array with one element per operation
  119. PBOOLEAN OperationWasProcessed;
  120. // Number of operations that have already been processed
  121. ULONG ProcessedOperationCount;
  122. // Number of operations that were resolved from the operation cache
  123. ULONG CachedOperationCount;
  124. //
  125. // Scope the access check is being performed on
  126. //
  127. AZP_STRING ScopeNameString;
  128. PAZP_SCOPE Scope;
  129. //
  130. // Roles that match the Scope
  131. ULONG RoleCount;
  132. PAZ_ROLE_INFO RoleInfo;
  133. //
  134. // Tasks that apply to the access check
  135. //
  136. ULONG TaskCount;
  137. PAZ_TASK_INFO TaskInfo;
  138. //
  139. // Parameters to pass to Bizrules
  140. // See AzContextAccessCheck parameters for descriptions
  141. //
  142. // Arrays actually passed to AzContextAccessCheck
  143. SAFEARRAY* SaParameterNames;
  144. VARIANT *ParameterNames;
  145. SAFEARRAY* SaParameterValues;
  146. VARIANT *ParameterValues;
  147. // Array indicating whether each parameter is actually used
  148. BOOLEAN *UsedParameters;
  149. ULONG UsedParameterCount;
  150. // Number of elements in the above arrays
  151. ULONG ParameterCount;
  152. //
  153. // Interfaces to pass to Bizrules
  154. // See AzContextAccessCheck parameters for descriptions
  155. //
  156. SAFEARRAY *InterfaceNames;
  157. SAFEARRAY *InterfaceFlags;
  158. SAFEARRAY *Interfaces;
  159. LONG InterfaceLower; // Lower bound of above arrays
  160. LONG InterfaceUpper; // Upper bound of above arrays
  161. } ACCESS_CHECK_CONTEXT, *PACCESS_CHECK_CONTEXT;
  162. /////////////////////////////////////////////////////////////////////////////
  163. //
  164. // Procedure definitions
  165. //
  166. /////////////////////////////////////////////////////////////////////////////
  167. //
  168. // Procedures from context.cxx
  169. //
  170. INT __cdecl
  171. AzpCompareParameterNames(
  172. IN const void *pArg1,
  173. IN const void *pArg2
  174. );
  175. INT __cdecl
  176. AzpCaseInsensitiveCompareParameterNames(
  177. IN const void *pArg1,
  178. IN const void *pArg2
  179. );
  180. //
  181. // Procedures from bizrule.cxx
  182. //
  183. DWORD
  184. AzpProcessBizRule(
  185. IN PACCESS_CHECK_CONTEXT AcContext,
  186. IN PAZP_TASK Task,
  187. OUT PBOOL BizRuleResult
  188. );
  189. DWORD
  190. AzpParseBizRule(
  191. IN PAZP_TASK Task
  192. );
  193. VOID
  194. AzpFlushBizRule(
  195. IN PAZP_TASK Task
  196. );
  197. //
  198. // Procedures from opcache.cxx
  199. //
  200. VOID
  201. AzpInitOperationCache(
  202. IN PAZP_CLIENT_CONTEXT ClientContext
  203. );
  204. BOOLEAN
  205. AzpCheckOperationCache(
  206. IN PACCESS_CHECK_CONTEXT AcContext
  207. );
  208. VOID
  209. AzpUpdateOperationCache(
  210. IN PACCESS_CHECK_CONTEXT AcContext
  211. );
  212. VOID
  213. AzpFlushOperationCache(
  214. IN PAZP_CLIENT_CONTEXT ClientContext
  215. );
  216. /////////////////////////////////////////////////////////////////////////////
  217. //
  218. // Class definitions
  219. //
  220. /////////////////////////////////////////////////////////////////////////////
  221. class CScriptEngine;
  222. //
  223. // Structure used for linking CScriptEngine instances into a list
  224. //
  225. typedef struct _LIST_ELEMENT {
  226. //
  227. // Link to the next entry in the list
  228. //
  229. LIST_ENTRY Next;
  230. //
  231. // Pointer to the ScriptEngine head
  232. //
  233. CScriptEngine *This;
  234. } LIST_ELEMENT, *PLIST_ELEMENT;
  235. //
  236. // IActiveScriptSite implementation.
  237. //
  238. // This interface allows the script engine to call back to the script host.
  239. //
  240. class CScriptEngine:public IActiveScriptSite
  241. {
  242. protected :
  243. LONG m_cRef; //variable to maintain the reference count
  244. //
  245. // Pointer to the task that defines this bizrule
  246. //
  247. PAZP_TASK m_Task;
  248. //
  249. // Pointer to the context for the active AccessCheck using this bizrule
  250. //
  251. PACCESS_CHECK_CONTEXT m_AcContext;
  252. //
  253. // Link to the next script engine in either the FreeScript list or RunningScript list
  254. //
  255. LIST_ELEMENT m_Next;
  256. //
  257. // Link to the next script engine in LRU FreeScript list
  258. //
  259. LIST_ELEMENT m_LruNext;
  260. //
  261. // Script engine references
  262. //
  263. IActiveScript *m_Engine;
  264. IActiveScriptParse *m_Parser;
  265. //
  266. // Pointer to the IAzBizRuleContext interface that the script will interact with
  267. //
  268. IAzBizRuleContext *m_BizRuleContext;
  269. //
  270. // Thread ID of the thread that initialized the script
  271. //
  272. SCRIPTTHREADID m_BaseThread;
  273. //
  274. // Copy of the BizRuleSerialNumber that was active when we parsed the BizRule script
  275. //
  276. DWORD m_BizRuleSerialNumber;
  277. //
  278. // Script failure status code
  279. //
  280. HRESULT m_ScriptError;
  281. //
  282. // Various state booleans
  283. //
  284. DWORD m_fInited:1; // Have we been inited?
  285. DWORD m_fCorrupted:1; // Might the engine be "unsafe" for reuse?
  286. DWORD m_fTimedOut:1; // Script timed out
  287. BOOL m_bCaseSensitive;
  288. public:
  289. //Constructor
  290. CScriptEngine();
  291. //Destructor
  292. ~CScriptEngine();
  293. HRESULT
  294. Init(
  295. IN PAZP_TASK Task,
  296. IN IActiveScript *ClonedActiveScript OPTIONAL,
  297. IN DWORD ClonedBizRuleSerialNumber OPTIONAL
  298. );
  299. HRESULT
  300. RunScript(
  301. IN PACCESS_CHECK_CONTEXT AcContext,
  302. OUT PBOOL BizRuleResult
  303. );
  304. HRESULT InterruptScript();
  305. HRESULT ResetToUninitialized();
  306. HRESULT ReuseEngine();
  307. BOOL IsBaseThread();
  308. VOID FinalRelease();
  309. //
  310. // Insert this engine into an externally managed list
  311. //
  312. VOID
  313. InsertHeadList(
  314. IN PLIST_ENTRY ListHead
  315. );
  316. VOID
  317. RemoveListEntry(
  318. VOID
  319. );
  320. VOID
  321. InsertHeadLruList(
  322. VOID
  323. );
  324. VOID
  325. RemoveLruListEntry(
  326. VOID
  327. );
  328. //
  329. // Inline interfaces
  330. //
  331. inline IActiveScript *GetActiveScript()
  332. {
  333. return (m_Engine);
  334. }
  335. inline DWORD GetBizRuleSerialNumber( VOID )
  336. {
  337. return (m_BizRuleSerialNumber);
  338. }
  339. inline BOOL FIsCorrupted()
  340. {
  341. return (m_fCorrupted);
  342. }
  343. #ifdef DBG
  344. inline VOID AssertValid()
  345. const {
  346. ASSERT(m_fInited);
  347. ASSERT(m_Engine != NULL);
  348. ASSERT(m_Parser != NULL);
  349. ASSERT(m_BizRuleContext != NULL);
  350. ASSERT(m_cRef != 0);
  351. }
  352. #else
  353. virtual VOID AssertValid() const {}
  354. #endif // DBG
  355. /******* IUnknown *******/
  356. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  357. STDMETHODIMP_(ULONG) AddRef();
  358. STDMETHODIMP_(ULONG) Release();
  359. /******* IActiveScriptSite *******/
  360. STDMETHODIMP GetLCID(LCID * plcid); // address of variable for language identifier
  361. STDMETHODIMP GetItemInfo(
  362. LPCOLESTR pstrName, // address of item name
  363. DWORD dwReturnMask, // bit mask for information retrieval
  364. IUnknown ** ppunkItem, // address of pointer to item's IUnknown
  365. ITypeInfo ** ppTypeInfo ); // address of pointer to item's ITypeInfo
  366. STDMETHODIMP GetDocVersionString(
  367. BSTR * pbstrVersionString); // address of document version string
  368. STDMETHODIMP OnScriptTerminate(
  369. const VARIANT * pvarResult, // address of script results
  370. const EXCEPINFO * pexcepinfo); // address of structure with exception information
  371. STDMETHODIMP OnStateChange(
  372. SCRIPTSTATE ssScriptState); // new state of engine
  373. STDMETHODIMP OnScriptError(
  374. IActiveScriptError * pase); // address of error interface
  375. STDMETHODIMP OnEnterScript(void);
  376. STDMETHODIMP OnLeaveScript(void);
  377. };