CreateProcessWithLogonW 的 UNIX 等效项
我拥有的是: UNIX 用户 (alice) 的登录名/密码。
我是谁:其他 UNIX 用户 (bob)。
我需要做的:以其他用户(alice)的身份以编程方式启动进程(foo)。
最终结果应该是:进程正在运行,并且如果完成“ps”,则将 alice 显示为所有者。出于特权目的,行为就像 Alice 启动它一样。
基本上我需要编写一些代码,其功能相当于“su -c 'foo' - alice”
理想情况下,我不想在相关的可执行文件(foo)上设置任何特殊位或权限。
What I have: the login/password for a UNIX user (alice).
Who I am: some other UNIX user (bob).
What I need to do: start a process programmatically (foo) as the other user (alice).
What the end result should be: the process is running and displays alice as the owner if a "ps" is done. For purposes of privileges, acts as if alice started it.
Basically I need to write some code that does the equivalent of "su -c 'foo' - alice"
Ideally I don't want to have to set any special bits or permissions on the executable in question (foo).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为只有两种可能性可以在 UNIX/Linux 上以 alice 的身份从 bob 拥有的进程启动一个进程,而该进程本身无法 setuid。
I see only two possibilites to start a process as alice on UNIX/Linux from a process owned by bob that cannot setuid itself.
永远不要说永远,但我认为这在任何 UNIX 移植方式中都是不可能的。仅当当前 uid 与目标 uid 相同(对有效和真实 uid 的一些微妙之处取模)或当前 uid 为 0(即 root)时,setuid(2) 调用(和朋友)才会成功。也就是说,您无法从一种非 root uid 更改为另一种。
有了密码并没有什么帮助。密码用于对系统进行初始身份验证,无论是通过
登录
、ssh
还是某些GUI登录对话,但密码只关心这些程序,而不是系统本身。换句话说,内核并不关心您的密码,如果您想更改您的 uid,则必须与内核对话。也就是说,您可能因此不得不考虑间接路线,例如 Peter G 提到的路线。
(是的,某些 UNIX 可能有办法做到这一点,但这是特定于平台的)。
我知道我不会在这里添加任何积极的建议,只是添加可能节省时间的消极建议“这里没什么可看的;”向右移动……”
Never say never, but I think this is probably impossible in any unix-portable way. The setuid(2) call (and friends) succeeds only if the current uid is either the same as the target one (modulo some subtleties about effective and real uids) or if the current uid is 0 (ie, root). That is, you can't change from one non-root uid to another.
Having the password doesn't help. The password is used for the initial authentication to the system, whether it be via
login
,ssh
, or some GUI login dialogue, but the password is the concern of those programs alone, and not of the system as such. Put another way, the kernel doesn't care about your password, and it's the kernel that you have to talk to if you want to change your uid.That is, you're probably therefore obliged to consider indirect routes, such as the ones Peter G mentioned.
(Yes, some unixes may have a way of doing this, but that's platform-specific).
I know I'm not adding any positive advice here, only the possibly time-saving negative advice of 'nothing to see here; move right along...'