给window内核对象赋予任何人都可以访问的权限的权限

 SECURITY_DESCRIPTOR sdEventSecurityDesc;
 SECURITY_ATTRIBUTES saEventSecurityAttr;
 if(InitializeSecurityDescriptor(&sdEventSecurityDesc, SECURITY_DESCRIPTOR_REVISION)) //Revision level
 {
  if(SetSecurityDescriptorDacl(&sdEventSecurityDesc,
   TRUE, // DACL presence
   NULL, // DACL (NULL DACL means all access granted)
   FALSE)) // default DACL
  {
   saEventSecurityAttr.nLength = sizeof(SECURITY_DESCRIPTOR);
   saEventSecurityAttr.lpSecurityDescriptor = (LPVOID)&sdEventSecurityDesc;
   saEventSecurityAttr.bInheritHandle = TRUE;

   // now you can fill param LPSECURITY_ATTRIBUTES while &saEventSecurityAttr
  }
 }
 

在vista及以上windows版本,如果要上低优先级的程序访问高优先级创建的对象,还必须通过下面代码来设置

#include <accctrl.h>
#include <Sddl.h>
#include <aclapi.h>
//LABEL_SECURITY_INFORMATION  SDDL  SACL被设为低完整性级别
LPCWSTR LOW_INTEGRITY_SDDL_SACL_W = L"S:(ML;;NW;;;LW)";

bool SetObjectToLowIntegrity(
        HANDLE hObject, SE_OBJECT_TYPE type)
{
 bool bRet = false;
 DWORD dwErr = ERROR_SUCCESS;
 PSECURITY_DESCRIPTOR pSD = NULL;
 PACL pSacl = NULL;
 BOOL fSaclPresent = FALSE;
 BOOL fSaclDefaulted = FALSE;

 if ( ConvertStringSecurityDescriptorToSecurityDescriptorW (
  LOW_INTEGRITY_SDDL_SACL_W, SDDL_REVISION_1, &pSD, NULL ) )
 {
  if ( GetSecurityDescriptorSacl (
   pSD, &fSaclPresent, &pSacl, &fSaclDefaulted ) )
  {
   dwErr = SetSecurityInfo (
    hObject, type, LABEL_SECURITY_INFORMATION,
    NULL, NULL, NULL, pSacl );

   bRet = (ERROR_SUCCESS == dwErr);
  }

  LocalFree ( pSD );
 }

 return bRet;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值