From b1ceb7853cf0d7abe99fd917e65a22507795f7de Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Thu, 22 Oct 2020 21:25:49 +0200 Subject: [PATCH] wbemprox: Also return system properties from IWbemClassObject::GetNames. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50038 Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/wbemprox/query.c | 67 ++++++++++++++++++++++++------------- dlls/wbemprox/tests/query.c | 17 ++++++++++ 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/dlls/wbemprox/query.c b/dlls/wbemprox/query.c index 525381d88d2..3d60825f24e 100644 --- a/dlls/wbemprox/query.c +++ b/dlls/wbemprox/query.c @@ -1375,40 +1375,61 @@ HRESULT put_propval( const struct view *view, UINT index, const WCHAR *name, VAR HRESULT get_properties( const struct view *view, UINT index, LONG flags, SAFEARRAY **props ) { + static const WCHAR * const system_props[] = + { L"__GENUS", L"__CLASS", L"__RELPATH", L"__PROPERTY_COUNT", L"__SERVER", L"__NAMESPACE", L"__PATH" }; SAFEARRAY *sa; BSTR str; - UINT i, table_index, result_index, num_props; + UINT i, table_index, result_index, count = 0; struct table *table; HRESULT hr; - LONG j; + LONG j = 0; if ((hr = map_view_index( view, index, &table_index, &result_index )) != S_OK) return hr; - - num_props = count_result_properties( view, table_index ); - if (!(sa = SafeArrayCreateVector( VT_BSTR, 0, num_props ))) return E_OUTOFMEMORY; - table = view->table[table_index]; - for (i = 0, j = 0; i < table->num_cols; i++) + + if (!(flags & WBEM_FLAG_NONSYSTEM_ONLY)) count += ARRAY_SIZE(system_props); + if (!(flags & WBEM_FLAG_SYSTEM_ONLY)) { - BOOL is_system; - - if (is_method( table, i )) continue; - if (!is_result_prop( view, table->columns[i].name )) continue; - - is_system = is_system_prop( table->columns[i].name ); - if ((flags & WBEM_FLAG_NONSYSTEM_ONLY) && is_system) continue; - else if ((flags & WBEM_FLAG_SYSTEM_ONLY) && !is_system) continue; - - str = SysAllocString( table->columns[i].name ); - if (!str || SafeArrayPutElement( sa, &j, str ) != S_OK) + for (i = 0; i < table->num_cols; i++) { - SysFreeString( str ); - SafeArrayDestroy( sa ); - return E_OUTOFMEMORY; + if (!is_method( table, i ) && is_result_prop( view, table->columns[i].name )) count++; } - SysFreeString( str ); - j++; } + + if (!(sa = SafeArrayCreateVector( VT_BSTR, 0, count ))) return E_OUTOFMEMORY; + + if (!(flags & WBEM_FLAG_NONSYSTEM_ONLY)) + { + for (j = 0; j < ARRAY_SIZE(system_props); j++) + { + str = SysAllocString( system_props[j] ); + if (!str || SafeArrayPutElement( sa, &j, str ) != S_OK) + { + SysFreeString( str ); + SafeArrayDestroy( sa ); + return E_OUTOFMEMORY; + } + SysFreeString( str ); + } + } + if (!(flags & WBEM_FLAG_SYSTEM_ONLY)) + { + for (i = 0; i < table->num_cols; i++) + { + if (is_method( table, i ) || !is_result_prop( view, table->columns[i].name )) continue; + + str = SysAllocString( table->columns[i].name ); + if (!str || SafeArrayPutElement( sa, &j, str ) != S_OK) + { + SysFreeString( str ); + SafeArrayDestroy( sa ); + return E_OUTOFMEMORY; + } + SysFreeString( str ); + j++; + } + } + *props = sa; return S_OK; } diff --git a/dlls/wbemprox/tests/query.c b/dlls/wbemprox/tests/query.c index d1ce42d64cb..7ba55dffdfb 100644 --- a/dlls/wbemprox/tests/query.c +++ b/dlls/wbemprox/tests/query.c @@ -460,6 +460,8 @@ static void test_Win32_Process( IWbemServices *services, BOOL use_full_path ) IWbemClassObject *process, *sig_in, *out; IWbemQualifierSet *qualifiers; VARIANT retval, val; + SAFEARRAY *names; + LONG bound, i; DWORD full_path_len = 0; LONG flavor; CIMTYPE type; @@ -484,6 +486,21 @@ static void test_Win32_Process( IWbemServices *services, BOOL use_full_path ) win_skip( "Win32_Process not available\n" ); return; } + names = NULL; + hr = IWbemClassObject_GetNames( process, NULL, 0, NULL, &names ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( names != NULL, "names not set\n" ); + hr = SafeArrayGetUBound( names, 1, &bound ); + ok( hr == S_OK, "got %08x\n", hr ); + for (i = 0; i <= bound; i++) + { + BSTR str; + hr = SafeArrayGetElement( names, &i, &str ); + ok( hr == S_OK, "%d: got %08x\n", i, hr ); + SysFreeString( str ); + } + SafeArrayDestroy( names ); + sig_in = (void*)0xdeadbeef; hr = IWbemClassObject_GetMethod( process, L"GetOwner", 0, &sig_in, NULL ); ok( hr == S_OK, "failed to get GetOwner method %08x\n", hr );