1 /* getugroups.c -- return a list of the groups a user is in
2 Copyright (C) 1990, 1991 Free Software Foundation.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 /* Written by David MacKenzie. */
24 #include <sys/types.h>
25 #include <stdio.h> /* grp.h on alpha OSF1 V2.0 uses "FILE *". */
32 /* setgrent, getgrent, and endgrent are not specified by POSIX.1,
33 so header files might not declare them.
34 If you don't have them at all, we can't implement this function.
36 struct group
*getgrent ();
38 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
44 /* Like `getgroups', but for user USERNAME instead of for
45 the current process. */
48 getugroups (maxcount
, grouplist
, username
)
50 GETGROUPS_T
*grouplist
;
55 register int count
= 0;
58 while ((grp
= getgrent ()) != 0)
59 for (cp
= grp
->gr_mem
; *cp
; ++cp
)
60 if (!strcmp (username
, *cp
))
64 if (count
>= maxcount
)
69 grouplist
[count
] = grp
->gr_gid
;