Opened 11 years ago

Closed 11 years ago

#5552 closed Bugs (fixed)

get_wmi_class_attribute hangs on win2003

Reported by: anonymous Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: interprocess
Version: Boost 1.46.1 Severity: Problem
Keywords: hang, COM Cc:

Description

I found this problem while I was using shared_memory. Function hangs on call to pIWbemLocator->ConnectServer.

The solution to this issue is changing CoInitialize(0) at the beginning of function to CoInitializeEx(0, COINIT_MULTITHREADED).

Change History (2)

comment:1 by Tsukasa Kusakabe <kusakabe@…>, 11 years ago

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

#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

  • boost/interprocess/detail/win32_api.hpp

     
    164164static unsigned long key_query_value    = 0x0001;
    165165
    166166//COM API
     167const long RPC_C_AUTHN_DEFAULT_IG = 0xffffffffL;
     168const long RPC_C_AUTHZ_DEFAULT_IG = 0xffffffffL;
    167169const long RPC_C_AUTHN_LEVEL_PKT_IG = 4;
    168170const long RPC_C_IMP_LEVEL_IMPERSONATE_IG = 3;
    169171const long EOAC_NONE_IG = 0;
     
    865867                    void                        *pAuthList,
    866868                    unsigned long                        dwCapabilities,
    867869                    void                        *pReserved3 );
     870extern "C" __declspec(dllimport) long __stdcall CoSetProxyBlanket(
     871                    IUnknown_IG *pProxy,
     872                    unsigned long dwAuthnSvc,
     873                    unsigned long dwAuthzSvc,
     874                    wchar_t *pServerPrincName,
     875                    unsigned long dwAuthnLevel,
     876                    unsigned long dwImpLevel,
     877                    void *pAuthInfo,
     878                    unsigned long dwCapabilities);
    868879
    869880extern "C" __declspec(dllimport) long __stdcall VariantClear(wchar_variant * pvarg);
    870881extern "C" __declspec(dllimport) long __stdcall CoCreateInstance(const GUID_IG & rclsid, IUnknown_IG *pUnkOuter,
     
    16481659         return false;
    16491660      }
    16501661
     1662      if( S_OK_IG != CoSetProxyBlanket(
     1663            pWbemServices,
     1664            RPC_C_AUTHN_DEFAULT_IG,
     1665            RPC_C_AUTHZ_DEFAULT_IG,
     1666            NULL,
     1667            RPC_C_AUTHN_LEVEL_PKT_IG,
     1668            RPC_C_IMP_LEVEL_IMPERSONATE_IG,
     1669            NULL,
     1670            EOAC_NONE_IG
     1671            )
     1672         ){
     1673         return false;
     1674      }
     1675
    16511676      com_releaser<IWbemServices_IG> IWbemServices_releaser(pWbemServices);
    16521677
    16531678      strValue.clear();

comment:2 by Ion Gaztañaga, 11 years ago

Resolution: fixed
Status: newclosed

Fixed in trunk, thanks for the patch. From 1.48, use of WMI is disabled, but I would be grateful if someone could enable it again uncommentting

#define BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME

#define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME

#include <boost/interprocess/detail/win32_api.hpp>

in detail/tmp_dir_helpders.hpp

so that we can enable it again.

Note: See TracTickets for help on using tickets.