From 4c5fbd10a4ddf551162154ffd815a9c4eb6ed818 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Thu, 26 Mar 2020 17:53:01 +0100 Subject: [feat] bitmask-root: search for the system commands in the common paths Find the right path of the system commands looking into /sbin, /usr/sbin and /usr/local/sbin - Resolves: #254 --- helpers/bitmask-root | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/helpers/bitmask-root b/helpers/bitmask-root index 3376ce7..13ba407 100644 --- a/helpers/bitmask-root +++ b/helpers/bitmask-root @@ -100,10 +100,23 @@ LOCAL_INTERFACE = "lo" IMAP_PORT = "1984" SMTP_PORT = "2013" -IP = "/sbin/ip" -IPTABLES = "/sbin/iptables" -IP6TABLES = "/sbin/ip6tables" -SYSCTL = "/sbin/sysctl" +def swhich(binary): + """ + Find the path to binary in sbin + + :rtype: str + """ + for folder in ["/sbin", "/usr/sbin", "/usr/local/sbin"]: + path = os.path.join(folder, binary) + if os.path.isfile(path): + return path + + raise Exception("Can't find %s" % (binary,)) + +IP = swhich("ip") +IPTABLES = swhich("iptables") +IP6TABLES = swhich("ip6tables") +SYSCTL = swhich("sysctl") OPENVPN_USER = "nobody" OPENVPN_GROUP = get_no_group_name() -- cgit v1.2.3