2 lines
1.7 KiB
Plaintext
2 lines
1.7 KiB
Plaintext
local a=syscall.getTask(syscall.getpid()).name;local b={}local c={help=false}for d,e in ipairs({...})do if e:sub(1,2)=="--"then local f=e:sub(3)if f=="help"then c.help=true else print(a..": unrecognized option '"..e.."'")print("try '"..a.." --help' for more information.")syscall.exit(1)return end elseif e:sub(1,1)=="-"then print(a..": invalid option '"..e.."'")print("try '"..a.." --help' for more information.")syscall.exit(1)return else table.insert(b,e)end end;if c.help then print("Usage: "..a.." NEWROOT [COMMAND [ARG]...]")print("Run COMMAND with root directory set to NEWROOT.")print("If COMMAND is omitted, runs the current user's shell.")print("")print("Requires root (uid 0).")return end;if#b<1 then print(a..": missing operand")print("try '"..a.." --help' for more information.")syscall.exit(1)return end;local g=syscall.geteuid and syscall.geteuid()or syscall.getuid()if g~=0 then print(a..": cannot change root directory: Permission denied")syscall.exit(1)return end;local h=b[1]if h:sub(1,1)~="/"then h=syscall.getcwd().."/"..h end;if not syscall.exists(h)then print(a..": cannot change root directory to '"..b[1].."': No such file or directory")syscall.exit(1)return end;if syscall.type(h)~="directory"then print(a..": '"..b[1].."': Not a directory")syscall.exit(1)return end;local i,j=pcall(syscall.chroot,h)if not i then print(a..": cannot change root directory to '"..b[1].."': "..tostring(j))syscall.exit(1)return end;local k;if#b>=2 then k=b[2]else local l=syscall.getuid()local m=syscall.getpasswd(l)k=m and m.shell or"/bin/hysh"end;local n={}for o=3,#b do table.insert(n,b[o])end;local p,q=pcall(syscall.exec,k,n)if not p then print(a..": failed to run command '"..k.."': "..tostring(q))syscall.exit(127)end
|