~ubuntu-branches/ubuntu/saucy/ufw/saucy

« back to all changes in this revision

Viewing changes to src/backend.py

  • Committer: Package Import Robot
  • Author(s): Jamie Strandboge
  • Date: 2012-08-17 14:32:01 UTC
  • mfrom: (30.1.15)
  • Revision ID: package-import@ubuntu.com-20120817143201-xj33z2za9mvzpw2k
Tags: 0.33-0ubuntu1
* New upstream release. Fixes the following bugs:
  - also use correct ports for DHCPv6. Thanks to Marco Davids (LP: #1007326)
  - add IPv6 limit support (LP: #951462)
  - add zh_TW translation (LP: #868195)
  - add 'show added' report (LP: #987784)
  - remove ACCEPT_NO_TRACK option since it never worked (LP: #787955)
* debian/(after|before)6.rules.md5sum: adjust for recently missed shipped
  configurations

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
        self.ip6tables_restore = os.path.join(iptables_dir, \
63
63
                                              "ip6tables-restore")
64
64
 
65
 
        self.iptables_version = ufw.util.get_iptables_version(self.iptables)
 
65
        try:
 
66
            self.iptables_version = ufw.util.get_iptables_version(self.iptables)
 
67
        except OSError:
 
68
            err_msg = _("Couldn't determine iptables version")
 
69
            raise UFWError(err_msg)
 
70
 
 
71
        self.caps = {}
 
72
        self.caps['limit'] = {}
 
73
 
 
74
        # Set defaults for dryrun, non-root, etc
 
75
        self.caps['limit']['4'] = True
 
76
        self.caps['limit']['6'] = False # historical default for the testsuite
 
77
 
 
78
        # Try to get capabilities from the running system if root
 
79
        if self.do_checks and os.getuid() == 0 and not self.dryrun:
 
80
            # v4
 
81
            nf_caps = ufw.util.get_netfilter_capabilities(self.iptables)
 
82
            if 'recent-set' in nf_caps and 'recent-update' in nf_caps:
 
83
                self.caps['limit']['4'] = True
 
84
            else:
 
85
                self.caps['limit']['4'] = False
 
86
 
 
87
            # v6
 
88
            nf_caps = ufw.util.get_netfilter_capabilities(self.ip6tables)
 
89
            if 'recent-set' in nf_caps and 'recent-update' in nf_caps:
 
90
                self.caps['limit']['6'] = True
 
91
            else:
 
92
                self.caps['limit']['6'] = False
66
93
 
67
94
    def is_enabled(self):
68
95
        '''Is firewall configured as enabled'''
86
113
        rstr = ""
87
114
        if self.defaults[policy] == "accept":
88
115
            rstr = "allow"
89
 
        elif self.defaults[policy] == "accept_no_track":
90
 
            rstr = "allow-without-tracking"
91
116
        elif self.defaults[policy] == "reject":
92
117
            rstr = "reject"
93
118
        else:
142
167
                if not pat.search(profile):
143
168
                    profiles.append(os.path.join(self.files['apps'], profile))
144
169
 
145
 
        for path in list(self.files.values()) + [ os.path.abspath(sys.argv[0]) ] + \
 
170
        for path in list(self.files.values()) + \
 
171
                [ os.path.abspath(sys.argv[0]) ] + \
146
172
                profiles:
 
173
            if not path.startswith('/'):
 
174
                path = "%s/%s" % (os.getcwd(), path)
147
175
            while True:
148
176
                debug("Checking " + path)
149
177
                if path == self.files['apps'] and \
178
206
                if path == "/":
179
207
                    break
180
208
 
 
209
                last_path = path
181
210
                path = os.path.dirname(path)
182
211
                if not path:
183
 
                    raise OSError(errno.ENOENT, "Could not find '%s'" % (path))
 
212
                    raise OSError(errno.ENOENT, \
 
213
                                  "Could not find parent for '%s'" % \
 
214
                                  (last_path))
184
215
 
185
216
        for f in self.files:
186
217
            if f != 'apps' and not os.path.isfile(self.files[f]):
206
237
            orig.close()
207
238
 
208
239
        # do some default policy sanity checking
209
 
        policies = ['accept', 'accept_no_track', 'drop', 'reject']
 
240
        policies = ['accept', 'drop', 'reject']
210
241
        for c in [ 'input', 'output', 'forward' ]:
211
242
            if 'default_%s_policy' % (c) not in self.defaults:
212
243
                err_msg = _("Missing policy for '%s'" % (c))
213
244
                raise UFWError(err_msg)
214
245
            p = self.defaults['default_%s_policy' % (c)]
215
 
            if p not in policies or \
216
 
               (p == 'accept_no_track' and c == 'forward'):
 
246
            if p not in policies:
217
247
                err_msg = _("Invalid policy '%(policy)s' for '%(chain)s'" % \
218
248
                            ({'policy': p, 'chain': c}))
219
249
                raise UFWError(err_msg)