This commit is contained in:
2026-02-20 11:34:53 -05:00
parent 287b146621
commit 10bc775e64
14 changed files with 57 additions and 60 deletions

View File

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

View File

@@ -2,4 +2,5 @@
local kernel=...
kernel.vfs.open("/dev/null", "r")
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:--
local kernel = ...
local pam = {}
kernel.pam = pam
local loggedIn = {}
local auth = {}
kernel.auth = auth
-- @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 file = kernel.vfs.open(path, "r")
@@ -13,7 +27,6 @@ local function getFile(path)
end
local blake2s
do
local MOD32 = 2^32
local function norm(x)
@@ -187,9 +200,10 @@ end
if not blake2s then error("Failed to load blake2s") end
if not kernel.vfs.exists("/etc/pam.d/secret") then
kernel.log("PAM SECRET REGENERATING PLEASE USE ROOT")
local key = ""
for i=1, 256 do
key=key..string.char(math.random(1,255))
key=key..string.char(math.random(0,255))
end
local handle = kernel.vfs.open("/etc/pam.d/secret", "w")
kernel.vfs.write(handle, key)
@@ -197,41 +211,22 @@ if not kernel.vfs.exists("/etc/pam.d/secret") then
end
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)
local fpasswd = getFile("/etc/passwd")
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
for _,v in ipairs(passwdLines) do
passwd[#passwd+1]=string.split(v,":")
end
function pam.authToken(username, token)
return loggedIn[username] == token
for _,v in ipairs(shadowLines) do
shadow[#shadow+1]=string.split(v,":")
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)] = {
coro = coroutine.create(function()
local ok, err = xpcall(func, debug.traceback,
table.unpack(args or {}))
local ok, err = xpcall(func, debug.traceback, table.unpack(args or {}))
if not ok then
if kernel.config.logTaskExit then
kernel.log(
"Task " .. tostring(id) .. " exited with err: " ..
tostring(err), "ERROR", 2)
end
tasks[tostring(id)].status = "Z"
if type(err) == "number" then
tasks[tostring(id)].exit = err
end
@@ -34,11 +33,14 @@ function sys.spawn(func, name, envars, args, tgid)
" exited without code", "INFO")
end
end
tasks[tostring(id)].status = "Z"
if type(err) == "number" then
tasks[tostring(id)].exit = err
end
end
for v, _ in ipairs(tasks[tostring(id)].fd) do pcall(kernel.vfs.close,v) end
tasks[tostring(id)].status = "Z"
end),
name = name or ("task" .. tostring(id)),
envars = envars or kernel.currentTask.envars,
@@ -46,7 +48,6 @@ function sys.spawn(func, name, envars, args, tgid)
status = "R",
pid = id,
tgid = tgid or kernel.currentTask.tgid,
username = kernel.username,
uid = kernel.uid,
fd = {},
sleep = 0,
@@ -87,7 +88,7 @@ function sys.getTask(pid)
status = task.status,
pid = task.pid,
tgid = task.tgid,
username = task.username,
username = kernel.users[task.uid],
uid = task.uid,
exit = task.exit,
sleep = task.sleep,
@@ -235,7 +236,6 @@ local function reapDeadTasks()
for pid, task in pairs(tasks) do
if task.status == "Z" and not task.reapTime then
kernel.currentTask = task
kernel.username = task.username
kernel.uid = task.uid
kernel.process = task.name
task.coro = nil
@@ -250,7 +250,6 @@ local function reapDeadTasks()
task.timeSlice = nil
task.syscallReturn = nil
task.sleep = nil
for v, _ in ipairs(task.fd) do pcall(kernel.vfs.close,v) end
task.fd = nil
task.reapTime = kernel.computer:time() + 30000
@@ -302,7 +301,6 @@ function kernel.main()
end
if task.status == "R" then
kernel.currentTask = task
kernel.username = task.username
kernel.uid = task.uid
kernel.process = task.name
N = N + 1

View File

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