[Scottish] Any C people out there?

Keith Sharp kms at passback.co.uk
Mon Jun 14 09:08:11 BST 2004


On Sun, 2004-06-13 at 23:59 +0100, Colin McKinnon wrote:
> Hi all,
> 
> I find myself writing in C again - its a bit of a shock to the system after so 
> much PHP. I have come up against a problem to whit:
> 
> I need to list all the groups a particular user is a member of. I know of 
> functions which will tell me who is in a prticular group, and functions which 
> will go through each group (although this is likely to be a rather expensive 
> way of solving problem - I'm not precluding it as a possibility, particularly 
> if I can cut & paste someone else's code ;). Can anyone point me in the right 
> direction? Know of any (GPL) program which does similar?
> 
> (BTW I need something which is uses the nss as it needs to be able to make 
> sense of NIS and LDAP as well as files)

Try getgroups(2).  It's part of posix so it should be fairly portable.
If you are looking for examples, try the source for the /usr/bin/id
command.

Keith,




More information about the Scottish mailing list