Commit 31d35585 authored by Hannah von Reth's avatar Hannah von Reth

Win: Create local socket named pipes based on the instalaltion prefix

Summary:
This allows multiple paralell akonadi installations running without
clashing.

Reviewers: dfaure, dvratil

Reviewed By: dvratil

Subscribers: kfunk, #windows, #kde_pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D9753
parent 565f4536
......@@ -129,7 +129,20 @@ void Connection::doReconnect()
<< 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 @@ void Connection::doReconnect()
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
......
......@@ -56,11 +56,6 @@
#include <QTimer>
#include <QDBusServiceWatcher>
#ifdef Q_OS_WIN
#include <windows.h>
#include <sddl.h>
#endif
using namespace Akonadi;
using namespace Akonadi::Server;
......@@ -127,40 +122,11 @@ bool AkonadiServer::init()
// own thread
connect(mNtfServer, QOverload<quintptr>::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<PTOKEN_USER>(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<ushort *>(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;
......@@ -168,7 +134,7 @@ bool AkonadiServer::init()
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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment