aboutsummaryrefslogtreecommitdiff
path: root/singleapplication.cpp
diff options
context:
space:
mode:
authorLe Liu <liulex@users.noreply.github.com>2016-11-27 01:40:47 +0800
committerItay Grudev <itay-grudev@users.noreply.github.com>2016-11-26 17:40:47 +0000
commit0f821d44f3cee46b866f29830ce0987c8b36ed5e (patch)
treeef6c80ff8a62f019e08747b19eaae64f9dc8dd96 /singleapplication.cpp
parentFixed typo in README.md (diff)
downloadsingleapplication-0f821d44f3cee46b866f29830ce0987c8b36ed5e.tar.xz
Allow data exclusion for the server name hash and Windows fixes (#16)
* Allows the application path and version to be excluded from the server name hash. The following flags were added for this purpose: * `SingleApplication::Mode::ExcludeAppVersion` * `SingleApplication::Mode::ExcludeAppPath` * Allow a non elevated process to connect to a local server created by an elevated process run by the same user on Windows * Fixes a problem with upper case letters in paths on Windows
Diffstat (limited to 'singleapplication.cpp')
-rw-r--r--singleapplication.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/singleapplication.cpp b/singleapplication.cpp
index 8fd8e7e..58eee7c 100644
--- a/singleapplication.cpp
+++ b/singleapplication.cpp
@@ -59,11 +59,21 @@ void SingleApplicationPrivate::genBlockServerName( int timeout )
QCryptographicHash appData( QCryptographicHash::Sha256 );
appData.addData( "SingleApplication", 17 );
appData.addData( SingleApplication::app_t::applicationName().toUtf8() );
- appData.addData( SingleApplication::app_t::applicationVersion().toUtf8() );
- appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() );
appData.addData( SingleApplication::app_t::organizationName().toUtf8() );
appData.addData( SingleApplication::app_t::organizationDomain().toUtf8() );
+ if( ! (options & SingleApplication::Mode::ExcludeAppVersion) ) {
+ appData.addData( SingleApplication::app_t::applicationVersion().toUtf8() );
+ }
+
+ if( ! (options & SingleApplication::Mode::ExcludeAppPath) ) {
+#ifdef Q_OS_WIN
+ appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() );
+#else
+ appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() );
+#endif
+ }
+
// User level block requires a user specific data in the hash
if( options & SingleApplication::Mode::User ) {
#ifdef Q_OS_WIN
@@ -108,6 +118,15 @@ void SingleApplicationPrivate::startPrimary( bool resetMemory )
// So we start a QLocalServer to listen for connections
QLocalServer::removeServer( blockServerName );
server = new QLocalServer();
+
+ // Restrict access to the socket according to the
+ // SingleApplication::Mode::User flag on User level or no restrictions
+ if( options & SingleApplication::Mode::User ) {
+ server->setSocketOptions( QLocalServer::UserAccessOption );
+ } else {
+ server->setSocketOptions( QLocalServer::WorldAccessOption );
+ }
+
server->listen( blockServerName );
QObject::connect(
server,