Compare commits
25 Commits
1.2.3
...
030e5bfd96
| Author | SHA1 | Date | |
|---|---|---|---|
| 030e5bfd96 | |||
| 099638c735 | |||
| 4f9eebade2 | |||
| 5172da1b5b | |||
| d08935b68a | |||
| 45b46cf3c4 | |||
| aeea68bc9b | |||
| f983b13d56 | |||
| 03c5b106c4 | |||
| 08323e00ff | |||
| 5e3cdbe40c | |||
| 8762b8f022 | |||
| 677b2cccec | |||
| a5e8624368 | |||
| bbda3b3937 | |||
| 585d39bec2 | |||
| b08b14763a | |||
| de6696003b | |||
| 9220281365 | |||
| 813ddabd9d | |||
| 5177639d71 | |||
| 528b4f31bd | |||
| 60162c7c57 | |||
| 18f5c454bb | |||
| 849ecb7dd6 |
@@ -6,31 +6,147 @@ local native = apis.peripheral
|
|||||||
local peripheral = {}
|
local peripheral = {}
|
||||||
local sides = {"top", "bottom", "left", "right", "front", "back"}
|
local sides = {"top", "bottom", "left", "right", "front", "back"}
|
||||||
|
|
||||||
function peripheral.getType(name)
|
function peripheral.getNames()
|
||||||
if native.isPresent(name) then return native.getType(name) end
|
local results = {}
|
||||||
for n = 1, #sides do
|
for n = 1, #sides do
|
||||||
local side = sides[n]
|
local side = sides[n]
|
||||||
if native.hasType(side, "peripheral_hub") and
|
if native.isPresent(side) then
|
||||||
native.call(side, "isPresentRemote", name) then
|
table.insert(results, side)
|
||||||
return native.call(side, "getTypeRemote", name)
|
if native.hasType(side, "peripheral_hub") then
|
||||||
|
local remote = native.call(side, "getNamesRemote")
|
||||||
|
for _, name in ipairs(remote) do
|
||||||
|
table.insert(results, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return results
|
||||||
|
end
|
||||||
|
|
||||||
|
function peripheral.isPresent(name)
|
||||||
|
if native.isPresent(name) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
for n = 1, #sides do
|
||||||
|
local side = sides[n]
|
||||||
|
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function peripheral.getType(peripheral)
|
||||||
|
if type(peripheral) == "string" then
|
||||||
|
if native.isPresent(peripheral) then
|
||||||
|
return native.getType(peripheral)
|
||||||
|
end
|
||||||
|
for n = 1, #sides do
|
||||||
|
local side = sides[n]
|
||||||
|
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", peripheral) then
|
||||||
|
return native.call(side, "getTypeRemote", peripheral)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
else
|
||||||
|
local mt = getmetatable(peripheral)
|
||||||
|
if not mt or mt.__name ~= "peripheral" or type(mt.types) ~= "table" then
|
||||||
|
error("bad argument #1 (table is not a peripheral)", 2)
|
||||||
|
end
|
||||||
|
return table.unpack(mt.types)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function peripheral.hasType(peripheral, peripheral_type)
|
||||||
|
if type(peripheral) == "string" then
|
||||||
|
if native.isPresent(peripheral) then
|
||||||
|
return native.hasType(peripheral, peripheral_type)
|
||||||
|
end
|
||||||
|
for n = 1, #sides do
|
||||||
|
local side = sides[n]
|
||||||
|
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", peripheral) then
|
||||||
|
return native.call(side, "hasTypeRemote", peripheral, peripheral_type)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
else
|
||||||
|
local mt = getmetatable(peripheral)
|
||||||
|
if not mt or mt.__name ~= "peripheral" or type(mt.types) ~= "table" then
|
||||||
|
error("bad argument #1 (table is not a peripheral)", 2)
|
||||||
|
end
|
||||||
|
return mt.types[peripheral_type] ~= nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function peripheral.getMethods(name)
|
||||||
|
if native.isPresent(name) then
|
||||||
|
return native.getMethods(name)
|
||||||
|
end
|
||||||
|
for n = 1, #sides do
|
||||||
|
local side = sides[n]
|
||||||
|
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
|
||||||
|
return native.call(side, "getMethodsRemote", name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function peripheral.getNames()
|
function peripheral.getName(peripheral)
|
||||||
local names = {}
|
local mt = getmetatable(peripheral)
|
||||||
|
if not mt or mt.__name ~= "peripheral" or type(mt.name) ~= "string" then
|
||||||
|
error("bad argument #1 (table is not a peripheral)", 2)
|
||||||
|
end
|
||||||
|
return mt.name
|
||||||
|
end
|
||||||
|
|
||||||
|
function peripheral.call(name, method, ...)
|
||||||
|
if native.isPresent(name) then
|
||||||
|
return native.call(name, method, ...)
|
||||||
|
end
|
||||||
|
|
||||||
for n = 1, #sides do
|
for n = 1, #sides do
|
||||||
local side = sides[n]
|
local side = sides[n]
|
||||||
if native.isPresent(side) then table.insert(names, side) end
|
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
|
||||||
if native.hasType(side, "peripheral_hub") then
|
return native.call(side, "callRemote", name, method, ...)
|
||||||
local hubSides = native.call(side, "getConnectedSides")
|
end
|
||||||
for _, hubSide in ipairs(hubSides) do
|
end
|
||||||
table.insert(names, hubSide)
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function peripheral.wrap(name)
|
||||||
|
local methods = peripheral.getMethods(name)
|
||||||
|
if not methods then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local types = { peripheral.getType(name) }
|
||||||
|
for i = 1, #types do types[types[i]] = true end
|
||||||
|
local result = setmetatable({}, {
|
||||||
|
__name = "peripheral",
|
||||||
|
name = name,
|
||||||
|
type = types[1],
|
||||||
|
types = types,
|
||||||
|
})
|
||||||
|
for _, method in ipairs(methods) do
|
||||||
|
result[method] = function(...)
|
||||||
|
return peripheral.call(name, method, ...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
function peripheral.find(ty, filter)
|
||||||
|
local results = {}
|
||||||
|
for _, name in ipairs(peripheral.getNames()) do
|
||||||
|
if peripheral.hasType(name, ty) then
|
||||||
|
local wrapped = peripheral.wrap(name)
|
||||||
|
if filter == nil or filter(name, wrapped) then
|
||||||
|
table.insert(results, wrapped)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return names
|
return table.unpack(results)
|
||||||
end
|
end
|
||||||
|
|
||||||
local disks = {}
|
local disks = {}
|
||||||
@@ -130,14 +246,9 @@ local function refresh()
|
|||||||
if not peripheral.getType(id) then disks[id] = nil end
|
if not peripheral.getType(id) then disks[id] = nil end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, name in ipairs(peripheral.getNames()) do
|
for _, disk in ipairs({peripheral.find("drive")}) do
|
||||||
if peripheral.getType(name) == "disk" then
|
if disk.isDiskPresent() then
|
||||||
if not disks[name] then
|
disks[tostring(disk.getDiskID())]=createDisk("cctdisk"..tostring(disk.getDiskID()), disk.getMountPath(), false, fs)
|
||||||
local mount = disk.getMountPath(name)
|
|
||||||
if mount then
|
|
||||||
disks[name] = createDisk(name, mount, false, disk)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
local args={...}
|
|
||||||
local kernel=args[1]
|
|
||||||
local driver={}
|
|
||||||
|
|
||||||
driver.name="CCT Term Module"
|
|
||||||
driver.version="0.1.0"
|
|
||||||
driver.type="gpio"
|
|
||||||
driver.description="CCT redstone Module Kernel Module"
|
|
||||||
driver.arch="cct"
|
|
||||||
driver.author="HyperionOS Dev Team"
|
|
||||||
driver.license="MIT"
|
|
||||||
driver.api={}
|
|
||||||
|
|
||||||
function driver.load()
|
|
||||||
-- will
|
|
||||||
end
|
|
||||||
|
|
||||||
function driver.unload()
|
|
||||||
-- Nothing to unload
|
|
||||||
end
|
|
||||||
|
|
||||||
function driver.main()
|
|
||||||
-- Nothing to run
|
|
||||||
end
|
|
||||||
|
|
||||||
-- kernel.drivers.register(driver)
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
--:Minify:--
|
--:Minify:--
|
||||||
|
|
||||||
local kernel = ...
|
local kernel = ...
|
||||||
local apis = kernel.apis
|
local apis = kernel.apis
|
||||||
local native = apis.peripheral
|
local native = apis.peripheral
|
||||||
@@ -130,18 +130,22 @@ if not initCfgStatus then
|
|||||||
end
|
end
|
||||||
kernel.config = config
|
kernel.config = config
|
||||||
|
|
||||||
|
local skip=false
|
||||||
for i,v in ipairs(split(fstab,"\n")) do
|
for i,v in ipairs(split(fstab,"\n")) do
|
||||||
if v:sub(1,1)=="U" then
|
if v:sub(1,1)=="U" then
|
||||||
local id=""
|
local id=""
|
||||||
for i=3,#v do
|
for i=3,#v do
|
||||||
if v:sub(i,i)==";" then
|
if v:sub(i,i)==";" then
|
||||||
if i==3 then kernel.log("Invalid fstab line... Skipping.","WARN") goto endline end
|
if i==3 then kernel.log("Invalid fstab line... Skipping.","WARN") skip = true break end
|
||||||
id=v:sub(3,i-1)
|
id=v:sub(3,i-1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local path=v:sub(#id+4)
|
if not skip then
|
||||||
ifs.mount(id,path)
|
local path=v:sub(#id+4)
|
||||||
::endline::
|
ifs.mount(id,path)
|
||||||
|
else
|
||||||
|
skip=false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
kernel.log("Disks initialized")
|
kernel.log("Disks initialized")
|
||||||
@@ -265,15 +269,13 @@ for _,p in ipairs(modules) do
|
|||||||
if kernel.config.showModLoad then kernel.log("Loading module "..v, "DBUG", 5) end
|
if kernel.config.showModLoad then kernel.log("Loading module "..v, "DBUG", 5) end
|
||||||
local code=ifs.readAllText(v)
|
local code=ifs.readAllText(v)
|
||||||
if not code then
|
if not code then
|
||||||
kernel.log("ModuReadErr: "..v, "WARN", 8)
|
kernel.panic("Failed to read module "..v)
|
||||||
goto skip
|
|
||||||
end
|
end
|
||||||
local func,err=load(code,"@"..v)
|
local func,err=load(code,"@"..v)
|
||||||
if not func then kernel.panic("ModuLoadErr: "..tostring(err)) goto skip end
|
if not func then kernel.panic("ModuLoadErr: "..tostring(err)) end
|
||||||
local status, err = xpcall(func,debug.traceback, kernel)
|
local status, err = xpcall(func,debug.traceback, kernel)
|
||||||
if not status then kernel.panic("ModuRunErr: "..tostring(err)) end
|
if not status then kernel.panic("ModuRunErr: "..tostring(err)) end
|
||||||
if kernel.config.showModLoad then kernel.log("Loaded module "..v, "DBUG", 5) end
|
if kernel.config.showModLoad then kernel.log("Loaded module "..v, "DBUG", 5) end
|
||||||
::skip::
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,17 @@ function proxy:open(path, mode)
|
|||||||
if type(step[steps[#steps]]) == "function" then
|
if type(step[steps[#steps]]) == "function" then
|
||||||
return step[steps[#steps]]("open", mode)
|
return step[steps[#steps]]("open", mode)
|
||||||
end
|
end
|
||||||
|
elseif tostring(steps[1])=="self" then
|
||||||
|
local task=kernel.currentTask
|
||||||
|
local step = newtaskproxy(task)
|
||||||
|
for i=2, #steps-1 do
|
||||||
|
local dat = step[steps[i]]
|
||||||
|
if type(dat) ~= "table" then error("ENFILE") end
|
||||||
|
step=dat
|
||||||
|
end
|
||||||
|
if type(step[steps[#steps]]) == "function" then
|
||||||
|
return step[steps[#steps]]("open", mode)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
for i=1, #steps-1 do
|
for i=1, #steps-1 do
|
||||||
local dat = step[steps[i]]
|
local dat = step[steps[i]]
|
||||||
@@ -166,6 +177,21 @@ function proxy:type(path, mode)
|
|||||||
if type(step[steps[#steps]]) == "table" then
|
if type(step[steps[#steps]]) == "table" then
|
||||||
return "directory"
|
return "directory"
|
||||||
end
|
end
|
||||||
|
elseif tostring(steps[1])=="self" then
|
||||||
|
local task=kernel.currentTask
|
||||||
|
if #steps==1 then return "directory" end
|
||||||
|
local step = newtaskproxy(task)
|
||||||
|
for i=2, #steps-1 do
|
||||||
|
local dat = step[steps[i]]
|
||||||
|
if type(dat) ~= "table" then error("ENFILE") end
|
||||||
|
step=dat
|
||||||
|
end
|
||||||
|
if type(step[steps[#steps]]) == "function" then
|
||||||
|
return step[steps[#steps]]("type", mode)
|
||||||
|
end
|
||||||
|
if type(step[steps[#steps]]) == "table" then
|
||||||
|
return "directory"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
for i=1, #steps-1 do
|
for i=1, #steps-1 do
|
||||||
local dat = step[steps[i]]
|
local dat = step[steps[i]]
|
||||||
@@ -186,7 +212,7 @@ function proxy:list(path)
|
|||||||
local steps = kernel.vfs.splitPath(path)
|
local steps = kernel.vfs.splitPath(path)
|
||||||
local step = data
|
local step = data
|
||||||
if #steps == 0 then
|
if #steps == 0 then
|
||||||
return table.merge(table.keys(data),table.keys(kernel.tasks))
|
return table.merge(table.keys(data),table.keys(kernel.tasks),{"self"})
|
||||||
end
|
end
|
||||||
if tonumber(steps[1]) then
|
if tonumber(steps[1]) then
|
||||||
local task=kernel.tasks[steps[1]]
|
local task=kernel.tasks[steps[1]]
|
||||||
@@ -200,6 +226,18 @@ function proxy:list(path)
|
|||||||
if type(step[steps[#steps]]) == "table" then
|
if type(step[steps[#steps]]) == "table" then
|
||||||
return table.keys(step[steps[#steps]])
|
return table.keys(step[steps[#steps]])
|
||||||
end
|
end
|
||||||
|
elseif tostring(steps[1])=="self" then
|
||||||
|
local task=kernel.currentTask
|
||||||
|
local step = newtaskproxy(task)
|
||||||
|
if #steps==1 then return table.keys(step) end
|
||||||
|
for i=2, #steps-1 do
|
||||||
|
local dat = step[steps[i]]
|
||||||
|
if type(dat) ~= "table" then error("ENOENT") end
|
||||||
|
step=dat
|
||||||
|
end
|
||||||
|
if type(step[steps[#steps]]) == "table" then
|
||||||
|
return table.keys(step[steps[#steps]])
|
||||||
|
end
|
||||||
else
|
else
|
||||||
for i=1, #steps-1 do
|
for i=1, #steps-1 do
|
||||||
local dat = step[steps[i]]
|
local dat = step[steps[i]]
|
||||||
|
|||||||
@@ -236,19 +236,18 @@ local function nextUID()
|
|||||||
return max + 1
|
return max + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function auth.login(username, password)
|
function auth.login(uid, password)
|
||||||
if type(username) ~= "string" or type(password) ~= "string" then
|
if type(uid) ~= "number" or type(password) ~= "string" then
|
||||||
return nil, "Authentication failure"
|
return nil, "Authentication failure"
|
||||||
end
|
end
|
||||||
|
|
||||||
local entry = getPasswdByUsername(username)
|
local entry = getPasswdByUID(uid)
|
||||||
if not entry then
|
if not entry then
|
||||||
-- timing attack resistance
|
-- timing attack resistance
|
||||||
hashPassword(password, "aaaaaaaaaaaaaaaa")
|
hashPassword(password, "aaaaaaaaaaaaaaaa")
|
||||||
return nil, "Authentication failure"
|
return nil, "Authentication failure"
|
||||||
end
|
end
|
||||||
|
|
||||||
local uid = tonumber(entry[1])
|
|
||||||
local sEntry = getShadowByUID(uid)
|
local sEntry = getShadowByUID(uid)
|
||||||
if not sEntry then
|
if not sEntry then
|
||||||
hashPassword(password, "aaaaaaaaaaaaaaaa")
|
hashPassword(password, "aaaaaaaaaaaaaaaa")
|
||||||
@@ -273,7 +272,7 @@ function auth.login(username, password)
|
|||||||
_task.egid = tonumber(entry[2]) or uid
|
_task.egid = tonumber(entry[2]) or uid
|
||||||
end
|
end
|
||||||
|
|
||||||
kernel.log("AUTH: login uid=" .. tostring(uid) .. " (" .. username .. ")")
|
kernel.log("AUTH: login uid=" .. tostring(uid) .. " (" .. getPasswdByUID(uid)[3] .. ")")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -619,4 +618,4 @@ if kernel.syscalls then
|
|||||||
kernel.syscalls["setshell"] = auth.setShell
|
kernel.syscalls["setshell"] = auth.setShell
|
||||||
kernel.syscalls["sethomedir"] = auth.setHomedir
|
kernel.syscalls["sethomedir"] = auth.setHomedir
|
||||||
kernel.syscalls["setgid"] = auth.setGID
|
kernel.syscalls["setgid"] = auth.setGID
|
||||||
end
|
end
|
||||||
@@ -96,8 +96,8 @@ if kernel.firstBoot then
|
|||||||
{"sbin", REG, 0, 0, RWX_RX_RX},
|
{"sbin", REG, 0, 0, RWX_RX_RX},
|
||||||
{"tmp", REG, 0, 0, RWXRWXRWX},
|
{"tmp", REG, 0, 0, RWXRWXRWX},
|
||||||
{"usr", REG, 0, 0, RWX_RX_RX},
|
{"usr", REG, 0, 0, RWX_RX_RX},
|
||||||
{"var", REG, 0, 0, RWX_RX_RX},
|
{"var", REG, 0, 0, RWXRWXRWX},
|
||||||
{"opt", REG, 0, 0, RWXRWXRWX},
|
{"opt", REG, 0, 0, RWX_RX_RX},
|
||||||
})
|
})
|
||||||
|
|
||||||
mergeMeta("/bin", {
|
mergeMeta("/bin", {
|
||||||
|
|||||||
@@ -126,35 +126,35 @@ local function doLogin()
|
|||||||
syscall.write(1, "Username: ")
|
syscall.write(1, "Username: ")
|
||||||
local username = readLine(nil)
|
local username = readLine(nil)
|
||||||
|
|
||||||
if username == "" then goto continue end
|
if username ~= "" then
|
||||||
|
|
||||||
syscall.write(1, "Password: ")
|
syscall.write(1, "Password: ")
|
||||||
local password = readLine("*")
|
local password = readLine("*")
|
||||||
|
local uid = syscall.getuidbyname(username)
|
||||||
|
|
||||||
local ok, err = syscall.login(username, password)
|
local ok, err = syscall.login(uid, password)
|
||||||
if ok then
|
if ok then
|
||||||
local uid = syscall.getuid()
|
local uid = syscall.getuid()
|
||||||
local pwent = syscall.getpasswd(uid)
|
local pwent = syscall.getpasswd(uid)
|
||||||
|
|
||||||
local shell = (pwent and pwent.shell) or "/bin/hysh"
|
local shell = (pwent and pwent.shell) or "/bin/hysh"
|
||||||
local homedir = (pwent and pwent.homedir) or "/"
|
local homedir = (pwent and pwent.homedir) or "/"
|
||||||
|
|
||||||
syscall.devctl(1, "sfgc", 3)
|
syscall.devctl(1, "sfgc", 3)
|
||||||
syscall.write(1, "\nWelcome, " .. username .. "!\n")
|
syscall.write(1, "\nWelcome, " .. username .. "!\n")
|
||||||
syscall.devctl(1, "sfgc", 1)
|
syscall.devctl(1, "sfgc", 1)
|
||||||
sleep(0.3)
|
sleep(0.3)
|
||||||
|
|
||||||
spawnShell(username, uid, shell, homedir)
|
spawnShell(username, uid, shell, homedir)
|
||||||
return -- back to login prompt
|
return -- back to login prompt
|
||||||
else
|
else
|
||||||
attempts = attempts + 1
|
attempts = attempts + 1
|
||||||
sleep(1)
|
sleep(1)
|
||||||
syscall.devctl(1, "sfgc", 2)
|
syscall.devctl(1, "sfgc", 2)
|
||||||
syscall.write(1, "Login incorrect.\n\n")
|
syscall.write(1, "Login incorrect.\n\n")
|
||||||
syscall.devctl(1, "sfgc", 1)
|
syscall.devctl(1, "sfgc", 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
::continue::
|
|
||||||
end
|
end
|
||||||
|
|
||||||
syscall.devctl(1, "sfgc", 2)
|
syscall.devctl(1, "sfgc", 2)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ local currentUid = syscall.getuid()
|
|||||||
|
|
||||||
local targetUid
|
local targetUid
|
||||||
if targetName then
|
if targetName then
|
||||||
targetUid = syscall.getuid(targetName)
|
targetUid = syscall.getuid()
|
||||||
if not targetUid then
|
if not targetUid then
|
||||||
print("passwd: user '" .. targetName .. "' does not exist")
|
print("passwd: user '" .. targetName .. "' does not exist")
|
||||||
syscall.exit(1); return
|
syscall.exit(1); return
|
||||||
@@ -36,7 +36,7 @@ if currentUid ~= 0 then
|
|||||||
if #cur > 0 then cur=cur:sub(1,-2); syscall.write(1,"\b \b") end
|
if #cur > 0 then cur=cur:sub(1,-2); syscall.write(1,"\b \b") end
|
||||||
else cur=cur..ch; syscall.write(1,"*") end
|
else cur=cur..ch; syscall.write(1,"*") end
|
||||||
end
|
end
|
||||||
local ok, err = syscall.elevate(targetName, cur)
|
local ok, err = syscall.login(targetUid, cur)
|
||||||
if not ok then
|
if not ok then
|
||||||
sleep(1)
|
sleep(1)
|
||||||
print("passwd: authentication failure")
|
print("passwd: authentication failure")
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
--:Minify:--
|
--:Minify:--
|
||||||
local targetUser = ({ ... })[1] or "root"
|
local targetUser = ({ ... })[1]
|
||||||
local currentUid = syscall.getuid()
|
local currentUid = syscall.getuid()
|
||||||
local targetUid = syscall.getuidbyname(targetUser)
|
local targetUid
|
||||||
|
if targetUser then
|
||||||
|
targetUid = syscall.getuidbyname(targetUser)
|
||||||
|
else
|
||||||
|
targetUid = 0
|
||||||
|
end
|
||||||
|
|
||||||
if not targetUid then
|
if not targetUid then
|
||||||
print("su: user '" .. targetUser .. "' does not exist")
|
print("su: user '" .. targetUser .. "' does not exist")
|
||||||
@@ -25,20 +30,21 @@ if currentUid ~= 0 then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, err = syscall.elevate(targetUser, pw)
|
local ok, err = syscall.login(targetUid, pw)
|
||||||
if not ok then
|
if not ok then
|
||||||
sleep(1)
|
sleep(1)
|
||||||
print("su: Authentication failure")
|
print("su: Authentication failure")
|
||||||
syscall.exit(1)
|
syscall.exit(1)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
syscall.setuid(targetUid)
|
||||||
end
|
end
|
||||||
|
|
||||||
syscall.setuid(targetUid)
|
|
||||||
|
|
||||||
local pwent = syscall.getpasswd(targetUid)
|
local pwent = syscall.getpasswd(targetUid)
|
||||||
local shell = (pwent and pwent.shell) or "/bin/hysh"
|
local shell = (pwent and pwent.shell) or "/bin/hysh"
|
||||||
local homedir = (pwent and pwent.homedir) or "/"
|
local homedir = (pwent and pwent.homedir) or "/"
|
||||||
|
local username= (pwent and pwent.username)or "Unknown"
|
||||||
|
|
||||||
local ok_cd, err_cd = pcall(syscall.chdir, homedir)
|
local ok_cd, err_cd = pcall(syscall.chdir, homedir)
|
||||||
if not ok_cd then
|
if not ok_cd then
|
||||||
@@ -46,11 +52,11 @@ if not ok_cd then
|
|||||||
syscall.chdir(homedir)
|
syscall.chdir(homedir)
|
||||||
end
|
end
|
||||||
syscall.setEnviron("HOME", homedir)
|
syscall.setEnviron("HOME", homedir)
|
||||||
syscall.setEnviron("USER", targetUser)
|
syscall.setEnviron("USER", username)
|
||||||
syscall.setEnviron("SHELL", shell)
|
syscall.setEnviron("SHELL", shell)
|
||||||
|
|
||||||
local ok, err = pcall(syscall.exec, shell)
|
local ok, err = pcall(syscall.exec, shell)
|
||||||
if not ok then
|
if not ok then
|
||||||
print("su: cannot exec shell '" .. shell .. "': " .. tostring(err))
|
print("su: cannot exec shell '" .. shell .. "': " .. tostring(err))
|
||||||
syscall.exit(1)
|
syscall.exit(1)
|
||||||
end
|
end
|
||||||
@@ -55,7 +55,7 @@ if currentUid ~= 0 then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, err = syscall.elevate("root", pw)
|
local ok, err = syscall.login(0, pw)
|
||||||
if not ok then
|
if not ok then
|
||||||
sleep(1)
|
sleep(1)
|
||||||
print("sudo: Authentication failure")
|
print("sudo: Authentication failure")
|
||||||
|
|||||||
@@ -308,16 +308,16 @@ local history = {}
|
|||||||
|
|
||||||
while true do
|
while true do
|
||||||
local code = getUserInput("lua> ", history)
|
local code = getUserInput("lua> ", history)
|
||||||
if code == "" then goto continue end
|
if code ~= "" then
|
||||||
|
|
||||||
while isIncomplete(code) do
|
while isIncomplete(code) do
|
||||||
code = code .. "\n" .. getUserInput("... ", nil)
|
code = code .. "\n" .. getUserInput("... ", nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
if code ~= history[#history] then
|
||||||
|
history[#history+1] = code
|
||||||
|
end
|
||||||
|
|
||||||
|
runCode(code)
|
||||||
end
|
end
|
||||||
|
|
||||||
if code ~= history[#history] then
|
|
||||||
history[#history+1] = code
|
|
||||||
end
|
|
||||||
|
|
||||||
runCode(code)
|
|
||||||
::continue::
|
|
||||||
end
|
end
|
||||||
|
|||||||
122
Src/sed/bin/sed
122
Src/sed/bin/sed
@@ -139,72 +139,68 @@ local function parseCommands(src)
|
|||||||
local c = src:sub(pos, pos)
|
local c = src:sub(pos, pos)
|
||||||
if c == "\n" or c == ";" then
|
if c == "\n" or c == ";" then
|
||||||
pos = pos + 1
|
pos = pos + 1
|
||||||
goto continue
|
elseif c == "#" then
|
||||||
end
|
|
||||||
if c == "#" then
|
|
||||||
while pos <= len and src:sub(pos,pos) ~= "\n" do pos = pos + 1 end
|
while pos <= len and src:sub(pos,pos) ~= "\n" do pos = pos + 1 end
|
||||||
goto continue
|
|
||||||
end
|
|
||||||
|
|
||||||
local addr1, addr2
|
|
||||||
addr1, pos = parseAddr(src, pos)
|
|
||||||
skip()
|
|
||||||
if addr1 and pos <= len and src:sub(pos,pos) == "," then
|
|
||||||
pos = pos + 1
|
|
||||||
skip()
|
|
||||||
addr2, pos = parseAddr(src, pos)
|
|
||||||
end
|
|
||||||
skip()
|
|
||||||
|
|
||||||
if pos > len then break end
|
|
||||||
local cmd = src:sub(pos, pos)
|
|
||||||
pos = pos + 1
|
|
||||||
|
|
||||||
if cmd == "s" then
|
|
||||||
local delim = src:sub(pos, pos); pos = pos + 1
|
|
||||||
local pat, p1 = parseDelim(src, pos, delim); pos = p1
|
|
||||||
local repl, p2 = parseDelim(src, pos, delim); pos = p2
|
|
||||||
local flags = ""
|
|
||||||
while pos <= len and src:sub(pos,pos):match("[giIp]") do
|
|
||||||
flags = flags .. src:sub(pos,pos); pos = pos + 1
|
|
||||||
end
|
|
||||||
table.insert(cmds, { addr1=addr1, addr2=addr2, cmd="s",
|
|
||||||
pat=pat, repl=repl, flags=flags })
|
|
||||||
|
|
||||||
elseif cmd == "y" then
|
|
||||||
local delim = src:sub(pos, pos); pos = pos + 1
|
|
||||||
local srcch, p1 = parseDelim(src, pos, delim); pos = p1
|
|
||||||
local dstch, p2 = parseDelim(src, pos, delim); pos = p2
|
|
||||||
table.insert(cmds, { addr1=addr1, addr2=addr2, cmd="y",
|
|
||||||
src=srcch, dst=dstch })
|
|
||||||
|
|
||||||
elseif cmd == "d" or cmd == "p" or cmd == "q" or cmd == "=" then
|
|
||||||
table.insert(cmds, { addr1=addr1, addr2=addr2, cmd=cmd })
|
|
||||||
|
|
||||||
elseif cmd == "{" then
|
|
||||||
local depth = 1
|
|
||||||
local start = pos
|
|
||||||
while pos <= len and depth > 0 do
|
|
||||||
local ch = src:sub(pos,pos)
|
|
||||||
if ch == "{" then depth = depth + 1
|
|
||||||
elseif ch == "}" then depth = depth - 1 end
|
|
||||||
pos = pos + 1
|
|
||||||
end
|
|
||||||
local inner = src:sub(start, pos - 2)
|
|
||||||
local innerCmds = parseCommands(inner)
|
|
||||||
for _, ic in ipairs(innerCmds) do
|
|
||||||
ic.addr1 = ic.addr1 or addr1
|
|
||||||
ic.addr2 = ic.addr2 or addr2
|
|
||||||
end
|
|
||||||
for _, ic in ipairs(innerCmds) do
|
|
||||||
table.insert(cmds, ic)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif cmd == "\n" or cmd == ";" then
|
|
||||||
else
|
else
|
||||||
end
|
|
||||||
|
|
||||||
::continue::
|
local addr1, addr2
|
||||||
|
addr1, pos = parseAddr(src, pos)
|
||||||
|
skip()
|
||||||
|
if addr1 and pos <= len and src:sub(pos,pos) == "," then
|
||||||
|
pos = pos + 1
|
||||||
|
skip()
|
||||||
|
addr2, pos = parseAddr(src, pos)
|
||||||
|
end
|
||||||
|
skip()
|
||||||
|
|
||||||
|
if pos > len then break end
|
||||||
|
local cmd = src:sub(pos, pos)
|
||||||
|
pos = pos + 1
|
||||||
|
|
||||||
|
if cmd == "s" then
|
||||||
|
local delim = src:sub(pos, pos); pos = pos + 1
|
||||||
|
local pat, p1 = parseDelim(src, pos, delim); pos = p1
|
||||||
|
local repl, p2 = parseDelim(src, pos, delim); pos = p2
|
||||||
|
local flags = ""
|
||||||
|
while pos <= len and src:sub(pos,pos):match("[giIp]") do
|
||||||
|
flags = flags .. src:sub(pos,pos); pos = pos + 1
|
||||||
|
end
|
||||||
|
table.insert(cmds, { addr1=addr1, addr2=addr2, cmd="s",
|
||||||
|
pat=pat, repl=repl, flags=flags })
|
||||||
|
|
||||||
|
elseif cmd == "y" then
|
||||||
|
local delim = src:sub(pos, pos); pos = pos + 1
|
||||||
|
local srcch, p1 = parseDelim(src, pos, delim); pos = p1
|
||||||
|
local dstch, p2 = parseDelim(src, pos, delim); pos = p2
|
||||||
|
table.insert(cmds, { addr1=addr1, addr2=addr2, cmd="y",
|
||||||
|
src=srcch, dst=dstch })
|
||||||
|
|
||||||
|
elseif cmd == "d" or cmd == "p" or cmd == "q" or cmd == "=" then
|
||||||
|
table.insert(cmds, { addr1=addr1, addr2=addr2, cmd=cmd })
|
||||||
|
|
||||||
|
elseif cmd == "{" then
|
||||||
|
local depth = 1
|
||||||
|
local start = pos
|
||||||
|
while pos <= len and depth > 0 do
|
||||||
|
local ch = src:sub(pos,pos)
|
||||||
|
if ch == "{" then depth = depth + 1
|
||||||
|
elseif ch == "}" then depth = depth - 1 end
|
||||||
|
pos = pos + 1
|
||||||
|
end
|
||||||
|
local inner = src:sub(start, pos - 2)
|
||||||
|
local innerCmds = parseCommands(inner)
|
||||||
|
for _, ic in ipairs(innerCmds) do
|
||||||
|
ic.addr1 = ic.addr1 or addr1
|
||||||
|
ic.addr2 = ic.addr2 or addr2
|
||||||
|
end
|
||||||
|
for _, ic in ipairs(innerCmds) do
|
||||||
|
table.insert(cmds, ic)
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif cmd == "\n" or cmd == ";" then
|
||||||
|
else
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return cmds
|
return cmds
|
||||||
|
|||||||
Binary file not shown.
@@ -4,24 +4,18 @@ term.clear()
|
|||||||
print("Do you want to install HyperionOS? [Y/n]")
|
print("Do you want to install HyperionOS? [Y/n]")
|
||||||
local input=read()
|
local input=read()
|
||||||
if input=="y" or input=="Y" or input=="" then
|
if input=="y" or input=="Y" or input=="" then
|
||||||
goto install
|
print("Installing tar but bad...")
|
||||||
else
|
shell.run("wget https://git.astronand.dev/Hyperion/HyperionOS/raw/branch/main/install/data/tarbad /tar.lua")
|
||||||
goto exit
|
print("Installing HyperionOS...")
|
||||||
end
|
print("Installing precompiled tar")
|
||||||
|
shell.run("wget https://git.astronand.dev/Hyperion/HyperionOS/raw/branch/main/install/data/Build.tar /Build.tar")
|
||||||
::install::
|
shell.run("tar Build.tar /")
|
||||||
print("Installing tar but bad...")
|
print("Removing tar but bad...")
|
||||||
shell.run("wget https://git.astronand.dev/Hyperion/HyperionOS/raw/branch/1.2-dev/install/data/tarbad /tar.lua")
|
shell.run("rm /tar.lua")
|
||||||
print("Installing HyperionOS...")
|
shell.run("rm $")
|
||||||
print("Installing precompiled tar")
|
shell.run("cp Build $")
|
||||||
shell.run("wget https://git.astronand.dev/Hyperion/HyperionOS/raw/branch/1.2-dev/install/data/Build.tar /Build.tar")
|
shell.run("rm Build")
|
||||||
shell.run("tar Build.tar /")
|
shell.run("rm Build.tar")
|
||||||
print("Removing tar but bad...")
|
fs.copy("/$/boot/cct/eeprom","/startup.lua")
|
||||||
shell.run("rm /tar.lua")
|
dofile("startup.lua")
|
||||||
shell.run("rm $")
|
end
|
||||||
shell.run("cp Build $")
|
|
||||||
shell.run("rm Build")
|
|
||||||
shell.run("rm Build.tar")
|
|
||||||
fs.copy("/$/boot/cct/eeprom","/startup.lua")
|
|
||||||
dofile("startup.lua")
|
|
||||||
::exit::
|
|
||||||
18
manifest.lua
18
manifest.lua
@@ -3,6 +3,8 @@
|
|||||||
--- @diagnostic disable: duplicate-set-field
|
--- @diagnostic disable: duplicate-set-field
|
||||||
syscall={}
|
syscall={}
|
||||||
|
|
||||||
|
--- @alias userinfo {username:string,homedir:string,shell:string,uid:number,gid:number}
|
||||||
|
|
||||||
--- Sets home directory of User with corresponding uid to homedir
|
--- Sets home directory of User with corresponding uid to homedir
|
||||||
--- @param uid integer
|
--- @param uid integer
|
||||||
--- @param homedir string
|
--- @param homedir string
|
||||||
@@ -164,7 +166,7 @@ syscall.setpassword=function(uid, newPassword) end
|
|||||||
|
|
||||||
--- Set environment variable
|
--- Set environment variable
|
||||||
--- @param key string
|
--- @param key string
|
||||||
--- @param value string
|
--- @param value any
|
||||||
--- @return boolean
|
--- @return boolean
|
||||||
syscall.setEnviron=function(key, value) end
|
syscall.setEnviron=function(key, value) end
|
||||||
|
|
||||||
@@ -197,7 +199,7 @@ syscall.exit=function(code) end
|
|||||||
|
|
||||||
--- Get environment variable
|
--- Get environment variable
|
||||||
--- @param key string
|
--- @param key string
|
||||||
--- @return string|nil
|
--- @return any
|
||||||
syscall.getEnviron=function(key) end
|
syscall.getEnviron=function(key) end
|
||||||
|
|
||||||
--- Continue a stopped task
|
--- Continue a stopped task
|
||||||
@@ -337,7 +339,7 @@ syscall.remove=function(path) end
|
|||||||
--- @return string|nil
|
--- @return string|nil
|
||||||
syscall.type=function(path) end
|
syscall.type=function(path) end
|
||||||
|
|
||||||
--- Elevate to another user with password
|
--- Elevate to root with password (Disabled due to VULN)
|
||||||
--- @param targetUsername string
|
--- @param targetUsername string
|
||||||
--- @param password string
|
--- @param password string
|
||||||
--- @return boolean
|
--- @return boolean
|
||||||
@@ -374,11 +376,11 @@ syscall.setusername=function(uid, newUsername) end
|
|||||||
--- @return integer
|
--- @return integer
|
||||||
syscall.geteuid=function() end
|
syscall.geteuid=function() end
|
||||||
|
|
||||||
--- Login user
|
--- Login as user
|
||||||
--- @param username string
|
--- @param uid integer
|
||||||
--- @param password string
|
--- @param password string
|
||||||
--- @return boolean
|
--- @return boolean
|
||||||
syscall.login=function(username, password) end
|
syscall.login=function(uid, password) end
|
||||||
|
|
||||||
--- Get system hostname
|
--- Get system hostname
|
||||||
--- @return string
|
--- @return string
|
||||||
@@ -514,9 +516,9 @@ syscall.access=function(path, mode) end
|
|||||||
--- Ignore current signal
|
--- Ignore current signal
|
||||||
syscall.sigignore=function() end
|
syscall.sigignore=function() end
|
||||||
|
|
||||||
--- Get user password hash
|
--- Get user information
|
||||||
--- @param uid integer
|
--- @param uid integer
|
||||||
--- @return string|nil
|
--- @return userinfo|nil
|
||||||
syscall.getpasswd=function(uid) end
|
syscall.getpasswd=function(uid) end
|
||||||
|
|
||||||
--- Get OS version
|
--- Get OS version
|
||||||
|
|||||||
Reference in New Issue
Block a user