热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

创建everyonefullcontrol的全局事件对象

2019独角兽企业重金招聘Python工程师标准#include#includeLPVOIDBuildRestrictedSD(PS

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

#include
#include LPVOID BuildRestrictedSD(PSECURITY_DESCRIPTOR pSD)
{DWORD dwAclLength;PSID psidEveryone = NULL;PACL pDACL = NULL;BOOL bResult = FALSE;PACCESS_ALLOWED_ACE pACE = NULL;SID_IDENTIFIER_AUTHORITY siaWorld = SECURITY_WORLD_SID_AUTHORITY ;SECURITY_INFORMATION si = DACL_SECURITY_INFORMATION;__try {// initialize the security descriptorif (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)) {__leave;}// obtain a sid for the Authenticated Users Groupif (!AllocateAndInitializeSid(&siaWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &psidEveryone)) {__leave;}// NOTE:// // The Authenticated Users group includes all user accounts that// have been successfully authenticated by the system. If access// must be restricted to a specific user or group other than // Authenticated Users, the SID can be constructed using the// LookupAccountSid() API based on a user or group name.// calculate the DACL lengthdwAclLength = sizeof(ACL)// add space for Authenticated Users group ACE+ sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)+ GetLengthSid(psidEveryone);// allocate memory for the DACLpDACL = (PACL) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwAclLength);if (!pDACL) {__leave;}// initialize the DACLif (!InitializeAcl(pDACL, dwAclLength, ACL_REVISION)) {__leave;}// add the Authenticated Users group ACE to the DACL with// GENERIC_READ, GENERIC_WRITE, and GENERIC_EXECUTE accessif (!AddAccessAllowedAce(pDACL, ACL_REVISION,GENERIC_ALL,psidEveryone)) {__leave;}// set the DACL in the security descriptorif (!SetSecurityDescriptorDacl(pSD, TRUE, pDACL, FALSE)) {__leave;}bResult = TRUE;} __finally {if (psidEveryone) FreeSid(psidEveryone);}if (bResult == FALSE) {if (pDACL) HeapFree(GetProcessHeap(), 0, pDACL);pDACL = NULL;}return (LPVOID) pDACL;
}// The following function frees memory allocated in the
// BuildRestrictedSD() function
VOID FreeRestrictedSD(LPVOID ptr)
{if (ptr) HeapFree(GetProcessHeap(), 0, ptr);
}int main(int argc,char **argv)
{LPVOID ptr;HANDLE hEvent;SECURITY_ATTRIBUTES sa;SECURITY_DESCRIPTOR sd;sa.nLength = sizeof(sa);sa.lpSecurityDescriptor = &sd;sa.bInheritHandle = FALSE;// build a restricted security descriptorptr = BuildRestrictedSD(&sd);hEvent = CreateEvent(&sa,FALSE,FALSE,"Global\\xxxx");FreeRestrictedSD(ptr);if(hEvent){printf("Create event OK \n");}elseprintf("error :%d \n",GetLastError());getchar();return 0;
}


转:https://my.oschina.net/sincoder/blog/119267



推荐阅读
author-avatar
牛奶姆姆_592
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有