Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame^] | 1 | From c54d36d0582a60fd281cd9287077cea205fd849d Mon Sep 17 00:00:00 2001 |
| 2 | From: Joe MacDonald <joe_macdonald@mentor.com> |
| 3 | Date: Thu, 27 Nov 2014 15:20:34 -0500 |
| 4 | Subject: [PATCH] setup: add an option to specify iptables location |
| 5 | |
| 6 | When cross-compiling it isn't certain that the location of iptables on the |
| 7 | target will be the same as on the host. It also doesn't make sense the |
| 8 | test the version of the host during setup. We provide an option to |
| 9 | specify an alternate iptables directory. This is assumed to be a |
| 10 | cross-compile environment and therefore no attempt is made to verify the |
| 11 | version of iptables to be used. |
| 12 | |
| 13 | Upstream-Status: Pending |
| 14 | |
| 15 | Signed-off-by: Joe MacDonald <joe_macdonald@mentor.com> |
| 16 | --- |
| 17 | setup.py | 69 ++++++++++++++++++++++++++++++++++++---------------------------- |
| 18 | 1 file changed, 39 insertions(+), 30 deletions(-) |
| 19 | |
| 20 | diff --git a/setup.py b/setup.py |
| 21 | index 6fb3751..b13d11c 100644 |
| 22 | --- a/setup.py |
| 23 | +++ b/setup.py |
| 24 | @@ -225,41 +225,50 @@ shutil.copytree('src', 'staging') |
| 25 | os.unlink(os.path.join('staging', 'ufw-init')) |
| 26 | os.unlink(os.path.join('staging', 'ufw-init-functions')) |
| 27 | |
| 28 | +iptables_set = 0 |
| 29 | iptables_exe = '' |
| 30 | iptables_dir = '' |
| 31 | |
| 32 | -for e in ['iptables']: |
| 33 | - for dir in ['/sbin', '/bin', '/usr/sbin', '/usr/bin', '/usr/local/sbin', \ |
| 34 | - '/usr/local/bin']: |
| 35 | - if e == "iptables": |
| 36 | - if os.path.exists(os.path.join(dir, e)): |
| 37 | - iptables_dir = dir |
| 38 | - iptables_exe = os.path.join(iptables_dir, "iptables") |
| 39 | - print("Found '%s'" % iptables_exe) |
| 40 | - else: |
| 41 | - continue |
| 42 | - |
| 43 | - if iptables_exe != "": |
| 44 | - break |
| 45 | - |
| 46 | - |
| 47 | -if iptables_exe == '': |
| 48 | - print("ERROR: could not find required binary 'iptables'", file=sys.stderr) |
| 49 | - sys.exit(1) |
| 50 | - |
| 51 | -for e in ['ip6tables', 'iptables-restore', 'ip6tables-restore']: |
| 52 | - if not os.path.exists(os.path.join(iptables_dir, e)): |
| 53 | - print("ERROR: could not find required binary '%s'" % (e), file=sys.stderr) |
| 54 | +if "--iptables-dir" in sys.argv: |
| 55 | + iptables_dir = sys.argv[sys.argv.index("--iptables-dir") + 1] |
| 56 | + iptables_exe = os.path.join(iptables_dir, "iptables") |
| 57 | + iptables_set = 1 |
| 58 | + print("INFO: iptables manually set: '%s'" % (iptables_exe)) |
| 59 | + sys.argv.remove(iptables_dir) |
| 60 | + sys.argv.remove("--iptables-dir") |
| 61 | + |
| 62 | +if not iptables_set: |
| 63 | + for e in ['iptables']: |
| 64 | + for dir in ['/sbin', '/bin', '/usr/sbin', '/usr/bin', '/usr/local/sbin', \ |
| 65 | + '/usr/local/bin']: |
| 66 | + if e == "iptables": |
| 67 | + if os.path.exists(os.path.join(dir, e)): |
| 68 | + iptables_dir = dir |
| 69 | + iptables_exe = os.path.join(iptables_dir, "iptables") |
| 70 | + print("Found '%s'" % iptables_exe) |
| 71 | + else: |
| 72 | + continue |
| 73 | + |
| 74 | + if iptables_exe != "": |
| 75 | + break |
| 76 | + |
| 77 | + if iptables_exe == '': |
| 78 | + print("ERROR: could not find required binary 'iptables'", file=sys.stderr) |
| 79 | sys.exit(1) |
| 80 | |
| 81 | -(rc, out) = cmd([iptables_exe, '-V']) |
| 82 | -if rc != 0: |
| 83 | - raise OSError(errno.ENOENT, "Could not find version for '%s'" % \ |
| 84 | - (iptables_exe)) |
| 85 | -version = re.sub('^v', '', re.split('\s', str(out))[1]) |
| 86 | -print("Found '%s' version '%s'" % (iptables_exe, version)) |
| 87 | -if version < "1.4": |
| 88 | - print("WARN: version '%s' has limited IPv6 support. See README for details." % (version), file=sys.stderr) |
| 89 | + for e in ['ip6tables', 'iptables-restore', 'ip6tables-restore']: |
| 90 | + if not os.path.exists(os.path.join(iptables_dir, e)): |
| 91 | + print("ERROR: could not find required binary '%s'" % (e), file=sys.stderr) |
| 92 | + sys.exit(1) |
| 93 | + |
| 94 | + (rc, out) = cmd([iptables_exe, '-V']) |
| 95 | + if rc != 0: |
| 96 | + raise OSError(errno.ENOENT, "Could not find version for '%s'" % \ |
| 97 | + (iptables_exe)) |
| 98 | + version = re.sub('^v', '', re.split('\s', str(out))[1]) |
| 99 | + print("Found '%s' version '%s'" % (iptables_exe, version)) |
| 100 | + if version < "1.4": |
| 101 | + print("WARN: version '%s' has limited IPv6 support. See README for details." % (version), file=sys.stderr) |
| 102 | |
| 103 | setup (name='ufw', |
| 104 | version=ufw_version, |
| 105 | -- |
| 106 | 1.9.1 |
| 107 | |