forked from Hyperion/HyperionOS
/home/user owned by user, user starts in cwd /home/user
This commit is contained in:
@@ -64,12 +64,18 @@ local newGid = resolveGid(groupStr)
|
||||
local function chgrpPath(path)
|
||||
local stat = syscall.stat(path)
|
||||
if not stat then
|
||||
print(name .. ": cannot stat '" .. path .. "': No such file or directory")
|
||||
print(name .. ": cannot stat '" .. path .. "': no such file or directory")
|
||||
return false
|
||||
end
|
||||
local ok, err = pcall(syscall.chown, path, stat.owner, newGid)
|
||||
if not ok then
|
||||
print(name .. ": cannot change group of '" .. path .. "': " .. tostring(err))
|
||||
local msg = tostring(err)
|
||||
if msg:find("EPERM") or msg:find("EACCES") then
|
||||
msg = "operation not permitted (must be root)"
|
||||
elseif msg:find("ENOENT") then
|
||||
msg = "no such file or directory"
|
||||
end
|
||||
print(name .. ": cannot change group of '" .. path .. "': " .. msg)
|
||||
return false
|
||||
end
|
||||
return true
|
||||
|
||||
@@ -220,7 +220,13 @@ local function chmodPath(path)
|
||||
|
||||
local ok, cerr = pcall(syscall.chmod, path, newPerms)
|
||||
if not ok then
|
||||
print(name .. ": cannot change permissions of '" .. path .. "': " .. tostring(cerr))
|
||||
local msg = tostring(cerr)
|
||||
if msg:find("EACCES") or msg:find("EPERM") then
|
||||
msg = "permission denied"
|
||||
elseif msg:find("ENOENT") then
|
||||
msg = "no such file or directory"
|
||||
end
|
||||
print(name .. ": cannot change permissions of '" .. path .. "': " .. msg)
|
||||
return false
|
||||
end
|
||||
return true
|
||||
|
||||
@@ -95,14 +95,20 @@ end
|
||||
local function chownPath(path)
|
||||
local stat = syscall.stat(path)
|
||||
if not stat then
|
||||
print(name .. ": cannot stat '" .. path .. "': No such file or directory")
|
||||
print(name .. ": cannot stat '" .. path .. "': no such file or directory")
|
||||
return false
|
||||
end
|
||||
local uid = newUid ~= nil and newUid or stat.owner
|
||||
local gid = newGid ~= nil and newGid or stat.group
|
||||
local ok, err = pcall(syscall.chown, path, uid, gid)
|
||||
if not ok then
|
||||
print(name .. ": cannot change owner of '" .. path .. "': " .. tostring(err))
|
||||
local msg = tostring(err)
|
||||
if msg:find("EPERM") or msg:find("EACCES") then
|
||||
msg = "operation not permitted (must be root)"
|
||||
elseif msg:find("ENOENT") then
|
||||
msg = "no such file or directory"
|
||||
end
|
||||
print(name .. ": cannot change owner of '" .. path .. "': " .. msg)
|
||||
return false
|
||||
end
|
||||
return true
|
||||
|
||||
@@ -17,7 +17,13 @@ local commandHistory = {}
|
||||
local terminate = false
|
||||
syscall.setEnviron("SHELL","rtbash")
|
||||
syscall.setEnviron("PATH","/bin/")
|
||||
syscall.chdir("/")
|
||||
local _home = syscall.getEnviron("HOME")
|
||||
if _home and _home ~= "" then
|
||||
local ok = pcall(syscall.chdir, _home)
|
||||
if not ok then syscall.chdir("/") end
|
||||
else
|
||||
syscall.chdir("/")
|
||||
end
|
||||
local oldWD = ""
|
||||
|
||||
for i = 1, 16 do
|
||||
|
||||
@@ -96,6 +96,9 @@ local function spawnShell(username, uid, shell, homedir)
|
||||
end
|
||||
|
||||
local chdirOk, chdirErr = pcall(syscall.chdir, homedir)
|
||||
if not chdirOk then
|
||||
pcall(syscall.chdir, "/")
|
||||
end
|
||||
|
||||
local ok, err = pcall(syscall.execspawn, shell, username .. ":shell")
|
||||
if not ok then
|
||||
|
||||
Reference in New Issue
Block a user