added process elevation support to the relauncher, very experimental, has some bugs.

This commit is contained in:
Nick Bolton
2012-07-28 02:59:20 +00:00
parent cf5a7d297d
commit 268f3a99bb
16 changed files with 246 additions and 150 deletions

View File

@@ -27,14 +27,14 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout">
<item row="6" column="6">
<item row="6" column="7">
<widget class="QPushButton" name="m_pButtonToggleStart">
<property name="text">
<string>&amp;Start</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="7">
<item row="1" column="0" colspan="8">
<widget class="QGroupBox" name="m_pGroupServer">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@@ -127,7 +127,7 @@
</layout>
</widget>
</item>
<item row="2" column="0" colspan="7">
<item row="2" column="0" colspan="8">
<widget class="QGroupBox" name="m_pGroupClient">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@@ -168,7 +168,7 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="7">
<item row="3" column="0" colspan="8">
<widget class="QGroupBox" name="m_pGroupLog">
<property name="title">
<string>Log</string>
@@ -223,7 +223,7 @@
<string/>
</property>
<property name="pixmap">
<pixmap resource="Synergy.qrc">:/res/icons/16x16/warning.png</pixmap>
<pixmap>:/res/icons/16x16/warning.png</pixmap>
</property>
</widget>
</item>
@@ -237,6 +237,13 @@
</property>
</widget>
</item>
<item row="6" column="6">
<widget class="QCheckBox" name="m_pElevateCheckBox">
<property name="text">
<string>&amp;Elevate</string>
</property>
</widget>
</item>
</layout>
</widget>
<action name="m_pActionAbout">
@@ -323,9 +330,7 @@
</property>
</action>
</widget>
<resources>
<include location="Synergy.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>m_pButtonToggleStart</sender>

View File

@@ -15,9 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// this class is a duplicate of /src/lib/ipc/Ipc.cpp
#include "Ipc.h"
const char* kIpcMsgHello = "IHEL%1i";
const char* kIpcMsgLogLine = "ILOG%s";
const char* kIpcMsgCommand = "ICMD%s";
const char* kIpcMsgCommand = "ICMD%s%1i";
const char* kIpcMsgShutdown = "ISDN";

View File

@@ -15,6 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// this class is a duplicate of /src/lib/ipc/Ipc.h
#pragma once
#define IPC_HOST "127.0.0.1"

View File

@@ -43,7 +43,7 @@ void IpcClient::connected()
{
char typeBuf[1];
typeBuf[0] = kIpcClientGui;
write(kIpcHello, 1, typeBuf);
sendHello();
infoMessage("connection established");
}
@@ -89,30 +89,34 @@ void IpcClient::retryConnect()
}
}
void IpcClient::write(int code, int length, const char* data)
void IpcClient::sendHello()
{
QDataStream stream(m_Socket);
stream.writeRawData(kIpcMsgHello, 4);
char typeBuf[1];
typeBuf[0] = kIpcClientGui;
stream.writeRawData(typeBuf, 1);
}
void IpcClient::sendCommand(const QString& command, bool elevate)
{
QDataStream stream(m_Socket);
switch (code) {
case kIpcHello:
stream.writeRawData(kIpcMsgHello, 4);
stream.writeRawData(data, 1);
break;
stream.writeRawData(kIpcMsgCommand, 4);
case kIpcCommand: {
char lenBuf[4];
intToBytes(length, lenBuf, 4);
std::string stdStringCommand = command.toStdString();
const char* charCommand = stdStringCommand.c_str();
int length = strlen(charCommand);
stream.writeRawData(kIpcMsgCommand, 4);
stream.writeRawData(lenBuf, 4);
stream.writeRawData(data, length);
break;
}
char lenBuf[4];
intToBytes(length, lenBuf, 4);
stream.writeRawData(lenBuf, 4);
stream.writeRawData(charCommand, length);
default:
std::cerr << "message type not supported: " << code << std::endl;
break;
}
char elevateBuf[1];
elevateBuf[0] = elevate ? 1 : 0;
stream.writeRawData(elevateBuf, 1);
}
void IpcClient::handleReadLogLine(const QString& text)

View File

@@ -31,7 +31,8 @@ public:
IpcClient();
virtual ~IpcClient();
void write(int code, int length, const char* data);
void sendHello();
void sendCommand(const QString& command, bool elevate);
void connectToHost();
void disconnectFromHost();

