If a Crystal language process is running as root, can it change it's euid/uid to something else? For example:
old_euid, old_ui = Process.euid, Process.uid
Process.euid = someone_else
Process.uid = someone_else
Yes, by using bindings to 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
The program needs to be running as root of course (i. e. sudo crystal source.cr)
来源:https://stackoverflow.com/questions/47557469/is-it-possible-for-a-crystal-lang-process-to-change-its-user-euid-uid