Nauchis~ programmirovat` na Delphi snachalo.
#include "stdafx.h"
#include "windows.h"
#include "Aclapi.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
SC_HANDLE hm = OpenSCManager(0, 0, GENERIC_EXECUTE);
if(!hm)
return 0;
SC_HANDLE hs = OpenService(hm, "Messenger", STANDARD_RIGHTS_REQUIRED);
if(!hs)
{
::CloseServiceHandle(hm);
return 0;
}
DWORD cb = 0, hr;
::PSECURITY_DESCRIPTOR psd;
QueryServiceObjectSecurity(hs, DACL_SECURITY_INFORMATION, psd, 0, &cb);
if(cb)
{
psd = ::LocalAlloc(LMEM_FIXED,cb);
if(QueryServiceObjectSecurity(hs, DACL_SECURITY_INFORMATION, psd, cb, &cb))
{
if(IsValidSecurityDescriptor(psd))
{
BOOL b1,b2;
PACL pacl;
if(GetSecurityDescriptorDacl(psd, &b1, &pacl, &b2))
{
ULONG ulc = 0;
PEXPLICIT_ACCESS pea;
hr = GetExplicitEntriesFromAcl(pacl, &ulc, &pea);
if(S_OK == hr)
{
printf("We are fine!\n");
::LocalFree(pea);
}
else
goto _ERROR_;
}
else
goto _ERROR_;
}
else
goto _ERROR_;
}
else
goto _ERROR_;
}
else
{
_ERROR_:
hr = ::GetLastError();
printf("Win32 error: %d\n",hr);
}
::CloseServiceHandle(hs);
::CloseServiceHandle(hm);
return 0;
}
---
> У кого Delphi5 или 6 могут напрямую ввести кусок вот такого > кода: > >
> implementation
> Uses AclAPI, AccCtrl, WinSvc;
>
> procedure TForm1.Button1Click(Sender: TObject);
>
> Type
> TExplicitAccessArray = Array[0..0] Of EXPLICIT_ACCESS;
> PExplicitAccessArray = ^TExplicitAccessArray;
>
> Function GetEAListFromService(ServiceKeyName: String):
> PExplicitAccessArray;
>
> Var scHndl, srvHndl: THandle;
>
> Function GetServiceSD(SDFlags: DWORD):
> PSecurityDescriptor;
> Var BytesNeeded: DWord;
> Begin
> New(Result);
> BytesNeeded := 0;
> QueryServiceObjectSecurity(srvHndl, SDFlags, Result,
> 0, BytesNeeded);
> If BytesNeeded = 0 Then RaiseLastWin32Error;
> If SizeOf(Result^) <> BytesNeeded Then
> Begin
> ReallocMem(Result, BytesNeeded);
> Win32Check(QueryServiceObjectSecurity(srvHndl,
> SDFlags, Result, BytesNeeded, BytesNeeded));
> End;
> End;
>
> Var
> aSD: PSecurityDescriptor;
> pDACL: PACL;
> dPresent, dDefaulted: Bool;
> EACount, ErrCode: DWORD;
>
> Begin
> scHndl := OpenSCManager(Nil, Nil, GENERIC_EXECUTE);
> Win32Check(scHndl <> 0);
> Try
> srvHndl := OpenService(SCHndl, PChar(ServiceKeyName),
> STANDARD_RIGHTS_REQUIRED);
> Win32Check(srvHndl <> 0);
> Try
> aSD := GetServiceSD(DACL_SECURITY_INFORMATION);
> Result := Nil;
> If Not IsValidSecurityDescriptor(aSD) Then Exit;
> Try
> Win32Check(GetSecurityDescriptorDacl(aSD,
> dPresent, pDACL, dDefaulted));
> If Not dPresent Then Exit;
> ErrCode := GetExplicitEntriesFromAcl(pDACL^,
> EACount, @Result);
> If ErrCode <> ERROR_SUCCESS Then
> Application.MessageBox(PChar(Format('Error
> (%d): %s', [ErrCode, SysErrorMessage(ErrCode)])), Nil,
> mb_IconError);
> Finally
> FreeMem(aSD);
> End;
> Finally
> CloseServiceHandle(srvHndl);
> End;
> Finally
> CloseServiceHandle(scHndl);
> End;
>
> End;
>
> Var
> pEAList: PExplicitAccessArray;
> begin
> pEAList := GetEAListFromService('Messenger');
> If pEAList = Nil Then Application.MessageBox('Найден
> новый баг! Call for service ;-))', 'Microsoft снова
> обложался?', mb_IconQuestion)
> Else LocalFree(DWord(pEAList));
> end;
> ---
> > Указание по компиляции на Delphi5: > Найти в каталоге Source\Rtl\Win библиотеку AclAPI.pas. > Открыть библиотеку каким-либо текстовым редактором. > Найти строчку: ModName = 'aclapi.dll' . > Поменять на: ModName = 'advapi32.dll' . (И здесь баги! > ;-)))))))) > Скомпилировать библиотеку командной строкой: dcc32 > AclAPI.pas . > Получившийся модуль aclapi.dcu переместить в каталог > Delphi5\LIB, затерев старый файл. > Запустить Delphi5. Дальше вроде всем понятно ;-))))) > > Очень было бы неплохо, если бы кто-нибудь сваял подобное на > С — так, на всякий случай. > По-моему, налицо явный баг.
|