Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Помогите создать DACL [D7, Win2k, WinXP]


Pearled ©   (2005-07-01 16:41:00) 

Нашел в MSDN пример на С++ создания стандартного DACL для каталога.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secbp/security/creating_a_dacl.asp
Попытался переписать в Delphi, но, видимо, что-то сделал не так, потому что не работает.. Ошибка происходит при вызове функции СonvertStringSecurityDescriptorToSecurityDescriptor.
В чем может быть ошибка? или может есть более легкий способ создания DACL?

function ConvertStringSecurityDescriptorToSecurityDescriptor(
StringSecurityDescriptor: LPCTSTR; StringSDRevision: DWORD;
SecurityDescriptor: PPSECURITY_DESCRIPTOR; SecurityDescriptorSize: PULONG): BOOL;
external 'advapi32.dll' name 'ConvertStringSecurityDescriptorToSecurityDescriptorA'

...

function CreateMyDACL(pSA: PSECURITYATTRIBUTES): BOOL;
var
  szSD: string;
  pc: PChar;
begin
szSD:= 'D:' +    // Discretionary ACL
'(D;OICI;GA;;;BG)' +    // Deny access to built-in guests
'(D;OICI;GA;;;AN)' +    // Deny access to anonymous logon
'(A;OICI;GRGWGX;;;AU)'+  // Allow read/write/execute to authenticated users
'(A;OICI;GA;;;BA)';    // Allow full control to administrators
GetMem(pc,length(szSD)+1);
StrPCopy(pc,szSD);
if (pSA = nil) then
  result:= false
else
  result:= ConvertStringSecurityDescriptorToSecurityDescriptor(
               pc,
               1,
               pSA^.lpSecurityDescriptor,
               nil);
end;

procedure main;
var
 sa: PSECURITYATTRIBUTES;
begin
sa^.nLength:= sizeof(SECURITY_ATTRIBUTES);
sa^.bInheritHandle:= FALSE;
if CreateMyDACL(sa) then
...........


BiN   (2005-07-01 17:26:00) [1]

Паараметры в догонку:
procedure TSecurityDescriptor.SetSDDLString(const StringSecurityDescriptor: String);

В том же msdn есть пример SDDL-строк.


BiN   (2005-07-01 17:22:00) [2]



function ConvertStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor: LPCSTR;
 StringSDRevision: DWORD; var SecurityDescriptor: PSECURITY_DESCRIPTOR;
 SecurityDescriptorSize: PULONG): BOOL; stdcall; external advapi32 name 'ConvertStringSecurityDescriptorToSecurityDescriptorA';

{$EXTERNALSYM ConvertStringSecurityDescriptorToSecurityDescriptor}

...

procedure TSecurityDescriptor.SetSDDLString;
var
 SRSecDesc: PSecurityDescriptor;
begin
 if ConvertStringSecurityDescriptorToSecurityDescriptor(Pchar(StringSecurityDescriptor),
                                                        SDDL_REVISION_1,
                                                        SRSecDesc, nil)
 then
 begin
   try
     SetSecurityDescriptor(SRSecDesc);
   finally
     LocalFree(HLOCAL(SRSecDesc));
   end;
 end
 else RaiseLastOSError;
end;


Наверх

Титульная страница Поиск, карта сайта Написать письмо