[285] in Info-AFS_Redistribution
Re: Perl file test operators (-r, -w, -x) and AFS
daemon@ATHENA.MIT.EDU (Marc Horowitz)
Thu Aug 15 22:38:06 1991
To: "Louis A. Mamakos" <louie@sayshell.umd.edu>
Cc: info-afs@transarc.com, perl-users@virginia.edu
Reply-To: Marc Horowitz <marc@MIT.EDU>
Date: Thu, 15 Aug 91 22:21:04 EDT
From: Marc Horowitz <marc@athena.mit.edu>
>> Has anyone modified Perl such that the file test operators work correctly on
>> files on an AFS volume? Perl currently just consults the mode bits returned
>> by stat(), which really isn't sufficient. I'd rather not re-invent this
>> wheel if I could avoid it.
Well, I haven't hacked perl to do it with the -r -w -x operators. I
also don't think this is a good idea, since the -? operators in perl
basically assume a stat buffer (what should -r "/afs" followed by -w _
do?).
If you want the same functionality, it's not that hard to do, using
perl's syscall (includes here are for BSD, your mileage may differ):
#!/usr/bin/perl
# The requires and the access sub are all you need to check privs
# in afs.
require "syscall.ph";
require "sys/file.ph";
sub access {
return(syscall(&SYS_access,@_) == 0);
}
sub writeable {
if (&access($_[0], &W_OK)) {
print "$_[0] is writeable\n";
} else {
print "$_[0] is not writeable\n";
}
}
&writeable("/afs/athena.mit.edu/contrib/perl");
&writeable("/afs/.athena.mit.edu/contrib/perl");
When I run this, I get
/afs/athena.mit.edu/contrib/perl is not writeable
/afs/.athena.mit.edu/contrib/perl is writeable
Even though:
% ls -ld /afs/{,.}athena/contrib/perl
drwxrwxrwx 7 salemme 2048 Jun 8 23:54 /afs/.athena/contrib/perl/
drwxrwxrwx 7 salemme 2048 Jun 8 23:54 /afs/athena/contrib/perl/
So the right thing is happening.
BTW, I didn't realize that access() on an afs file actually did a full
check against the acl to check the callers privileges. Thanks for
pointing that out.
Marc