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

« back to all changes in this revision

Viewing changes to src/backend.py

  • Committer: Package Import Robot
  • Author(s): Jamie Strandboge
  • Date: 2012-09-24 08:52:57 UTC
  • Revision ID: package-import@ubuntu.com-20120924085257-uqiulz242yd4ab2a
Tags: 0.33-0ubuntu2
* debian/patches/0002-lp1044361.patch: move netfilter capabilities checking
  into initcaps(), and call initcaps() only when we need it (LP: #1044361)
* 0003-fix-typeerror-on-error.patch: fix TypeError on error when using zh_CN

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import stat
22
22
import sys
23
23
import ufw.util
24
 
from ufw.util import warn, debug
 
24
from ufw.util import error, warn, debug
25
25
from ufw.common import UFWError, config_dir, iptables_dir, UFWRule
26
26
import ufw.applications
27
27
 
68
68
            err_msg = _("Couldn't determine iptables version")
69
69
            raise UFWError(err_msg)
70
70
 
 
71
        # Initialize via initcaps only when we need it (LP: #1044361)
 
72
        self.caps = None
 
73
 
 
74
    def initcaps(self):
 
75
        '''Initialize the capabilities database. This needs to be called
 
76
           before accessing the database.'''
 
77
 
 
78
        # Only initialize if not initialized already
 
79
        if self.caps != None:
 
80
            return
 
81
 
71
82
        self.caps = {}
72
83
        self.caps['limit'] = {}
73
84
 
78
89
        # Try to get capabilities from the running system if root
79
90
        if self.do_checks and os.getuid() == 0 and not self.dryrun:
80
91
            # v4
81
 
            nf_caps = ufw.util.get_netfilter_capabilities(self.iptables)
 
92
            try:
 
93
                nf_caps = ufw.util.get_netfilter_capabilities(self.iptables)
 
94
            except OSError as e:
 
95
                error("initcaps\n%s" % e)
82
96
            if 'recent-set' in nf_caps and 'recent-update' in nf_caps:
83
97
                self.caps['limit']['4'] = True
84
98
            else:
85
99
                self.caps['limit']['4'] = False
86
100
 
87
101
            # v6
88
 
            nf_caps = ufw.util.get_netfilter_capabilities(self.ip6tables)
 
102
            try:
 
103
                nf_caps = ufw.util.get_netfilter_capabilities(self.ip6tables)
 
104
            except OSError as e:
 
105
                error("initcaps\n%s" % e)
89
106
            if 'recent-set' in nf_caps and 'recent-update' in nf_caps:
90
107
                self.caps['limit']['6'] = True
91
108
            else: