Changing UNIX primary group

Discussion in 'Python' started by Justin Johnson, Aug 12, 2003.

  1. I have a unix id that has group1 for a primary group, and group2, group3,
    and group4 for supplementary groups. I'd like to change my primary group
    before running certain commands. So sometimes I might want group2 to be
    the primary group, and other times group3 or group4.

    I saw the posix module's setgid method, but it failed for me unless I was
    running as root. Also it only accepts the gid, but I'd rather pass in
    the group name, or somehow lookup the gid based on the name.

    Does anyone know a way to do all of this?
    Thanks much.
    -Justin
    Justin Johnson, Aug 12, 2003
    #1
    1. Advertising

  2. Justin Johnson

    Inyeol Lee Guest

    "Justin Johnson" <> wrote in message news:<>...
    > I have a unix id that has group1 for a primary group, and group2, group3,
    > and group4 for supplementary groups. I'd like to change my primary group
    > before running certain commands. So sometimes I might want group2 to be
    > the primary group, and other times group3 or group4.
    >
    > I saw the posix module's setgid method, but it failed for me unless I was
    > running as root. Also it only accepts the gid, but I'd rather pass in
    > the group name, or somehow lookup the gid based on the name.
    >
    > Does anyone know a way to do all of this?
    > Thanks much.
    > -Justin


    These are not python solution;

    1) make a setgid script and put your commands there, or
    2) use shell commands;

    echo "command1; command2;" | newgrp group2

    -Inyeol
    Inyeol Lee, Aug 13, 2003
    #2
    1. Advertising

  3. Thanks. I was hoping for a python solution though. :-( Does anyone
    know of a way to do this in python?

    On 13 Aug 2003 08:52:40 -0700, "Inyeol Lee" <> said:
    > "Justin Johnson" <> wrote in message
    > news:<>...
    > > I have a unix id that has group1 for a primary group, and group2, group3,
    > > and group4 for supplementary groups. I'd like to change my primary group
    > > before running certain commands. So sometimes I might want group2 to be
    > > the primary group, and other times group3 or group4.
    > >
    > > I saw the posix module's setgid method, but it failed for me unless I was
    > > running as root. Also it only accepts the gid, but I'd rather pass in
    > > the group name, or somehow lookup the gid based on the name.
    > >
    > > Does anyone know a way to do all of this?
    > > Thanks much.
    > > -Justin

    >
    > These are not python solution;
    >
    > 1) make a setgid script and put your commands there, or
    > 2) use shell commands;
    >
    > echo "command1; command2;" | newgrp group2
    >
    > -Inyeol
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    Justin Johnson, Aug 13, 2003
    #3
  4. Okay, I'll have to do some more research. Maybe I *will* have to run the
    script setuid root. Shucks! Thanks for the grp.getgrnam help. Just
    what I needed. :)

    On Wed, 13 Aug 2003 14:11:01 -0500, "Jeff Epler" <>
    said:
    > On Wed, Aug 13, 2003 at 12:10:02PM -0600, Justin Johnson wrote:
    > > Thanks. I was hoping for a python solution though. :-( Does anyone
    > > know of a way to do this in python?

    >
    > Unix doesn't let you setgid() to groups in the supplemental group list
    > without the same permission needed to change to any group.
    >
    > But depending what you need to do, you might be able to use set-group-id
    > directories. For instance, if I am group g1 and have a group list [g1,
    > g2, g3], then I can read files readable by any of those groups, and
    > create files in directories writable by any of those groups. But if you
    > make a directory d2 that is setgid g2 and d3 setgid g3, then when I
    > create a file in d2 it will belong to group g2.
    >
    > Barring that, you could modify the setgid() call in the kernel, to permit
    > the change if the requested group is in the auxiliary group list.
    > It looks like something you could do in an afternoon if you have the
    > source for your kernel (bsd, linux, etc) and can program C.
    >
    > "Justin Johnson" <> wrote in message
    > news:<>...
    > > Also [setgid] only accepts the gid, but I'd rather pass in
    > > the group name, or somehow lookup the gid based on the name.

    >
    > See grp.getgrnam(). Example:
    > >>> grp.getgrnam("utmp")

    > ('utmp', 'x', 22, [])
    >
    > Jeff
    Justin Johnson, Aug 13, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    12
    Views:
    1,618
    Dave Thompson
    Jan 10, 2005
  2. Replies:
    18
    Views:
    609
    Dave Thompson
    Jan 10, 2005
  3. Jonay Aloat
    Replies:
    5
    Views:
    276
    Alex Buell
    Mar 13, 2006
  4. Sidhartha
    Replies:
    2
    Views:
    432
    Tom Anderson
    Jul 7, 2008
  5. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    268
    Michele Dondi
    Jan 22, 2004
Loading...

Share This Page