From 4e540697f4fbd26c0ec047b763d2b0177008917e Mon Sep 17 00:00:00 2001 From: root Date: Thu, 31 Jan 2013 20:35:35 +0100 Subject: //retiolum update_tinc_hosts: don't modify PATH Don't modify PATH but explicitly locate required executables (i.e. hosts), so no other executables from //retiolum/bin can sneak into update_tinc_hosts. --- retiolum/bin/update_tinc_hosts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/update_tinc_hosts b/retiolum/bin/update_tinc_hosts index 7be30c2a..ce1be497 100755 --- a/retiolum/bin/update_tinc_hosts +++ b/retiolum/bin/update_tinc_hosts @@ -7,8 +7,12 @@ if test "${nosudo-false}" != true -a `id -u` != 0; then exit 23 # go to hell fi -DIRNAME=`dirname $0` -export PATH="`readlink -f $DIRNAME`:$PATH" +list_hosts="$( + basename="`readlink -f "$0"`" + bindir="`dirname "$basename"`" + echo "$bindir/hosts" +)" +hosts() { "$list_hosts"; } hosts="${hosts-/etc/hosts}" -- cgit v1.2.3 From 0b2528347d6ece0d6bac5b51982d78cdb002c8e8 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 31 Jan 2013 20:45:04 +0100 Subject: //retiolum update-retiolum-hosts: don't HUP/ALRM tincd --- retiolum/bin/update-retiolum-hosts | 2 -- 1 file changed, 2 deletions(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/update-retiolum-hosts b/retiolum/bin/update-retiolum-hosts index 2a379459..e9fca25c 100755 --- a/retiolum/bin/update-retiolum-hosts +++ b/retiolum/bin/update-retiolum-hosts @@ -12,5 +12,3 @@ cd $(dirname $(readlink -f $0))/.. mkdir -p /etc/tinc/retiolum/hosts cp -v -r hosts/* /etc/tinc/retiolum/hosts -pkill -HUP tincd -pkill -ALRM tincd -- cgit v1.2.3 From 367edf6e568b9d9ac094693e2c6345f120e2a99c Mon Sep 17 00:00:00 2001 From: root Date: Thu, 31 Jan 2013 20:46:22 +0100 Subject: //retiolum update-retiolum-hosts: s/cp/rsync/ Now old hosts will be removed from /etc/tinc/retiolum/hosts. --- retiolum/bin/update-retiolum-hosts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/update-retiolum-hosts b/retiolum/bin/update-retiolum-hosts index e9fca25c..214ac205 100755 --- a/retiolum/bin/update-retiolum-hosts +++ b/retiolum/bin/update-retiolum-hosts @@ -1,5 +1,5 @@ #! /bin/sh -set -eu +set -euf if test "${nosudo-false}" != true -a `id -u` != 0; then echo "we're going sudo..." >&2 @@ -11,4 +11,4 @@ fi cd $(dirname $(readlink -f $0))/.. mkdir -p /etc/tinc/retiolum/hosts -cp -v -r hosts/* /etc/tinc/retiolum/hosts +rsync -va --delete hosts/ /etc/tinc/retiolum/hosts/ -- cgit v1.2.3 From 453593943e41edc1b55372951af1e3b2768e59c0 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 31 Jan 2013 21:13:44 +0100 Subject: //retiolum patch-retiolum-hosts: allow --reverse --- retiolum/bin/apply-custom-hosts-patches | 8 -------- retiolum/bin/patch-retiolum-hosts | 13 +++++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) delete mode 100755 retiolum/bin/apply-custom-hosts-patches create mode 100755 retiolum/bin/patch-retiolum-hosts (limited to 'retiolum/bin') diff --git a/retiolum/bin/apply-custom-hosts-patches b/retiolum/bin/apply-custom-hosts-patches deleted file mode 100755 index 2b2fda80..00000000 --- a/retiolum/bin/apply-custom-hosts-patches +++ /dev/null @@ -1,8 +0,0 @@ -#! /bin/sh -set -euf - -patch=/etc/tinc/retiolum/hosts.patch - -if test -e $patch; then - patch -N -d /etc/tinc/retiolum/hosts -r - < $patch -fi diff --git a/retiolum/bin/patch-retiolum-hosts b/retiolum/bin/patch-retiolum-hosts new file mode 100755 index 00000000..69d7b92c --- /dev/null +++ b/retiolum/bin/patch-retiolum-hosts @@ -0,0 +1,13 @@ +#! /bin/sh +# +# Apply custom retiolum hosts patches, if any. +# +# usage: patch-retiolum-hosts [--reverse] +# +set -euf + +patch=/etc/tinc/retiolum/hosts.patch + +if test -e $patch; then + patch -N -d /etc/tinc/retiolum/hosts -r - "$@" < $patch +fi -- cgit v1.2.3 From f2992565ab8be0544ae328c3d11243131a3b7441 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 2 Feb 2013 00:19:20 +0100 Subject: //retiolum list-known-public-addresses: initial commit --- retiolum/bin/list-known-public-addresses | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 retiolum/bin/list-known-public-addresses (limited to 'retiolum/bin') diff --git a/retiolum/bin/list-known-public-addresses b/retiolum/bin/list-known-public-addresses new file mode 100755 index 00000000..d157cea4 --- /dev/null +++ b/retiolum/bin/list-known-public-addresses @@ -0,0 +1,28 @@ +#! /bin/sh +# +# printf '%s %s\n' hostname IP-address for each known public retiolum address +# +set -eu + +cd /etc/tinc/retiolum/hosts + +grep --with-filename '^Address' * | +sed ' + # filter "%s %s %s\n" hostname var val + s/: */ / + s/ *= */ / + # filter "%s %s\n" hostname address + s/ Address \([a-zA-Z0-9.:_]*\) \?.*/ \1/ + T + # prepare hostname lookup + /:/!{/ [0-9.]*$/!{s/ / `dig +short /;s/$/` \&/}} + s/^/echo / + $s/$/\nwait/ + # perform hostname lookup +' | sh | sed ' + # drop private IPv4 addresses + / 10\./d + / 172\.\(1[6-9]\|2[0-9]\|3[01]\)\./d + / 192\.168\./d + # TODO drop private IPv6 addresses +' -- cgit v1.2.3 From c6f8c72d483fdcdf2ba4554ca7f578089df9f1c2 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 2 Feb 2013 01:22:08 +0100 Subject: //retiolum list-known-public-addresses: factorize --- retiolum/bin/list-known-public-addresses | 46 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/list-known-public-addresses b/retiolum/bin/list-known-public-addresses index d157cea4..d8073791 100755 --- a/retiolum/bin/list-known-public-addresses +++ b/retiolum/bin/list-known-public-addresses @@ -4,25 +4,29 @@ # set -eu -cd /etc/tinc/retiolum/hosts +_list_hostname_address() { + cd /etc/tinc/retiolum/hosts + grep --with-filename '^Address' * | + sed -n ' + s/: */ / + s/ *= */ / + s/ Address \([a-zA-Z0-9.:_]*\) \?.*/ \1/p' +} +_lookup_address() { + sed ' + /:/!{/ [0-9.]*$/!{s/ / `dig +short /;s/$/` \&/}} + s/^/echo / + $s/$/\nwait/ + ' | sh +} +_filter_public() { + sed ' + # drop private IPv4 addresses + / 10\./d + / 172\.\(1[6-9]\|2[0-9]\|3[01]\)\./d + / 192\.168\./d + # TODO drop private IPv6 addresses + ' +} -grep --with-filename '^Address' * | -sed ' - # filter "%s %s %s\n" hostname var val - s/: */ / - s/ *= */ / - # filter "%s %s\n" hostname address - s/ Address \([a-zA-Z0-9.:_]*\) \?.*/ \1/ - T - # prepare hostname lookup - /:/!{/ [0-9.]*$/!{s/ / `dig +short /;s/$/` \&/}} - s/^/echo / - $s/$/\nwait/ - # perform hostname lookup -' | sh | sed ' - # drop private IPv4 addresses - / 10\./d - / 172\.\(1[6-9]\|2[0-9]\|3[01]\)\./d - / 192\.168\./d - # TODO drop private IPv6 addresses -' +_list_hostname_address | _lookup_address | _filter_public -- cgit v1.2.3 From e929315a0b734aab77a68bcfa41f24faf28b8896 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 2 Feb 2013 01:31:29 +0100 Subject: //retiolum list-known-public-addresses: add online filter --- retiolum/bin/list-known-public-addresses | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/list-known-public-addresses b/retiolum/bin/list-known-public-addresses index d8073791..00d8d4b9 100755 --- a/retiolum/bin/list-known-public-addresses +++ b/retiolum/bin/list-known-public-addresses @@ -28,5 +28,11 @@ _filter_public() { # TODO drop private IPv6 addresses ' } +_filter_online() { + awk ' + {print"nc -zw 2 "$2" 655 2>/dev/null && echo "$1" "$2" &"} + END {print"wait"} + ' | sh +} -_list_hostname_address | _lookup_address | _filter_public +_list_hostname_address | _lookup_address | _filter_public | _filter_online -- cgit v1.2.3 From ae5b25d9c15b598460e44f2fc54168936abaca81 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 2 Feb 2013 01:50:33 +0100 Subject: //retiolum list-known-public-addresses: don't check if online --- retiolum/bin/list-known-public-addresses | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/list-known-public-addresses b/retiolum/bin/list-known-public-addresses index 00d8d4b9..21b1c389 100755 --- a/retiolum/bin/list-known-public-addresses +++ b/retiolum/bin/list-known-public-addresses @@ -35,4 +35,4 @@ _filter_online() { ' | sh } -_list_hostname_address | _lookup_address | _filter_public | _filter_online +_list_hostname_address | _lookup_address | _filter_public -- cgit v1.2.3