Hi all,

as a first attempt at testing "ping" without requiring root, the following
patch works for me.  Do we need to add a check if "cut" is available?
Since the "id -G" is only used on systems with the kernel Linux, it may
be OK without a check, or should we add one?

Any additional comments?

Br,
Erik
---
diff --git a/tests/ping-localhost.sh b/tests/ping-localhost.sh
index 65802810..ddaff188 100755
--- a/tests/ping-localhost.sh
+++ b/tests/ping-localhost.sh
@@ -56,11 +56,28 @@ if test "$TEST_IPV4" = "no" && test "$TEST_IPV6" = "no"; 
then
     exit 77
 fi
 
-if test `func_id_uid` != 0; then
+have_root="yes"
+test `func_id_uid` != 0 && have_root="no"
+
+need_root="yes"
+if test `uname -s` = "Linux" && test -f "/proc/sys/net/ipv4/ping_group_range"
+then
+    low=`cut -f1 "/proc/sys/net/ipv4/ping_group_range"`
+    high=`cut -f2 "/proc/sys/net/ipv4/ping_group_range"`
+    for grp_id in `id -G`; do
+        test "$low" -le "$grp_id" && test "$high" -ge "$grp_id" &&
+            need_root="no" && break
+    done
+fi
+
+if test "$need_root" = "yes" && test "$have_root" = "no"; then
     echo "ping needs to run as root"
     exit 77
 fi
 
+# ping6 requires root
+test "$need_root" = "no" && test "$have_root" = "no" && TEST_IPV6="no"
+
 errno=0
 errno2=0
 

Reply via email to