http://qs321.pair.com?node_id=509985


in reply to Re: getcwd() as different user
in thread getcwd() as different user

Oh grief, I misinterpreted the error to be the result of the "$<" operation. The actual problem is the fact that my now lesser-privileged user is not authorised to perform the next "$< = $> = $newid" iteration.

Hmm, my question should actually read: "How do I perform seteid()" or "How do I temporarily drop my privileges before calling a function? ". The obvious answer is $>. *hides in shame*

-0xbeef

Replies are listed 'Best First'.
Re^3: getcwd() as different user
by 0xbeef (Hermit) on Nov 19, 2005 at 12:53 UTC
    If anyone's interested, here's a snippet with the basic working logic. Although the "id -G" portion is not the safest way of doing this, I just don't know how:

    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, +$blksize,$blocks) = stat($targetdir); $newuser = getpwuid($uid); $groups = `/usr/bin/id -G $newuser`; $) = "$groups"; $> = $uid; if ( not chdir("$targetdir")) { print "$targetdir is inaccessible to its owner\n"; next; } else { $currentdir = Cwd::getcwd(); my $lasterr = $!; if (not defined $currentdir) { # incorrect underlying mount-point permissions print "getcwd() failed for $targetdir:$lasterr\n"; } else { print "getcwd() for $over is OK."); } }