本文介绍了Crystal lang 进程是否可以更改其用户(euid/uid)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果 Crystal 语言进程以 root 身份运行,是否可以将其 euid/uid 更改为其他内容?例如:
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
推荐答案
是的,通过使用 libc 绑定:
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
程序当然需要以root身份运行(即sudo crystal source.cr
)
The program needs to be running as root of course (i. e. sudo crystal source.cr
)
这篇关于Crystal lang 进程是否可以更改其用户(euid/uid)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!