It works nicely and returns errors if the program is crashing BUT on the other hand you can easily edit the _G.currentUsr (I tried setting currentUsr to local and NOT copying it over to _G.currentUsr, but the program can still edit it. I guess it has to do with the fact, that I load the programs with loadfile() ) and _G.currentPw to grant you root access.
So I thought about "copying" the whole Enviroment os.lua is in (I copied _G, if that's right) on nother enviroment:
limitFunctions() --This limits the fs API, as I said everything worked, but the user could edit the _G variables to run program as root, without knowing the password (copy the hashed password from /sys/.rootpw)
SandBox = _G --Here I thought the whole enviroment, which my OS was in with the limited FS API, would get copied over
restoreFunctions() --This restores the original fs API, giving the OS' Enviroment normal access
And then did this:
local a = loadfile("/usr/bin/"..command, "prog", "t", SandBox) --I don't know if "prog" does ANYTHING, so I kinda want to know exactly what arguments I have to give to loadfile()
local ok, err = pcall(a, unpack(args))
if ok == false then
local col = term.getTextColor()
term.setTextColor(colors.red)
print(err)
term.setTextColor(col)
end
And what happens?
Well basically it looks like the OS gets restarted when entering a, in /usr/bin existing, command (or like it gets started AGAIN in another enviroment) and then doesn't restart again but completely shuts down upon the next command (I mean in the terminal when entering a command, which is located in /usr/bin)
Pls halp? :D/>
My goal is to have a command/program (located in /usr/bin) started (with all the variables of _G, e.g. _G.currentUsr) WITHOUT the ability to edit these variables, but I guess the idea above would lead to the executed program having as long rootaccess, as long the program runs, meaning that you could edit the variables at the first line of your program to get full access.
Right now you can run ONE program to edit these variables and this way grant every next program rootaccess.