我正在开发一个需要使用 dd 的应用程序(我使用应用程序包中的 shell 脚本来执行此操作,该脚本从应用程序本身收集参数,进行一些检查,然后启动 dd)。
为了进行此操作,我需要使用 root 调用 dd,并且我已经在 StackOverflow 上查看了几个解决方案。在我看来,最简单的实现是这个 http://www.sveinbjorn.org/STPrivilegedTask
问题是我的 NSTask 进行一些复杂的读/写操作(STPrivilegedTask 中不存在)并且不需要全部特权。
因此,我用 c 语言编写了一个小辅助工具,它使用应用程序中的正确参数调用我的脚本。我想的解决方案是使用 STPrivilegedTask 来 SUID 一旦我的小帮助工具,这样我就可以用 root 启动它(以及我的脚本和 dd),成功启动后不久,我将帮助工具设置为非 SUID (如果有任何错误,我会在应用程序退出、应用程序启动等时执行相同的操作。为了更安全)。
我实现了它并且工作得很好,也许它并不完美,但我认为全部都在捆绑包内,并且在 SUID 中使用辅助工具来启动听起来足够安全。
有什么想法吗?
谢谢!
I'm working on an app that needs to use dd (I do this with a shell script in the app bundle, that collects parameters from the app itself, makes some checks and then launches dd).
To make this operation I need to call dd with root, and I already looked at several solutions on StackOverflow. The simplest to implements seemed to me this one http://www.sveinbjorn.org/STPrivilegedTask
Problem is that my NSTask makes some complex read/write operations (not present in STPrivilegedTask) and does not need to be all privileged.
So I wrote a small helper tool in c that calls my script with correct parameters from my app. The solution I thought is to use the STPrivilegedTask to SUID once the fly my small helper tool, so I can launch it (and so my script and dd) with root, and soon after successful launch I set back the helper tool to non SUID (and I do the same if any error, on app exit, app start etc.. to be safer).
I implemented it and works quite well, maybe it's not perfect but I think that being all inside the bundle, and working with the helper tool in SUID just for the launch sounds safe enough.
Any thoughts?
Thanks!
发布评论
评论(1)
您可以使用沙箱在 NSTask 中运行新进程
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/sandbox-exec.1.html
您在此处有一些配置文件示例
你必须给予 dd 足够的访问权限才能工作,我还没有尝试或检查 dd 需要什么,我会从这样的开始:
更新:
值得一提的是,您可以使用
sandbox-exec -p 命令
You can use a sandbox for running the new Process in your NSTask
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/sandbox-exec.1.html
You have some profile examples in here
You have to give enough access for dd to work, I haven't tried or checked what dd requires, I would start with something like this:
Update:
Worth mention, you can use
sandbox-exec -p command