Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- computer=require("computer")
- getPath=require("filesystem").path
- fs=require("component").proxy(computer.getBootAddress())
- function computer.addUser()
- return nil, "Function 'addUser' is disabled"
- end
- local protectList
- local function checkPath(path)
- return true
- end
- local function whiteList(path)
- if fs.isDirectory(path) then path=path.."/" end
- if protectList["/"] then return true end
- repeat
- if protectList[path] then return true end
- path=getPath(path)
- until path=="/"
- return nil, "no such file, or permission denied"
- end
- local function blackList(path)
- if fs.isDirectory(path) then path=path.."/" end
- if protectList["/"] then return nil, "no such file, or permission denied" end
- repeat
- if protectList[path] then return nil, "no such file, or permission denied" end
- path=getPath(path)
- until path=="/"
- return true
- end
- do
- local env = {}
- local config = loadfile("/etc/protect.cfg", nil, env)
- if config then
- pcall(config)
- if env.writeEnabled then
- protectList={}
- for i=1,#env.writeEnabled do
- protectList[env.writeEnabled[i]]=true
- end
- checkPath=whiteList
- end
- if env.writeDisabled then
- protectList={}
- for i=1,#env.writeDisabled do
- protectList[env.writeDisabled[i]]=true
- end
- checkPath=blackList
- end
- end
- end
- local nativeFS={}
- nativeFS.makeDirectory=fs.makeDirectory
- function fs.makeDirectory(path)
- local ok,err=checkPath(path)
- if not ok then return nil, err end
- return nativeFS.makeDirectory(path)
- end
- nativeFS.remove=fs.remove
- function fs.remove(path)
- local ok,err=checkPath(path)
- if not ok then return nil, err end
- return nativeFS.remove(path)
- end
- nativeFS.rename=fs.rename
- function fs.rename(from,to)
- local ok,err=checkPath(from)
- if not ok then return nil, err end
- ok,err=checkPath(to)
- if not ok then return nil, err end
- return nativeFS.rename(from,to)
- end
- nativeFS.open=fs.open
- function fs.open(path, mode)
- if mode=="w" or mode=="wb" or mode=="a" or mode=="ab" then
- local ok,err=checkPath(path)
- if not ok then return nil, err end
- end
- return nativeFS.open(path,mode)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement