1 Star 0 Fork 0

王泓/deb_maker

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.cpp 2.00 KB
一键复制 编辑 原始数据 按行查看 历史
oosman 提交于 2020-06-24 12:28 . init
#include "MainWindow.h"
#include <QApplication>
#include <QDebug>
#include <unistd.h>
#include "CmdHandler.h"
#include "PrivilegedCmdDispatcher.h"
#include "TcpServer.h"
/*
*
To Run:
sudo rm -fr $HOME/Documents
sudo rm -fr /opt/debmaker
sudo rm -fr /opt/debzy
sudo cp debmaker debzy && sudo chown root:root debzy && sudo chmod 4755 debzy && QT_QPA_PLATFORM_PLUGIN_PATH=$HOME/Qt/5.11.2/gcc_64/plugins/platforms QT_DEBUG_PLUGINS=1 ./debzy &
...
*/
namespace
{
bool IsSetuidBitSet()
{
qDebug() << "geteuid()" << geteuid() << "getuid()" << getuid();
return (geteuid() == 0 && getuid() != 0);
}
void dropToNormalUser()
{
setuid(getuid());
}
bool runningWithSetuidBitSet()
{
if(!IsSetuidBitSet())
{
qDebug() << "You must cd to buildDir, and run \"sudo chown root:root debmaker\"";
qDebug() << "followed by \"sudo chmod 4755 debmaker\"";
qDebug() << "Do not forget to create this symlink";
qDebug() << "ln -s /home/dev/oosman/Qt5.12.1/Tools/QtCreator/lib/Qt/plugins/platforms platforms";
qDebug() << "Use this run command";
qDebug() << "LD_LIBRARY_PATH=/home/dev/oosman/Qt5.12.1/5.12.1/gcc_64/lib:/home/dev/oosman/Qt5.12.1/5.12.1/gcc_64/lib/:/home/dev/oosman/work.git/libs/build/linux/bin/ ./debmaker";
return false;
}
auto pid = fork();
if(pid < 0)
{
qDebug() << "Failed to fork child process";
return false;
}
else if(pid == 0) // child process
{
QCoreApplication::setSetuidAllowed(true);
qDebug() << "child process 1";
TcpServer server;
server.run();
return false;
}
dropToNormalUser();
return true;
}
}//namespace
int main(int argc, char *argv[])
{
QCoreApplication::setSetuidAllowed(true);
if(!runningWithSetuidBitSet())
{
return 0;
}
QApplication a(argc, argv);
MainWindow w;
if(argc > 1 && QString(argv[1]).endsWith(".deb.mkr"))
{
w.loadProjectFromFile(argv[1]);
}
w.show();
return a.exec();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kuletco/deb_maker.git
git@gitee.com:kuletco/deb_maker.git
kuletco
deb_maker
deb_maker
master

搜索帮助