设备管理器、分区编辑器之类的应用程序需要管理员权限才能正常运行。但每次打开都要输入密码验证,这太麻烦了。
我的想法是把程序的拥有者设置为root,再设置setUID就能以root有效权限运行程序。Qt中main函数判断有效用户ID是否为0。
但是运行的时候出现了错误:FATAL: The application binary appears to be running setuid, this is a security hole.
这个错误在Qt文档中给出了说明
Qt is not an appropriate solution for setuid programs due to its large attack surface. However some applications may be required to run in this manner for historical reasons. This flag will prevent Qt from aborting the application when this is detected, and must be set before a QCoreApplication instance is created.
为了避免错误,要增加下面的语句:
QCoreApplication::setSetuidAllowed(true);
QCoreApplication app(argc, argv);
网友评论