From 29a79857c3cb53a94007bb7887234d2fe27850b2 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 25 Mar 2020 17:31:12 +0100 Subject: ubuntu: http: Add non-interactive to user agent if run by systemd Include that apt is being run from a service in the user agent, so traffic can be analysed for interactive vs non-interactive use, and prioritised accordingly. It looks like this now: User-Agent: Debian APT-HTTP/1.3 (2.0.1) non-interactive A previous version included the full service names, but this raised some privacy concerns. LP: #1825000 --- doc/examples/configure-index | 1 + methods/CMakeLists.txt | 3 ++- methods/http.cc | 20 +++++++++++++++++++- vendor/ubuntu/apt.conf-01-vendor-ubuntu | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/examples/configure-index b/doc/examples/configure-index index 7664e0760..497483ccc 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -271,6 +271,7 @@ Acquire No-Store "false"; // Prevent the cache from storing archives Dl-Limit ""; // Kb/sec maximum download rate User-Agent "Debian APT-HTTP/1.3"; + User-Agent-Non-Interactive "false"; // include non-interactive if run in systemd service (true on Ubuntu) Referer ""; // Set the HTTP Referer [sic!] header to given value }; diff --git a/methods/CMakeLists.txt b/methods/CMakeLists.txt index c4a32b4f5..8589484cf 100644 --- a/methods/CMakeLists.txt +++ b/methods/CMakeLists.txt @@ -17,9 +17,10 @@ add_executable(rsh rsh.cc) target_compile_definitions(connectlib PRIVATE ${GNUTLS_DEFINITIONS}) target_include_directories(connectlib PRIVATE ${GNUTLS_INCLUDE_DIR}) +target_include_directories(http PRIVATE $<$:${SYSTEMD_INCLUDE_DIRS}>) # Additional libraries to link against for networked stuff -target_link_libraries(http ${GNUTLS_LIBRARIES}) +target_link_libraries(http ${GNUTLS_LIBRARIES} $<$:${SYSTEMD_LIBRARIES}>) target_link_libraries(ftp ${GNUTLS_LIBRARIES}) # Install the library diff --git a/methods/http.cc b/methods/http.cc index bd866d321..71aa56751 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -45,6 +45,10 @@ #include "http.h" #include + +#ifdef HAVE_SYSTEMD +#include +#endif /*}}}*/ using namespace std; @@ -972,7 +976,21 @@ void HttpMethod::SendReq(FetchItem *Itm) << Base64Encode(Uri.User + ":" + Uri.Password) << "\r\n"; Req << "User-Agent: " << ConfigFind("User-Agent", - "Debian APT-HTTP/1.3 (" PACKAGE_VERSION ")") << "\r\n"; + "Debian APT-HTTP/1.3 (" PACKAGE_VERSION ")"); + +#ifdef HAVE_SYSTEMD + char *unit = nullptr; + sd_pid_get_unit(getpid(), &unit); + if (unit != nullptr && *unit != '\0' && not APT::String::Startswith(unit, "user@") // user@ _is_ interactive + && unit != "packagekit.service"s // packagekit likely is interactive + && unit != "dbus.service"s // aptdaemon and qapt don't have systemd services + && ConfigFindB("User-Agent-Non-Interactive", false)) + Req << " non-interactive"; + + free(unit); +#endif + + Req << "\r\n"; // the famously typoed HTTP header field auto const referrer = ConfigFind("Referer", ""); diff --git a/vendor/ubuntu/apt.conf-01-vendor-ubuntu b/vendor/ubuntu/apt.conf-01-vendor-ubuntu index 44e684710..30d25a717 100644 --- a/vendor/ubuntu/apt.conf-01-vendor-ubuntu +++ b/vendor/ubuntu/apt.conf-01-vendor-ubuntu @@ -1 +1,2 @@ Acquire::Changelogs::AlwaysOnline "true"; +Acquire::http::User-Agent-Non-Interactive "true"; -- cgit v1.2.3