aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-03-31 11:19:56 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-03-31 19:07:51 +0300
commit385bd7791ee1a11a8ab017f260013b5d8080703f (patch)
treedc6d15ce0f09fa534d6b1f5c0b21215d5cfc1e66
parent2656abb8e17b5537420538309ddaed34aee3e7f1 (diff)
downloadawall-385bd7791ee1a11a8ab017f260013b5d8080703f.tar.bz2
awall-385bd7791ee1a11a8ab017f260013b5d8080703f.tar.xz
eliminate explicit use of string module
-rwxr-xr-xawall-cli6
-rw-r--r--awall/host.lua10
-rw-r--r--awall/init.lua10
-rw-r--r--awall/model.lua6
-rw-r--r--awall/modules/filter.lua12
-rw-r--r--awall/modules/log.lua2
-rw-r--r--awall/policy.lua15
-rw-r--r--awall/uerror.lua4
-rw-r--r--awall/util.lua12
9 files changed, 38 insertions, 39 deletions
diff --git a/awall-cli b/awall-cli
index e8d8f3c..fbc6144 100755
--- a/awall-cli
+++ b/awall-cli
@@ -107,12 +107,12 @@ if not util.contains({'translate', 'activate', 'fallback', 'flush',
pol_paths = {}
for i, cls in ipairs{'mandatory', 'optional', 'private'} do
- path = os.getenv('AWALL_PATH_'..string.upper(cls))
+ path = os.getenv('AWALL_PATH_'..cls:upper())
if path then pol_paths[cls] = util.split(path, ':') end
end
if stringy.endswith(arg[0], '/awall-cli') then
- basedir = string.sub(arg[0], 1, -11)
+ basedir = arg[0]:sub(1, -11)
if not pol_paths.mandatory then
pol_paths.mandatory = {'/etc/awall'}
end
@@ -185,7 +185,7 @@ if not uerror.call(
expinput = input:expand()
function capitalize(cls)
- return string.upper(string.sub(cls, 1, 1))..string.sub(cls, 2, -1)
+ return cls:sub(1, 1):upper()..cls:sub(2, -1)
end
for cls, objs in pairs(input.data) do
diff --git a/awall/host.lua b/awall/host.lua
index 2e94c3d..0a5fde6 100644
--- a/awall/host.lua
+++ b/awall/host.lua
@@ -1,6 +1,6 @@
--[[
Host address resolver for Alpine Wall
-Copyright (C) 2012 Kaarle Ritvanen
+Copyright (C) 2012-2014 Kaarle Ritvanen
See LICENSE file for license details
]]--
@@ -13,7 +13,7 @@ local familypatterns = {inet='%d[%.%d/]+',
local function getfamily(addr, context)
for k, v in pairs(familypatterns) do
- if string.match(addr, '^'..v..'$') then return k end
+ if addr:match('^'..v..'$') then return k end
end
context:error('Malformed host specification: '..addr)
end
@@ -28,9 +28,11 @@ function resolve(host, context)
dnscache[host] = {}
for rec in io.popen('dig -t ANY '..host):lines() do
local name, rtype, addr =
- string.match(rec, '^('..familypatterns.domain..')%s+%d+%s+IN%s+(A+)%s+(.+)')
+ rec:match(
+ '^('..familypatterns.domain..')%s+%d+%s+IN%s+(A+)%s+(.+)'
+ )
- if name and string.sub(name, 1, string.len(host) + 1) == host..'.' then
+ if name and name:sub(1, host:len() + 1) == host..'.' then
if rtype == 'A' then family = 'inet'
elseif rtype == 'AAAA' then family = 'inet6'
else family = nil end
diff --git a/awall/init.lua b/awall/init.lua
index 7af4d92..f3dcaab 100644
--- a/awall/init.lua
+++ b/awall/init.lua
@@ -1,6 +1,6 @@
--[[
Alpine Wall main module
-Copyright (C) 2012-2013 Kaarle Ritvanen
+Copyright (C) 2012-2014 Kaarle Ritvanen
See LICENSE file for license details
]]--
@@ -49,7 +49,7 @@ function loadmodules(path)
local modules = {}
for modfile in lfs.dir((path or '/usr/share/lua/5.1')..'/awall/modules') do
if stringy.endswith(modfile, '.lua') then
- table.insert(modules, 'awall.modules.'..string.sub(modfile, 1, -5))
+ table.insert(modules, 'awall.modules.'..modfile:sub(1, -5))
end
end
table.sort(modules)
@@ -67,7 +67,7 @@ function loadmodules(path)
end
function loadclass(path)
- assert(string.sub(path, 1, 1) ~= '%')
+ assert(path:sub(1, 1) ~= '%')
return events[path] and events[path].class
end
@@ -103,7 +103,7 @@ function Config:init(policyconfig)
end
for i, path in ipairs(procorder) do
- if string.sub(path, 1, 1) ~= '%' then
+ if path:sub(1, 1) ~= '%' then
local objs = self.objects[path]
if objs then
for k, v in pairs(objs) do
@@ -118,7 +118,7 @@ function Config:init(policyconfig)
end
for i, event in ipairs(procorder) do
- if string.sub(event, 1, 1) == '%' then
+ if event:sub(1, 1) == '%' then
local r = events[event].rules
if r then
if type(r) == 'function' then r = r(self.objects) end
diff --git a/awall/model.lua b/awall/model.lua
index fec6e84..b0da33b 100644
--- a/awall/model.lua
+++ b/awall/model.lua
@@ -173,7 +173,7 @@ function Rule:zoneoptfrags()
if zin == zout then return {} end
local dir, z = 'in', zin
if zin == fwzone then dir, z = 'out', zout end
- chain = string.upper(dir)..'PUT'
+ chain = dir:upper()..'PUT'
ofrags = zofs(z, dir)
elseif not zin or not zout then
@@ -243,7 +243,7 @@ function Rule:servoptfrags()
ports[sdef.proto],
util.maplist(
sdef.port,
- function(p) return string.gsub(p, '-', ':') end
+ function(p) return tostring(p):gsub('-', ':') end
)
)
else ports[sdef.proto] = {} end
@@ -310,7 +310,7 @@ function Rule:servoptfrags()
local sep = pc == 0 and '' or ','
local port = ports[1]
- pc = pc + (string.find(port, ':') and 2 or 1)
+ pc = pc + (port:find(':') and 2 or 1)
if pc > 15 then break end
opts = opts..sep..port
diff --git a/awall/modules/filter.lua b/awall/modules/filter.lua
index 55c6144..aa0959a 100644
--- a/awall/modules/filter.lua
+++ b/awall/modules/filter.lua
@@ -49,7 +49,7 @@ function Filter:init(...)
-- alpine v2.4 compatibility
if util.contains({'logdrop', 'logreject'}, self.action) then
self:warning('Deprecated action: '..self.action)
- self.action = string.sub(self.action, 4, -1)
+ self.action = self.action:sub(4, -1)
end
local log = require('awall').loadclass('log').get
@@ -100,7 +100,7 @@ function Filter:trules()
if not self.dest then
self:error('Destination address must be specified with DNAT')
end
- if string.find(self.dnat, '/') then
+ if self.dnat:find('/') then
self:error('DNAT target cannot be a network address')
end
for i, attr in ipairs({'ipsec', 'ipset'}) do
@@ -177,7 +177,7 @@ end
function Filter:actiontarget()
if self.action == 'tarpit' then return 'tarpit' end
if util.contains({'accept', 'drop', 'reject'}, self.action) then
- return string.upper(self.action)
+ return self.action:upper()
end
self:error('Invalid filter action: '..self.action)
end
@@ -268,11 +268,7 @@ function stateful(config)
)
for i, chain in ipairs({'INPUT', 'OUTPUT'}) do
table.insert(
- er,
- {
- chain=chain,
- opts='-'..string.lower(string.sub(chain, 1, 1))..' lo'
- }
+ er, {chain=chain, opts='-'..chain:sub(1, 1):lower()..' lo'}
)
end
extend(
diff --git a/awall/modules/log.lua b/awall/modules/log.lua
index 728db03..b204f74 100644
--- a/awall/modules/log.lua
+++ b/awall/modules/log.lua
@@ -59,7 +59,7 @@ function Log:target()
local mode = self.mode or 'log'
if not optmap[mode] then self:error('Invalid logging mode: '..mode) end
- local res = string.upper(mode)
+ local res = mode:upper()
for s, t in pairs(optmap[mode]) do
if self[s] then res = res..' --'..mode..'-'..t..' '..self[s] end
end
diff --git a/awall/policy.lua b/awall/policy.lua
index d7e28d4..36f319b 100644
--- a/awall/policy.lua
+++ b/awall/policy.lua
@@ -34,8 +34,9 @@ function PolicyConfig:expand()
local visited = {}
local pattern = '%$(%a[%w_]*)'
- while type(value) == 'string' and string.find(value, pattern) do
- local si, ei, name = string.find(value, pattern)
+ while type(value) == 'string' do
+ local si, ei, name = value:find(pattern)
+ if not si then break end
if contains(visited, name) then
raise('Circular variable definition: '..name)
@@ -45,9 +46,9 @@ function PolicyConfig:expand()
local var = self.data.variable[name]
if var == nil then raise('Invalid variable reference: '..name) end
- if si == 1 and ei == string.len(value) then value = var
+ if si == 1 and ei == value:len() then value = var
elseif contains({'number', 'string'}, type(var)) then
- value = string.sub(value, 1, si - 1)..var..string.sub(value, ei + 1, -1)
+ value = value:sub(1, si - 1)..var..value:sub(ei + 1, -1)
else
raise('Attempted to concatenate complex variable: '..name)
end
@@ -110,12 +111,12 @@ function PolicySet:init(dirs)
for i, cls in ipairs{'private', 'optional', 'mandatory'} do
for i, dir in ipairs(dirs[cls] or defdirs[cls]) do
for fname in lfs.dir(dir) do
- local si, ei, name = string.find(fname, '^([%w-]+)%.json$')
+ local si, ei, name = fname:find('^([%w-]+)%.json$')
if name then
local pol = self.policies[name]
local path = dir..'/'..fname
- if string.sub(path, 1, 1) ~= '/' then
+ if path:sub(1, 1) ~= '/' then
path = lfs.currentdir()..'/'..path
end
@@ -173,7 +174,7 @@ function PolicySet:load()
end
for i, name in listpairs(data.import) do
- if string.sub(name, 1, 1) ~= '%' then
+ if name:sub(1, 1) ~= '%' then
local pol = self.policies[name]
if not pol then
raise('Invalid policy reference from '..policy.name..': '..name)
diff --git a/awall/uerror.lua b/awall/uerror.lua
index 263025f..6b6e875 100644
--- a/awall/uerror.lua
+++ b/awall/uerror.lua
@@ -15,8 +15,8 @@ function call(f, ...)
return xpcall(
function() f(unpack(arg)) end,
function(msg)
- local si, ei = string.find(msg, prefix, 1, true)
- if si then msg = 'awall: '..string.sub(msg, ei + 1, -1) end
+ local si, ei = msg:find(prefix, 1, true)
+ if si then msg = 'awall: '..msg:sub(ei + 1, -1) end
io.stderr:write(msg..'\n')
if not si then io.stderr:write(debug.traceback()..'\n') end
end
diff --git a/awall/util.lua b/awall/util.lua
index 68090bd..2d0c445 100644
--- a/awall/util.lua
+++ b/awall/util.lua
@@ -1,6 +1,6 @@
--[[
Utility module for Alpine Wall
-Copyright (C) 2012-2013 Kaarle Ritvanen
+Copyright (C) 2012-2014 Kaarle Ritvanen
See LICENSE file for license details
]]--
@@ -11,13 +11,13 @@ function split(s, sep)
if s == '' then return {} end
local res = {}
while true do
- local si, ei = string.find(s, sep, 1, true)
+ local si, ei = s:find(sep, 1, true)
if not si then
table.insert(res, s)
return res
end
- table.insert(res, string.sub(s, 1, si - 1))
- s = string.sub(s, ei + 1, -1)
+ table.insert(res, s:sub(1, si - 1))
+ s = s:sub(ei + 1, -1)
end
end
@@ -104,7 +104,7 @@ function printtabulars(tables)
for i, tbl in ipairs(tables) do
for j, row in ipairs(tbl) do
for k, col in ipairs(row) do
- colwidth[k] = math.max(colwidth[k] or 0, string.len(col))
+ colwidth[k] = math.max(colwidth[k] or 0, col:len())
end
end
end
@@ -114,7 +114,7 @@ function printtabulars(tables)
if k > 1 then io.write(' ') end
io.write(row[k])
if k < #row then
- for l = 1,colwidth[k] - string.len(row[k]) do io.write(' ') end
+ for l = 1,colwidth[k] - row[k]:len() do io.write(' ') end
end
end
io.write('\n')