summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Kerola <kerolasa@iki.fi>2018-10-01 21:29:44 +0100
committerSami Kerola <kerolasa@iki.fi>2018-10-03 20:28:46 +0100
commite982cde6ef2c26d82fcefc1b4bd07a533000e8dc (patch)
tree35303935064c832715435fe5b5180efd38251efd
parent86323ed69b8cf227364173584e76167974eef2e6 (diff)
downloadiputils-e982cde6ef2c26d82fcefc1b4bd07a533000e8dc.tar.gz
build-sys: add setcap or setuid to ping when installing
Capacity is preferred, but when that does not work make ping to be setuid root binary, that is the legacy way to install this software. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rwxr-xr-xbuild-aux/setcap-setuid.sh25
-rw-r--r--meson.build12
2 files changed, 37 insertions, 0 deletions
diff --git a/build-aux/setcap-setuid.sh b/build-aux/setcap-setuid.sh
new file mode 100755
index 0000000..dba6c03
--- /dev/null
+++ b/build-aux/setcap-setuid.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# Meson install script to setcap or setuid to an executable.
+
+exec_path="$1/$2"
+perm_type="$3"
+setcap="$4"
+
+case "$perm_type" in
+ 'caps')
+ echo "$0: calling: $setcap cap_net_raw+ep $exec_path"
+ "$setcap" 'cap_net_raw+ep' "$exec_path" || true
+ ;;
+ 'setuid')
+ echo "$0: changing $exec_path to be setuid root executable"
+ chown root "$exec_path" || true
+ chmod u+s "$exec_path" || true
+ ;;
+ *)
+ echo "$0: unexpected argument: $perm_type"
+ exit 1
+ ;;
+esac
+
+exit 0
diff --git a/meson.build b/meson.build
index d1c5e80..cb1adc3 100644
--- a/meson.build
+++ b/meson.build
@@ -167,6 +167,18 @@ if build_ping == true
executable('ping', ['ping.c', 'ping_common.c', 'ping6_common.c', git_version_h],
dependencies : [m_dep, cap_dep, idn_dep, crypto_dep, resolv_dep],
install: true)
+ setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required : false)
+ if cap_dep.found() and setcap.found()
+ perm_type = 'caps'
+ else
+ perm_type = 'setuid'
+ endif
+ meson.add_install_script('build-aux/setcap-setuid.sh',
+ join_paths(get_option('prefix'), get_option('bindir')),
+ 'ping',
+ perm_type,
+ setcap.path()
+ )
endif
if build_tracepath == true