如果Crystal语言进程以root身份运行,是否可以将其更改为euid / uid?例如:
old_euid, old_ui = Process.euid, Process.uid
Process.euid = someone_else
Process.uid = someone_else
答案 0 :(得分:3)
是的,通过使用绑定到libc:
lib LibC
fun setuid(uid_t : Int)
fun getuid : Int
end
LibC.getuid #=> 0
Process.run("whoami", output: true) #=> root
LibC.setuid(uid)
LibC.getuid #=> my uid
Process.run("whoami", output: true) #=> my user name
程序需要以root身份运行(即sudo crystal source.cr
)