Browse Source

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
tags/devuan/2.0.2+devuan1
Julian Andres Klode 6 months ago
parent
commit
29a79857c3
4 changed files with 23 additions and 2 deletions
  1. +1
    -0
      doc/examples/configure-index
  2. +2
    -1
      methods/CMakeLists.txt
  3. +19
    -1
      methods/http.cc
  4. +1
    -0
      vendor/ubuntu/apt.conf-01-vendor-ubuntu

+ 1
- 0
doc/examples/configure-index View File

@@ -271,6 +271,7 @@ Acquire
No-Store "false"; // Prevent the cache from storing archives
Dl-Limit "<INT>"; // 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 "<STRING>"; // Set the HTTP Referer [sic!] header to given value
};



+ 2
- 1
methods/CMakeLists.txt View File

@@ -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 $<$<BOOL:${SYSTEMD_FOUND}>:${SYSTEMD_INCLUDE_DIRS}>)

# Additional libraries to link against for networked stuff
target_link_libraries(http ${GNUTLS_LIBRARIES})
target_link_libraries(http ${GNUTLS_LIBRARIES} $<$<BOOL:${SYSTEMD_FOUND}>:${SYSTEMD_LIBRARIES}>)
target_link_libraries(ftp ${GNUTLS_LIBRARIES})

# Install the library


+ 19
- 1
methods/http.cc View File

@@ -45,6 +45,10 @@
#include "http.h"

#include <apti18n.h>

#ifdef HAVE_SYSTEMD
#include <systemd/sd-login.h>
#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", "");


+ 1
- 0
vendor/ubuntu/apt.conf-01-vendor-ubuntu View File

@@ -1 +1,2 @@
Acquire::Changelogs::AlwaysOnline "true";
Acquire::http::User-Agent-Non-Interactive "true";

Loading…
Cancel
Save