Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a couple of perl programmatical problems which due to my lack of indepth knowledge of Perl I'm struggling to find a solution for.
Here in a nutshell is what I wish to achieve
Note that the perlscript runs as userA who does not own the target directories these are owned by UserB
# get target directory path (this will change through each iteration o +f the utility) $destination = "/abc/def/ghi/jkl" # this is a directory `sudo -u UserB setfacl ....set group level perms on $destination` # is target direcory readable now -r $destination or $newdestination = traverse backwards to next level (e.g. "/abc/def/ghi +") run the sudo command to set the perms on $newdestination Do the read test again on the original $destination If successful finish otherwise traverse back up the directory chain again and redo the setfacl and re +ad test
Note that UserB is the owner of the directory tree, hence the reason the setfacl is run as UserB.
A further problem I have is with the gid of UserA. At a unix level UserA has the group that UserB is setting the file perms for BUT it's not the primary group of UserA.
The other question is how do I change the gid of UserA so that the test above will be successful once the correct perms have been set down the directory path by UserB ?
This may sound overly complicated but unfortunately this is due to the security of the arena I'm working in. I can manually achieve the desired result but can't seem to translate this into a perl.
Any ideas on how the above could be achieved would be welcome.

Replies are listed 'Best First'.
Re: Directory traversal backwards
by Skeeve (Parson) on Jun 20, 2006 at 09:23 UTC
    Untested!
    use strict; use warnings; my @path= split /\//,'/abc/def/ghi/jkl'; my $currentpath= undef; while ($#path) { $currentpath= join '/',@path # your setfacl here last if -r $currentpath; $currentpath= undef; pop @path; } die "Couldn't setfacl" unless $currentpath;
    Update Thanks Grandfather for pointing me to the "it" instead of "if"

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e