From e39a973778198c638c5062d4e2e436bfa24a13c0 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Mon, 3 Jun 2024 15:06:21 +0200 Subject: [PATCH] ntdll: Provide fallback values for DMI fields only readable by root. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56744 --- dlls/ntdll/unix/system.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index b0d87dbc6bd..eb5e60af7b9 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -1700,6 +1700,32 @@ static GUID *get_system_uuid( GUID *uuid ) return uuid; } +static const char *get_system_serial( char *str, size_t size ) +{ + get_smbios_string( "/sys/class/dmi/id/product_serial", str, size ); + if (!str[0]) strcpy( str, "System Serial Number" ); + return str; +} + +static const char *get_chassis_serial( char *str, size_t size ) +{ + get_smbios_string( "/sys/class/dmi/id/chassis_serial", str, size ); + if (!str[0]) strcpy( str, "Chassis Serial Number" ); + return str; +} + +static const char *get_board_serial( char *str, size_t size, const GUID *uuid ) +{ + get_smbios_string( "/sys/class/dmi/id/board_serial", str, size ); + if (!str[0]) + { + const BYTE *p = (const BYTE *)uuid; + snprintf( str, 33, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", p[0], p[1], + p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15] ); + } + return str; +} + static struct smbios_prologue *create_smbios_data(void) { char vendor[128], version[128], date[128], product[128], serial[128]; @@ -1718,7 +1744,7 @@ static struct smbios_prologue *create_smbios_data(void) get_smbios_string( "/sys/class/dmi/id/sys_vendor", S(vendor) ), get_smbios_string( "/sys/class/dmi/id/product_name", S(product) ), get_smbios_string( "/sys/class/dmi/id/product_version", S(version) ), - get_smbios_string( "/sys/class/dmi/id/product_serial", S(serial) ), + get_system_serial( S(serial) ), get_smbios_string( "/sys/class/dmi/id/product_sku", S(sku) ), get_smbios_string( "/sys/class/dmi/id/product_family", S(family) ), get_system_uuid( &uuid )); @@ -1727,14 +1753,14 @@ static struct smbios_prologue *create_smbios_data(void) chassis = append_smbios_chassis( &buf, atoi(type), get_smbios_string( "/sys/class/dmi/id/chassis_vendor", S(vendor) ), get_smbios_string( "/sys/class/dmi/id/chassis_version", S(version) ), - get_smbios_string( "/sys/class/dmi/id/chassis_serial", S(serial) ), + get_chassis_serial( S(serial) ), get_smbios_string( "/sys/class/dmi/id/chassis_tag", S(asset_tag) )); append_smbios_board( &buf, chassis, get_smbios_string( "/sys/class/dmi/id/board_vendor", S(vendor) ), get_smbios_string( "/sys/class/dmi/id/board_name", S(product) ), get_smbios_string( "/sys/class/dmi/id/board_version", S(version) ), - get_smbios_string( "/sys/class/dmi/id/board_serial", S(serial) ), + get_board_serial( S(serial), &uuid ), get_smbios_string( "/sys/class/dmi/id/board_asset_tag", S(asset_tag) )); #undef S