Crystal lang流程是否有可能改变它的用户(euid / uid)?

时间:2017-11-29 16:30:05

标签: process crystal-lang

如果Crystal语言进程以root身份运行,是否可以将其更改为euid / uid?例如:

 old_euid, old_ui = Process.euid, Process.uid
 Process.euid = someone_else
 Process.uid  = someone_else

1 个答案:

答案 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