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.

171 lines
3.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // iasnap.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Implementation of DLL exports for an ATL in proc server.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/05/1998 Original version.
  16. // 02/03/2000 Added ProxyPolicyEnforcer & UserRestrictions.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <ias.h>
  20. #include <iasutil.h>
  21. #include <newop.cpp>
  22. #include <enforcer.h>
  23. #include <match.h>
  24. #include <ntgroups.h>
  25. #include <timeofday.h>
  26. #include <userr.h>
  27. CComModule _Module;
  28. #include <atlimpl.cpp>
  29. BEGIN_OBJECT_MAP(ObjectMap)
  30. OBJECT_ENTRY(__uuidof(AttributeMatch), AttributeMatch)
  31. OBJECT_ENTRY(__uuidof(NTGroups), NTGroups)
  32. OBJECT_ENTRY(__uuidof(TimeOfDay), TimeOfDay)
  33. OBJECT_ENTRY(__uuidof(PolicyEnforcer),
  34. IASTL::IASRequestHandlerObject<PolicyEnforcer> )
  35. OBJECT_ENTRY(__uuidof(ProxyPolicyEnforcer),
  36. IASTL::IASRequestHandlerObject<ProxyPolicyEnforcer> )
  37. OBJECT_ENTRY(__uuidof(URHandler),
  38. IASTL::IASRequestHandlerObject<UserRestrictions> )
  39. END_OBJECT_MAP()
  40. //////////
  41. // DLL Entry Point
  42. //////////
  43. BOOL
  44. WINAPI
  45. DllMain(
  46. HINSTANCE hInstance,
  47. DWORD dwReason,
  48. LPVOID /*lpReserved*/
  49. )
  50. {
  51. if (dwReason == DLL_PROCESS_ATTACH)
  52. {
  53. _Module.Init(ObjectMap, hInstance);
  54. DisableThreadLibraryCalls(hInstance);
  55. }
  56. else if (dwReason == DLL_PROCESS_DETACH)
  57. {
  58. _Module.Term();
  59. }
  60. return TRUE;
  61. }
  62. //////////
  63. // Used to determine whether the DLL can be unloaded by OLE
  64. //////////
  65. STDAPI DllCanUnloadNow(void)
  66. {
  67. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  68. }
  69. //////////
  70. // Returns a class factory to create an object of the requested type.
  71. //////////
  72. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  73. {
  74. return _Module.GetClassObject(rclsid, riid, ppv);
  75. }
  76. //////////
  77. // DllRegisterServer - Adds entries to the system registry
  78. //////////
  79. STDAPI DllRegisterServer(void)
  80. {
  81. return _Module.RegisterServer(TRUE);
  82. }
  83. //////////
  84. // DllUnregisterServer - Removes entries from the system registry
  85. //////////
  86. STDAPI DllUnregisterServer(void)
  87. {
  88. HRESULT hr = _Module.UnregisterServer();
  89. if (FAILED(hr)) return hr;
  90. hr = UnRegisterTypeLib(__uuidof(NetworkPolicy),
  91. 1,
  92. 0,
  93. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  94. SYS_WIN32);
  95. return hr;
  96. }
  97. #include <BuildTree.h>
  98. #define IASNAPAPI
  99. #include <xprparse.h>
  100. //////////
  101. // Apply an expression to a request.
  102. //////////
  103. HRESULT
  104. WINAPI
  105. IASEvaluateExpression(
  106. IRequest* pRequest,
  107. PCWSTR szExpression,
  108. VARIANT_BOOL *pVal
  109. )
  110. {
  111. if (pRequest == NULL || pVal == NULL) { return E_INVALIDARG; }
  112. // Parse the expression into an array of tokens.
  113. _variant_t v;
  114. RETURN_ERROR(IASParseExpression(szExpression, &v));
  115. // Build a logic tree from the tokens.
  116. CComPtr<ICondition> condition;
  117. RETURN_ERROR(IASBuildExpression(&v, &condition));
  118. // Evaluate the expression.
  119. return condition->IsTrue(pRequest, pVal);
  120. }
  121. //////////
  122. // Evaluate a one-shot time of day constraint.
  123. //////////
  124. HRESULT
  125. WINAPI
  126. IASEvaluateTimeOfDay(
  127. PCWSTR szTimeOfDay,
  128. VARIANT_BOOL *pVal
  129. )
  130. {
  131. if (pVal == NULL) { return E_INVALIDARG; }
  132. // Convert the text to an hour map.
  133. BYTE hourMap[IAS_HOUR_MAP_LENGTH];
  134. DWORD dw = IASHourMapFromText(szTimeOfDay, hourMap);
  135. if (dw != NO_ERROR) { return HRESULT_FROM_WIN32(dw); }
  136. // Test the current hour.
  137. *pVal = theTimeOfDayEvaluator.isCurrentHourSet(hourMap) ? VARIANT_TRUE
  138. : VARIANT_FALSE;
  139. return S_OK;
  140. }
  141. #include <xprparse.cpp>