From e8412d654ca0b6ebf0f24939517f501e08ac6b74 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 1 Oct 2021 13:32:04 +0200 Subject: [PATCH] Use /etc/machine-id as unique id on Linux --- src/slic3r/GUI/SendSystemInfoDialog.cpp | 19 +++++++++++++++++-- src/slic3r/GUI/format.hpp | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/SendSystemInfoDialog.cpp b/src/slic3r/GUI/SendSystemInfoDialog.cpp index 34178133f..ee1e4c5c3 100644 --- a/src/slic3r/GUI/SendSystemInfoDialog.cpp +++ b/src/slic3r/GUI/SendSystemInfoDialog.cpp @@ -279,9 +279,25 @@ static std::string get_unique_id() for (char* c = buf; *c != 0; ++c) unique.emplace_back((unsigned char)(*c)); #else // Linux/BSD - + constexpr size_t max_len = 100; + char cline[max_len] = ""; + FILE* fp = popen("cat /etc/machine-id", "r"); + if (fp != NULL) { + // Maybe the only way to silence -Wunused-result on gcc... + // cline is simply not modified on failure, who cares. + [[maybe_unused]]auto dummy = fgets(cline, max_len, fp); + pclose(fp); + } + // Now convert the string to std::vector. + for (char* c = cline; *c != 0; ++c) + unique.emplace_back((unsigned char)(*c)); #endif + // In case that we did not manage to get the unique info, just return an empty + // string, so it is easily detectable and not masked by the hashing. + if (unique.empty()) + return ""; + // We should have a unique vector. Append a long prime to be // absolutely safe against unhashing. uint64_t prime = 1171432692373; @@ -306,7 +322,6 @@ static std::string get_unique_id() // and later sent if confirmed by the user. static std::string generate_system_info_json() { - get_unique_id(); // Calculate hash of username so it is possible to identify duplicates. // The result is mod 10000 so most of the information is lost and it is // not possible to unhash the username. It is more than enough to help diff --git a/src/slic3r/GUI/format.hpp b/src/slic3r/GUI/format.hpp index 894803917..928171cd5 100644 --- a/src/slic3r/GUI/format.hpp +++ b/src/slic3r/GUI/format.hpp @@ -9,6 +9,8 @@ #include +#include + namespace Slic3r { namespace GUI {