Bug#1034472: reportbug: auto-apt-proxy prints IPv6 literally incorrectly

2023-09-18 Thread Alexander Clouter
Hello,

On Sat, 16 Sep 2023, at 17:46, Helmut Grohne wrote:
>
> I also experience this problem. I'm attaching a patch that makes it work
> for me, but I am unsure whether the patch is universally correct as it
> may need some quoting of the ip in "Acquire::http::Proxy::${ip}=DIRECT"
> if the ip contains "::". In my case, the ip does not and therefore it
> works. Could you give the patch a try in your environment where "::"
> does happen?

The patch does work for me, thanks.

I suspect a better fix, especially given the escaping problem you have 
highlighted, would be just to pass through the DNS name to connect to.

For where 'apt-proxy' is a CNAME or are A/ records, then probably just 
returning 'apt-proxy' is the right thing to do. For SRV records, I think all 
that needs to be done is to return the target.

Do you think this would be suitable?

Happy to put it together myself, but it would be great if Antonio Terceiro 
could chip in.

Thanks



Bug#1034472: reportbug: auto-apt-proxy prints IPv6 literally incorrectly

2023-09-16 Thread Helmut Grohne
Control: tags -1 + patch

On Sun, Apr 16, 2023 at 11:08:30AM +0100, Alexander Clouter wrote:
> Though the package functions perfectly (thanks!) when you just run
> auto-apt-proxy on its own, the IPv6 literal is incorrectly concatenated
> to the port.
> 
> It should emit:
> 
> http://[fd69:dead:beef:1::1]:3142
> 
> My local setup has apt-cacher-ng running at apt-proxy:
> 
> alex@sarasti:~$ dig ANY apt-proxy
> 
> ; <<>> DiG 9.18.12-1-Debian <<>> ANY apt-proxy
> ;; global options: +cmd
> ;; Got answer:
> ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33640
> ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
> 
> ;; OPT PSEUDOSECTION:
> ; EDNS: version: 0, flags:; udp: 65494
> ;; QUESTION SECTION:
> ;apt-proxy.   IN  ANY
> 
> ;; ANSWER SECTION:
> apt-proxy.0   IN  fd69:dead:beef:1::1
> apt-proxy.0   IN  A   192.168.1.1
> 
> ;; Query time: 16 msec
> ;; SERVER: 127.0.0.53#53(127.0.0.53) (TCP)
> ;; WHEN: Sun Apr 16 11:00:14 BST 2023
> ;; MSG SIZE  rcvd: 82
> 
> alex@sarasti:~$ auto-apt-proxy 
> http://fd69:dead:beef:1::1:3142
> 
> 
> If you need anything else, do ask.

I also experience this problem. I'm attaching a patch that makes it work
for me, but I am unsure whether the patch is universally correct as it
may need some quoting of the ip in "Acquire::http::Proxy::${ip}=DIRECT"
if the ip contains "::". In my case, the ip does not and therefore it
works. Could you give the patch a try in your environment where "::"
does happen?

Helmut
--- a/auto-apt-proxy
+++ b/auto-apt-proxy
@@ -24,6 +24,17 @@
 }
 trap cleanup INT EXIT TERM
 
+proxy_url() {
+	case "$1" in
+		*:*)
+			echo "http://[$1]:$2";
+		;;
+		*)
+			echo "http://$1:$2";
+		;;
+	esac
+}
+
 hit() {
   timeout 5 /usr/lib/apt/apt-helper \
 -o Acquire::http::Proxy=DIRECT -o Acquire::Retries=0 \
@@ -76,7 +87,7 @@
 
 detect_apt_cacher() {
   local ip="$1"
-  local proxy=http://$ip:3142
+  local proxy="$(proxy_url "$ip" 3142)"
   hit -o "Acquire::http::Proxy::${ip}=DIRECT" "$proxy" >/dev/null 2>&1 || true;
   if [ -s "$tmpfile" ] && grep -q -i 'Apt-cacher' "$tmpfile"; then
 echo "$proxy"
@@ -87,7 +98,7 @@
 
 detect_apt_cacher_ng() {
   local ip="$1"
-  local proxy=http://$ip:3142
+  local proxy="$(proxy_url "$ip" 3142)"
   if hit -o "Acquire::http::Proxy::${ip}=DIRECT" "$proxy" | grep -q -i '406.*usage.information'; then
 echo "$proxy"
 return 0
@@ -97,7 +108,7 @@
 
 detect_approx() {
   local ip="$1"
-  local proxy=http://$ip:
+  local proxy="$(proxy_url "$ip" )"
   hit -o "Acquire::http::Proxy::${ip}=DIRECT" "$proxy" >/dev/null 2>&1 || true;
   if [ -s "$tmpfile" ] && grep -q -i 'approx\s*server' "$tmpfile"; then
 echo "$proxy"
@@ -110,7 +121,7 @@
 #   If you want that, use squid-deb-proxy-client, which depends on avahi.
 detect_squid_deb_proxy() {
   local ip="$1"
-  local proxy=http://$ip:8000
+  local proxy="$(proxy_url "$ip" 8000)"
   if hit -oDebug::acquire::http=1 -o "Acquire::http::Proxy::${ip}=DIRECT" "$proxy" 2>&1 | grep -q 'Via: .*squid-deb-proxy'; then
 echo "$proxy"
 return 0


Bug#1034472: reportbug: auto-apt-proxy prints IPv6 literally incorrectly

2023-04-16 Thread Alexander Clouter
Package: auto-apt-proxy
Version: 14
Severity: normal

Dear Maintainer,

Though the package functions perfectly (thanks!) when you just run
auto-apt-proxy on its own, the IPv6 literal is incorrectly concatenated
to the port.

It should emit:

http://[fd69:dead:beef:1::1]:3142

My local setup has apt-cacher-ng running at apt-proxy:

alex@sarasti:~$ dig ANY apt-proxy

; <<>> DiG 9.18.12-1-Debian <<>> ANY apt-proxy
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33640
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;apt-proxy. IN  ANY

;; ANSWER SECTION:
apt-proxy.  0   IN  fd69:dead:beef:1::1
apt-proxy.  0   IN  A   192.168.1.1

;; Query time: 16 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (TCP)
;; WHEN: Sun Apr 16 11:00:14 BST 2023
;; MSG SIZE  rcvd: 82

alex@sarasti:~$ auto-apt-proxy 
http://fd69:dead:beef:1::1:3142


If you need anything else, do ask.

Kind regards

Alex

-- System Information:
Debian Release: 12.0
  APT prefers testing-security
  APT policy: (500, 'testing-security'), (100, 'testing'), (10, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.1.0-7-amd64 (SMP w/16 CPU threads; PREEMPT)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages auto-apt-proxy depends on:
ii  apt  2.6.0

Versions of packages auto-apt-proxy recommends:
ii  busybox   1:1.35.0-4+b2
ii  iproute2  6.1.0-2

auto-apt-proxy suggests no packages.

-- no debconf information