3 can_user_push.c -- check project membership in group file
4 Copyright (c) 2013 Kyle J. McKay. All rights reserved.
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 USAGE: can_user_push groupname [username]
24 Exit code 0 for yes, non-zero for no
25 If username is an explicit member of groupname returns yes
26 If username is omitted, the LOGNAME environment variable will be used
27 Wrong number of or bad arguments exits with non-zero
32 #include <sys/types.h>
35 int main(int argc
, char *argv
[])
42 if (argc
< 2 || argc
> 3)
46 user
= (argc
>= 3) ? argv
[2] : getenv("LOGNAME");
47 if (!group
|| !*group
|| !user
|| !*user
)
50 ent
= getgrnam(group
);
55 for (; *memb
; ++memb
) {
56 if (strcmp(*memb
, user
) == 0) {
64 return found
? EXIT_SUCCESS
: EXIT_FAILURE
;