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.

198 lines
5.4 KiB

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