Hans Leidekker : wbemprox: Implement Win32_NetworkAdapter.GUID.

Alexandre Julliard julliard at winehq.org
Thu Jan 21 16:19:15 CST 2021


Module: wine
Branch: master
Commit: ebff7de0c986f68b9c065e513c7a6bd125f3f616
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=ebff7de0c986f68b9c065e513c7a6bd125f3f616

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Thu Jan 21 12:36:39 2021 +0100

wbemprox: Implement Win32_NetworkAdapter.GUID.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50256
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wbemprox/builtin.c     | 27 ++++++++++++++++++++++-----
 dlls/wbemprox/tests/query.c | 27 +++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/dlls/wbemprox/builtin.c b/dlls/wbemprox/builtin.c
index 39166a21171..d33cf1d03cc 100644
--- a/dlls/wbemprox/builtin.c
+++ b/dlls/wbemprox/builtin.c
@@ -197,6 +197,7 @@ static const struct column col_networkadapter[] =
     { L"AdapterTypeID",       CIM_UINT16 },
     { L"Description",         CIM_STRING|COL_FLAG_DYNAMIC },
     { L"DeviceId",            CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
+    { L"GUID",                CIM_STRING|COL_FLAG_DYNAMIC },
     { L"Index",               CIM_UINT32 },
     { L"InterfaceIndex",      CIM_UINT32 },
     { L"MACAddress",          CIM_STRING|COL_FLAG_DYNAMIC },
@@ -603,6 +604,7 @@ struct record_networkadapter
     UINT16       adaptertypeid;
     const WCHAR *description;
     const WCHAR *device_id;
+    const WCHAR *guid;
     UINT32       index;
     UINT32       interface_index;
     const WCHAR *mac_address;
@@ -2651,6 +2653,24 @@ static const WCHAR *get_adaptertype( DWORD type, int *id, int *physical )
     }
 }
 
+#define GUID_SIZE 39
+static WCHAR *guid_to_str( const GUID *ptr )
+{
+    WCHAR *ret;
+    if (!(ret = heap_alloc( GUID_SIZE * sizeof(WCHAR) ))) return NULL;
+    swprintf( ret, GUID_SIZE, L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
+              ptr->Data1, ptr->Data2, ptr->Data3, ptr->Data4[0], ptr->Data4[1], ptr->Data4[2],
+              ptr->Data4[3], ptr->Data4[4], ptr->Data4[5], ptr->Data4[6], ptr->Data4[7] );
+    return ret;
+}
+
+static WCHAR *get_networkadapter_guid( const IF_LUID *luid )
+{
+    GUID guid;
+    if (ConvertInterfaceLuidToGuid( luid, &guid )) return NULL;
+    return guid_to_str( &guid );
+}
+
 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
 {
     WCHAR device_id[11];
@@ -2689,6 +2709,7 @@ static enum fill_status fill_networkadapter( struct table *table, const struct e
         rec->adaptertypeid        = adaptertypeid;
         rec->description          = heap_strdupW( aa->Description );
         rec->device_id            = heap_strdupW( device_id );
+        rec->guid                 = get_networkadapter_guid( &aa->Luid );
         rec->index                = aa->u.s.IfIndex;
         rec->interface_index      = aa->u.s.IfIndex;
         rec->mac_address          = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
@@ -2877,13 +2898,9 @@ static struct array *get_ipsubnet( IP_ADAPTER_UNICAST_ADDRESS_LH *list )
 static WCHAR *get_settingid( UINT32 index )
 {
     GUID guid;
-    WCHAR *ret, *str;
     memset( &guid, 0, sizeof(guid) );
     guid.Data1 = index;
-    UuidToStringW( &guid, &str );
-    ret = heap_strdupW( str );
-    RpcStringFreeW( &str );
-    return ret;
+    return guid_to_str( &guid );
 }
 
 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
diff --git a/dlls/wbemprox/tests/query.c b/dlls/wbemprox/tests/query.c
index 67c0b218ce1..5a59f0a8f8f 100644
--- a/dlls/wbemprox/tests/query.c
+++ b/dlls/wbemprox/tests/query.c
@@ -1144,6 +1144,32 @@ static void test_SystemSecurity( IWbemServices *services )
     SysFreeString( class );
 }
 
+static void test_Win32_NetworkAdapter( IWbemServices *services )
+{
+    BSTR wql = SysAllocString( L"wql" ), query = SysAllocString( L"SELECT * FROM Win32_NetworkAdapter" );
+    IEnumWbemClassObject *result;
+    IWbemClassObject *obj;
+    HRESULT hr;
+    DWORD count;
+
+    hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
+    ok( hr == S_OK, "got %08x\n", hr );
+
+    for (;;)
+    {
+        hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
+        if (hr != S_OK) break;
+
+        check_property( obj, L"DeviceID", VT_BSTR, CIM_STRING );
+        check_property( obj, L"Index", VT_I4, CIM_UINT32 );
+        IWbemClassObject_Release( obj );
+    }
+
+    IEnumWbemClassObject_Release( result );
+    SysFreeString( query );
+    SysFreeString( wql );
+}
+
 static void test_Win32_OperatingSystem( IWbemServices *services )
 {
     BSTR wql = SysAllocString( L"wql" ), query = SysAllocString( L"SELECT * FROM Win32_OperatingSystem" );
@@ -1874,6 +1900,7 @@ START_TEST(query)
     test_Win32_DiskDrive( services );
     test_Win32_DisplayControllerConfiguration( services );
     test_Win32_IP4RouteTable( services );
+    test_Win32_NetworkAdapter( services );
     test_Win32_OperatingSystem( services );
     test_Win32_PhysicalMemory( services );
     test_Win32_PnPEntity( services );




More information about the wine-cvs mailing list