Re: Get User Groups
From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 09/29/04
- Next message: Ian Northeast: "Re: root loggin in to console without network?"
- Previous message: Dragan Cvetkovic: "Re: root loggin in to console without network?"
- In reply to: Kushal Agarwal: "Get User Groups"
- Next in thread: jpd: "Re: Get User Groups"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 ***
- Next message: Ian Northeast: "Re: root loggin in to console without network?"
- Previous message: Dragan Cvetkovic: "Re: root loggin in to console without network?"
- In reply to: Kushal Agarwal: "Get User Groups"
- Next in thread: jpd: "Re: Get User Groups"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|