在 QtService 上使用 QLocalServer :如何为 QLocalServer 创建的命名管道设置安全属性?

发布于 2024-10-07 23:04:25 字数 481 浏览 0 评论 0原文

我正在尝试在win7上的服务应用程序中使用QLocalServer。 QLocalServer 的 Windows 实现使用命名管道,并且由于 winVista 尝试从 GUI 访问它会导致错误。甚至还有关于它的 QT 错误,但巨魔们在没有任何修复的情况下关闭了它。 所以我的问题是: 有没有办法更改已在服务命名管道中创建的安全属性,以使其可以从 GUI 应用程序访问? 或者唯一的方法是复制粘贴 QT QLocalServer 对象并向其创建管道的代码添加安全属性? 我授予对管道句柄的访问权限

template <class To, class From> inline To* d_ptr(From* ptr)
{
    return (To*)QObjectPrivate::get(ptr);
}
...
QLocalServerPrivate* p=d_ptr<QLocalServerPrivate>(this);

但是现在如何处理它们呢?

I am trying to use QLocalServer in service application on win7.
QLocalServer's windows implementation uses named pipes, and since winVista 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

禾厶谷欠 2024-10-14 23:04:25

如果相信此管道无法在 LocalAdmin 用户下更改安全属性...
所以我编辑了 QLocalServer,这是我不想做的:(

if believe to this pipe security attributes cannot be changed under LocalAdmin user...
so I edited QLocalServer, which i did not wanted to do :(

梦开始←不甜 2024-10-14 23:04:25

几年前我也遇到过同样的问题。也许它已经在最新的 Qt 版本中修复了。我通过下一个解决方法解决了该问题:

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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文