View File

@@ -64,7 +64,9 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
m_pTrayIcon(NULL),
m_pTrayIconMenu(NULL),
m_alreadyHidden(false),
m_SetupWizard(NULL)
m_SetupWizard(NULL),
m_ElevateProcess(false),
m_SuppressElevateWarning(false)
{
setupUi(this);
@@ -85,6 +87,9 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
connect(&m_IpcClient, SIGNAL(errorMessage(const QString&)), this, SLOT(appendLogError(const QString&)));
connect(&m_IpcClient, SIGNAL(infoMessage(const QString&)), this, SLOT(appendLogNote(const QString&)));
m_IpcClient.connectToHost();
#else
// elevate checkbox is only useful on ms windows.
m_pElevateCheckBox->hide();
#endif
}
@@ -133,13 +138,15 @@ void MainWindow::onModeChanged(bool firstRun, bool forceServiceApply)
else
{
// cause the service to stop creating processes.
sendDaemonCommand("", false);
m_IpcClient.sendCommand("", false);
}
if ((appConfig().processMode() == Desktop) && !firstRun && appConfig().autoConnect())
{
startSynergy();
}
m_pElevateCheckBox->setEnabled(appConfig().processMode() == Service);
}
void MainWindow::refreshStartButton()
@@ -221,6 +228,10 @@ void MainWindow::loadSettings()
m_pLineEditConfigFile->setText(settings().value("configFile", QDir::homePath() + "/" + synergyConfigName).toString());
m_pGroupClient->setChecked(settings().value("groupClientChecked", true).toBool());
m_pLineEditHostname->setText(settings().value("serverHostname").toString());
m_SuppressElevateWarning = true;
m_pElevateCheckBox->setChecked(settings().value("elevateChecked", false).toBool());
m_SuppressElevateWarning = false;
}
void MainWindow::initConnections()
@@ -452,7 +463,7 @@ void MainWindow::startSynergy()
if (serviceMode)
{
QString command(app + " " + args.join(" "));
sendDaemonCommand(command, true);
m_IpcClient.sendCommand(command, m_ElevateProcess);
}
}
@@ -702,14 +713,29 @@ void MainWindow::on_m_pButtonConfigureServer_clicked()
dlg.exec();
}
void MainWindow::sendDaemonCommand(const QString& command, bool showErrors)
{
std::string s = command.toStdString();
const char* data = s.c_str();
m_IpcClient.write(kIpcCommand, strlen(data), data);
}
void MainWindow::on_m_pActionWizard_triggered()
{
m_SetupWizard->show();
}
void MainWindow::on_m_pElevateCheckBox_toggled(bool checked)
{
if (checked && !m_SuppressElevateWarning) {
int r = QMessageBox::warning(
this, tr("Elevate Synergy"),
tr("Are you sure you want to elevate Synergy?\n\n"
"This allows Synergy to interact with elevated processes "
"and the UAC dialog, but can cause problems with non-elevated "
"processes. Elevate Synergy only if you really need to."),
QMessageBox::Yes | QMessageBox::No);
if (r != QMessageBox::Yes) {
m_pElevateCheckBox->setChecked(false);
return;
}
}
m_ElevateProcess = checked;
settings().setValue("elevateChecked", checked);
settings().sync();
}

View File

@@ -104,6 +104,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
void on_m_pActionAbout_triggered();
void on_m_pActionSettings_triggered();
void on_m_pActionWizard_triggered();
void on_m_pElevateCheckBox_toggled(bool checked);
void synergyFinished(int exitCode, QProcess::ExitStatus);
void iconActivated(QSystemTrayIcon::ActivationReason reason);
void startSynergy();
@@ -132,7 +133,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
bool clientArgs(QStringList& args, QString& app);
bool serverArgs(QStringList& args, QString& app);
void setStatus(const QString& status);
void sendDaemonCommand(const QString& command, bool showErrors);
void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors);
void onModeChanged(bool firstRun, bool forceServiceApply);
@@ -149,6 +149,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
VersionChecker m_versionChecker;
SetupWizard* m_SetupWizard;
IpcClient m_IpcClient;
bool m_ElevateProcess;
bool m_SuppressElevateWarning;
};
#endif