termux-packages/packages/apt/0012-termux-id.patch

58 lines
2.4 KiB
Diff
Raw Normal View History

diff -uNr apt-2.1.18/methods/http.cc apt-2.1.18.mod/methods/http.cc
--- apt-2.1.18/methods/http.cc 2021-01-13 18:37:30.000000000 +0200
+++ apt-2.1.18.mod/methods/http.cc 2021-02-03 22:06:04.242782879 +0200
@@ -341,7 +341,26 @@
Req << "Proxy-Authorization: Basic "
<< Base64Encode(Proxy.User + ":" + Proxy.Password) << "\r\n";
- Req << "User-Agent: " << Owner->ConfigFind("User-Agent", "Debian APT-HTTP/1.3 (" PACKAGE_VERSION ")") << "\r\n";
+ // Determine the actual installation prefix to send as part of user-agent string.
+ // Mirrors can use this information to distinguish legit Termux installations from
+ // third parties using Termux repositories.
+ char binPath[PATH_MAX] = {0};
+ ssize_t binPathLen = readlink("/proc/self/exe", binPath, sizeof(binPath)-1);
+ if (binPathLen != -1) {
+ binPath[binPathLen] = '\0';
+
+ char *aptMethodsSub = strstr(binPath, "/lib/apt/methods");
+ if (aptMethodsSub) {
+ // Cut /lib/apt/methods.. from prefix, if possible.
+ aptMethodsSub[0] = '\0';
+ }
+ } else {
+ // Use hardcoded as fallback.
+ // Mostly useless as will help to detect only binary-patched apt.
+ strncpy(binPath, "@TERMUX_PREFIX@", PATH_MAX - 1);
+ }
+
+ Req << "User-Agent: Debian APT-HTTP/1.3 (" PACKAGE_VERSION ") Termux (@TERMUX_APP_PACKAGE@; install-prefix:" << binPath <<")" << "\r\n";
Req << "\r\n";
@@ -954,8 +973,23 @@
Req << "Authorization: Basic "
<< Base64Encode(Uri.User + ":" + Uri.Password) << "\r\n";
- Req << "User-Agent: " << ConfigFind("User-Agent",
- "Debian APT-HTTP/1.3 (" PACKAGE_VERSION ")");
+ char binPath[PATH_MAX] = {0};
+ ssize_t binPathLen = readlink("/proc/self/exe", binPath, sizeof(binPath)-1);
+ if (binPathLen != -1) {
+ binPath[binPathLen] = '\0';
+
+ char *aptMethodsSub = strstr(binPath, "/lib/apt/methods");
+ if (aptMethodsSub) {
+ // Cut /lib/apt/methods.. from prefix, if possible.
+ aptMethodsSub[0] = '\0';
+ }
+ } else {
+ // Use hardcoded as fallback.
+ // Mostly useless as will help to detect only binary-patched apt.
+ strncpy(binPath, "@TERMUX_PREFIX@", PATH_MAX - 1);
+ }
+
+ Req << "User-Agent: Debian APT-HTTP/1.3 (" PACKAGE_VERSION ") Termux (@TERMUX_APP_PACKAGE@; install-prefix:" << binPath << ")";
#ifdef HAVE_SYSTEMD
if (ConfigFindB("User-Agent-Non-Interactive", false))