【发布时间】:2011-10-04 18:59:42
【问题描述】:
我的故事是我正在设计一个必须与 Windows 服务通信的新应用程序。经过大量研究,我得出的结论是命名管道是推荐的方法(How do I send a string from one instance of my Delphi program to another?)但是,由于安全问题,我似乎无法在 Win7 中使用 SendMessage 或命名管道......消息永远不会到达外部为应用程序提供服务。
我正在使用 Russell Libby 的命名管道组件,这些组件可以在普通桌面应用程序之间顺利运行,但 Windows 服务似乎在解决方案中遇到了麻烦。进一步的研究告诉我,有可能在双方都开放安全性以让他们进行通信,但是,我对此的知识水平充其量是最低限度的,而且我无法对可能的 API 调用做出正面或反面.
基于Delphi组件pipes.pas,需要做什么才能打开这个宝贝让双方开始对话?我确定 pipes.pas 文件中的以下两个函数标识了安全属性,有人可以在这里帮助我吗?
谢谢!
procedure InitializeSecurity(var SA: TSecurityAttributes);
var
sd: PSecurityDescriptor;
begin
// Allocate memory for the security descriptor
sd := AllocMem(SECURITY_DESCRIPTOR_MIN_LENGTH);
// Initialize the new security descriptor
if InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION) then
begin
// Add a NULL descriptor ACL to the security descriptor
if SetSecurityDescriptorDacl(sd, True, nil, False) then
begin
// Set up the security attributes structure
SA.nLength := SizeOf(TSecurityAttributes);
SA.lpSecurityDescriptor := sd;
SA.bInheritHandle := True;
end
else
// Failed to init the sec descriptor
RaiseWindowsError;
end
else
// Failed to init the sec descriptor
RaiseWindowsError;
end;
procedure FinalizeSecurity(var SA: TSecurityAttributes);
begin
// Release memory that was assigned to security descriptor
if Assigned(SA.lpSecurityDescriptor) then
begin
// Reource protection
try
// Free memory
FreeMem(SA.lpSecurityDescriptor);
finally
// Clear pointer
SA.lpSecurityDescriptor := nil;
end;
end;
end;
【问题讨论】:
-
此代码已将空 DACL 分配给安全属性。这意味着 everybody 可以对与之关联的任何对象执行anything。 (阅读代码中使用的函数的文档。)您的问题出在其他地方。
-
@Rob 出于安全原因,这适用于本地,但不适用于网络。自 Vista 以来,匿名访问处于 中等 安全级别。因此,即使在匿名模式下,连接也会失败。这就是问题所在。
-
我已经遇到了同样的问题。见this article。但我还没有找到正确的解决方案。我会尝试
S:(ML;;NW;;;S-1-16-0)技巧。 ;) -
使用 TCP 不会有安全问题
-
@Warren P,仅当您打开了本地防火墙时,如果我在使用路由器访问 Internet 的内部网络上运行,我从不打扰。即便如此,还是有办法解决这个问题的。
标签: delphi windows-services desktop-application c++builder named-pipes