From 50d77f2904d297a0cf077fe2222b59562d81342a Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Fri, 15 Sep 2017 19:57:11 +1000 Subject: [PATCH] added some programs to manage permissions from the shell --- exec/addperm.lua | 19 +++++++++++++++++++ exec/rmperm.lua | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 exec/addperm.lua create mode 100644 exec/rmperm.lua diff --git a/exec/addperm.lua b/exec/addperm.lua new file mode 100644 index 0000000..345814f --- /dev/null +++ b/exec/addperm.lua @@ -0,0 +1,19 @@ +local tA = {...} +if #tA < 3 then return false, "not enough arguments" end +local rwx = table.remove(tA,1):sub(1,1):lower() +if rwx ~= "r" and rwx ~= "w" and rwx ~= "x" then return false, "not a valid mode" end +local trwx = {r = "read", w = "write", x = "execute"} +local nrwx = trwx[rwx] +local un = table.remove(tA,1) +for k,v in ipairs(tA) do + local cacl = fs.parseacl(fs.getattr(v,nrwx)) or {} + cacl[un] = true + local sacl = "" + for l,m in pairs(cacl) do + if m then + sacl = l .. "," + end + end + print(v.."\t"..nrwx.." = "..sacl) + fs.setattr(v,nrwx,sacl) +end diff --git a/exec/rmperm.lua b/exec/rmperm.lua new file mode 100644 index 0000000..6f7d9b6 --- /dev/null +++ b/exec/rmperm.lua @@ -0,0 +1,19 @@ +local tA = {...} +if #tA < 3 then return false, "not enough arguments" end +local rwx = table.remove(tA,1):sub(1,1):lower() +if rwx ~= "r" and rwx ~= "w" and rwx ~= "x" then return false, "not a valid mode" end +local trwx = {r = "read", w = "write", x = "execute"} +local nrwx = trwx[rwx] +local un = table.remove(tA,1) +for k,v in ipairs(tA) do + local cacl = fs.parseacl(fs.getattr(v,nrwx)) or {} + cacl[un] = false + local sacl = "" + for l,m in pairs(cacl) do + if m then + sacl = l .. "," + end + end + print(v.."\t"..nrwx.." = "..sacl) + fs.setattr(v,nrwx,sacl) +end