首页
社区
课程
招聘
[求助] RegSetKeySecurity 使用方法。。
发表于: 2008-4-15 07:56 6736

[求助] RegSetKeySecurity 使用方法。。

2008-4-15 07:56
6736
procedure TForm1.FormCreate(Sender: TObject);
var
  Reg : TRegistry;
  TempKey: HKEY;
  SD : SECURITY_DESCRIPTOR;
  Ret : integer;
begin
  // 我想把  “SOFTWARE\ACD Systems”这个键设成:administrator 也只能有读入的权限 ,不能写
  if RegOpenKeyEx(HKEY_LOCAL_MACHINE, PChar('SOFTWARE\ACD Systems'), 0,
      WRITE_OWNER, TempKey) = ERROR_SUCCESS then
  begin
  Ret:=RegSetKeySecurity(TempKey,
                         OWNER_SECURITY_INFORMATION,    // 对要保存的信息进行描述的标志
                         @SD);    // 这个结构包含了注册表项新的安全特性设置
  end;

end;

  关于“OWNER_SECURITY_INFORMATION” 和“SD” 完全不明。。。

网上大部分都是 VC++ 写的,看不明。。。。

void WINAPI SetRegPermission(char *KeyStr)
{
// TODO: Add your control notification handler code here
HKEY hKey = 0;
SID_IDENTIFIER_AUTHORITY sia = SECURITY_NT_AUTHORITY;
     PSID pInteractiveSid = NULL;
PSID pAdministratorsSid = NULL;
SECURITY_DESCRIPTOR sd;
PACL pDacl = NULL;
     DWORD dwAclSize;
LONG lRetCode;
BOOL bRet;
     //char KeyStr[200];

//strcpy(KeyStr,"SOFTWARE\\LEGEND\\test");

lRetCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT(KeyStr),
0,
WRITE_DAC,
&hKey);
//open key
/*lRetCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\LEGEND\\test"),
0,
WRITE_DAC,
&hKey);*/
//
     // prepare a Sid representing any Interactively logged-on user
     //
     bRet = AllocateAndInitializeSid(
         &sia,
         1,
         SECURITY_INTERACTIVE_RID,
         0, 0, 0, 0, 0, 0, 0,
         &pInteractiveSid
         );

//
     // preprate a Sid representing the well-known admin group
     //
     bRet = AllocateAndInitializeSid(
         &sia,
         2,
         SECURITY_BUILTIN_DOMAIN_RID,
         DOMAIN_ALIAS_RID_ADMINS,
         0, 0, 0, 0, 0, 0,
         &pAdministratorsSid
         );
   
//
     // compute size of new acl
     //
     dwAclSize = sizeof(ACL) +
         2 * ( sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) ) +
         GetLengthSid(pInteractiveSid) +
         GetLengthSid(pAdministratorsSid) ;

     //
     // allocate storage for Acl
     //
     pDacl = (PACL)HeapAlloc(GetProcessHeap(), 0, dwAclSize);
   
     bRet = InitializeAcl(pDacl, dwAclSize, ACL_REVISION);

//
     // grant the Interactive Sid KEY_READ access to the perf key
     //
bRet = AddAccessAllowedAce(
         pDacl,
         ACL_REVISION,
         KEY_ALL_ACCESS,
         pInteractiveSid
         );
     /*bRet = AddAccessAllowedAce(
         pDacl,
         ACL_REVISION,
         samDesired,
         pInteractiveSid
         );*/

     //
     // grant the Administrators Sid KEY_ALL_ACCESS access to the perf key
     //
     bRet = AddAccessAllowedAce(
         pDacl,
         ACL_REVISION,
         KEY_ALL_ACCESS,
         pAdministratorsSid
         );

bRet = InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);

     bRet = SetSecurityDescriptorDacl(&sd, TRUE, pDacl, FALSE);

//
     // apply the security descriptor to the registry key
     //
     lRetCode = RegSetKeySecurity(
         hKey,
         (SECURITY_INFORMATION)DACL_SECURITY_INFORMATION,
         &sd
         );

//clean up
RegCloseKey(hKey);
     RegCloseKey(HKEY_LOCAL_MACHINE);

     //
     // free allocated resources
     //
     if(pDacl != NULL)
         HeapFree(GetProcessHeap(), 0, pDacl);

     if(pInteractiveSid != NULL)
         FreeSid(pInteractiveSid);

     if(pAdministratorsSid != NULL)
         FreeSid(pAdministratorsSid);
}

请大家帮一下!!!!

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 189
活跃值: (4810)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
2
顶起来!!!!!!!!!!!!
2008-4-16 01:08
0
雪    币: 101
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
RegSetKeySecurity(TempKey,DACL_SECURITY_INFORMATION,SD)<> ERROR_SUCCESS
2008-4-16 13:45
0
雪    币: 189
活跃值: (4810)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
4
RegSetKeySecurity(TempKey,DACL_SECURITY_INFORMATION,SD)<> ERROR_SUCCESS

谢谢,能不能说一下如何用“SD”来设指定用户(Administrator 或 Everyone)呀访问权限是只读......
2008-4-16 18:58
0
游客
登录 | 注册 方可回帖
返回
//