in reply to setuid and setgid leaves user in 0 (wheel) group
According to perlvar for $):
The first number sets the effective gid, and the rest (if any) are passed to setgroups(). To get the effect of an empty list for setgroups(), just repeat the new effective gid
So:
$) = "$gid $gid";
The following code on my machine (NetBSD):
use strict; use warnings; use POSIX; my( $uid, $gid ) = qw/32767 32766/; setgid( $gid ); $) = "$gid $gid"; $( = $gid; die "Set group ($gid): $! +" if ( $( != $gid ) or ( $) != $gid ); setuid( $uid ); $> = $uid; $< = $uid; die "Set user ($uid): $!" if ( $< != $uid ) or ( $> != $uid ); print `id`;
Produces:
uid=32767(nobody) gid=32766(nogroup) groups=32766(nogroup)
In Section
Seekers of Perl Wisdom