Just like the "reboot" UUID, I couldn't just leave this UUID not working
on Windows. Remove the commented out failed implementation and replace
it with something else that works. "WMIC" to the rescue.
Signed-off-by: Russell Bryant <rbryant(a)redhat.com>
---
src/host/schema.xml | 2 +-
src/lib/host_windows.c | 65 +++++++++++++++++++++++++-----------------------
2 files changed, 35 insertions(+), 32 deletions(-)
diff --git a/src/host/schema.xml b/src/host/schema.xml
index 904a3ab..cb179cf 100644
--- a/src/host/schema.xml
+++ b/src/host/schema.xml
@@ -53,7 +53,7 @@
<varlistentry><term><literal>Hardware</literal></term>
<listitem><para>
- UUID supplied by or generated from the underlying hardware. (Linux only).
+ UUID supplied by or generated from the underlying hardware.
</para></listitem>
</varlistentry>
diff --git a/src/lib/host_windows.c b/src/lib/host_windows.c
index 5031c4f..aae2166 100644
--- a/src/lib/host_windows.c
+++ b/src/lib/host_windows.c
@@ -103,51 +103,54 @@ host_os_identify(void)
char *
host_os_machine_uuid(void)
{
-#if 0
- UINT res;
- char *uuid = NULL;
- struct RawSMBIOSDData *smbios_data;
+ gchar *output = NULL, *begin, *end;
+ char *ret;
+ GError *error = NULL;
+ gboolean res;
+ gchar *argv[] = { "WMIC", "CSPRODUCT", "Get",
"UUID", NULL };
- /*
- * Doc on SMBIOS support in windows:
- *
http://msdn.microsoft.com/en-us/windows/hardware/gg463136
- *
- * See GetSystemFirmwareTable()
- *
http://msdn.microsoft.com/en-us/library/ms724379%28v=VS.85%29.aspx
- */
+ res = g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
+ NULL, NULL, &output, NULL, NULL, &error);
- res = GetSystemFirmwareTable('RSMB', 0, NULL, 0);
+ if (res == FALSE) {
+ mh_err("Failed to run WMIC.exe to get SMBIOS UUID: %s\n",
error->message);
+ g_error_free(error);
+ error = NULL;
+ }
- if (!res) {
- mh_info("Failed to get required SMBIOS buffer size.");
- return NULL;
+ if (!output) {
+ mh_err("Got no output from WMIC.exe when trying to get SMBIOS
UUID.\n");
+ return -1;
}
- if (!(buf = malloc(res))) {
- return NULL;
+ if (!(begin = strstr(output, "\r\n"))) {
+ mh_err("Unexpected format of output: '%s'", output);
+ g_free(output);
+ return -1;
}
- res = GetSystemFirmwareTable('RSMB', 0, (void *) smbios_data, res);
+ begin += 2;
- if (!res) {
- mh_info("Failed to get SMBIOS data.");
- goto return_cleanup;
+ if (mh_strlen_zero(begin)) {
+ mh_err("Unexpected format of output: '%s'", output);
+ g_free(output);
+ return -1;
}
- uuid = find_uuid(smbios_data->SMBIOSTableData, smbios_data->Length);
-
-return_cleanup:
+ if (!(end = strstr(begin, "\r\n"))) {
+ mh_err("Unexpected format of output: '%s'", output);
+ g_free(output);
+ return -1;
+ }
- free(buf);
+ *end = '\0';
- return uuid;
-#endif
+ ret = strdup(begin);
- /*
- * GetSystemFirmwareTable() does not appear to be available with mingw32.
- */
+ g_free(output);
+ output = NULL;
- return NULL;
+ return ret;
}
/**
--
1.7.6.2