From: Kyle J. McKay Date: Sun, 25 Aug 2013 04:15:40 +0000 (-0700) Subject: can_user_push.c: simplify code X-Git-Url: https://repo.or.cz/w/girocco.git/commitdiff_plain/5fea41abc1755f824b24c2affcbe3eda8bb54afc can_user_push.c: simplify code Replace the getgrent/endgrent loop with a single getgrnam call. There's no need to enumerate all group entries when a single call to getgrnam will do the same job. --- diff --git a/src/can_user_push.c b/src/can_user_push.c index c71bac9..6ea89c0 100644 --- a/src/can_user_push.c +++ b/src/can_user_push.c @@ -47,20 +47,19 @@ int main(int argc, char *argv[]) if (!group || !*group || !user || !*user) return EXIT_FAILURE; - while (ent = getgrent()) { + ent = getgrnam(group); + if (ent) { char **memb; - if (strcmp(ent->gr_name, group) != 0) - continue; memb = ent->gr_mem; - if (!memb) - continue; - for (; *memb; ++memb) { - if (strcmp(*memb, user) == 0) { - found = 1; - break; + if (memb) { + for (; *memb; ++memb) { + if (strcmp(*memb, user) == 0) { + found = 1; + break; + } } } } - endgrent(); + return found ? EXIT_SUCCESS : EXIT_FAILURE; }