From 4c462a5d4e840320dc71a6205b9dded82cbbdb80 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sat, 17 Oct 2020 18:50:30 +1100 Subject: [PATCH] add access control support to MTFS --- MTFS/OpenOS/usr/bin/exportfs.lua | 17 ++++++++++++++++- MTFS/OpenOS/usr/bin/importfs.lua | 5 ++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/MTFS/OpenOS/usr/bin/exportfs.lua b/MTFS/OpenOS/usr/bin/exportfs.lua index 106dc26..74d0cc0 100644 --- a/MTFS/OpenOS/usr/bin/exportfs.lua +++ b/MTFS/OpenOS/usr/bin/exportfs.lua @@ -5,13 +5,28 @@ local rpc = require "rpc" local tA, tO = shell.parse(...) if #tA < 1 then - print("Usage: exportfs [-d] [--rw] [--name=]") + print("Usage: exportfs [-d] [--rw] [--name=] [--allow=hostname[,hostname,...]] [--deny=hostname[,hostname,...]]") return end + +local allow, deny = {}, {} +for host in (tO.allow or ""):gmatch("[^,]+") do + allow[#allow+1] = host +end +for host in (tO.deny or ""):gmatch("[^,]+") do + deny[#deny+1] = host +end + local px = fsproxy.new(tA[1], not tO.rw) local name = tO.name or tA[1] for l,m in pairs(px) do m = not tO.d and m or nil rpc.register("fs_"..name.."_"..l,m) + for k,v in pairs(allow) do + rpc.allow("fs_"..name.."_"..l,v) + end + for k,v in pairs(deny) do + rpc.deny("fs_"..name.."_"..l,v) + end end print(string.format("%s (%s)", name, (tO.rw and "rw") or "ro")) diff --git a/MTFS/OpenOS/usr/bin/importfs.lua b/MTFS/OpenOS/usr/bin/importfs.lua index 159912a..4659fb0 100644 --- a/MTFS/OpenOS/usr/bin/importfs.lua +++ b/MTFS/OpenOS/usr/bin/importfs.lua @@ -57,7 +57,10 @@ if px.dirstat then -- use single call for file info return gce(path, 4) or olm(path) end end -local iro = px.isReadOnly() +local iro,e = px.isReadOnly() +if not iro then + error(e) +end function px.isReadOnly() return iro end