Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Tru Huynh 2018-03-14 20:03:25 +01:00
commit 8e65de070f
16 changed files with 56 additions and 95 deletions

View File

@ -18,9 +18,8 @@
cmake_minimum_required (VERSION 3.4) cmake_minimum_required (VERSION 3.4)
project (barrier C CXX) project (barrier C CXX)
option (BARRIER_BUILD_LEGACY_GUI "Build the legacy GUI" ON) option (BARRIER_BUILD_GUI "Build the GUI" ON)
option (BARRIER_BUILD_LEGACY_SERVICE "Build the legacy service (barrierd)" ON) option (BARRIER_BUILD_INSTALLER "Build the installer" ON)
option (BARRIER_BUILD_LEGACY_INSTALLER "Build the legacy installer" ON)
set (CMAKE_CXX_STANDARD 14) set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_EXTENSIONS OFF) set (CMAKE_CXX_EXTENSIONS OFF)
@ -355,7 +354,7 @@ macro (configure_files srcDir destDir)
endforeach (templateFile) endforeach (templateFile)
endmacro (configure_files) endmacro (configure_files)
if (${BARRIER_BUILD_LEGACY_INSTALLER}) if (${BARRIER_BUILD_INSTALLER})
# #
# macOS app Bundle # macOS app Bundle
# #
@ -393,6 +392,6 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
endif() endif()
else() else()
message (STATUS "NOT configuring the v1 installer") message (STATUS "NOT configuring the installer")
endif() endif()
add_subdirectory (src) add_subdirectory (src)

View File

@ -27,7 +27,7 @@ if ERRORLEVEL 1 goto failed
cd build cd build
cmake -G "Visual Studio 15 2017 Win64" -D CMAKE_BUILD_TYPE=%B_BUILD_TYPE% -D CMAKE_PREFIX_PATH="%B_QT_FULLPATH%" -D DNSSD_LIB="%B_BONJOUR%\Lib\x64\dnssd.lib" -D QT_VERSION=%B_QT_VER% .. cmake -G "Visual Studio 15 2017 Win64" -D CMAKE_BUILD_TYPE=%B_BUILD_TYPE% -D CMAKE_PREFIX_PATH="%B_QT_FULLPATH%" -D DNSSD_LIB="%B_BONJOUR%\Lib\x64\dnssd.lib" -D QT_VERSION=%B_QT_VER% ..
if ERRORLEVEL 1 goto failed if ERRORLEVEL 1 goto failed
echo @msbuild barrier.sln /p:Platform="x64" /p:Configuration=%B_BUILD_TYPE% /m > make.bat echo @msbuild barrier.sln /p:Platform="x64" /p:Configuration=%B_BUILD_TYPE% /m %B_BUILD_OPTIONS% > make.bat
call make.bat call make.bat
if ERRORLEVEL 1 goto failed if ERRORLEVEL 1 goto failed
if exist bin\Debug ( if exist bin\Debug (

View File

@ -1,5 +1,9 @@
cmake_minimum_required (VERSION 3.4) cmake_minimum_required (VERSION 3.4)
set (BARRIER_VERSION_MAJOR 2)
set (BARRIER_VERSION_MINOR 0)
set (BARRIER_VERSION_PATCH 0)
# #
# Barrier Version # Barrier Version
# #

View File

@ -31,12 +31,6 @@
<Property Id="ARPPRODUCTICON" Value="barrier.ico"/> <Property Id="ARPPRODUCTICON" Value="barrier.ico"/>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER"/> <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER"/>
<Property Id="MSIRESTARTMANAGERCONTROL" Value="Disable"/> <Property Id="MSIRESTARTMANAGERCONTROL" Value="Disable"/>
<Property Id="LEGACY_UNINSTALL_EXISTS">
<RegistrySearch Id="LegacyRegistrySearch" Key="SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Barrier" Name="UninstallString" Root="HKLM" Type="file" Win64="no">
<FileSearch Id="LegacyFileSearch" Name="uninstall.exe"/>
</RegistrySearch>
</Property>
<Condition Message="An existing installation of $(var.Name) was detected, please uninstall it before continuing.">NOT LEGACY_UNINSTALL_EXISTS
</Condition> </Condition>
<CustomAction ExeCommand="" FileKey="GuiProgram" Id="StartGui" Return="asyncNoWait"/> <CustomAction ExeCommand="" FileKey="GuiProgram" Id="StartGui" Return="asyncNoWait"/>
<UI> <UI>

View File

@ -19,6 +19,7 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR}/lib)
add_subdirectory(lib) add_subdirectory(lib)
add_subdirectory(cmd) add_subdirectory(cmd)
if (BARRIER_BUILD_LEGACY_GUI)
if (BARRIER_BUILD_GUI)
add_subdirectory(gui) add_subdirectory(gui)
endif (BARRIER_BUILD_LEGACY_GUI) endif()

