Re: [Boost-bugs] [Boost C++ Libraries] #5552: get_wmi_class_attribute hangs on win2003

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5552: get_wmi_class_attribute hangs on win2003
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-09-06 04:20:53


#5552: get_wmi_class_attribute hangs on win2003
-------------------------------+--------------------------------------------
  Reporter: anonymous | Owner: igaztanaga
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: interprocess
   Version: Boost 1.46.1 | Severity: Problem
Resolution: | Keywords: hang, COM
-------------------------------+--------------------------------------------

Comment (by Tsukasa Kusakabe <kusakabe@…>):

 This problem is irrelevant to "CoInitializeEx(0, COINIT_MULTITHREADED)".
 (There is a possibility of operating by chance.)

 The problem is dependence on "CoInitializeSecurity" that cannot be used
 two times or more.

 Therefore, the problem that "ExecQuery" fails when "CoInitializeSecurity"
 has already been used happens.
 (Please refer to the following reproduction code.)

 Solving it by using both "CoInitializeSecurity" and "CoSetProxyBlanket" is
 correct.

  === Reproduction code ===
 {{{
 #!cpp

 #include <iostream>
 #include <Windows.h>
 #include <boost/interprocess/detail/win32_api.hpp>

 int main() {
         ::CoInitialize(NULL);
         ::CoInitializeSecurity(
                 NULL,
                 -1,
                 NULL,
                 NULL,
                 RPC_C_AUTHN_LEVEL_CONNECT,
                 RPC_C_IMP_LEVEL_IDENTIFY,
                 NULL,
                 EOAC_NONE,
                 NULL);
         std::string str;
         const bool result =
 boost::interprocess::winapi::get_last_bootup_time(str);
         const char * const boolean[2] = {"true", "false"};
         std::cout << boolean[result ? 0 : 1] << ":" << str << std::endl;
 // => "false:Select LastBootUpTime from Win32_OperatingSystem"
         return 0;
 }
 }}}

  === Patch ===
 {{{
 #!diff

 Index: boost/interprocess/detail/win32_api.hpp
 ===================================================================
 --- boost/interprocess/detail/win32_api.hpp (revision 74236)
 +++ boost/interprocess/detail/win32_api.hpp (working copy)
 @@ -164,6 +164,8 @@
  static unsigned long key_query_value = 0x0001;

  //COM API
 +const long RPC_C_AUTHN_DEFAULT_IG = 0xffffffffL;
 +const long RPC_C_AUTHZ_DEFAULT_IG = 0xffffffffL;
  const long RPC_C_AUTHN_LEVEL_PKT_IG = 4;
  const long RPC_C_IMP_LEVEL_IMPERSONATE_IG = 3;
  const long EOAC_NONE_IG = 0;
 @@ -865,6 +867,15 @@
                      void *pAuthList,
                      unsigned long dwCapabilities,
                      void *pReserved3 );
 +extern "C" __declspec(dllimport) long __stdcall CoSetProxyBlanket(
 + IUnknown_IG *pProxy,
 + unsigned long dwAuthnSvc,
 + unsigned long dwAuthzSvc,
 + wchar_t *pServerPrincName,
 + unsigned long dwAuthnLevel,
 + unsigned long dwImpLevel,
 + void *pAuthInfo,
 + unsigned long dwCapabilities);

  extern "C" __declspec(dllimport) long __stdcall
 VariantClear(wchar_variant * pvarg);
  extern "C" __declspec(dllimport) long __stdcall CoCreateInstance(const
 GUID_IG & rclsid, IUnknown_IG *pUnkOuter,
 @@ -1648,6 +1659,20 @@
           return false;
        }

 + if( S_OK_IG != CoSetProxyBlanket(
 + pWbemServices,
 + RPC_C_AUTHN_DEFAULT_IG,
 + RPC_C_AUTHZ_DEFAULT_IG,
 + NULL,
 + RPC_C_AUTHN_LEVEL_PKT_IG,
 + RPC_C_IMP_LEVEL_IMPERSONATE_IG,
 + NULL,
 + EOAC_NONE_IG
 + )
 + ){
 + return false;
 + }
 +
        com_releaser<IWbemServices_IG>
 IWbemServices_releaser(pWbemServices);

        strValue.clear();
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5552#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC