mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:12:53 +02:00
Simple fallback now
If the bios uuid isn't a valid UUID (on mac or windows it 'should be`) then we read the fallback from the settings and use that, or create and write one to the settings if it is missing.
This commit is contained in:
parent
54716f70e5
commit
7880b5bfe0
2 changed files with 33 additions and 21 deletions
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include "FingerprintUtils.h"
|
#include "FingerprintUtils.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <SettingHandle.h>
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include <comdef.h>
|
#include <comdef.h>
|
||||||
#include <Wbemidl.h>
|
#include <Wbemidl.h>
|
||||||
|
@ -23,8 +23,11 @@
|
||||||
#include <IOKit/storage/IOMedia.h>
|
#include <IOKit/storage/IOMedia.h>
|
||||||
#endif //Q_OS_MAC
|
#endif //Q_OS_MAC
|
||||||
|
|
||||||
QString FingerprintUtils::getMachineFingerprint() {
|
static const QString FALLBACK_FINGERPRINT_KEY = "fallbackFingerprint";
|
||||||
QString retval;
|
|
||||||
|
QUuid FingerprintUtils::getMachineFingerprint() {
|
||||||
|
|
||||||
|
QString uuidString;
|
||||||
|
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
// sadly need to be root to get smbios guid from linux, so
|
// sadly need to be root to get smbios guid from linux, so
|
||||||
|
@ -35,9 +38,9 @@ QString FingerprintUtils::getMachineFingerprint() {
|
||||||
io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
|
io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
|
||||||
CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
|
CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
|
||||||
IOObjectRelease(ioRegistryRoot);
|
IOObjectRelease(ioRegistryRoot);
|
||||||
retval = QString::fromCFString(uuidCf);
|
uuidString = QString::fromCFString(uuidCf);
|
||||||
CFRelease(uuidCf);
|
CFRelease(uuidCf);
|
||||||
qDebug() << "Mac serial number: " << retval;
|
qDebug() << "Mac serial number: " << uuidString;
|
||||||
#endif //Q_OS_MAC
|
#endif //Q_OS_MAC
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
@ -53,7 +56,7 @@ QString FingerprintUtils::getMachineFingerprint() {
|
||||||
|
|
||||||
if (FAILED(hres)) {
|
if (FAILED(hres)) {
|
||||||
qDebug() << "Failed to initialize WbemLocator";
|
qDebug() << "Failed to initialize WbemLocator";
|
||||||
return retval;
|
return uuidString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to WMI through the IWbemLocator::ConnectServer method
|
// Connect to WMI through the IWbemLocator::ConnectServer method
|
||||||
|
@ -76,7 +79,7 @@ QString FingerprintUtils::getMachineFingerprint() {
|
||||||
if (FAILED(hres)) {
|
if (FAILED(hres)) {
|
||||||
pLoc->Release();
|
pLoc->Release();
|
||||||
qDebug() << "Failed to connect to WMI";
|
qDebug() << "Failed to connect to WMI";
|
||||||
return retval;
|
return uuidString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set security levels on the proxy
|
// Set security levels on the proxy
|
||||||
|
@ -95,7 +98,7 @@ QString FingerprintUtils::getMachineFingerprint() {
|
||||||
pSvc->Release();
|
pSvc->Release();
|
||||||
pLoc->Release();
|
pLoc->Release();
|
||||||
qDebug() << "Failed to set security on proxy blanket";
|
qDebug() << "Failed to set security on proxy blanket";
|
||||||
return retval;
|
return uuidString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the IWbemServices pointer to grab the Win32_BIOS stuff
|
// Use the IWbemServices pointer to grab the Win32_BIOS stuff
|
||||||
|
@ -111,7 +114,7 @@ QString FingerprintUtils::getMachineFingerprint() {
|
||||||
pSvc->Release();
|
pSvc->Release();
|
||||||
pLoc->Release();
|
pLoc->Release();
|
||||||
qDebug() << "query to get Win32_ComputerSystemProduct info";
|
qDebug() << "query to get Win32_ComputerSystemProduct info";
|
||||||
return retval;
|
return uuidString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the SerialNumber from the Win32_BIOS data
|
// Get the SerialNumber from the Win32_BIOS data
|
||||||
|
@ -134,7 +137,7 @@ QString FingerprintUtils::getMachineFingerprint() {
|
||||||
if (!FAILED(hres)) {
|
if (!FAILED(hres)) {
|
||||||
switch (vtProp.vt) {
|
switch (vtProp.vt) {
|
||||||
case VT_BSTR:
|
case VT_BSTR:
|
||||||
retval = QString::fromWCharArray(vtProp.bstrVal);
|
uuidString = QString::fromWCharArray(vtProp.bstrVal);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,13 +151,24 @@ QString FingerprintUtils::getMachineFingerprint() {
|
||||||
pSvc->Release();
|
pSvc->Release();
|
||||||
pLoc->Release();
|
pLoc->Release();
|
||||||
|
|
||||||
qDebug() << "Windows BIOS UUID: " << retval;
|
qDebug() << "Windows BIOS UUID: " << uuidString;
|
||||||
#endif //Q_OS_WIN
|
#endif //Q_OS_WIN
|
||||||
|
|
||||||
// TODO: should we have a fallback for cases where this failed,
|
// now, turn into uuid. A malformed string will
|
||||||
// leaving us with an empty string or something that isn't a
|
// return QUuid() ("{00000...}")
|
||||||
// guid? For now keeping this a string, but maybe best to return
|
QUuid uuid(uuidString);
|
||||||
// a QUuid?
|
if (uuid == QUuid()) {
|
||||||
return retval;
|
// read fallback key (if any)
|
||||||
|
Settings settings;
|
||||||
|
uuid = QUuid(settings.value(FALLBACK_FINGERPRINT_KEY).toString());
|
||||||
|
qDebug() << "read fallback maching fingerprint: " << uuid.toString();
|
||||||
|
if (uuid == QUuid()) {
|
||||||
|
// no fallback yet, set one
|
||||||
|
uuid = QUuid::createUuid();
|
||||||
|
settings.setValue(FALLBACK_FINGERPRINT_KEY, uuid.toString());
|
||||||
|
qDebug() << "no fallback machine fingerprint, setting it to: " << uuid.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,10 @@
|
||||||
#define hifi_FingerprintUtils_h
|
#define hifi_FingerprintUtils_h
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
namespace FingerprintUtils {
|
||||||
class FingerprintUtils {
|
QUuid getMachineFingerprint();
|
||||||
public:
|
|
||||||
static QString getMachineFingerprint();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_FingerprintUtils_h
|
#endif // hifi_FingerprintUtils_h
|
||||||
|
|
Loading…
Reference in a new issue