Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

setuid and setgid leaves user in 0 (wheel) group

by petr999 (Acolyte)
on Dec 17, 2010 at 10:59 UTC ( [id://877616]=perlquestion: print w/replies, xml ) Need Help??

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

Hello, I do setgid the way I'm aware of. But user is still in 0 group after that:
uid=20020(fcgi) gid=20020(fcgi) groups=20020(fcgi),0(wheel)
of course it is not included in 0 group in /etc/groups
use POSIX; my( $uid, $gid ) = qw/20020 20020/; setgid( $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`;
There are definitely things I'm missing here. Is it possible to avoid any other group from to appear on getgroups() ?
Thank you.
Peter Vereshagin peter@vereshagin.org http://vereshagin.org

Replies are listed 'Best First'.
Re: setuid and setgid leaves user in 0 (wheel) group
by bingos (Vicar) on Dec 17, 2010 at 12:21 UTC

    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)
      $) = "$gid $gid"
      Cool, it works, thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://877616]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-06-13 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.