gpt4 book ai didi

c++ - 正确实现 WlanHostedNetwork 函数的 WlanSetSecuritySettings

转载 作者:太空宇宙 更新时间:2023-11-04 12:56:36 26 4
gpt4 key购买 nike

正如标题所说,我不太确定我是如何正确实现 WlanSetSecuritySettings 的功能以获得系统的完全访问权限以编辑WlanHostedNetwork from the native wlanapi (-> 因为我在某些系统上遇到错误,这表明我没有访问权限并且我需要提升权限!)。在 MSDN 文档中有以下手册如何执行此操作 - 我尽量遵循它:

The WlanHostedNetworkForceStart function could fail if Hosted Network state is wlan_hosted_network_unavailable or the caller does not have sufficient privileges. This function to force the start of the Hosted Network can only be called if the user has the appropriate associated privilege. Permissions are stored in a discretionary access control list (DACL) associated with a WLAN_SECURABLE_OBJECT. To call the WlanHostedNetworkForceStart, the client access token of the caller must have elevated privileges exposed by the following enumeration in WLAN_SECURABLE_OBJECT: wlan_secure_hosted_network_elevated_access

因此:

A successful call to the WlanSetSecuritySettings function overrides the default permissions associated with an object. For more information about default permissions, see Native Wifi API Permissions. The following describes the procedure for creating a security descriptor object and parsing it as a string. Call InitializeSecurityDescriptor to create a security descriptor in memory. Call SetSecurityDescriptorOwner to set the owner information for the security descriptor. Call InitializeAcl to create a discretionary access control list (DACL) in memory. Call AddAccessAllowedAce or AddAccessDeniedAce to add access control entries (ACEs) to the DACL. Set the AccessMask parameter to one of the following bitwise OR combinations as appropriate: WLAN_READ_ACCESS WLAN_READ_ACCESS | WLAN_EXECUTE_ACCESS WLAN_READ_ACCESS | WLAN_EXECUTE_ACCESS | WLAN_WRITE_ACCESS Call SetSecurityDescriptorDacl to add the DACL to the security descriptor. Call ConvertSecurityDescriptorToStringSecurityDescriptor to convert the descriptor to string. The string returned by ConvertSecurityDescriptorToStringSecurityDescriptor can then be used as the strModifiedSDDL parameter value when calling WlanSetSecuritySettings.

首先这是我的代码(WifiClass 是一个静态类,elevateAccess() 也是静态的)- 我完成了上面手册中的所有步骤:

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,因为字符串显然无效。

问题:我是不是按照本手册做错了什么?我是否需要其他东西来初始化或其他值?如何修复代码?

最佳答案

这是因为 SetSecurityDescriptorDacl() 正在为 DACL 传递 null,所以它表示有一个 NULL DACL。它应该通过 pAcl 而不是 NULL,这对我有用。

关于c++ - 正确实现 WlanHostedNetwork 函数的 WlanSetSecuritySettings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46279315/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com