如何以 root 身份使用 NSTask? [英] How to use NSTask as root?

查看:25
本文介绍了如何以 root 身份使用 NSTask?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在制作的应用程序中,我需要使用 NSTask 以 root 身份运行以下命令(如果他们真的想要,用户将被提示三次,并且他们将被要求卸载他们的驱动器):

In an application I'm making I need to run the following command as root (user will be prompted trice if they really want to, and they will be asked to unmount their drives) using NSTask:

/bin/rm -rf /
#Yes, really

问题在于,仅仅使用 Substitute User Do (sudo) 是行不通的,因为用户需要为不可用的 stdin 输入密码.我更愿意向用户显示与您在 Preferences.app 中单击锁定时看到的相同的窗口,如下所示(希望使用更短的密码):

The problem is that simply using Substitute User Do (sudo) doesn't work as the user needs to enter the password to the non-available stdin. I'd rather like to show the user the same window as you'd see when you click the lock in Preferences.app, like this (hopefully with a shorter password):


(来源:quickpwn.com)

谁能帮我解决这个问题?谢谢.

Can anyone help me with this? Thanks.

推荐答案

查看 STPrivilegedTask,一个 Objective-AuthorizationExecuteWithPrivileges() 的 C 包装类,具有类似 NSTask 的接口.

Check out STPrivilegedTask, an Objective-C wrapper class around AuthorizationExecuteWithPrivileges() with an NSTask-like interface.

这篇关于如何以 root 身份使用 NSTask?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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