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.

166 lines
4.4 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. // DynExten.cpp : enumerates installed services on (possibly remote) computer
  3. //
  4. // HISTORY
  5. // 30-Oct-97 JonN Creation.
  6. /////////////////////////////////////////////////////////////////////
  7. #include "stdafx.h"
  8. #include "macros.h"
  9. USE_HANDLE_MACROS("MMCFMGMT(dynexten.cpp)")
  10. #include "compdata.h"
  11. #include "cookie.h"
  12. #include "regkey.h" // AMC::CRegKey
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. const TCHAR SERVICES_KEY[] = TEXT("System\\CurrentControlSet\\Control\\Server Applications");
  19. const TCHAR CLSID_KEY[] = TEXT("Clsid\\");
  20. HRESULT DynextenCheckInstall( const GUID& guidExtension, const TCHAR* pszExtension )
  21. {
  22. HRESULT hr = S_OK;
  23. #ifdef USE_CLASS_STORE
  24. IClassAccess* pIClassAccess = NULL;
  25. #endif
  26. try
  27. {
  28. CString strRegPath = CLSID_KEY; // JonN 2/19/02 Security Push
  29. strRegPath += pszExtension;
  30. AMC::CRegKey regkeyInstalled;
  31. BOOL fFound = regkeyInstalled.OpenKeyEx( HKEY_CLASSES_ROOT, strRegPath, KEY_READ );
  32. if ( fFound )
  33. {
  34. return S_OK; // it is already installed
  35. }
  36. // CODEWORK It would be more efficient to access the Class Store directly
  37. // by calling CoGetClassAccess, then IClassAccess->GetAppInfo(), then CoInstall().
  38. #ifdef USE_CLASS_STORE
  39. // now we have to get the Class Store to install it
  40. do { // false loop
  41. hr = CoGetClassAccess( &pIClassAccess );
  42. if ( FAILED(hr) )
  43. break;
  44. // now what???
  45. } while (FALSE); // false loop
  46. #else
  47. IUnknown* pIUnknown = NULL;
  48. hr = ::CoCreateInstance( guidExtension,
  49. NULL,
  50. CLSCTX_INPROC,
  51. IID_IComponentData,
  52. (PVOID*)&pIUnknown );
  53. if (NULL != pIUnknown)
  54. pIUnknown->Release();
  55. // allow hr to fall through
  56. #endif
  57. }
  58. catch (COleException* e)
  59. {
  60. // 2002/02/27-JonN I confirmed that this error path is called when
  61. // AMC::RegKey throws an exception
  62. e->Delete();
  63. return E_FAIL;
  64. }
  65. #ifdef USE_CLASS_STORE
  66. if (NULL != pIClassAccess)
  67. pIClassAccess->Release();
  68. #endif
  69. return hr;
  70. }
  71. //
  72. // CMyComputerComponentData
  73. //
  74. static CLSID CLSID_DnsSnapin =
  75. { 0x80105023, 0x50B1, 0x11d1, { 0xB9, 0x30, 0x00, 0xA0, 0xC9, 0xA0, 0x6D, 0x2D } };
  76. static CLSID CLSID_FileServiceManagementExt = {0x58221C69,0xEA27,0x11CF,{0xAD,0xCF,0x00,0xAA,0x00,0xA8,0x00,0x33}};
  77. HRESULT CMyComputerComponentData::ExpandServerApps(
  78. HSCOPEITEM hParent,
  79. CMyComputerCookie* pcookie )
  80. {
  81. // ISSUE-2002/02/27-JonN check parameters
  82. try
  83. {
  84. AMC::CRegKey regkeyServices;
  85. BOOL fFound = TRUE;
  86. if (NULL == pcookie->QueryTargetServer())
  87. {
  88. fFound = regkeyServices.OpenKeyEx( HKEY_LOCAL_MACHINE, SERVICES_KEY, KEY_READ );
  89. }
  90. else
  91. {
  92. AMC::CRegKey regkeyRemoteComputer;
  93. regkeyRemoteComputer.ConnectRegistry(
  94. const_cast<LPTSTR>(pcookie->QueryTargetServer()) );
  95. fFound = regkeyServices.OpenKeyEx( regkeyRemoteComputer, SERVICES_KEY, KEY_READ );
  96. }
  97. if ( !fFound )
  98. {
  99. return S_OK; // CODEWORK what return code?
  100. }
  101. CComQIPtr<IConsoleNameSpace2, &IID_IConsoleNameSpace2> pIConsoleNameSpace2
  102. = m_pConsole;
  103. if ( !pIConsoleNameSpace2 )
  104. {
  105. ASSERT(FALSE);
  106. return E_UNEXPECTED;
  107. }
  108. TCHAR achValue[ MAX_PATH ];
  109. DWORD iSubkey;
  110. // 2002/02/15-JonN Security Push: handle ERROR_MORE_DATA better
  111. // MYCOMPUT appears to be the only user of EnumValue at this time
  112. for ( iSubkey = 0;
  113. true;
  114. iSubkey++ )
  115. {
  116. ZeroMemory( achValue, sizeof(achValue) );
  117. DWORD cchValue = sizeof(achValue)/sizeof(TCHAR);
  118. HRESULT hr = regkeyServices.EnumValue(
  119. iSubkey,
  120. achValue,
  121. &cchValue );
  122. if (S_OK != hr)
  123. {
  124. if (ERROR_MORE_DATA == hr)
  125. continue;
  126. ASSERT(ERROR_NO_MORE_ITEMS == hr);
  127. break;
  128. }
  129. GUID guidExtension;
  130. hr = ::CLSIDFromString( achValue, &guidExtension );
  131. if ( !SUCCEEDED(hr) )
  132. continue;
  133. hr = DynextenCheckInstall( guidExtension, achValue );
  134. if ( !SUCCEEDED(hr) )
  135. continue;
  136. hr = pIConsoleNameSpace2->AddExtension( hParent, &guidExtension );
  137. // ignore the return value
  138. }
  139. }
  140. catch (COleException* e)
  141. {
  142. e->Delete();
  143. return S_OK; // CODEWORK what return code?
  144. }
  145. return S_OK;
  146. }