View File

@ -18,7 +18,7 @@ add_subdirectory(barrierc)
add_subdirectory(barriers) add_subdirectory(barriers)
add_subdirectory(syntool) add_subdirectory(syntool)
if (BARRIER_BUILD_LEGACY_SERVICE) if (WIN32)
add_subdirectory(barrierd) add_subdirectory(barrierd)
endif (BARRIER_BUILD_LEGACY_SERVICE) endif()

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "barrier/DaemonApp.h" #include "barrier/win32/DaemonApp.h"
#include <iostream> #include <iostream>

View File

@ -6,17 +6,17 @@ set (CMAKE_AUTORCC ON)
set (CMAKE_AUTOUIC ON) set (CMAKE_AUTOUIC ON)
set (CMAKE_INCLUDE_CURRENT_DIR ON) set (CMAKE_INCLUDE_CURRENT_DIR ON)
file (GLOB LEGACY_GUI_SOURCE_FILES src/*.cpp src/*.h) file (GLOB GUI_SOURCE_FILES src/*.cpp src/*.h)
file (GLOB LEGACY_GUI_UI_FILES src/*.ui) file (GLOB GUI_UI_FILES src/*.ui)
if (WIN32) if (WIN32)
set (LEGACY_GUI_RC_FILES res/win/Barrier.rc) set (GUI_RC_FILES res/win/Barrier.rc)
endif() endif()
add_executable (barrier WIN32 add_executable (barrier WIN32
${LEGACY_GUI_SOURCE_FILES} ${GUI_SOURCE_FILES}
${LEGACY_GUI_UI_FILES} ${GUI_UI_FILES}
${LEGACY_GUI_RC_FILES} ${GUI_RC_FILES}
res/Barrier.qrc res/Barrier.qrc
) )

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>600</width> <width>800</width>
<height>371</height> <height>371</height>
</rect> </rect>
</property> </property>

View File

@ -980,7 +980,7 @@ bool MainWindow::on_m_pButtonBrowseConfigFile_clicked()
bool MainWindow::on_m_pActionSave_triggered() bool MainWindow::on_m_pActionSave_triggered()
{ {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save configuration as...")); QString fileName = QFileDialog::getSaveFileName(this, tr("Save configuration as..."), QString(), tr("Barrier Configuration (*.sgc)"));
if (!fileName.isEmpty() && !serverConfig().save(fileName)) if (!fileName.isEmpty() && !serverConfig().save(fileName))
{ {

View File

@ -27,6 +27,13 @@
#include <stdint.h> #include <stdint.h>
#include <dns_sd.h> #include <dns_sd.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <stdlib.h>
#endif
static const QStringList preferedIPAddress( static const QStringList preferedIPAddress(
QStringList() << QStringList() <<
"192.168." << "192.168." <<
@ -36,12 +43,29 @@ static const QStringList preferedIPAddress(
const char* ZeroconfService:: m_ServerServiceName = "_barrierServerZeroconf._tcp"; const char* ZeroconfService:: m_ServerServiceName = "_barrierServerZeroconf._tcp";
const char* ZeroconfService:: m_ClientServiceName = "_barrierClientZeroconf._tcp"; const char* ZeroconfService:: m_ClientServiceName = "_barrierClientZeroconf._tcp";
static void silence_avahi_warning()
{
// the libavahi folks seemingly find Apple's bonjour API distasteful
// and are quite liberal in taking it out on users...unless we set
// this environmental variable before calling the avahi library.
// additionally, Microsoft does not give us a POSIX setenv() so
// we use their OS-specific API instead
const char *name = "AVAHI_COMPAT_NOWARN";
const char *value = "1";
#ifdef _WIN32
SetEnvironmentVariable(name, value);
#else
setenv(name, value, 1);
#endif
}
ZeroconfService::ZeroconfService(MainWindow* mainWindow) : ZeroconfService::ZeroconfService(MainWindow* mainWindow) :
m_pMainWindow(mainWindow), m_pMainWindow(mainWindow),
m_pZeroconfBrowser(0), m_pZeroconfBrowser(0),
m_pZeroconfRegister(0), m_pZeroconfRegister(0),
m_ServiceRegistered(false) m_ServiceRegistered(false)
{ {
silence_avahi_warning();
if (m_pMainWindow->barrierType() == MainWindow::barrierServer) { if (m_pMainWindow->barrierType() == MainWindow::barrierServer) {
if (registerService(true)) { if (registerService(true)) {
m_pZeroconfBrowser = new ZeroconfBrowser(this); m_pZeroconfBrowser = new ZeroconfBrowser(this);

View File

@ -697,15 +697,7 @@ ArchDaemonWindows::installDaemon()
void void
ArchDaemonWindows::uninstallDaemon() ArchDaemonWindows::uninstallDaemon()
{ {
// remove legacy services if installed. // remove service if installed.
if (isDaemonInstalled(LEGACY_SERVER_DAEMON_NAME)) {
uninstallDaemon(LEGACY_SERVER_DAEMON_NAME);
}
if (isDaemonInstalled(LEGACY_CLIENT_DAEMON_NAME)) {
uninstallDaemon(LEGACY_CLIENT_DAEMON_NAME);
}
// remove new service if installed.
if (isDaemonInstalled(DEFAULT_DAEMON_NAME)) { if (isDaemonInstalled(DEFAULT_DAEMON_NAME)) {
uninstallDaemon(DEFAULT_DAEMON_NAME); uninstallDaemon(DEFAULT_DAEMON_NAME);
} }

View File

@ -142,9 +142,6 @@ private:
#define DEFAULT_DAEMON_NAME _T("Barrier") #define DEFAULT_DAEMON_NAME _T("Barrier")
#define DEFAULT_DAEMON_INFO _T("Manages the Barrier foreground processes.") #define DEFAULT_DAEMON_INFO _T("Manages the Barrier foreground processes.")
#define LEGACY_SERVER_DAEMON_NAME _T("Barrier Server")
#define LEGACY_CLIENT_DAEMON_NAME _T("Barrier Client")
static const TCHAR* const g_daemonKeyPath[] = { static const TCHAR* const g_daemonKeyPath[] = {
_T("SOFTWARE"), _T("SOFTWARE"),
_T("The Barrier Project"), _T("The Barrier Project"),

View File

@ -16,10 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// TODO: split this class into windows and unix to get rid #include "barrier/win32/DaemonApp.h"
// of all the #ifdefs!
#include "barrier/DaemonApp.h"
#include "barrier/App.h" #include "barrier/App.h"
#include "barrier/ArgParser.h" #include "barrier/ArgParser.h"
@ -37,8 +34,6 @@
#include "base/log_outputters.h" #include "base/log_outputters.h"
#include "base/Log.h" #include "base/Log.h"
#if SYSAPI_WIN32
#include "arch/win32/ArchMiscWindows.h" #include "arch/win32/ArchMiscWindows.h"
#include "arch/win32/XArchWindows.h" #include "arch/win32/XArchWindows.h"
#include "barrier/Screen.h" #include "barrier/Screen.h"
@ -50,8 +45,6 @@
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
#endif
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -68,25 +61,15 @@ mainLoopStatic()
} }
int int
unixMainLoopStatic(int, const char**) mainLoopStatic(int, const char**)
{
return mainLoopStatic();
}
#if SYSAPI_WIN32
int
winMainLoopStatic(int, const char**)
{ {
return ArchMiscWindows::runDaemon(mainLoopStatic); return ArchMiscWindows::runDaemon(mainLoopStatic);
} }
#endif
DaemonApp::DaemonApp() : DaemonApp::DaemonApp() :
m_ipcServer(nullptr), m_ipcServer(nullptr),
m_ipcLogOutputter(nullptr), m_ipcLogOutputter(nullptr),
#if SYSAPI_WIN32
m_watchdog(nullptr), m_watchdog(nullptr),
#endif
m_events(nullptr), m_events(nullptr),
m_fileLogOutputter(nullptr) m_fileLogOutputter(nullptr)
{ {
@ -100,10 +83,8 @@ DaemonApp::~DaemonApp()
int int
DaemonApp::run(int argc, char** argv) DaemonApp::run(int argc, char** argv)
{ {
#if SYSAPI_WIN32
// win32 instance needed for threading, etc. // win32 instance needed for threading, etc.
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#endif
Arch arch; Arch arch;
arch.init(); arch.init();
@ -115,10 +96,8 @@ DaemonApp::run(int argc, char** argv)
bool uninstall = false; bool uninstall = false;
try try
{ {
#if SYSAPI_WIN32
// sends debug messages to visual studio console window. // sends debug messages to visual studio console window.
log.insert(new MSWindowsDebugOutputter()); log.insert(new MSWindowsDebugOutputter());
#endif
// default log level to system setting. // default log level to system setting.
string logLevel = arch.setting("LogLevel"); string logLevel = arch.setting("LogLevel");
@ -133,7 +112,6 @@ DaemonApp::run(int argc, char** argv)
if (arg == "/f" || arg == "-f") { if (arg == "/f" || arg == "-f") {
foreground = true; foreground = true;
} }
#if SYSAPI_WIN32
else if (arg == "/install") { else if (arg == "/install") {
uninstall = true; uninstall = true;
arch.installDaemon(); arch.installDaemon();
@ -143,7 +121,6 @@ DaemonApp::run(int argc, char** argv)
arch.uninstallDaemon(); arch.uninstallDaemon();
return kExitSuccess; return kExitSuccess;
} }
#endif
else { else {
stringstream ss; stringstream ss;
ss << "Unrecognized argument: " << arg; ss << "Unrecognized argument: " << arg;
@ -158,11 +135,7 @@ DaemonApp::run(int argc, char** argv)
mainLoop(false); mainLoop(false);
} }
else { else {
#if SYSAPI_WIN32 arch.daemonize("Barrier", mainLoopStatic);
arch.daemonize("Barrier", winMainLoopStatic);
#elif SYSAPI_UNIX
arch.daemonize("Barrier", unixMainLoopStatic);
#endif
} }
return kExitSuccess; return kExitSuccess;
@ -214,10 +187,8 @@ DaemonApp::mainLoop(bool daemonized)
m_ipcLogOutputter = new IpcLogOutputter(*m_ipcServer, kIpcClientGui, true); m_ipcLogOutputter = new IpcLogOutputter(*m_ipcServer, kIpcClientGui, true);
CLOG->insert(m_ipcLogOutputter); CLOG->insert(m_ipcLogOutputter);
#if SYSAPI_WIN32
m_watchdog = new MSWindowsWatchdog(daemonized, false, *m_ipcServer, *m_ipcLogOutputter); m_watchdog = new MSWindowsWatchdog(daemonized, false, *m_ipcServer, *m_ipcLogOutputter);
m_watchdog->setFileLogOutputter(m_fileLogOutputter); m_watchdog->setFileLogOutputter(m_fileLogOutputter);
#endif
m_events->adoptHandler( m_events->adoptHandler(
m_events->forIpcServer().messageReceived(), m_ipcServer, m_events->forIpcServer().messageReceived(), m_ipcServer,
@ -225,8 +196,6 @@ DaemonApp::mainLoop(bool daemonized)
m_ipcServer->listen(); m_ipcServer->listen();
#if SYSAPI_WIN32
// install the platform event queue to handle service stop events. // install the platform event queue to handle service stop events.
m_events->adoptBuffer(new MSWindowsEventQueueBuffer(m_events)); m_events->adoptBuffer(new MSWindowsEventQueueBuffer(m_events));
@ -238,13 +207,11 @@ DaemonApp::mainLoop(bool daemonized)
} }
m_watchdog->startAsync(); m_watchdog->startAsync();
#endif
m_events->loop(); m_events->loop();
#if SYSAPI_WIN32
m_watchdog->stop(); m_watchdog->stop();
delete m_watchdog; delete m_watchdog;
#endif
m_events->removeHandler( m_events->removeHandler(
m_events->forIpcServer().messageReceived(), m_ipcServer); m_events->forIpcServer().messageReceived(), m_ipcServer);
@ -266,11 +233,7 @@ DaemonApp::mainLoop(bool daemonized)
void void
DaemonApp::foregroundError(const char* message) DaemonApp::foregroundError(const char* message)
{ {
#if SYSAPI_WIN32
MessageBox(NULL, message, "Barrier Service", MB_OK | MB_ICONERROR); MessageBox(NULL, message, "Barrier Service", MB_OK | MB_ICONERROR);
#elif SYSAPI_UNIX
cerr << message << endl;
#endif
} }
std::string std::string
@ -338,7 +301,6 @@ DaemonApp::handleIpcMessage(const Event& e, void*)
} }
} }
#if SYSAPI_WIN32
// eg. no log-to-file while running in foreground // eg. no log-to-file while running in foreground
if (m_fileLogOutputter != nullptr) { if (m_fileLogOutputter != nullptr) {
String logFilename; String logFilename;
@ -354,7 +316,6 @@ DaemonApp::handleIpcMessage(const Event& e, void*)
} }
m_fileLogOutputter->setLogFilename(logFilename.c_str()); m_fileLogOutputter->setLogFilename(logFilename.c_str());
} }
#endif
} }
else { else {
LOG((CLOG_DEBUG "empty command, elevate=%d", cm->elevate())); LOG((CLOG_DEBUG "empty command, elevate=%d", cm->elevate()));
@ -372,12 +333,11 @@ DaemonApp::handleIpcMessage(const Event& e, void*)
LOG((CLOG_ERR "failed to save settings, %s", e.what())); LOG((CLOG_ERR "failed to save settings, %s", e.what()));
} }
#if SYSAPI_WIN32
// tell the relauncher about the new command. this causes the // tell the relauncher about the new command. this causes the
// relauncher to stop the existing command and start the new // relauncher to stop the existing command and start the new
// command. // command.
m_watchdog->setCommand(command, cm->elevate()); m_watchdog->setCommand(command, cm->elevate());
#endif
break; break;
} }
@ -392,10 +352,8 @@ DaemonApp::handleIpcMessage(const Event& e, void*)
LOG((CLOG_DEBUG "ipc hello, type=%s", type.c_str())); LOG((CLOG_DEBUG "ipc hello, type=%s", type.c_str()));
#if SYSAPI_WIN32
const char * serverstatus = m_watchdog->isProcessActive() ? "active" : "not active"; const char * serverstatus = m_watchdog->isProcessActive() ? "active" : "not active";
LOG((CLOG_INFO "server status: %s", serverstatus)); LOG((CLOG_INFO "server status: %s", serverstatus));
#endif
m_ipcLogOutputter->notifyBuffer(); m_ipcLogOutputter->notifyBuffer();
break; break;

View File

@ -27,9 +27,7 @@ class Event;
class IpcLogOutputter; class IpcLogOutputter;
class FileLogOutputter; class FileLogOutputter;
#if SYSAPI_WIN32
class MSWindowsWatchdog; class MSWindowsWatchdog;
#endif
class DaemonApp { class DaemonApp {
@ -48,9 +46,7 @@ private:
public: public:
static DaemonApp* s_instance; static DaemonApp* s_instance;
#if SYSAPI_WIN32
MSWindowsWatchdog* m_watchdog; MSWindowsWatchdog* m_watchdog;
#endif
private: private:
IpcServer* m_ipcServer; IpcServer* m_ipcServer;

View File

@ -142,10 +142,7 @@ MSWindowsWatchdog::getUserToken(LPSECURITY_ATTRIBUTES security)
// elevate for the uac dialog (consent.exe) but this would be pointless, // elevate for the uac dialog (consent.exe) but this would be pointless,
// since barrier would re-launch as non-elevated after the desk switch, // since barrier would re-launch as non-elevated after the desk switch,
// and so would be unusable with the new elevated process taking focus. // and so would be unusable with the new elevated process taking focus.
if (m_elevateProcess if (m_elevateProcess || m_autoElevated) {
|| m_autoElevated
|| m_session.isProcessInSession("logonui.exe", NULL)) {
LOG((CLOG_DEBUG "getting elevated token, %s", LOG((CLOG_DEBUG "getting elevated token, %s",
(m_elevateProcess ? "elevation required" : "at login screen"))); (m_elevateProcess ? "elevation required" : "at login screen")));
@ -155,8 +152,7 @@ MSWindowsWatchdog::getUserToken(LPSECURITY_ATTRIBUTES security)
} }
return duplicateProcessToken(process, security); return duplicateProcessToken(process, security);
} } else {
else {
LOG((CLOG_DEBUG "getting non-elevated token")); LOG((CLOG_DEBUG "getting non-elevated token"));
return m_session.getUserToken(security); return m_session.getUserToken(security);
} }