Use /etc/machine-id as unique id on Linux

This commit is contained in:
Lukas Matena 2021-10-01 13:32:04 +02:00
parent 1bef2eacc5
commit e8412d654c
2 changed files with 19 additions and 2 deletions

View File

@ -279,9 +279,25 @@ static std::string get_unique_id()
for (char* c = buf; *c != 0; ++c) for (char* c = buf; *c != 0; ++c)
unique.emplace_back((unsigned char)(*c)); unique.emplace_back((unsigned char)(*c));
#else // Linux/BSD #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<unsigned char>.
for (char* c = cline; *c != 0; ++c)
unique.emplace_back((unsigned char)(*c));
#endif #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<unsigned char>. Append a long prime to be // We should have a unique vector<unsigned char>. Append a long prime to be
// absolutely safe against unhashing. // absolutely safe against unhashing.
uint64_t prime = 1171432692373; uint64_t prime = 1171432692373;
@ -306,7 +322,6 @@ static std::string get_unique_id()
// and later sent if confirmed by the user. // and later sent if confirmed by the user.
static std::string generate_system_info_json() static std::string generate_system_info_json()
{ {
get_unique_id();
// Calculate hash of username so it is possible to identify duplicates. // 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 // 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 // not possible to unhash the username. It is more than enough to help

View File

@ -9,6 +9,8 @@
#include <libslic3r/format.hpp> #include <libslic3r/format.hpp>
#include <wx/string.h>
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {