1

Topic: Selection of necessary storage under a security descriptor in 32/64 windows

Greetings to all;
At copying of the rights in windows through GetFileSecurity it is necessary to select sufficient memory size under structure of a security descriptor of a copied file/folder. That then through GetMem or HeapAlloc it to select and transfer in GetFileSecurity.
In Delphi there is such constant SECURITY_DESCRIPTOR_MIN_LENGTH, but it sets the minimum size and suits only reset of adjustments of safety. Is as GetSecurityDescriptorLength but it works with already filled structure and sense from it a little.
Advise how to define necessary memory size in this case?
Thanks.

2

Re: Selection of necessary storage under a security descriptor in 32/64 windows

hlopotun wrote:

Advise as to define necessary memory size in this case?

I will give smart advice. Only without insults. The documentation normally contains necessary answers.

BOOL WINAPI GetFileSecurity (
_In_ LPCTSTR lpFileName;
_In_ SECURITY_INFORMATION RequestedInformation;
_Out_opt_ PSECURITY_DESCRIPTOR pSecurityDescriptor;
_In_ DWORD nLength;
>>> _Out_ LPDWORD lpnLengthNeeded <<<
);

3

Re: Selection of necessary storage under a security descriptor in 32/64 windows

;
GetLastError throws out an error 122 (there is no selected place)

... ...
oSecurityInformation: = OWNER_SECURITY_INFORMATION
+ GROUP_SECURITY_INFORMATION
+ DACL_SECURITY_INFORMATION
+ SACL_SECURITY_INFORMATION;
....
var dwSize: DWord;
oSecurityInformation: SECURITY_INFORMATION;
... ...
if not GetFileSecurity (PChar (inFile), oSecurityInformation, Pointer (1), 0;
dwSize) and (GetLastError = ERROR_INSUFFICIENT_BUFFER) then
begin
....
GetMem (psd, dwSize);
if psd <> nil then
begin
if not (GetFileSecurity (PChar (inFile), oSecurityInformation, psd;
dwSize, dwSize)) then
begin
//here does not get from what it is possible to draw an output that storage all the same sufficed, but
result: = false;
end
else
begin
nLE: = GetLastError;//= throws out 122  an error. It turns out and GetFileSecurity fulfilled and returned True and the error thus is.
end;
................

As that it is not absolutely clear, the error and is and is not present

4

Re: Selection of necessary storage under a security descriptor in 32/64 windows

Yes, it is clear that
psd: PSECURITY_DESCRIPTOR;

5

Re: Selection of necessary storage under a security descriptor in 32/64 windows

hlopotun;
If it returned TRUE - means fulfilled, GetLastError in this case can not be installed at all, and 122 the error remains from the previous call, for example.

6

Re: Selection of necessary storage under a security descriptor in 32/64 windows

alekcvp wrote:

hlopotun;
If it returned TRUE - means fulfilled, GetLastError in this case can not be installed at all, and 122 the error remains from the previous call, for example.

After dock GetLastError like drops the last error condition. And it there is explicitly caused. That then not so.

7

Re: Selection of necessary storage under a security descriptor in 32/64 windows

hlopotun wrote:

after dock GetLastError like drops the last error condition.

And muzhiks do not know that!!
It is possible a reference on dock?

8

Re: Selection of necessary storage under a security descriptor in 32/64 windows

Tactical Nuclear Penguin wrote:

it is passed...
And muzhiks do not know that!!
It is possible a reference on dock?

here like.

Calling this function usually resets the operating system error state.

9

Re: Selection of necessary storage under a security descriptor in 32/64 windows

hlopotun;
1. The documentation on an API function it is better to look here .
2. There, by the way, it is directly written:

MSDN wrote:

However, some functions also set the last-error code when they succeed.;

I.e. not all functions drop error status code at successful end.