Changeset View
Changeset View
Standalone View
Standalone View
src/server/akonadi.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
51 | #include <QSqlError> | 51 | #include <QSqlError> | ||
52 | 52 | | |||
53 | #include <QCoreApplication> | 53 | #include <QCoreApplication> | ||
54 | #include <QDir> | 54 | #include <QDir> | ||
55 | #include <QSettings> | 55 | #include <QSettings> | ||
56 | #include <QTimer> | 56 | #include <QTimer> | ||
57 | #include <QDBusServiceWatcher> | 57 | #include <QDBusServiceWatcher> | ||
58 | 58 | | |||
59 | #ifdef Q_OS_WIN | | |||
60 | #include <windows.h> | | |||
61 | #include <sddl.h> | | |||
62 | #endif | | |||
63 | | ||||
64 | using namespace Akonadi; | 59 | using namespace Akonadi; | ||
65 | using namespace Akonadi::Server; | 60 | using namespace Akonadi::Server; | ||
66 | 61 | | |||
67 | AkonadiServer *AkonadiServer::s_instance = nullptr; | 62 | AkonadiServer *AkonadiServer::s_instance = nullptr; | ||
68 | 63 | | |||
69 | AkonadiServer::AkonadiServer(QObject *parent) | 64 | AkonadiServer::AkonadiServer(QObject *parent) | ||
70 | : QObject(parent) | 65 | : QObject(parent) | ||
71 | , mCmdServer(nullptr) | 66 | , mCmdServer(nullptr) | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 86 | { | |||
122 | connect(mCmdServer, QOverload<quintptr>::of(&AkLocalServer::newConnection), this, &AkonadiServer::newCmdConnection); | 117 | connect(mCmdServer, QOverload<quintptr>::of(&AkLocalServer::newConnection), this, &AkonadiServer::newCmdConnection); | ||
123 | 118 | | |||
124 | mNotificationManager = new NotificationManager(); | 119 | mNotificationManager = new NotificationManager(); | ||
125 | mNtfServer = new AkLocalServer(this); | 120 | mNtfServer = new AkLocalServer(this); | ||
126 | // Note: this is a queued connection, as NotificationManager lives in its | 121 | // Note: this is a queued connection, as NotificationManager lives in its | ||
127 | // own thread | 122 | // own thread | ||
128 | connect(mNtfServer, QOverload<quintptr>::of(&AkLocalServer::newConnection), mNotificationManager, &NotificationManager::registerConnection); | 123 | connect(mNtfServer, QOverload<quintptr>::of(&AkLocalServer::newConnection), mNotificationManager, &NotificationManager::registerConnection); | ||
129 | 124 | | |||
125 | // TODO: share socket setup with client | ||||
130 | #ifdef Q_OS_WIN | 126 | #ifdef Q_OS_WIN | ||
131 | HANDLE hToken = NULL; | 127 | // use the installation prefix as uid | ||
132 | PSID sid; | 128 | const QString prefix = QString::fromUtf8(QUrl::toPercentEncoding(qApp->applicationDirPath())); | ||
133 | QString userID; | 129 | const QString defaultCmdPipe = QStringLiteral("Akonadi-Cmd-") % prefix; | ||
134 | | ||||
135 | OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &hToken); | | |||
136 | if (hToken) { | | |||
137 | DWORD size; | | |||
138 | PTOKEN_USER userStruct; | | |||
139 | | ||||
140 | GetTokenInformation(hToken, TokenUser, NULL, 0, &size); | | |||
141 | if (ERROR_INSUFFICIENT_BUFFER == GetLastError()) { | | |||
142 | userStruct = reinterpret_cast<PTOKEN_USER>(new BYTE[size]); | | |||
143 | GetTokenInformation(hToken, TokenUser, userStruct, size, &size); | | |||
144 | | ||||
145 | int sidLength = GetLengthSid(userStruct->User.Sid); | | |||
146 | sid = (PSID) malloc(sidLength); | | |||
147 | CopySid(sidLength, sid, userStruct->User.Sid); | | |||
148 | CloseHandle(hToken); | | |||
149 | delete [] userStruct; | | |||
150 | } | | |||
151 | | ||||
152 | LPWSTR s; | | |||
153 | if (!ConvertSidToStringSidW(sid, &s)) { | | |||
154 | qCCritical(AKONADISERVER_LOG) << "Could not determine user id for current process."; | | |||
155 | userID = QString(); | | |||
156 | } else { | | |||
157 | userID = QString::fromUtf16(reinterpret_cast<ushort *>(s)); | | |||
158 | LocalFree(s); | | |||
159 | } | | |||
160 | free(sid); | | |||
161 | } | | |||
162 | | ||||
163 | const QString defaultCmdPipe = QStringLiteral("Akonadi-Cmd-") % userID; | | |||
164 | const QString cmdPipe = settings.value(QStringLiteral("Connection/NamedPipe"), defaultCmdPipe).toString(); | 130 | const QString cmdPipe = settings.value(QStringLiteral("Connection/NamedPipe"), defaultCmdPipe).toString(); | ||
165 | if (!mCmdServer->listen(cmdPipe)) { | 131 | if (!mCmdServer->listen(cmdPipe)) { | ||
166 | qCCritical(AKONADISERVER_LOG) << "Unable to listen on Named Pipe" << cmdPipe; | 132 | qCCritical(AKONADISERVER_LOG) << "Unable to listen on Named Pipe" << cmdPipe; | ||
167 | quit(); | 133 | quit(); | ||
168 | return false; | 134 | return false; | ||
169 | } | 135 | } | ||
170 | 136 | | |||
171 | const QString defaultNtfPipe = QStringLiteral("Akonadi-Ntf-") % userID; | 137 | const QString defaultNtfPipe = QStringLiteral("Akonadi-Ntf-") % prefix; | ||
172 | const QString ntfPipe = settings.value(QStringLiteral("Connection/NtfNamedPipe"), defaultNtfPipe).toString(); | 138 | const QString ntfPipe = settings.value(QStringLiteral("Connection/NtfNamedPipe"), defaultNtfPipe).toString(); | ||
173 | if (!mNtfServer->listen(ntfPipe)) { | 139 | if (!mNtfServer->listen(ntfPipe)) { | ||
174 | qCCritical(AKONADISERVER_LOG) << "Unable to listen on Named Pipe" << ntfPipe; | 140 | qCCritical(AKONADISERVER_LOG) << "Unable to listen on Named Pipe" << ntfPipe; | ||
175 | quit(); | 141 | quit(); | ||
176 | return false; | 142 | return false; | ||
177 | } | 143 | } | ||
178 | 144 | | |||
179 | connectionSettings.setValue(QStringLiteral("Data/Method"), QStringLiteral("NamedPipe")); | 145 | connectionSettings.setValue(QStringLiteral("Data/Method"), QStringLiteral("NamedPipe")); | ||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |