1
0

JSAPI2_SecurityAPI.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "JSAPI2_SecurityAPI.h"
  2. #include "JSAPI2_Security.h"
  3. #include "main.h"
  4. #include "JSAPI.h"
  5. JSAPI2::SecurityAPI::SecurityAPI(const wchar_t *_key, JSAPI::ifc_info *_info)
  6. {
  7. info = _info;
  8. key = _key;
  9. refCount = 1;
  10. }
  11. enum
  12. {
  13. DISPID_SECURITYAPI_SETACTIONAUTHORIZATION,
  14. DISPID_SECURITYAPI_GETACTIONAUTHORIZATION,
  15. };
  16. #define DISP_TABLE \
  17. CHECK_ID(SetActionAuthorization, DISPID_SECURITYAPI_SETACTIONAUTHORIZATION)\
  18. CHECK_ID(GetActionAuthorization, DISPID_SECURITYAPI_GETACTIONAUTHORIZATION)\
  19. #define CHECK_ID(str, id)\
  20. if (CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, rgszNames[i], -1, L## #str, -1))\
  21. { rgdispid[i] = id; continue; }
  22. HRESULT JSAPI2::SecurityAPI::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
  23. {
  24. bool unknowns = false;
  25. for (unsigned int i = 0;i != cNames;i++)
  26. {
  27. DISP_TABLE
  28. rgdispid[i] = DISPID_UNKNOWN;
  29. unknowns = true;
  30. }
  31. if (unknowns)
  32. return DISP_E_UNKNOWNNAME;
  33. else
  34. return S_OK;
  35. }
  36. HRESULT JSAPI2::SecurityAPI::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  37. {
  38. return E_NOTIMPL;
  39. }
  40. HRESULT JSAPI2::SecurityAPI::GetTypeInfoCount(unsigned int FAR * pctinfo)
  41. {
  42. return E_NOTIMPL;
  43. }
  44. HRESULT JSAPI2::SecurityAPI::GetActionAuthorization(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  45. {
  46. JSAPI_VERIFY_METHOD(wFlags);
  47. JSAPI_VERIFY_PARAMCOUNT_OPTIONAL(pdispparams, 1, 2);
  48. JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_BSTR, puArgErr);
  49. JSAPI_VERIFY_PARAMTYPE_OPTIONAL(pdispparams, 2, VT_BSTR, puArgErr);
  50. JSAPI_INIT_RESULT(pvarResult, VT_I4);
  51. JSAPI_SET_RESULT(pvarResult, lVal, security.GetActionAuthorization(JSAPI_PARAM(pdispparams, 1).bstrVal, JSAPI_PARAM_OPTIONAL(pdispparams, 2, bstrVal, 0), key, info, JSAPI2::api_security::ACTION_UNDEFINED));
  52. return S_OK;
  53. }
  54. HRESULT JSAPI2::SecurityAPI::SetActionAuthorization(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  55. {
  56. JSAPI_VERIFY_METHOD(wFlags);
  57. JSAPI_VERIFY_PARAMCOUNT(pdispparams, 3);
  58. JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_BSTR, puArgErr);
  59. JSAPI_VERIFY_PARAMTYPE(pdispparams, 2, VT_BSTR, puArgErr);
  60. JSAPI_VERIFY_PARAMTYPE(pdispparams, 3, VT_I4, puArgErr);
  61. JSAPI_INIT_RESULT(pvarResult, VT_BOOL);
  62. if (security.GetActionAuthorization(L"security", L"set", key, info, JSAPI2::api_security::ACTION_DISALLOWED) == JSAPI2::api_security::ACTION_ALLOWED)
  63. {
  64. JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_TRUE);
  65. const wchar_t *group = JSAPI_PARAM(pdispparams, 1).bstrVal;
  66. const wchar_t *action = JSAPI_PARAM(pdispparams, 2).bstrVal;
  67. int authorization = JSAPI_PARAM(pdispparams, 2).lVal;
  68. security.SetActionAuthorization(group, action, key, authorization);
  69. }
  70. else
  71. {
  72. JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_FALSE);
  73. }
  74. return S_OK;
  75. }
  76. #undef CHECK_ID
  77. #define CHECK_ID(str, id) case id: return str(wFlags, pdispparams, pvarResult, puArgErr);
  78. HRESULT JSAPI2::SecurityAPI::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
  79. {
  80. switch (dispid)
  81. {
  82. DISP_TABLE
  83. }
  84. return DISP_E_MEMBERNOTFOUND;
  85. }
  86. STDMETHODIMP JSAPI2::SecurityAPI::QueryInterface(REFIID riid, PVOID *ppvObject)
  87. {
  88. if (!ppvObject)
  89. return E_POINTER;
  90. else if (IsEqualIID(riid, IID_IDispatch))
  91. *ppvObject = (IDispatch *)this;
  92. else if (IsEqualIID(riid, IID_IUnknown))
  93. *ppvObject = this;
  94. else
  95. {
  96. *ppvObject = NULL;
  97. return E_NOINTERFACE;
  98. }
  99. AddRef();
  100. return S_OK;
  101. }
  102. ULONG JSAPI2::SecurityAPI::AddRef(void)
  103. {
  104. return InterlockedIncrement(&refCount);
  105. }
  106. ULONG JSAPI2::SecurityAPI::Release(void)
  107. {
  108. LONG lRef = InterlockedDecrement(&refCount);
  109. if (lRef == 0) delete this;
  110. return lRef;
  111. }