convinced the io.open stuff to work properly

This commit is contained in:
Izaya 2017-09-15 19:30:04 +10:00 committed by Izaya
parent cab958f677
commit dcb37236af

View File

@ -17,17 +17,22 @@ do
return tacl return tacl
end end
local function canread(fn) local function canread(fn)
if os.getuid() ~= "superuser" then if os.getuid() ~= "superuser" and fsattr[fn] then
if not parseacl(fsattr[fn].read or "")[os.getuid()] then return false end if not parseacl(fsattr[fn].read or "")[os.getuid()] then return false end
end end
return true
end end
local function canwrite(fn) local function canwrite(fn)
if os.getuid() ~= "superuser" then if os.getuid() ~= "superuser" and fsattr[fn] then
if not parseacl(getattr(fn,"write"))[os.getuid()] then return false end if not parseacl(getattr(fn,"write"))[os.getuid()] then return false end
end end
return true
end end
fs.parseacl = parseacl fs.parseacl = parseacl
fs.canread = canread
fs.canwrite = canwrite
local function getattr(fn,k) local function getattr(fn,k)
fn = fs.simplify(fn)
if not canread(fn) then return false end if not canread(fn) then return false end
if fsattr[fn] then if fsattr[fn] then
return fsattr[fn][k] return fsattr[fn][k]
@ -36,6 +41,7 @@ do
end end
end end
local function setattr(fn,k,v) local function setattr(fn,k,v)
fn = fs.simplify(fn)
if not canwrite(fn) then return false end if not canwrite(fn) then return false end
if k:find("\t") or v:find("\t") then return false end if k:find("\t") or v:find("\t") then return false end
log(parseacl(getattr(fn,"write"))[os.getuid()]) log(parseacl(getattr(fn,"write"))[os.getuid()])
@ -84,6 +90,11 @@ do
return fT[fc][m](...) return fT[fc][m](...)
end end
function fs.open(p,m) function fs.open(p,m)
if m:sub(1,1) == "r" then
if not canread(p) then return false end
elseif m:sub(1,1) == "w" or m:sub(1,1) == "a" then
if not canwrite(p) then return false end
end
local _,d,p = fs.resolve(p) local _,d,p = fs.resolve(p)
local d = fT[d] local d = fT[d]
if d then if d then