如何枚举已分配指定用户权限的所有 SID?C++
How to enumerate all SIDs to which a specified user privilege has been assigned? c++
我在Windows和C++我想恢复给定权限的所有 SID。为了恢复 SID,我使用了以下方法:LsaOpenPolicy, LsaEnumerateAccountsWithUserRight 和 ConvertSidToStringSidA.问题来自返回错误 ConvertSidToStringSidA 方法:无效的 SID。这是我使用的代码:
LSA_HANDLE lsaPolicyHandle;
LSA_OBJECT_ATTRIBUTES lsaObjectAttributes;
ZeroMemory(&lsaObjectAttributes, sizeof (lsaObjectAttributes));
NTSTATUS ntStatus;
ntStatus=LsaOpenPolicy(nullptr,&lsaObjectAttributes, POLICY_ALL_ACCESS, &lsaPolicyHandle);
//Here ntstatus == ERROR_SUCCESS
if(ntStatus != ERROR_SUCCESS)
{
qDebug()<<"error";
}
LSA_UNICODE_STRING lsaUSerRight;
DWORD64 dwLen=0;
LPCWSTR pcwStr = L"SeServiceLogonRight";
dwLen = wcslen(pcwStr);
lsaUSerRight.Buffer = const_cast<wchar_t*>(pcwStr);
lsaUSerRight.Length = static_cast<unsigned short>(dwLen) * sizeof(WCHAR);
lsaUSerRight.MaximumLength= static_cast<unsigned short>(dwLen+1) *sizeof(WCHAR);
LSA_ENUMERATION_INFORMATION pEnumInfo;
ULONG ulCount;
ntStatus=LsaEnumerateAccountsWithUserRight(lsaPolicyHandle,
&lsaUSerRight,
reinterpret_cast<PVOID*>(&pEnumInfo),
&ulCount);
//Here ntstatus == ERROR_SUCCESS
if(ntStatus != ERROR_SUCCESS)
{
qDebug()<<"error";
}
//here pEnumInfo has an adress 0x45FF34c et ulCount = 2
LPSTR lpStringSid;
PSID pSid=pEnumInfo.Sid;
//Here invalid SID
BOOL bResultConvert=ConvertSidToStringSidA(pSid, &lpStringSid);
if(bResultConvert==0)
{
qDebug()<<"error";
}
LsaEnumerateAccountsWithUserRight
填充指向LSA_ENUMERATION_INFORMATION
的指针,因此您需要更改以下内容:
LSA_ENUMERATION_INFORMATION pEnumInfo;
对此:
LSA_ENUMERATION_INFORMATION *pEnumInfo;
要访问返回的第一个 SID,请更改以下内容:
PSID pSid=pEnumInfo.Sid;
对此:
PSID pSid=pEnumInfo->Sid;
然后它起作用了。
完成后,不要忘记释放随LsaFreeMemory
返回的结构,并用LsaClose
清理。
相关文章:
- C++如何通过用户输入删除列表元素
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何使用用户输入在C++中正确填充2D数组
- C++MySQL C api用户输入行
- 使用用户定义函数的字符串反转
- 如何枚举已分配指定用户权限的所有 SID?C++
- 为可执行文件授予比运行用户更多的权限
- 如何在C++中检查用户的系统权限
- 在不作为超级用户的情况下更改文件权限
- 程序删除其他用户的文件 - 权限被拒绝
- 在C++中创建一个文件,该文件具有只有用户才能查看和编辑该文件的权限
- Visual Studio Online(调整用户权限-不是TFS用户,而是windows用户)
- 正在检查非提升用户在Windows上的文件权限
- 如何授予用户对Web服务的权限
- 您是否可以拥有一个具有管理员权限的DLL,该DLL从仅具有用户级权限的客户端应用程序链接
- 如何使用C++为特定用户获取文件夹的ACL权限
- 如何在运行时向用户请求提升的权限
- c++ /Linux如何获取其他用户的读权限状态?
- 用户权限和COM对象
- XP SP3中的用户界面权限隔离