in reply to How do I check if another user can access a file?
Why not fork of a child process as the target user and directly test if the specific set of files are accessible?
Something like this: (Untested)
#!/usr/bin/perl -w use strict; use English; my $child_pid = open(FROM_KID, "|-") or die "can't fork: $!"; if ($child_pid) { # am the parent read FROM_KID my $child_message = <FROM_KID>; if( $child_message =~ m/ERROR accessing files/ ) { # Alert the sysadmin } # Else OK. wait $child_pid; # Wait for the child to quit before continuing +. } else { # Change userID $EGID=22; # aka: $> $UID=22; # aka: $< # am the child; use STDIN/STDOUT normally if( test_access_files() ) { print "OK accessing files as userID 22\n"; } else { print "ERROR accessing files as userID 22\n"; } exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I check if another user can access a file?
by thargas (Deacon) on Aug 18, 2011 at 13:45 UTC |