Forum > General
Linux file attributes(permissions)
(1/1)
lagprogramming:
I don't really understand the documentation. To set the attributes(permissions) most probably I have to use BaseUnix.fpChmod. The Execute attribute can be set for owner, group and others but to read the attribute of the file I have to use BaseUnix.fpAccess. fpAccess tests for the execute attribute but it does it only for "real user ID". What's the equivalent of "real user ID" within owner, group and others?
I expect BaseUnix to be unavailable in windows. Within what ifdef do I have to enclose BaseUnix when I put it an the uses?
marcov:
ifdef: Unix
Both FPAccess and FPChMod are basically unix calls. Just look at their man pages (without the fp- prefix):
man 2 chmod
or
man 3 chmod
(without 2 or 3 you get the manual page for the cmdline utility of the same name)
chmod sets the _filesystems_ permissions, access checks the actual permission
Real user id vs effective userid is mainly related to setuid utilities. See e.g. http://www.lst.de/~okir/blackhats/node23.html
Jonas Maebe:
To read the permissions of a file, you generally use fpstat (man 2 stat). fpaccess is a shortcut for getting the permissions of the file, your own effective user and possibly group id, checking whether this combination allows you access, and in possibly checking any additional file system specific access control mechanisms (e.g., OpenAFS even completely ignores standard Unix permission flags and uses its own access control lists instead).
lagprogramming:
--- Code: ---function CopyFileAttributes(const sourcefile,destinationfile:string):boolean;
//Might require {$ifdef unix}baseunix{$endif} within uses
var fileinfo:{$ifdef unix}
stat;
{$endif}
{$ifdef windows}
longint;
{$endif}
begin
if (fileexists(sourcefile) and fileexists(destinationfile)) then
begin
{$ifdef unix}
exit((fpstat(sourcefile,fileinfo)=0)and(fpchmod(destinationfile,fileinfo.st_mode)=0));
{$endif}
{$ifdef windows}
fileinfo:=filegetattr(sourcefile);
if fileinfo>=0 then exit(filesetattr(destinationfile,fileinfo)=0);
{$endif}
end;
result:=false;
end;
--- End code ---
If fpc's rtl already has such a function, you're welcome to reply it's name. If not, I'm pretty sure that you might improve this one.
In the future, I'd like a pair of cross platform functions like FileGetAttr/FileSetAttr. The fact that the pair would use data that makes sense only on the same file system, would not bother me.
Navigation
[0] Message Index