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

Under AIX when I'm running as root, I can't seem to set $< (aka $UID) properly...

# perl -e '$< = 81' setruid() not implemented at -e line 1.

I can understand this, since this function doesn't exist on AIX. Is there a workaround here to get perl to execute the C function setuid() instead? I'd really like to do something like this...

$pid = fork; die unless defined $pid; unless ($pid) { $< = $> = $bobs_uid; exec "foo"; }

... so that the child runs unpriviledged.

I can't just set $> ($EUID) since the child can just set it back to zero. I can't use POSIX::setuid() since that give the same error. I suppose I could do something outside of perl like use a C wrapper that calls setuid() or something grotesque like...

system("su bob -c foo &"); #syntax?
... but I'd really like to do this in perl.

Thanks

Replies are listed 'Best First'.
Re: Why can't I set $< ?
by pg (Canon) on Mar 08, 2003 at 04:10 UTC
    Unfortunately, on AIX, it is useless to wrap setruid(), as that function always returns EPERM on AIX, i.e. it is AIX's intention to disallow the resetting of real user id.

    And that's exactly why you cannot set $< on AIX. This is not Perl's fault ;-)