如果水晶语言过程作为root运行,它可以将其更改为euid/uid吗?例如:
old_euid, old_ui = Process.euid, Process.uid
Process.euid = someone_else
Process.uid = someone_else
是的,通过将绑定到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
该程序当然需要作为词根运行(即sudo crystal source.cr
)