访问/私人的/ etc与C [英] Access /Private/etc with c

查看:197
本文介绍了访问/私人的/ etc与C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个简单的问题,但我怎么请求系统/根在一个C控制台应用程序的用户特权时。我需要写/个人/等,但我不能。这是MAC / UNIX。

this might be a simple question, but how do I "request" system / root priviliges from the user in a c console application. I need to write to /Private/etc but i can't. This is for mac / unix.

我已经看到了它在其他控制台中使用命令例如当您运行下面的命令:命令/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder,终端要求您输入密码。我该怎么做呢?

I've seen it being used in other console commands e.g. when you run the following command: "sudo /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder", Terminal asks you for your Password. How do I do this?

感谢,JNK

推荐答案

有没有任何系统调用,这将让过程获得root权限。你可能期望个seteuid 这样的工作方式,但它只能由具有root工艺过程中使用(非特权进程只能设置EUID等于UID)。

There isn't any system call which will let a process obtain root privileges. You might expect seteuid to work this way, but it can only be used by processes with root processes (unprivileged processes can only set the euid equal to the uid).

须藤是特殊的,因为它的可执行文件的setuid权限。这意味着,当运行须藤,它会作为拥有它(根),而不是执行它的用户的用户。 须藤可以验证你必须检查您的密码和读取配置文件的root权限。如果检查成功,它调用的execve 来执行所请求的命令。

sudo is special because its executable file has setuid permissions. This means that when sudo is run, it runs as the user that owns it (root) rather than the user executing it. sudo can verify you have root access by checking your password and reading a configuration file. If the check succeeds, it calls fork and execve to execute the command you requested.

要获得一个无特权的应用程序中的root权限,你将不得不通过一些跳铁圈。您可以使用 / 的execve 调用须藤为您自己的命令。一旦通过验证,你将有一个特权的子进程。你可以通过一个特殊的参数或环境变量,子进程可以跳转到code,它是为了享有特权。父进程只想等待子进程完成。

To obtain root privileges within an unprivileged application, you would have to jump through some hoops. You can use fork/execve to call sudo for your own command. Once authenticated, you would have a privileged child process. You could pass a special argument or environment variable so the child process can jump to code that is intended to be privileged. The parent process would just wait for the child process to complete.

这篇关于访问/私人的/ etc与C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