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.

154 lines
4.0 KiB

  1. #include "cabinet.h"
  2. #include "tray.h"
  3. #include "ssomgr.h"
  4. #include <regstr.h>
  5. HRESULT CShellServiceObjectMgr::_LoadObject(REFCLSID rclsid, DWORD dwFlags)
  6. {
  7. ASSERT(dwFlags & LIPF_ENABLE);
  8. HRESULT hr = E_FAIL;
  9. if (dwFlags & LIPF_HOLDREF)
  10. {
  11. if (_dsaSSO)
  12. {
  13. SHELLSERVICEOBJECT sso = {0};
  14. sso.clsid = rclsid;
  15. // SECURITY: this clsid was given to us by another application and we are pulling them into
  16. // our process
  17. hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
  18. IID_PPV_ARG(IOleCommandTarget, &sso.pct));
  19. if (SUCCEEDED(hr))
  20. {
  21. if (_dsaSSO.AppendItem(&sso) != -1)
  22. {
  23. sso.pct->Exec(&CGID_ShellServiceObject, SSOCMDID_OPEN, 0, NULL, NULL);
  24. }
  25. else
  26. {
  27. sso.pct->Release();
  28. hr = E_OUTOFMEMORY;
  29. }
  30. }
  31. }
  32. }
  33. else
  34. {
  35. // just ask for IUnknown for these dudes
  36. IUnknown *punk;
  37. hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
  38. IID_PPV_ARG(IUnknown, &punk));
  39. if (SUCCEEDED(hr))
  40. {
  41. punk->Release();
  42. }
  43. }
  44. return hr;
  45. }
  46. // The following code manages shell service objects. We load inproc dlls
  47. // from the registry key and QI them for IOleCommandTarget. Note that all
  48. // Shell Service Objects are loaded on the desktop thread.
  49. // CGID_ShellServiceObject notifications are sent to these objects letting
  50. // them know about shell status.
  51. STDAPI_(BOOL) CShellServiceObjectMgr::EnumRegAppProc(LPCTSTR pszSubkey, LPCTSTR pszCmdLine, RRA_FLAGS fFlags, LPARAM lParam)
  52. {
  53. CShellServiceObjectMgr* pssomgr = (CShellServiceObjectMgr*)lParam;
  54. CLSID clsid;
  55. HRESULT hr = SHCLSIDFromString(pszCmdLine, &clsid);
  56. if (SUCCEEDED(hr))
  57. {
  58. hr = pssomgr->_LoadObject(clsid, LIPF_ENABLE | LIPF_HOLDREF);
  59. }
  60. if (FAILED(hr))
  61. {
  62. c_tray.LogFailedStartupApp();
  63. }
  64. return SUCCEEDED(hr);
  65. }
  66. HRESULT CShellServiceObjectMgr::LoadRegObjects()
  67. {
  68. Cabinet_EnumRegApps(HKEY_LOCAL_MACHINE, REGSTR_PATH_SHELLSERVICEOBJECTDELAYED, 0,
  69. EnumRegAppProc, (LPARAM)this);
  70. Cabinet_EnumRegApps(HKEY_CURRENT_USER, REGSTR_PATH_SHELLSERVICEOBJECTDELAYED, 0,
  71. EnumRegAppProc, (LPARAM)this);
  72. return S_OK;
  73. }
  74. HRESULT CShellServiceObjectMgr::EnableObject(const CLSID *pclsid, DWORD dwFlags)
  75. {
  76. HRESULT hr = E_FAIL;
  77. if (dwFlags & LIPF_ENABLE)
  78. {
  79. hr = _LoadObject(*pclsid, dwFlags);
  80. }
  81. else
  82. {
  83. int i = _FindItemByCLSID(*pclsid);
  84. if (i != -1)
  85. {
  86. PSHELLSERVICEOBJECT psso = _dsaSSO.GetItemPtr(i);
  87. DestroyItemCB(psso, this);
  88. _dsaSSO.DeleteItem(i);
  89. hr = S_OK;
  90. }
  91. }
  92. return hr;
  93. }
  94. int CShellServiceObjectMgr::_FindItemByCLSID(REFCLSID rclsid)
  95. {
  96. if (_dsaSSO)
  97. {
  98. for (int i = _dsaSSO.GetItemCount() - 1; i >= 0; i--)
  99. {
  100. PSHELLSERVICEOBJECT psso = _dsaSSO.GetItemPtr(i);
  101. if (IsEqualCLSID(psso->clsid, rclsid))
  102. {
  103. return i;
  104. }
  105. }
  106. }
  107. return -1;
  108. }
  109. HRESULT CShellServiceObjectMgr::Init()
  110. {
  111. ASSERT(!_dsaSSO);
  112. return _dsaSSO.Create(2) ? S_OK : E_FAIL;
  113. }
  114. CShellServiceObjectMgr::~CShellServiceObjectMgr()
  115. {
  116. Destroy();
  117. }
  118. int WINAPI CShellServiceObjectMgr::DestroyItemCB(SHELLSERVICEOBJECT *psso, CShellServiceObjectMgr *pssomgr)
  119. {
  120. psso->pct->Exec(&CGID_ShellServiceObject, SSOCMDID_CLOSE, 0, NULL, NULL);
  121. psso->pct->Release();
  122. return 1;
  123. }
  124. void CShellServiceObjectMgr::Destroy()
  125. {
  126. if (_dsaSSO)
  127. {
  128. _dsaSSO.DestroyCallbackEx<CShellServiceObjectMgr*>(DestroyItemCB, this);
  129. }
  130. }