1 Commits

Author SHA1 Message Date
e41bd6bee7 Merge pull request '1.2-dev merge' (#5) from 1.2-dev into main
Reviewed-on: #5
2026-03-10 12:27:08 -04:00
18 changed files with 82 additions and 214 deletions

View File

@@ -6,147 +6,31 @@ 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)
if native.isPresent(name) then return native.getType(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, "getTypeRemote", name)
end
end
return nil
end
function peripheral.getNames() function peripheral.getNames()
local results = {} local names = {}
for n = 1, #sides do for n = 1, #sides do
local side = sides[n] local side = sides[n]
if native.isPresent(side) then if native.isPresent(side) then table.insert(names, side) end
table.insert(results, side) if native.hasType(side, "peripheral_hub") then
if native.hasType(side, "peripheral_hub") then local hubSides = native.call(side, "getConnectedSides")
local remote = native.call(side, "getNamesRemote") for _, hubSide in ipairs(hubSides) do
for _, name in ipairs(remote) do table.insert(names, hubSide)
table.insert(results, name)
end
end end
end end
end end
return results return names
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
return nil
end
function peripheral.getName(peripheral)
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
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
return native.call(side, "callRemote", name, method, ...)
end
end
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
return table.unpack(results)
end end
local disks = {} local disks = {}
@@ -246,9 +130,14 @@ 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 _, disk in ipairs({peripheral.find("drive")}) do for _, name in ipairs(peripheral.getNames()) do
if disk.isDiskPresent() then if peripheral.getType(name) == "disk" then
disks[tostring(disk.getDiskID())]=createDisk("cctdisk"..tostring(disk.getDiskID()), disk.getMountPath(), false, fs) if not disks[name] then
local mount = disk.getMountPath(name)
if mount then
disks[name] = createDisk(name, mount, false, disk)
end
end
end end
end end
end end

View File

@@ -1,5 +1,4 @@
--:Minify:-- --:Minify:--
local kernel = ... local kernel = ...
local apis = kernel.apis local apis = kernel.apis
local native = apis.peripheral local native = apis.peripheral

View File

@@ -0,0 +1,26 @@
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)

View File

@@ -132,17 +132,6 @@ 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]]
@@ -177,21 +166,6 @@ 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]]
@@ -212,7 +186,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),{"self"}) return table.merge(table.keys(data),table.keys(kernel.tasks))
end end
if tonumber(steps[1]) then if tonumber(steps[1]) then
local task=kernel.tasks[steps[1]] local task=kernel.tasks[steps[1]]
@@ -226,18 +200,6 @@ 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]]

View File

@@ -236,18 +236,19 @@ local function nextUID()
return max + 1 return max + 1
end end
function auth.login(uid, password) function auth.login(username, password)
if type(uid) ~= "number" or type(password) ~= "string" then if type(username) ~= "string" or type(password) ~= "string" then
return nil, "Authentication failure" return nil, "Authentication failure"
end end
local entry = getPasswdByUID(uid) local entry = getPasswdByUsername(username)
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")
@@ -272,7 +273,7 @@ function auth.login(uid, password)
_task.egid = tonumber(entry[2]) or uid _task.egid = tonumber(entry[2]) or uid
end end
kernel.log("AUTH: login uid=" .. tostring(uid) .. " (" .. getPasswdByUID(uid)[3] .. ")") kernel.log("AUTH: login uid=" .. tostring(uid) .. " (" .. username .. ")")
return true return true
end end

View File

