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.

76 lines
2.3 KiB

  1. // WMIObjectBroker.cpp : Implementation of CWMIObjectBroker
  2. #include "stdafx.h"
  3. #include "WMIScriptUtils.h"
  4. #include "WMIObjectBroker.h"
  5. #include "CommonFuncs.h"
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CWMIObjectBroker
  8. STDMETHODIMP CWMIObjectBroker::CreateObject(BSTR strProgId, IDispatch **obj)
  9. {
  10. HRESULT hr = E_FAIL;
  11. CLSID clsid;
  12. IUnknown *pUnk = NULL;
  13. __try
  14. {
  15. BOOL fSafetyEnabled = TRUE;
  16. // TODO: Do we want this check to enable us to work from WSH?
  17. // BUG in IE/JScript/VBScript: We should be checking to see if
  18. // m_dwCurrentSafety != INTERFACE_USES_SECURITY_MANAGER, but current
  19. // IE/JScript/VBScript versions do not call SetInterfaceSafetyOptions
  20. // with anything but INTERFACESAFE_FOR_UNTRUSTED_CALLER
  21. // If we are run though CScript.exe or WScript.exe, we will never be
  22. // asked to set safety options through SetInterfaceSafetyOptions. In
  23. // addition, there will not be an InternetHostSecurityManager available
  24. // through our 'site'. In this case, we allow any object to be created.
  25. if(m_dwCurrentSafety == 0 && !IsInternetHostSecurityManagerAvailable(GetUnknown()))
  26. fSafetyEnabled = FALSE;
  27. // We can override the safety check if this insance of the 'broker'
  28. // control is allowed to create the object specified by strProbId
  29. if(fSafetyEnabled && SUCCEEDED(IsCreateObjectAllowed(GetUnknown(), strProgId, NULL)))
  30. fSafetyEnabled = FALSE;
  31. // Convert the ProgId to a CLSID
  32. if(FAILED(hr = CLSIDFromProgID(strProgId, &clsid)))
  33. __leave;
  34. // Create the requested object
  35. #if 0
  36. if(FAILED(hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&pUnk)))
  37. __leave;
  38. #endif
  39. if(FAILED(hr = SafeCreateObject(GetUnknown(),fSafetyEnabled, clsid, &pUnk)))
  40. __leave;
  41. // Get the IDispatch for the caller
  42. hr = pUnk->QueryInterface(IID_IDispatch, (void**)obj);
  43. }
  44. __finally
  45. {
  46. if(pUnk)
  47. pUnk->Release();
  48. }
  49. return hr;
  50. }
  51. STDMETHODIMP CWMIObjectBroker::CanCreateObject(BSTR strProgId, VARIANT_BOOL *bResult)
  52. {
  53. *bResult = VARIANT_FALSE;
  54. if(SUCCEEDED(IsCreateObjectAllowed(GetUnknown(), strProgId, NULL)))
  55. *bResult = VARIANT_TRUE;
  56. return S_OK;
  57. }
  58. STDMETHODIMP CWMIObjectBroker::SetDevEnvironment(IDispatch *pEnv)
  59. {
  60. return SetVSInstallDirectory(pEnv);
  61. }