正确实现Wlanhostednetwork-inscontions的WlansetsecuritySettings
Correctly implement WlanSetSecuritySettings for WlanHostedNetwork-functions
,标题说我不确定我如何正确实现WlanSetsecuritySettings函数,以便从系统中获得完整访问权限,以从本机Wlanapi编辑Wlanhostednetwork( - - >当我在某些系统上遇到错误时,它说我没有访问权限,需要高程!)。在MSDN文档中,有以下手册如何执行此操作 - 我尝试尽可能地遵循它:
如果托管网络,wlanhostednetworkforcestart功能可能会失败 状态为wlan_hosted_network_unavailable或呼叫者没有 足够的权限。此功能强迫托管的开始 仅当用户拥有适当的关联时才能调用网络 特权。权限存储在可支配的访问控制中 列表(DACL)与WLAN_SECURABLE_OBJECT关联。打电话 wlanhostednetworkforcestart,客户端访问呼叫者的代币 必须在以下枚举中获得提高的特权 wlan_securable_object:wlan_secure_hosted_network_elevated_access
,因此:
成功呼叫WlanSetsecuritySettings功能覆盖了 与对象关联的默认权限。更多 有关默认权限的信息,请参阅本机WiFi API 权限。以下描述了创建一个的过程 安全描述符对象并将其解析为字符串。称呼 初始化eCurityDescriptor以创建安全描述符 记忆。调用SetSecurityDescriptorowner以设置所有者信息 对于安全描述符。调用pinitializeacl创建一个 内存中的可支配访问控制列表(DACL)。称呼 AddAccessloweredace或AddAccessDeniedace,以添加访问控件 DACL的条目(ACE)。将AccessMask参数设置为一个 遵循位或组合适当:WLAN_READ_ACCESS wlan_read_access |wlan_execute_access wlan_read_access | wlan_execute_access |wlan_write_access call setSecurityDescriptordAcl 将DACL添加到安全描述符中。称呼 转换securityDescriptOrtostRingSecurityDescriptor以转换 字符串的描述符。返回的字符串 然后可以使用ConvertSecurityDescriptOrtoRtoStringScurityDescriptor 作为呼叫时的strmodifiedSDDL参数值 wlansetsecuritySettings。
所以这是我的代码首先(Wificlass是静态类,而everateaccess()也是静态的) - 我从上面的手册中完成了所有步骤:
bool WifiClass::elevateAccess() {
PSECURITY_DESCRIPTOR securityDescriptor = (PSECURITY_DESCRIPTOR)LocalAlloc(LMEM_FIXED, sizeof(PACL));
PACL pAcl = (PACL)LocalAlloc(LMEM_FIXED, sizeof(PACL));
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
PSID pEveryoneSID = NULL;
bool bRet, bRes = true;
DWORD dRet;
bRet = InitializeSecurityDescriptor(securityDescriptor, SECURITY_DESCRIPTOR_REVISION);
if (!bRet)
{
bRes = false;
}
bRet = IsValidSecurityDescriptor(securityDescriptor);
bRet = AllocateAndInitializeSid(&SIDAuthWorld, 1,
SECURITY_WORLD_RID,
0, 0, 0, 0, 0, 0, 0,
&pEveryoneSID);
if (!bRet)
{
bRes = false;
}
bRet = IsValidSecurityDescriptor(securityDescriptor);
bRet = SetSecurityDescriptorOwner(securityDescriptor, pEveryoneSID, TRUE);
if (!bRet)
{
bRes = false;
}
bRet = IsValidSecurityDescriptor(securityDescriptor);
DWORD cbAcl = sizeof(ACL) +
(sizeof(ACCESS_ALLOWED_ACE)) + (GetLengthSid(securityDescriptor) - sizeof(DWORD));
bRet = InitializeAcl(pAcl, cbAcl, ACL_REVISION);
if (!bRet)
{
bRes = false;
}
bRet = IsValidAcl(pAcl);
bRet = AddAccessAllowedAce(pAcl, ACL_REVISION, WLAN_READ_ACCESS | WLAN_EXECUTE_ACCESS | WLAN_WRITE_ACCESS, securityDescriptor);
if (!bRet)
{
bRes = false;
}
bRet = IsValidSecurityDescriptor(securityDescriptor);
bRet = SetSecurityDescriptorDacl(securityDescriptor, TRUE, NULL, FALSE);
if (!bRet)
{
bRes = false;
}
bRet = IsValidSecurityDescriptor(securityDescriptor);
LPWSTR* pStringSecurityDescriptor = new LPWSTR;
bRet = ConvertSecurityDescriptorToStringSecurityDescriptor(securityDescriptor,
SDDL_REVISION_1,
DACL_SECURITY_INFORMATION,
pStringSecurityDescriptor,
NULL
);
if (!bRet)
{
bRes = false;
}
WLAN_SECURABLE_OBJECT wso = wlan_secure_hosted_network_elevated_access;
dRet = WlanSetSecuritySettings(wlanHandle, wso, (LPCWSTR)pStringSecurityDescriptor);
if (dRet != ERROR_SUCCESS)
{
bRes = false;
}
return bRes;
}
我的问题:一切似乎都起作用,所有Isvalid函数总是返回" true"。唯一不起作用的部分是
ConvertSecurityDescriptorToStringSecurityDescriptor(securityDescriptor,
SDDL_REVISION_1,
DACL_SECURITY_INFORMATION,
pStringSecurityDescriptor,
NULL
);
此部分返回pStringSecurityDescriptor
中的L"D:NO_ACCESS_CONTROL"
。正如预期的那样,下一个功能WlanSetSecuritySettings(wlanHandle, wso, (LPCWSTR)pStringSecurityDescriptor)
返回87:INVALID_PARAMETER
,因为字符串显然无效。
问题:此手册后我有问题吗?我需要其他一些初始化还是其他值?如何修复代码?
这是因为setSecurityDescriptordOdAcl()正在通过dACL传递,因此说有一个null dacl。它应该通过PACL而不是Null,它对我有用。
- 没有找到相关文章