|
|
462afb |
From 1dffef87fc2f07763f64eeabc1ea891e68d23541 Mon Sep 17 00:00:00 2001
|
|
|
462afb |
From: Michal Domonkos <mdomonko@redhat.com>
|
|
|
462afb |
Date: Tue, 26 Nov 2019 13:05:49 +0100
|
|
|
462afb |
Subject: [PATCH] [user-agent] Drop the whitelist
|
|
|
462afb |
|
|
|
462afb |
- Stop checking os-release(5) data against a hard-coded whitelist and
|
|
|
462afb |
just use them as they are, to avoid a maintenance burden in the
|
|
|
462afb |
future (see [1] for details)
|
|
|
462afb |
|
|
|
462afb |
- Clean up the getUserAgent() function a bit
|
|
|
462afb |
|
|
|
462afb |
Note that, by removing the whitelist, there's a risk of leaking a
|
|
|
462afb |
"unique" value from the os-release file now, but a rather small one.
|
|
|
462afb |
|
|
|
462afb |
[1] https://github.com/rpm-software-management/libdnf/pull/851
|
|
|
462afb |
---
|
|
|
462afb |
libdnf/utils/os-release.cpp | 58 ++++++++++++++++++++--------------------------------------
|
|
|
462afb |
libdnf/utils/os-release.hpp | 7 ++-----
|
|
|
462afb |
2 files changed, 22 insertions(+), 43 deletions(-)
|
|
|
462afb |
|
|
|
462afb |
diff --git a/libdnf/utils/os-release.cpp b/libdnf/utils/os-release.cpp
|
|
|
462afb |
index 57be110..1d8a95b 100644
|
|
|
462afb |
--- a/libdnf/utils/os-release.cpp
|
|
|
462afb |
+++ b/libdnf/utils/os-release.cpp
|
|
|
462afb |
@@ -36,17 +36,8 @@
|
|
|
462afb |
namespace libdnf {
|
|
|
462afb |
|
|
|
462afb |
// sorted by precedence (see os-release(5) for details)
|
|
|
462afb |
-static const std::array<const std::string, 2> paths = {"/etc/os-release", "/usr/lib/os-release"};
|
|
|
462afb |
-// whitelists used for sanity-checking the os-release data when constructing a
|
|
|
462afb |
-// User-Agent string (to avoid reporting rare systems or platforms that could
|
|
|
462afb |
-// be tracked)
|
|
|
462afb |
-static const std::map<std::string, std::vector<std::string>> distros = {
|
|
|
462afb |
- // taken from the {fedora,generic}-release.spec files
|
|
|
462afb |
- { "Fedora", { "cinnamon", "cloud", "container", "coreos", "generic", "iot",
|
|
|
462afb |
- "kde", "matecompiz", "server", "silverblue", "snappy", "soas",
|
|
|
462afb |
- "workstation", "xfce" } },
|
|
|
462afb |
-};
|
|
|
462afb |
-std::array<const std::string, 1> canons = { "Linux" };
|
|
|
462afb |
+static const std::array<const std::string, 2>
|
|
|
462afb |
+paths = {"/etc/os-release", "/usr/lib/os-release"};
|
|
|
462afb |
|
|
|
462afb |
std::map<std::string, std::string> getOsReleaseData()
|
|
|
462afb |
{
|
|
|
462afb |
@@ -118,47 +109,38 @@ std::string getUserAgent(const std::map<std::string, std::string> & osReleaseDat
|
|
|
462afb |
{
|
|
|
462afb |
std::ostringstream oss;
|
|
|
462afb |
auto logger(Log::getLogger());
|
|
|
462afb |
- std::string msg = "os-release: falling back to basic User-Agent";
|
|
|
462afb |
|
|
|
462afb |
- // start with the basic libdnf string
|
|
|
462afb |
oss << USER_AGENT;
|
|
|
462afb |
+ std::string fallback = oss.str();
|
|
|
462afb |
|
|
|
462afb |
- // mandatory OS data (bail out if missing or unknown)
|
|
|
462afb |
if (!osReleaseData.count("NAME") || !osReleaseData.count("VERSION_ID")) {
|
|
|
462afb |
- logger->debug(tfm::format("%s: missing NAME or VERSION_ID", msg));
|
|
|
462afb |
- return oss.str();
|
|
|
462afb |
+ logger->debug(tfm::format(
|
|
|
462afb |
+ "User-Agent: falling back to '%s': missing NAME or VERSION_ID",
|
|
|
462afb |
+ fallback
|
|
|
462afb |
+ ));
|
|
|
462afb |
+ return fallback;
|
|
|
462afb |
}
|
|
|
462afb |
std::string name = osReleaseData.at("NAME");
|
|
|
462afb |
std::string version = osReleaseData.at("VERSION_ID");
|
|
|
462afb |
- if (!distros.count(name)) {
|
|
|
462afb |
- logger->debug(tfm::format("%s: distro %s not whitelisted", msg, name));
|
|
|
462afb |
- return oss.str();
|
|
|
462afb |
- }
|
|
|
462afb |
+ std::string variant = "generic";
|
|
|
462afb |
+ if (osReleaseData.count("VARIANT_ID"))
|
|
|
462afb |
+ variant = osReleaseData.at("VARIANT_ID");
|
|
|
462afb |
|
|
|
462afb |
- // mandatory platform data from RPM (bail out if missing or unknown)
|
|
|
462afb |
std::string canon = getCanonOs();
|
|
|
462afb |
std::string arch = getBaseArch();
|
|
|
462afb |
- if (canon.empty() || arch.empty()
|
|
|
462afb |
- || std::find(canons.begin(), canons.end(), canon) == canons.end()) {
|
|
|
462afb |
- logger->debug(tfm::format("%s: could not detect canonical OS or basearch", msg));
|
|
|
462afb |
- return oss.str();
|
|
|
462afb |
- }
|
|
|
462afb |
-
|
|
|
462afb |
- // optional OS data (use fallback values if missing or unknown)
|
|
|
462afb |
- std::string variant = "generic";
|
|
|
462afb |
- auto list = distros.at(name);
|
|
|
462afb |
- if (osReleaseData.count("VARIANT_ID")) {
|
|
|
462afb |
- std::string value = osReleaseData.at("VARIANT_ID");
|
|
|
462afb |
- if (std::find(list.begin(), list.end(), value) != list.end())
|
|
|
462afb |
- variant = value;
|
|
|
462afb |
+ if (canon.empty() || arch.empty()) {
|
|
|
462afb |
+ logger->debug(tfm::format(
|
|
|
462afb |
+ "User-Agent: falling back to '%s': could not detect OS or basearch",
|
|
|
462afb |
+ fallback
|
|
|
462afb |
+ ));
|
|
|
462afb |
+ return fallback;
|
|
|
462afb |
}
|
|
|
462afb |
|
|
|
462afb |
- // good to go!
|
|
|
462afb |
- oss << " (" << name << " " << version << "; " << variant << "; "
|
|
|
462afb |
- << canon << "." << arch << ")";
|
|
|
462afb |
+ oss << " (" << name << " " << version << "; " << variant << "; " << canon
|
|
|
462afb |
+ << "." << arch << ")";
|
|
|
462afb |
|
|
|
462afb |
std::string result = oss.str();
|
|
|
462afb |
- logger->debug(tfm::format("os-release: User-Agent constructed: %s", result));
|
|
|
462afb |
+ logger->debug(tfm::format("User-Agent: constructed: '%s'", result));
|
|
|
462afb |
return result;
|
|
|
462afb |
}
|
|
|
462afb |
|
|
|
462afb |
diff --git a/libdnf/utils/os-release.hpp b/libdnf/utils/os-release.hpp
|
|
|
462afb |
index ef4d14f..e7b24a7 100644
|
|
|
462afb |
--- a/libdnf/utils/os-release.hpp
|
|
|
462afb |
+++ b/libdnf/utils/os-release.hpp
|
|
|
462afb |
@@ -50,11 +50,8 @@ getOsReleaseData();
|
|
|
462afb |
* libdnf (NAME VERSION_ID; VARIANT_ID; OS.BASEARCH)
|
|
|
462afb |
*
|
|
|
462afb |
* where NAME, VERSION_ID and VARIANT_ID are OS identifiers read from the
|
|
|
462afb |
- * passed os-release data, and OS and BASEARCH (if found) are the canonical OS
|
|
|
462afb |
- * name and base architecture, respectively, detected using RPM.
|
|
|
462afb |
- *
|
|
|
462afb |
- * Note that the OS part (enclosed in parentheses) will only be included for
|
|
|
462afb |
- * whitelisted values.
|
|
|
462afb |
+ * passed os-release data, and OS and BASEARCH are the canonical OS name and
|
|
|
462afb |
+ * base architecture, respectively, detected using RPM.
|
|
|
462afb |
*
|
|
|
462afb |
* @param osReleaseData a map containing os-release data (will be loaded from
|
|
|
462afb |
* disk if not specified)
|
|
|
462afb |
--
|
|
|
462afb |
libgit2 0.28.2
|
|
|
462afb |
|