diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-02-19 07:08:01 +0000 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-02-19 07:08:01 +0000 |
commit | 045ca4a948940c3257efd3997d3aa0ff6acc8b8a (patch) | |
tree | 3fb0f0558daf6ffcc2110f312df95f4d0fbb6164 | |
parent | cb6011fac4342a4cb6a913ae0e3a82306260c188 (diff) | |
download | awall-045ca4a948940c3257efd3997d3aa0ff6acc8b8a.tar.bz2 awall-045ca4a948940c3257efd3997d3aa0ff6acc8b8a.tar.xz |
ensure that awall's default policies are processed first
(and thus allow overriding them)
-rw-r--r-- | awall/policy.lua | 30 | ||||
-rw-r--r-- | json/default-log.json | 5 | ||||
-rw-r--r-- | json/services.json | 2 |
3 files changed, 26 insertions, 11 deletions
diff --git a/awall/policy.lua b/awall/policy.lua index cda8fcd..418fb9a 100644 --- a/awall/policy.lua +++ b/awall/policy.lua @@ -12,7 +12,9 @@ require 'lfs' require 'awall.dependency' local class = require('awall.object').class local raise = require('awall.uerror').raise + local util = require('awall.util') +local contains = util.contains local PolicyConfig = class() @@ -34,7 +36,7 @@ function PolicyConfig:expand() while type(value) == 'string' and string.find(value, pattern) do local si, ei, name = string.find(value, pattern) - if util.contains(visited, name) then + if contains(visited, name) then raise('Circular variable definition: '..name) end table.insert(visited, name) @@ -43,7 +45,7 @@ function PolicyConfig:expand() if not var then raise('Invalid variable reference: '..name) end if si == 1 and ei == string.len(value) then value = var - elseif util.contains({'number', 'string'}, type(var)) then + elseif contains({'number', 'string'}, type(var)) then value = string.sub(value, 1, si - 1)..var..string.sub(value, ei + 1, -1) else raise('Attempted to concatenate complex variable: '..name) @@ -147,7 +149,7 @@ end function PolicySet:load() - local imported = {} + local imported = {['%defaults']={}} local function require(policy) if imported[policy.name] then return end @@ -155,13 +157,19 @@ function PolicySet:load() local data = policy:load() imported[policy.name] = data - if not data.after then data.after = data.import end + if not data.after then data.after = util.copy(util.list(data.import)) end + if not contains(data.before, '%defaults') then + table.insert(data.after, '%defaults') + end + for i, name in util.listpairs(data.import) do - local pol = self.policies[name] - if not pol then - raise('Invalid policy reference from '..policy.name..': '..name) + if string.sub(name, 1, 1) ~= '%' then + local pol = self.policies[name] + if not pol then + raise('Invalid policy reference from '..policy.name..': '..name) + end + require(pol) end - require(pol) end end @@ -181,8 +189,10 @@ function PolicySet:load() for i, name in ipairs(order) do for cls, objs in pairs(imported[name]) do - if not util.contains({'description', 'import', 'after', 'before'}, - cls) then + if not contains( + {'description', 'import', 'after', 'before'}, + cls + ) then if not source[cls] then source[cls] = {} end if not input[cls] then diff --git a/json/default-log.json b/json/default-log.json index c85a5a7..da387e0 100644 --- a/json/default-log.json +++ b/json/default-log.json @@ -1 +1,4 @@ -{ "log": { "_default": { "limit": 1 } } } +{ + "before": "%defaults", + "log": { "_default": { "limit": 1 } } +} diff --git a/json/services.json b/json/services.json index 5016c04..25216af 100644 --- a/json/services.json +++ b/json/services.json @@ -1,4 +1,6 @@ { + "before": "%defaults", + "service": { "babel": { "proto": "tcp", "port": 6697 }, "bacula-dir": { "proto": "tcp", "port": 9101 }, |