Re: Get User Groups

From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 09/29/04


Date: Wed, 29 Sep 2004 17:32:33 -0400

In article <e9d0a198.0409291135.7d04bc62@posting.google.com>,
 kushal.agarwal@gmail.com (Kushal Agarwal) wrote:

> Hello,
>
> I am wondering what is the system call to get all the groups a user
> belongs to. I need both the group ids and the group names. I need to
> make this call from a c++ module.

I don't think there's a standard Unix function that does this. You have
to call getpwnam() to get their primary group, and then loop through the
group list with getgrent() looking for all the groups that they belong
to. And to translate the primary group id to a name, call getgrgid().

You might want to take a look at the groups(1) command from the Linux or
BSD sources, since it has to do all this.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


Relevant Pages

  • Re: [opensuse] postfix master.cf question
    ... I have a mail to fax gateway, but the fax jobs are sent always with the ... Have you checked the man pages for faxmail to see what options are ... it is notifying the user passed in $but the job of the fax belongs ... with the following command in the ...
    (SuSE)
  • Re: Another guitar tabs site taken down by MPA
    ... "belongs in the public domain" and sharing themes have created ... Linux was created with this underling theme in mind... ... anything, not just music, then it belongs to him. ...
    (alt.guitar.beginner)
  • Re: memory address
    ... I have a memory address in linux, Is it possible to know which ... belongs to which process. ... You need to study some OS fundamentals first. ...
    (comp.unix.programmer)
  • Re: Uninstalling a slave hard drive problems
    ... put your HD back in IDE 1 where it belongs. ... After that you'll see a command prompt...enter the following command: ... After the process is completed enter the command EXIT to quit (and the ...
    (microsoft.public.windowsxp.hardware)
  • Re: Running TCE on FC7
    ... command line with the file that you need, even when you don't know the ... package it belongs to. ... There's no harm, ...
    (Fedora)