SetNamedSecurityInfo 抛出错误代码 87

huangapple go评论46阅读模式
英文:

SetNamedSecurityInfo throwing error code 87

问题

我们已经面临了几个月的这个问题。

在使用Windows API函数SetNamedSecurityInfo()时,返回错误代码87。我尝试过修复它,但无法解决。请帮我修复这个问题。

LPWSTR shareName = (LPWSTR)L"//TEST/test";
DWORD dwRes = SetNamedSecurityInfo(shareName, SE_FILE_OBJECT, SACL_SECURITY_INFORMATION, NULL, NULL, NULL, NULL);
if (ERROR_SUCCESS != dwRes) {
    cout << "在SetNamedSecurityInfo中设置SACL时出错 " << dwRes << endl;
    return -1;
}

我们只传递shareName作为参数,其余参数都是常量。

通常情况下,这段代码应该在不设置任何SACL权限和不出现错误的情况下运行。

但是,在这种情况下返回错误87,这意味着“参数不正确”。但是唯一传递的参数是shareName,如果shareName不正确,那么函数应该返回错误67,这意味着“找不到网络名称”。

为什么在这种情况下返回错误87?

英文:

We have been facing this issue for several months.

While using the Windows API function SetNamedSecurityInfo(), the error code 87 is returned. I have tried to fix it, but couldn't. Please help me fix this.

LPWSTR shareName = (LPWSTR)L&quot;//TEST/test&quot;;	
DWORD dwRes = SetNamedSecurityInfo(shareName, SE_FILE_OBJECT, SACL_SECURITY_INFORMATION, NULL, NULL, NULL, NULL);
if (ERROR_SUCCESS != dwRes) {		
	cout &lt;&lt; &quot;Error while setting SACL in SetNamedSecurityInfo Error  &quot; &lt;&lt; dwRes &lt;&lt; endl;		
	return -1;	
}

We are passing only the shareName as a parameter, and all the remaining parameters are constant.

Normally this code should function without setting any SACL permissions, and without any errors.

But, this is returning error 87, which means "The parameter is incorrect". But the only parameter that has been passed is the shareName, and if the shareName is wrong then the function should return error 67 instead, which means "The network name cannot be found".

Why is error 87 being returned in this case?

答案1

得分: 1

你正在指定 SACL_SECURITY_INFORMATION 标志,但将 pSACL 参数设置为 NULL。这就是为什么你会收到 ERROR_INVALID_PARAMETER(87)错误。当使用 SACL_SECURITY_INFORMATION 标志时,pSACL 参数必须指向一个有效的 SACL 对象。

英文:

You are specifying the SACL_SECURITY_INFORMATION flag, but you are setting the pSACL parameter to NULL. That is why you are getting the ERROR_INVALID_PARAMETER (87) error. When the SACL_SECURITY_INFORMATION flag is used, the pSACL parameter must point to a valid SACL object.

huangapple
  • 本文由 发表于 2023年7月17日 22:47:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76705643.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定