以编程方式请求Linux中的提升权限

以编程方式请求Linux中的提升权限,第1张

概述( This question具有相同的标题,但问题正文以脚本的角度要求它,例如su -c,不要欺骗它) 我有一个Qt GUI应用程序,需要根据用户输入在/ etc中执行一些文件 *** 作.一个选项可能会使用带有sudo的system(),但即使这样也需要在某些时候弄乱sudoers文件.我也不想做系统()加脚本黑客修改文件,但正确的文件 *** 作. 以编程方式提升我的应用程序权限以执行此 *** 作的最佳方法是什么 ( This question具有相同的标题,但问题正文以脚本的角度要求它,例如su -c,不要欺骗它)

我有一个Qt GUI应用程序,需要根据用户输入在/ etc中执行一些文件 *** 作.一个选项可能会使用带有sudo的system(),但即使这样也需要在某些时候弄乱sudoers文件.我也不想做系统()加脚本黑客修改文件,但正确的文件 *** 作.

以编程方式提升我的应用程序权限以执行此 *** 作的最佳方法是什么?

编辑:作为奖励,它会很好,如果它也可以在Maemo / Meego /其他手持设备上工作(afaik PolicyKit在那里不可用..)

解决方法 我会写一个单独的程序.这个 philosophy的内容.基本上 – 编写一个简单的程序,完全满足您的需要,并使用文件系统上的文件权限控制其行为.主要是,

Do as little as possible in setuID programs.

A setuID program must operate in a
very dangerous environment: a user is
under complete control of its fds,
args,environ,cwd,tty,rlimits,
timers,signals,and more. Even worse,
the List of controlled items varIEs
from one vendor’s UNIX to the next,so
it is very difficult to write portable
code that cleans up everything.

Of the twenty most recent sendmail
security holes,eleven worked only
because the entire sendmail system is
setuID.

Only one qmail program is setuID:
qmail-queue. Its only purpose is to
add a new mail message to the outgoing
queue.

和,

Do as little as possible as root.

The entire sendmail system runs as root,so there’s no way that its mistakes can be caught by the operating system’s built-in protections. In contrast,only two qmail programs,qmail-start and qmail-lspawn,run as root.

总结

以上是内存溢出为你收集整理的以编程方式请求Linux中的提升权限全部内容,希望文章能够帮你解决以编程方式请求Linux中的提升权限所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/yw/1027469.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存