3 posts
Posted 19 June 2014 - 09:31 PM
Ok, so I have code on startup which asks for the username and depending on the username given you will have to give your correct password, how can I make it so that when someone enters their password it'll put them in a directory and lock them into it so they cannot cd .. out?
I'm using CraftOS 1.3
570 posts
Posted 19 June 2014 - 10:29 PM
You would be better off making your own shell but you could overwrite shell.setDir.
Assuming ".." is referring to root:
local oldSetDir = shell.setDir --# Keep a copy of the old shell.setDir.
shell.setDir = function(path)
local prev = shell.dir() --# The dir we're in right now.
oldSetDir(path) --# Set the dir.
if shell.dir() == "" then
oldSetDir(prev) --# If the current dir is root, reset.
error("Access Denied") --# This will make it behave like attempting to delete rom.
end
end
Keep in mind that you can still access files in the previous directory like so: ../afile. You could override shell.resolve and shell.resolveProgram for that.
Also, your own program will also have no access to root, so use oldSetDir instead of shell.setDir.