QLocalServer: use std::unique_ptr instead of QScopedPointer
Task-number: QTBUG-132213 Change-Id: I6a18e787efa9a2ecfe89339569a9724467ac3e6a Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
9eb2c404ee
commit
ffc5491757
@ -12,6 +12,8 @@
|
|||||||
#include <accctrl.h>
|
#include <accctrl.h>
|
||||||
#include <sddl.h>
|
#include <sddl.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
// The buffer size need to be 0 otherwise data could be
|
// The buffer size need to be 0 otherwise data could be
|
||||||
// lost if the socket that has written data closes the connection
|
// lost if the socket that has written data closes the connection
|
||||||
// before it is read. Pipewriter is used for write buffering.
|
// before it is read. Pipewriter is used for write buffering.
|
||||||
@ -33,7 +35,7 @@ bool QLocalServerPrivate::addListener()
|
|||||||
sa.bInheritHandle = FALSE; //non inheritable handle, same as default
|
sa.bInheritHandle = FALSE; //non inheritable handle, same as default
|
||||||
sa.lpSecurityDescriptor = 0; //default security descriptor
|
sa.lpSecurityDescriptor = 0; //default security descriptor
|
||||||
|
|
||||||
QScopedPointer<SECURITY_DESCRIPTOR> pSD;
|
std::unique_ptr<SECURITY_DESCRIPTOR> pSD;
|
||||||
PSID worldSID = 0;
|
PSID worldSID = 0;
|
||||||
QByteArray aclBuffer;
|
QByteArray aclBuffer;
|
||||||
QByteArray tokenUserBuffer;
|
QByteArray tokenUserBuffer;
|
||||||
@ -42,7 +44,7 @@ bool QLocalServerPrivate::addListener()
|
|||||||
// create security descriptor if access options were specified
|
// create security descriptor if access options were specified
|
||||||
if ((socketOptions.value() & QLocalServer::WorldAccessOption)) {
|
if ((socketOptions.value() & QLocalServer::WorldAccessOption)) {
|
||||||
pSD.reset(new SECURITY_DESCRIPTOR);
|
pSD.reset(new SECURITY_DESCRIPTOR);
|
||||||
if (!InitializeSecurityDescriptor(pSD.data(), SECURITY_DESCRIPTOR_REVISION)) {
|
if (!InitializeSecurityDescriptor(pSD.get(), SECURITY_DESCRIPTOR_REVISION)) {
|
||||||
setError("QLocalServerPrivate::addListener"_L1);
|
setError("QLocalServerPrivate::addListener"_L1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -76,10 +78,14 @@ bool QLocalServerPrivate::addListener()
|
|||||||
SID_NAME_USE groupNameUse;
|
SID_NAME_USE groupNameUse;
|
||||||
LPWSTR groupNameSid;
|
LPWSTR groupNameSid;
|
||||||
LookupAccountSid(0, pTokenGroup->PrimaryGroup, 0, &groupNameSize, 0, &domainNameSize, &groupNameUse);
|
LookupAccountSid(0, pTokenGroup->PrimaryGroup, 0, &groupNameSize, 0, &domainNameSize, &groupNameUse);
|
||||||
QScopedPointer<wchar_t, QScopedPointerArrayDeleter<wchar_t>> groupName(new wchar_t[groupNameSize]);
|
auto groupName = std::unique_ptr<wchar_t[]>(new wchar_t[groupNameSize]);
|
||||||
QScopedPointer<wchar_t, QScopedPointerArrayDeleter<wchar_t>> domainName(new wchar_t[domainNameSize]);
|
auto domainName = std::unique_ptr<wchar_t[]>(new wchar_t[domainNameSize]);
|
||||||
if (LookupAccountSid(0, pTokenGroup->PrimaryGroup, groupName.data(), &groupNameSize, domainName.data(), &domainNameSize, &groupNameUse)) {
|
const bool lookup = LookupAccountSid(0, pTokenGroup->PrimaryGroup, groupName.get(),
|
||||||
qDebug() << "primary group" << QString::fromWCharArray(domainName.data()) << "\\" << QString::fromWCharArray(groupName.data()) << "type=" << groupNameUse;
|
&groupNameSize, domainName.get(), &domainNameSize,
|
||||||
|
&groupNameUse);
|
||||||
|
if (lookup) {
|
||||||
|
qDebug() << "primary group" << QString::fromWCharArray(domainName.get()) << "\\"
|
||||||
|
<< QString::fromWCharArray(groupName.get()) << "type=" << groupNameUse;
|
||||||
}
|
}
|
||||||
if (ConvertSidToStringSid(pTokenGroup->PrimaryGroup, &groupNameSid)) {
|
if (ConvertSidToStringSid(pTokenGroup->PrimaryGroup, &groupNameSid)) {
|
||||||
qDebug() << "primary group SID" << QString::fromWCharArray(groupNameSid) << "valid" << IsValidSid(pTokenGroup->PrimaryGroup);
|
qDebug() << "primary group SID" << QString::fromWCharArray(groupNameSid) << "valid" << IsValidSid(pTokenGroup->PrimaryGroup);
|
||||||
@ -127,15 +133,15 @@ bool QLocalServerPrivate::addListener()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetSecurityDescriptorOwner(pSD.data(), pTokenUser->User.Sid, FALSE);
|
SetSecurityDescriptorOwner(pSD.get(), pTokenUser->User.Sid, FALSE);
|
||||||
SetSecurityDescriptorGroup(pSD.data(), pTokenGroup->PrimaryGroup, FALSE);
|
SetSecurityDescriptorGroup(pSD.get(), pTokenGroup->PrimaryGroup, FALSE);
|
||||||
if (!SetSecurityDescriptorDacl(pSD.data(), TRUE, acl, FALSE)) {
|
if (!SetSecurityDescriptorDacl(pSD.get(), TRUE, acl, FALSE)) {
|
||||||
setError("QLocalServerPrivate::addListener"_L1);
|
setError("QLocalServerPrivate::addListener"_L1);
|
||||||
FreeSid(worldSID);
|
FreeSid(worldSID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.lpSecurityDescriptor = pSD.data();
|
sa.lpSecurityDescriptor = pSD.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
listener->handle = CreateNamedPipe(
|
listener->handle = CreateNamedPipe(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user