From e982cde6ef2c26d82fcefc1b4bd07a533000e8dc Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Mon, 1 Oct 2018 21:29:44 +0100 Subject: 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 --- build-aux/setcap-setuid.sh | 25 +++++++++++++++++++++++++ meson.build | 12 ++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 build-aux/setcap-setuid.sh 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 -- cgit v1.2.1