@@ -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, RWXRWXRWX}, {"var", REG, 0, 0, RWX_RX_RX},
{"opt", REG, 0, 0, RWX_RX_RX}, {"opt", REG, 0, 0, RWXRWXRWX},
}) })
mergeMeta("/bin", { mergeMeta("/bin", {

View File

@@ -130,9 +130,8 @@ local function doLogin()
syscall.write(1, "Password: ") syscall.write(1, "Password: ")
local password = readLine("*") local password = readLine("*")
local uid = syscall.getuidbyname(username)
local ok, err = syscall.login(uid, password) local ok, err = syscall.login(username, 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)

View File

@@ -9,7 +9,7 @@ local currentUid = syscall.getuid()
local targetUid local targetUid
if targetName then if targetName then
targetUid = syscall.getuid() targetUid = syscall.getuid(targetName)
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.login(targetUid, cur) local ok, err = syscall.elevate(targetName, cur)
if not ok then if not ok then
sleep(1) sleep(1)
print("passwd: authentication failure") print("passwd: authentication failure")

View File

@@ -1,12 +1,7 @@
--:Minify:-- --:Minify:--
local targetUser = ({ ... })[1] local targetUser = ({ ... })[1] or "root"
local currentUid = syscall.getuid() local currentUid = syscall.getuid()
local targetUid local targetUid = syscall.getuidbyname(targetUser)
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")
@@ -30,21 +25,20 @@ if currentUid ~= 0 then
end end
end end
local ok, err = syscall.login(targetUid, pw) local ok, err = syscall.elevate(targetUser, 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
@@ -52,7 +46,7 @@ if not ok_cd then
syscall.chdir(homedir) syscall.chdir(homedir)
end end
syscall.setEnviron("HOME", homedir) syscall.setEnviron("HOME", homedir)
syscall.setEnviron("USER", username) syscall.setEnviron("USER", targetUser)
syscall.setEnviron("SHELL", shell) syscall.setEnviron("SHELL", shell)
local ok, err = pcall(syscall.exec, shell) local ok, err = pcall(syscall.exec, shell)

View File

@@ -55,7 +55,7 @@ if currentUid ~= 0 then
end end
end end
local ok, err = syscall.login(0, pw) local ok, err = syscall.elevate("root", pw)
if not ok then if not ok then
sleep(1) sleep(1)
print("sudo: Authentication failure") print("sudo: Authentication failure")

Binary file not shown.

View File

@@ -3,8 +3,6 @@
--- @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
@@ -166,7 +164,7 @@ syscall.setpassword=function(uid, newPassword) end
--- Set environment variable --- Set environment variable
--- @param key string --- @param key string
--- @param value any --- @param value string
--- @return boolean --- @return boolean
syscall.setEnviron=function(key, value) end syscall.setEnviron=function(key, value) end
@@ -199,7 +197,7 @@ syscall.exit=function(code) end
--- Get environment variable --- Get environment variable
--- @param key string --- @param key string
--- @return any --- @return string|nil
syscall.getEnviron=function(key) end syscall.getEnviron=function(key) end
--- Continue a stopped task --- Continue a stopped task
@@ -339,7 +337,7 @@ syscall.remove=function(path) end
--- @return string|nil --- @return string|nil
syscall.type=function(path) end syscall.type=function(path) end
--- Elevate to root with password (Disabled due to VULN) --- Elevate to another user with password
--- @param targetUsername string --- @param targetUsername string
--- @param password string --- @param password string
--- @return boolean --- @return boolean
@@ -376,11 +374,11 @@ syscall.setusername=function(uid, newUsername) end
--- @return integer --- @return integer
syscall.geteuid=function() end syscall.geteuid=function() end
--- Login as user --- Login user
--- @param uid integer --- @param username string
--- @param password string --- @param password string
--- @return boolean --- @return boolean
syscall.login=function(uid, password) end syscall.login=function(username, password) end
--- Get system hostname --- Get system hostname
--- @return string --- @return string
@@ -516,9 +514,9 @@ syscall.access=function(path, mode) end
--- Ignore current signal --- Ignore current signal
syscall.sigignore=function() end syscall.sigignore=function() end
--- Get user information --- Get user password hash
--- @param uid integer --- @param uid integer
--- @return userinfo|nil --- @return string|nil
syscall.getpasswd=function(uid) end syscall.getpasswd=function(uid) end
--- Get OS version --- Get OS version