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; }

In reply to Re: How do I check if another user can access a file? by chrestomanci
in thread How do I check if another user can access a file? by mtnboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.