This commit is contained in:
Ryan T
2026-02-20 15:23:48 -05:00
15 changed files with 68 additions and 60 deletions

View File

@@ -4,6 +4,7 @@
"isEqualToAll", "isEqualToAll",
"syscall", "syscall",
"printf", "printf",
"printInline" "printInline",
"toHex"
] ]
} }

View File

@@ -173,6 +173,17 @@ local function getUserInput()
end end
local function runCommand(command) local function runCommand(command)
do
local func = load("return " .. command, "@equation", "t", {})
if func then
local success, result = pcall(func)
if success and type(result) == "number" then
print(result)
return
end
end
end
terminate = false terminate = false
local args = string.split(command, " ") local args = string.split(command, " ")
if builtinCmds[args[1]] then if builtinCmds[args[1]] then

View File

@@ -21,3 +21,4 @@ while content~=nil or file == 0 do
printInline(content) printInline(content)
end end
syscall.close(file) syscall.close(file)
print("")

View File

View File

@@ -25,7 +25,6 @@ for i,v in ipairs(files) do
kernel.log("Error loading startup script '" .. filepath .. "': " .. err, "ERROR") kernel.log("Error loading startup script '" .. filepath .. "': " .. err, "ERROR")
else else
syscall.spawn(function() syscall.spawn(function()
syscall.setUsername("User")
syscall.setuid(1) syscall.setuid(1)
local status, err = pcall(startupFunc) local status, err = pcall(startupFunc)
if not status then if not status then

View File

@@ -10,7 +10,7 @@ local kernel = {}
kernel.LOG_Text="" kernel.LOG_Text=""
kernel.version="HyperionOS V1.0.0" kernel.version="HyperionOS V1.0.0"
kernel.process = "Kernel" kernel.process = "Kernel"
kernel.username = "root" kernel.users={[0]="root",[1]="User"}
kernel.hostname = "hyperion" kernel.hostname = "hyperion"
kernel.groups = {} kernel.groups = {}
kernel.uid = 0 kernel.uid = 0
@@ -27,15 +27,15 @@ local windowsExp = false
function kernel.log(msg, level, c) function kernel.log(msg, level, c)
c=c or 12 c=c or 12
kernel.LOG_Text = kernel.LOG_Text..tostring(computer:time()).." "..kernel.username.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg.."\n" kernel.LOG_Text = kernel.LOG_Text..tostring(computer:time()).." "..kernel.users[kernel.uid].." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg.."\n"
if kernel.status == "start" then if kernel.status == "start" then
screen:setTextColor(c) screen:setTextColor(c)
screen:print(tostring(computer:time()).." "..kernel.username.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg) screen:print(string.format("%X",c-1).." "..tostring(computer:time()).." "..kernel.users[kernel.uid].." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg)
elseif kernel.status == "init" then elseif kernel.status == "term" then
kernel.standbyTask=kernel.currentTask kernel.standbyTask=kernel.currentTask
kernel.currentTask=kernel.kernelTask kernel.currentTask=kernel.kernelTask
kernel.vfs.devctl(1,"sfgc",c) kernel.vfs.devctl(1,"sfgc",c)
kernel.vfs.write(1,tostring(computer:time()).." "..kernel.username.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg) kernel.vfs.write(1,string.format("%X",c-1).." "..tostring(computer:time()).." "..kernel.users[kernel.uid].." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg.."\n")
kernel.currentTask=kernel.standbyTask kernel.currentTask=kernel.standbyTask
end end
end end
@@ -204,7 +204,6 @@ kernel.kernelTask = {
status="R", status="R",
pid=0, pid=0,
tgid=0, tgid=0,
username="root",
uid=0, uid=0,
fd={}, fd={},
exit="", exit="",
@@ -232,12 +231,11 @@ end
kernel.syscalls["time"]=function() return kernel.computer:time() end kernel.syscalls["time"]=function() return kernel.computer:time() end
kernel.syscalls["log"]=kernel.log kernel.syscalls["log"]=kernel.log
kernel.syscalls["getUptime"]=function() return kernel.computer:clock() end kernel.syscalls["getUptime"]=function() return kernel.computer:clock() end
kernel.syscalls["getUsername"]=function() return kernel.username end kernel.syscalls["getUsername"]=function(uid) return kernel.users[uid or kernel.uid] end
kernel.syscalls["getHostname"]=function() return kernel.hostname end kernel.syscalls["getHostname"]=function() return kernel.hostname end
kernel.syscalls["getHost"]=function() return kernel.apis._HOST end kernel.syscalls["getHost"]=function() return kernel.apis._HOST end
kernel.syscalls["version"]=function() return kernel.version end kernel.syscalls["version"]=function() return kernel.version end
kernel.syscalls["setHostname"]=function(name) if kernel.uid~=0 then error("Permission denied") end kernel.hostname=name end kernel.syscalls["setHostname"]=function(name) if kernel.uid~=0 then error("Permission denied") end kernel.hostname=name end
kernel.syscalls["setUsername"]=function(user) if kernel.uid~=0 then error("Permission denied") end kernel.currentTask.username=user end
kernel.syscalls["arch"]=function() return arch end kernel.syscalls["arch"]=function() return arch end
kernel.syscalls["sysdump"]=function() kernel.syscalls["sysdump"]=function()
local rv={} local rv={}

View File

@@ -0,0 +1 @@
0:0:root:/root:/bin/bash

View File

View File

@@ -205,6 +205,10 @@ function string.replace(s, target, repl)
return table.concat(result) return table.concat(result)
end end
function toHex(num)
return string.format("%X", num)
end
syscall = setmetatable({}, { syscall = setmetatable({}, {
__index = function(self, name) __index = function(self, name)
return function(...) return function(...)

View File

@@ -3,3 +3,4 @@ local kernel=...
kernel.vfs.open("/dev/null", "r") kernel.vfs.open("/dev/null", "r")
kernel.vfs.open("/dev/tty/TTY1", "w") kernel.vfs.open("/dev/tty/TTY1", "w")
kernel.vfs.open("/dev/null", "w") kernel.vfs.open("/dev/null", "w")
kernel.status="term"

View File

@@ -1,8 +1,22 @@
--:Minify:-- --:Minify:--
local kernel = ... local kernel = ...
local pam = {} local auth = {}
kernel.pam = pam kernel.auth = auth
local loggedIn = {}
-- @SPSF work here
-- needed
-- login -- sets the current proccess to the specifyed user id
-- setPassword -- sets the password for specifiyed user id
-- setUsername -- sets
-- newUser -- sets
-- PASSWD FILE FORMAT
-- uid:gid:username:homedir:shell
-- SHADOW FILE FORMAT
-- uid:salt:hash
local function getFile(path) local function getFile(path)
local file = kernel.vfs.open(path, "r") local file = kernel.vfs.open(path, "r")
@@ -13,7 +27,6 @@ local function getFile(path)
end end
local blake2s local blake2s
do do
local MOD32 = 2^32 local MOD32 = 2^32
local function norm(x) local function norm(x)
@@ -187,9 +200,10 @@ end
if not blake2s then error("Failed to load blake2s") end if not blake2s then error("Failed to load blake2s") end
if not kernel.vfs.exists("/etc/pam.d/secret") then if not kernel.vfs.exists("/etc/pam.d/secret") then
kernel.log("PAM SECRET REGENERATING PLEASE USE ROOT")
local key = "" local key = ""
for i=1, 256 do for i=1, 256 do
key=key..string.char(math.random(1,255)) key=key..string.char(math.random(0,255))
end end
local handle = kernel.vfs.open("/etc/pam.d/secret", "w") local handle = kernel.vfs.open("/etc/pam.d/secret", "w")
kernel.vfs.write(handle, key) kernel.vfs.write(handle, key)
@@ -197,41 +211,22 @@ if not kernel.vfs.exists("/etc/pam.d/secret") then
end end
local pepper = getFile("/etc/pam.d/secret") local pepper = getFile("/etc/pam.d/secret")
local passwdFile = getFile("/etc/passwd")
local shadowFile = getFile("/etc/shadow")
local passwdLines = string.split(passwdFile,"\n")
local shadowLines = string.split(shadowFile,"\n")
local passwd,shadow={},{}
function pam.authenticate(username, password) for _,v in ipairs(passwdLines) do
local fpasswd = getFile("/etc/passwd") passwd[#passwd+1]=string.split(v,":")
local fshadow = getFile("/etc/shadow")
local passwdLines = string.split(fpasswd, "\n")
local shadowLines = string.split(fshadow, "\n")
local passwd = {}
local shadow = {}
for _, line in ipairs(passwdLines) do
local fields = string.split(line, ":")
passwd[fields[1]] = fields
end
for _, line in ipairs(shadowLines) do
local fields = string.split(line, ":")
shadow[fields[1]] = fields
end
for user, fields in pairs(passwd) do
if user == username then
local shadowPasswd = string.split(shadow[user][2], "$")
local salt = shadowPasswd[2]
local hashedPassword = blake2s(password .. salt, pepper)
if hashedPassword == shadowPasswd[3] then
loggedIn[username] = kernel.newUUID()
return loggedIn[username]
else
return false
end
end
end
end end
function pam.authToken(username, token) for _,v in ipairs(shadowLines) do
return loggedIn[username] == token shadow[#shadow+1]=string.split(v,":")
end end
for i,v in pairs(passwd) do
kernel.users[tonumber(v[1])]=v[3]
end
kernel.passwd=passwd

View File

@@ -11,15 +11,14 @@ function sys.spawn(func, name, envars, args, tgid)
tasks[tostring(id)] = { tasks[tostring(id)] = {
coro = coroutine.create(function() coro = coroutine.create(function()
local ok, err = xpcall(func, debug.traceback, local ok, err = xpcall(func, debug.traceback, table.unpack(args or {}))
table.unpack(args or {}))
if not ok then if not ok then
if kernel.config.logTaskExit then if kernel.config.logTaskExit then
kernel.log( kernel.log(
"Task " .. tostring(id) .. " exited with err: " .. "Task " .. tostring(id) .. " exited with err: " ..
tostring(err), "ERROR", 2) tostring(err), "ERROR", 2)
end end
tasks[tostring(id)].status = "Z"
if type(err) == "number" then if type(err) == "number" then
tasks[tostring(id)].exit = err tasks[tostring(id)].exit = err
end end
@@ -34,11 +33,14 @@ function sys.spawn(func, name, envars, args, tgid)
" exited without code", "INFO") " exited without code", "INFO")
end end
end end
tasks[tostring(id)].status = "Z"
if type(err) == "number" then if type(err) == "number" then
tasks[tostring(id)].exit = err tasks[tostring(id)].exit = err
end end
end end
for v, _ in ipairs(tasks[tostring(id)].fd) do pcall(kernel.vfs.close,v) end
tasks[tostring(id)].status = "Z"
end), end),
name = name or ("task" .. tostring(id)), name = name or ("task" .. tostring(id)),
envars = envars or kernel.currentTask.envars, envars = envars or kernel.currentTask.envars,
@@ -46,7 +48,6 @@ function sys.spawn(func, name, envars, args, tgid)
status = "R", status = "R",
pid = id, pid = id,
tgid = tgid or kernel.currentTask.tgid, tgid = tgid or kernel.currentTask.tgid,
username = kernel.username,
uid = kernel.uid, uid = kernel.uid,
fd = {}, fd = {},
sleep = 0, sleep = 0,
@@ -87,7 +88,7 @@ function sys.getTask(pid)
status = task.status, status = task.status,
pid = task.pid, pid = task.pid,
tgid = task.tgid, tgid = task.tgid,
username = task.username, username = kernel.users[task.uid],
uid = task.uid, uid = task.uid,
exit = task.exit, exit = task.exit,
sleep = task.sleep, sleep = task.sleep,
@@ -235,7 +236,6 @@ local function reapDeadTasks()
for pid, task in pairs(tasks) do for pid, task in pairs(tasks) do
if task.status == "Z" and not task.reapTime then if task.status == "Z" and not task.reapTime then
kernel.currentTask = task kernel.currentTask = task
kernel.username = task.username
kernel.uid = task.uid kernel.uid = task.uid
kernel.process = task.name kernel.process = task.name
task.coro = nil task.coro = nil
@@ -250,7 +250,6 @@ local function reapDeadTasks()
task.timeSlice = nil task.timeSlice = nil
task.syscallReturn = nil task.syscallReturn = nil
task.sleep = nil task.sleep = nil
for v, _ in ipairs(task.fd) do pcall(kernel.vfs.close,v) end
task.fd = nil task.fd = nil
task.reapTime = kernel.computer:time() + 30000 task.reapTime = kernel.computer:time() + 30000
@@ -302,7 +301,6 @@ function kernel.main()
end end
if task.status == "R" then if task.status == "R" then
kernel.currentTask = task kernel.currentTask = task
kernel.username = task.username
kernel.uid = task.uid kernel.uid = task.uid
kernel.process = task.name kernel.process = task.name
N = N + 1 N = N + 1

View File

@@ -24,7 +24,6 @@ kernel.tasks["1"] = {
status = "R", status = "R",
pid = 1, pid = 1,
tgid = 1, tgid = 1,
username = "root",
uid = 0, uid = 0,
fd = {}, fd = {},
envars = {}, envars = {},