User:Liny odell/misc/cc startup security patch

By default, the computers in ComputerCraft boot off the first floppy disk they find, specifically booting off the top drive first. With that said, anyone can come by, place down a floppy drive next to your computer with a blank startup file and bypass yours, gaining full access to your computer and anything on it/connected to it. This page shows how to edit one of the included lua files to add the ability to make the computers boot only from internal storage, external floppy, or the original behavior of searching the internal storage, then the external drives.

Setup
The file that needs editing is located on the computers at: "/rom/programs/shell", however, don't try editing that file on a computer as all files inside the /rom directory are read only. To edit this file you need ftp access to the server itself.

The file location on the server is: "/tekkit/mods/ComputerCraft/lua/rom/programs/shell". Download this file and open it up on your computer using a text editor (I personally use Notepad++) and scroll down to near the bottom of the file, line 137 specifically.

At this location insert the following code:

local file = io.open(shell.resolve("/bios_config"), "r") local configs = {} if file then local line = file:read while line do    local place = string.find(line,".",1,true) configs[string.sub(line,1,place-1)] = string.sub(line,place+1) line = file:read end file:close end What the above code does is search the root of the computers storage for a file named "bios_config" and reads the options defined in there into a table.

Now, once that's inserted, go to line 159 (or somewhere around there, depending on how you inserted the above text) and replace the code of lines 159 through 168 with:

local sUserStartup = nil local startup = configs["startup"] if startup then if startup == "disk" then for n,sSide in pairs( redstone.getSides ) do        if disk.isPresent( sSide ) and disk.hasData( sSide ) then local sDiskStartup = shell.resolveProgram( fs.combine(disk.getMountPath( sSide ), "startup") ) if sDiskStartup then sUserStartup = sDiskStartup break end end end elseif startup == "hdd" then sUserStartup = shell.resolveProgram( "/startup" ) end else sUserStartup = shell.resolveProgram( "/startup" ) for n,sSide in pairs( redstone.getSides ) do      if disk.isPresent( sSide ) and disk.hasData( sSide ) then local sDiskStartup = shell.resolveProgram( fs.combine(disk.getMountPath( sSide ), "startup") ) if sDiskStartup then sUserStartup = sDiskStartup break end end end end Now, what that code does is it reads the table of options that was created in the above code and check to see if an option ("startup" in this case) exists and if so, what it is set to for where it should look for the /startup program.

Once both edits have been made to the file, save it and upload it back onto the server, over-writing the original (remember to make a backup first!) if prompted.

Once the edits are uploaded onto the server, DO NOT restart the server, because if anything went wrong in editing the file, you will break ALL computers on the server till the shell file is fixed. Instead, go to a computer, any will do, as long as you have permission to reboot it, and reboot it, either with the lua command, shell command, or the ctrl-r keyboard command. If all went well, it should start right up and load the first startup file it finds, or drop you at a normal shell if there is no startup file. Otherwise go back to your text editor and make sure you copied the code pieces into the right locations ect.

Config File
Once you have the above process done and your test computer starts up without errors, now you will create a file on the computer which will tell it what to start from.

On the computer you want to protect/set the startup option on, type "edit /bios_config" at the shell prompt to open edit and point it to save in that file.

Once edit is open, enter in "startup.hdd" or "startup.disk" depending on if you want to force the computer to load the startup file from the internal storage or external disk respectively.

Note
If the config file is set to hdd bootup and there is no startup file in the computer, it will start up a shell prompt just like normal. The same goes for if it is set to any other value other then "hdd" or "disk", it will just fall into a shell. So if you want to keep the default behavior of searching for the startup file, don't enter that line into the "bios_config" file or don't even create the file if wanted.

Note2
This does NOT globally force all computers to use default, internal only or external only bootup, it is ONLY configuring the option per computer.