From c0d08bbdeed4523cf89bf55b64ce2c16476c3e26 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 5 Apr 2019 23:39:41 +0200 Subject: fix #5352 --- src/dns/gnunet-helper-dns.c | 22 +++++++++++++++++- src/exit/gnunet-helper-exit.c | 12 +++++++++- src/util/os_network.c | 52 +++++++++++++++++++++++++++++++++++-------- src/util/test_os_network.c | 30 ++++++++++++++++++------- 4 files changed, 97 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/dns/gnunet-helper-dns.c b/src/dns/gnunet-helper-dns.c index fb970224a..554727094 100644 --- a/src/dns/gnunet-helper-dns.c +++ b/src/dns/gnunet-helper-dns.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -768,6 +768,11 @@ main (int argc, char *const*argv) if (0 == nortsetup) { /* verify that the binaries we care about are executable */ +#ifdef IPTABLES + if (0 == access (IPTABLES, X_OK)) + sbin_iptables = IPTABLES; + else +#endif if (0 == access ("/sbin/iptables", X_OK)) sbin_iptables = "/sbin/iptables"; else if (0 == access ("/usr/sbin/iptables", X_OK)) @@ -779,6 +784,11 @@ main (int argc, char *const*argv) strerror (errno)); return 3; } +#ifdef IP6TABLES + if (0 == access (IP6TABLES, X_OK)) + sbin_ip6tables = IP6TABLES; + else +#endif if (0 == access ("/sbin/ip6tables", X_OK)) sbin_ip6tables = "/sbin/ip6tables"; else if (0 == access ("/usr/sbin/ip6tables", X_OK)) @@ -790,6 +800,11 @@ main (int argc, char *const*argv) strerror (errno)); return 3; } +#ifdef PATH_TO_IP + if (0 == access (PATH_TO_IP, X_OK)) + sbin_ip = PATH_TO_IP; + else +#endif if (0 == access ("/sbin/ip", X_OK)) sbin_ip = "/sbin/ip"; else if (0 == access ("/usr/sbin/ip", X_OK)) @@ -803,6 +818,11 @@ main (int argc, char *const*argv) strerror (errno)); return 4; } +#ifdef SYSCTL + if (0 == access (SYSCTL, X_OK)) + sbin_sysctl = SYSCTL; + else +#endif if (0 == access ("/sbin/sysctl", X_OK)) sbin_sysctl = "/sbin/sysctl"; else if (0 == access ("/usr/sbin/sysctl", X_OK)) diff --git a/src/exit/gnunet-helper-exit.c b/src/exit/gnunet-helper-exit.c index de9ea39be..cda38710f 100644 --- a/src/exit/gnunet-helper-exit.c +++ b/src/exit/gnunet-helper-exit.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -670,6 +670,11 @@ main (int argc, char **argv) } if (0 != strcmp (argv[2], "-")) { +#ifdef IPTABLES + if (0 == access (IPTABLES, X_OK)) + sbin_iptables = IPTABLES; + else +#endif if (0 == access ("/sbin/iptables", X_OK)) sbin_iptables = "/sbin/iptables"; else if (0 == access ("/usr/sbin/iptables", X_OK)) @@ -681,6 +686,11 @@ main (int argc, char **argv) strerror (errno)); return 1; } +#ifdef SYSCTL + if (0 == access (SYSCTL, X_OK)) + sbin_sysctl = SYSCTL; + else +#endif if (0 == access ("/sbin/sysctl", X_OK)) sbin_sysctl = "/sbin/sysctl"; else if (0 == access ("/usr/sbin/sysctl", X_OK)) diff --git a/src/util/os_network.c b/src/util/os_network.c index dba61f1e4..9008c5c5a 100644 --- a/src/util/os_network.c +++ b/src/util/os_network.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -67,15 +67,29 @@ try_ifconfig (GNUNET_OS_NetworkInterfaceProcessor proc, struct sockaddr *pass_bcaddr; struct sockaddr *pass_netmask; int prefixlen; + static char *pcall; + + if (NULL == pcall) + { + const char *sbin_ifconfig; - if (system ("ifconfig -a > /dev/null 2> /dev/null")) - if (0 == system ("/sbin/ifconfig -a > /dev/null 2> /dev/null")) - f = popen ("/sbin/ifconfig -a 2> /dev/null", "r"); +#ifdef IFCONFIG + if (0 == access (IFCONFIG, X_OK)) + sbin_ifconfig = IFCONFIG; else - f = NULL; - else - f = popen ("ifconfig -a 2> /dev/null", "r"); - if (! f) +#endif + if (0 == access ("/sbin/ifconfig", X_OK)) + sbin_ifconfig = "/sbin/ifconfig"; + else if (0 == access ("/usr/sbin/ifconfig", X_OK)) + sbin_ifconfig = "/usr/sbin/ifconfig"; + else + sbin_ifconfig = "ifconfig"; + GNUNET_asprintf (&pcall, + "%s -a 2> /dev/null", + sbin_ifconfig); + } + f = popen (pcall, "r"); + if (NULL == f) { LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "popen", @@ -238,8 +252,28 @@ try_ip (GNUNET_OS_NetworkInterfaceProcessor proc, struct sockaddr_in6 netmask6; unsigned int i; unsigned int prefixlen; + static char *pcall; - f = popen ("ip -o add 2> /dev/null", "r"); + if (NULL == pcall) + { + const char *sbin_ip; + +#ifdef IFCONFIG + if (0 == access (PATH_TO_IP, X_OK)) + sbin_ip = PATH_TO_IP; + else +#endif + if (0 == access ("/sbin/ip", X_OK)) + sbin_ip = "/sbin/ip"; + else if (0 == access ("/usr/sbin/ip", X_OK)) + sbin_ip = "/usr/sbin/ip"; + else + sbin_ip = "if"; + GNUNET_asprintf (&pcall, + "%s -o add 2> /dev/null", + sbin_ip); + } + f = popen (pcall, "r"); if (! f) { LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, diff --git a/src/util/test_os_network.c b/src/util/test_os_network.c index b6e981bc3..fa769de6f 100644 --- a/src/util/test_os_network.c +++ b/src/util/test_os_network.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -31,8 +31,12 @@ * (success). */ static int -proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr, - const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, +proc (void *cls, + const char *name, + int isDefault, + const struct sockaddr *addr, + const struct sockaddr *broadcast_addr, + const struct sockaddr *netmask, socklen_t addrlen) { int *ok = cls; @@ -46,11 +50,18 @@ proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr, else protocol = "IPv6"; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "%s Address `%s'\n", protocol, GNUNET_a2s ((const struct sockaddr *) addr,addrlen) ); + "%s Address `%s'\n", + protocol, + GNUNET_a2s ((const struct sockaddr *) addr, + addrlen) ); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Netmask `%s'\n", GNUNET_a2s ((const struct sockaddr *) netmask, addrlen) ); + "Netmask `%s'\n", + GNUNET_a2s ((const struct sockaddr *) netmask, + addrlen) ); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "`%s'\n", GNUNET_a2s ((const struct sockaddr *) broadcast_addr,addrlen) ); + "`%s'\n", + GNUNET_a2s ((const struct sockaddr *) broadcast_addr, + addrlen) ); inet_ntop (addr->sa_family, (addr->sa_family == AF_INET) ? (void *) &((struct sockaddr_in *) addr)->sin_addr @@ -67,9 +78,12 @@ main (int argc, char *argv[]) { int ret; - GNUNET_log_setup ("test-os-network", "WARNING", NULL); + GNUNET_log_setup ("test-os-network", + "WARNING", + NULL); ret = 1; - GNUNET_OS_network_interfaces_list (&proc, &ret); + GNUNET_OS_network_interfaces_list (&proc, + &ret); return ret; } -- cgit v1.2.3