I am trying to use QLocalServer in service application on win7. QLocalServer's windows implementation uses named pipes, and since winV开发者_运维技巧ista try to access it from GUI causes error. There was even QT bug about it, but trolls closed it without any fixing. So my question is: Is there a way to change security attributes of already created in service named pipe to make it accessible from gui applications? Or the only way is copypaste QT QLocalServer object and add security attributes to its code which creates pipe? I grant access to pipes handles with
template <class To, class From> inline To* d_ptr(From* ptr)
{
return (To*)QObjectPrivate::get(ptr);
}
...
QLocalServerPrivate* p=d_ptr<QLocalServerPrivate>(this);
But what to do with them now?
if believe to this pipe security attributes cannot be changed under LocalAdmin user... so I edited QLocalServer, which i did not wanted to do :(
I faced with the same problem few years ago. Maybe it already fixed in latest Qt version. I resolved the problem with next workaround:
bool fixLocalServerPermissions(QLocalServer *server)
{
QString pipeName = server->fullServerName();
HANDLE h = CreateNamedPipeA(pipeName.toStdString().c_str(), PIPE_ACCESS_DUPLEX | WRITE_DAC,
PIPE_TYPE_MESSAGE, PIPE_UNLIMITED_INSTANCES, 1024*16, 1024*16, 0, NULL);
if (h == INVALID_HANDLE_VALUE)
return false;
bool status = SetSecurityInfo(h, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, NULL, NULL) == ERROR_SUCCESS;
CloseHandle(h);
return status;
}
精彩评论