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.

173 lines
4.8 KiB

  1. // ProductEnvironment.cpp: implementation of the CProductEnvironment class.
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "ProductEnvironment.h"
  8. #include "ExtendString.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CProductEnvironment::CProductEnvironment(CRequestObject *pObj, IWbemServices *pNamespace,
  13. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  14. {
  15. }
  16. CProductEnvironment::~CProductEnvironment()
  17. {
  18. }
  19. HRESULT CProductEnvironment::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
  20. {
  21. HRESULT hr = WBEM_S_NO_ERROR;
  22. MSIHANDLE hView = NULL;
  23. MSIHANDLE hRecord = NULL;
  24. int i = -1;
  25. WCHAR wcBuf[BUFF_SIZE];
  26. WCHAR wcProduct[BUFF_SIZE];
  27. WCHAR wcQuery[BUFF_SIZE];
  28. WCHAR wcProductCode[39];
  29. DWORD dwBufSize;
  30. UINT uiStatus;
  31. bool bMatch = false;
  32. bool bResource, bProduct;
  33. CStringExt wcResource;
  34. // safe operation
  35. // lenght is smaller than BUFF_SIZE ( 512 )
  36. wcscpy(wcQuery, L"select distinct `Environment`, `Component_` from Environment");
  37. LPWSTR Buffer = NULL;
  38. LPWSTR dynBuffer = NULL;
  39. DWORD dwDynBuffer = 0L;
  40. while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
  41. {
  42. // safe operation:
  43. // Package ( i ) returns NULL ( tested above ) or valid WCHAR [39]
  44. wcscpy(wcProductCode, m_pRequest->Package(i));
  45. if(CreateProductString(wcProductCode, wcProduct)){
  46. //Open our database
  47. try
  48. {
  49. if ( GetView ( &hView, wcProductCode, wcQuery, L"Environment", TRUE, FALSE ) )
  50. {
  51. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  52. while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
  53. CheckMSI(uiStatus);
  54. // safe operation
  55. wcResource.Copy ( L"Win32_EnvironmentSpecification.CheckID=\"" );
  56. if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
  57. //----------------------------------------------------
  58. dwBufSize = BUFF_SIZE;
  59. GetBufferToPut ( hRecord, 1, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  60. if ( Buffer && Buffer [ 0 ] != 0 )
  61. {
  62. wcResource.Append ( 3, Buffer, wcProductCode, L"\"" );
  63. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  64. {
  65. dynBuffer [ 0 ] = 0;
  66. }
  67. dwBufSize = BUFF_SIZE;
  68. GetBufferToPut ( hRecord, 2, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  69. if ( ValidateComponentName ( msidata.GetDatabase (), wcProductCode, Buffer ) )
  70. {
  71. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  72. {
  73. dynBuffer [ 0 ] = 0;
  74. }
  75. PutKeyProperty(m_pObj, pCheck, wcResource, &bResource, m_pRequest);
  76. PutKeyProperty(m_pObj, pProduct, wcProduct, &bProduct, m_pRequest);
  77. //====================================================
  78. //----------------------------------------------------
  79. if(bResource && bProduct) bMatch = true;
  80. if((atAction != ACTIONTYPE_GET) || bMatch){
  81. hr = pHandler->Indicate(1, &m_pObj);
  82. }
  83. }
  84. else
  85. {
  86. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  87. {
  88. dynBuffer [ 0 ] = 0;
  89. }
  90. }
  91. }
  92. m_pObj->Release();
  93. m_pObj = NULL;
  94. g_fpMsiCloseHandle(hRecord);
  95. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  96. }
  97. }
  98. }
  99. catch(...)
  100. {
  101. if ( dynBuffer )
  102. {
  103. delete [] dynBuffer;
  104. dynBuffer = NULL;
  105. }
  106. g_fpMsiCloseHandle(hRecord);
  107. g_fpMsiViewClose(hView);
  108. g_fpMsiCloseHandle(hView);
  109. msidata.CloseDatabase ();
  110. if(m_pObj)
  111. {
  112. m_pObj->Release();
  113. m_pObj = NULL;
  114. }
  115. throw;
  116. }
  117. g_fpMsiCloseHandle(hRecord);
  118. g_fpMsiViewClose(hView);
  119. g_fpMsiCloseHandle(hView);
  120. msidata.CloseDatabase ();
  121. }
  122. }
  123. if ( dynBuffer )
  124. {
  125. delete [] dynBuffer;
  126. dynBuffer = NULL;
  127. }
  128. return hr;
  129. }