diff --git a/Android.mk b/Android.mk index 0991eeb..d20d1c1 100644 --- a/Android.mk +++ b/Android.mk @@ -3,5 +3,5 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= ping6.c LOCAL_MODULE := ping6 -LOCAL_MODULE_TAGS := eng +LOCAL_MODULE_TAGS := debug include $(BUILD_EXECUTABLE) diff --git a/ping6.c b/ping6.c index ccf9c4c..fc1eb84 100644 --- a/ping6.c +++ b/ping6.c @@ -131,6 +131,8 @@ __RCSID("$NetBSD: ping6.c,v 1.73 2010/09/20 11:49:48 ahoka Exp $"); #include <unistd.h> #include <poll.h> +#include <private/android_filesystem_config.h> + #ifdef IPSEC #include <netinet6/ah.h> #include <netinet6/ipsec.h> @@ -297,6 +299,23 @@ char *nigroup(char *); #endif void usage(void); +int +isInSupplementaryGroup(gid_t group) +{ + int numgroups, i; + gid_t groups[sysconf(_SC_NGROUPS_MAX) + 1]; + numgroups = getgroups(sizeof(groups) / sizeof(groups[0]), groups); + if (numgroups < 0) { + perror("getgroups"); + return 0; + } + for (i = 0; i < numgroups; i++) { + if (group == groups[i]) + return 1; + } + return 0; +} + int main(int argc, char *argv[]) { @@ -331,6 +350,11 @@ main(int argc, char *argv[]) int mflag = 0; #endif + if (getuid() != 0 && !isInSupplementaryGroup(AID_INET)) { + fprintf(stderr, "%s: not root or in group AID_INET\n", argv[0]); + exit(3); + } + /* just to be sure */ memset(&smsghdr, 0, sizeof(smsghdr)); memset(&smsgiov, 0, sizeof(smsgiov));