Determining if I can access certain file

delphi package - easy access to security apis

Determining if I can access certain file

Postby smithmarkduane » Mon Nov 07, 2005 7:47 pm

Hi:

Is it possible to use madSecurity to determine if the current user can create or write to a specific file.

For example, if the app needs to update a file at:

\\server\someshare\somefile.txt

Can I determine access before trying to update the file?

Thanks,
Mark
smithmarkduane
 
Posts: 2
Joined: Mon Nov 07, 2005 7:42 pm

Postby madshi » Tue Nov 08, 2005 7:43 pm

Well, theoretically it's possible. I mean you can list all the elements of the ACL. However, you'd need quite a complicated logic to try and find out what the ACL sais about your user. So I don't recommend this approach. The most simple way is to try to open the file. If it succeeds then you had enough rights.
madshi
Site Admin
 
Posts: 9645
Joined: Sun Mar 21, 2004 5:25 pm

Postby smithmarkduane » Tue Nov 08, 2005 7:51 pm

Thanks for the reply. I came to the same conclusion shortly after I posted this message. I am now using successfully using:

function IsFileAccessible(fName: string): boolean;
var
HFileRes: HFILE;
begin
Result := false;
HFileRes := CreateFile(
pchar(fName),
GENERIC_READ or GENERIC_WRITE,
0,
nil,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);

Result := (HFileRes <> INVALID_HANDLE_VALUE);
if Result then CloseHandle(HFileRes);
end;
smithmarkduane
 
Posts: 2
Joined: Mon Nov 07, 2005 7:42 pm


Return to madSecurity

Who is online

Users browsing this forum: No registered users and 1 guest