diff --git a/src/core/connection.cpp b/src/core/connection.cpp --- a/src/core/connection.cpp +++ b/src/core/connection.cpp @@ -129,7 +129,20 @@ << XdgBaseDirs::homePath("config") << "nor in any of" << XdgBaseDirs::systemPathList("config"); } + + // TODO: share socket setup with server const QSettings connectionSettings(connectionConfigFile, QSettings::IniFormat); +#ifdef Q_OS_WIN + // use the installation prefix as uid + const QString prefix = QString::fromUtf8(QUrl::toPercentEncoding(qApp->applicationDirPath())); + if (mConnectionType == CommandConnection) { + const QString defaultPipe = QStringLiteral("Akonadi-Cmd-") % prefix; + serverAddress = connectionSettings.value(QStringLiteral("Connection/NamedPipe"), defaultPipe).toString(); + } else if (mConnectionType == NotificationConnection) { + const QString defaultPipe = QStringLiteral("Akonadi-Ntf-") % prefix; + serverAddress = connectionSettings.value(QStringLiteral("Connection/NtfNamedPipe"), defaultPipe).toString(); + } +#else const QString defaultSocketDir = StandardDirs::saveDir("data"); if (mConnectionType == CommandConnection) { @@ -139,6 +152,7 @@ const QString defaultSocketPath = defaultSocketDir % QStringLiteral("/akonadiserver-ntf.socket"); serverAddress = connectionSettings.value(QStringLiteral("Notifications/UnixPath"), defaultSocketPath).toString(); } +#endif } // create sockets if not yet done, note that this does not yet allow changing socket types on the fly diff --git a/src/server/akonadi.cpp b/src/server/akonadi.cpp --- a/src/server/akonadi.cpp +++ b/src/server/akonadi.cpp @@ -56,11 +56,6 @@ #include #include -#ifdef Q_OS_WIN -#include -#include -#endif - using namespace Akonadi; using namespace Akonadi::Server; @@ -127,48 +122,19 @@ // own thread connect(mNtfServer, QOverload::of(&AkLocalServer::newConnection), mNotificationManager, &NotificationManager::registerConnection); + // TODO: share socket setup with client #ifdef Q_OS_WIN - HANDLE hToken = NULL; - PSID sid; - QString userID; - - OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &hToken); - if (hToken) { - DWORD size; - PTOKEN_USER userStruct; - - GetTokenInformation(hToken, TokenUser, NULL, 0, &size); - if (ERROR_INSUFFICIENT_BUFFER == GetLastError()) { - userStruct = reinterpret_cast(new BYTE[size]); - GetTokenInformation(hToken, TokenUser, userStruct, size, &size); - - int sidLength = GetLengthSid(userStruct->User.Sid); - sid = (PSID) malloc(sidLength); - CopySid(sidLength, sid, userStruct->User.Sid); - CloseHandle(hToken); - delete [] userStruct; - } - - LPWSTR s; - if (!ConvertSidToStringSidW(sid, &s)) { - qCCritical(AKONADISERVER_LOG) << "Could not determine user id for current process."; - userID = QString(); - } else { - userID = QString::fromUtf16(reinterpret_cast(s)); - LocalFree(s); - } - free(sid); - } - - const QString defaultCmdPipe = QStringLiteral("Akonadi-Cmd-") % userID; + // use the installation prefix as uid + const QString prefix = QString::fromUtf8(QUrl::toPercentEncoding(qApp->applicationDirPath())); + const QString defaultCmdPipe = QStringLiteral("Akonadi-Cmd-") % prefix; const QString cmdPipe = settings.value(QStringLiteral("Connection/NamedPipe"), defaultCmdPipe).toString(); if (!mCmdServer->listen(cmdPipe)) { qCCritical(AKONADISERVER_LOG) << "Unable to listen on Named Pipe" << cmdPipe; quit(); return false; } - const QString defaultNtfPipe = QStringLiteral("Akonadi-Ntf-") % userID; + const QString defaultNtfPipe = QStringLiteral("Akonadi-Ntf-") % prefix; const QString ntfPipe = settings.value(QStringLiteral("Connection/NtfNamedPipe"), defaultNtfPipe).toString(); if (!mNtfServer->listen(ntfPipe)) { qCCritical(AKONADISERVER_LOG) << "Unable to listen on Named Pipe" << ntfPipe;