]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Use LSEARCH() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Thu, 14 Nov 2024 17:43:40 +0000 (18:43 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 24 Jan 2025 13:58:13 +0000 (07:58 -0600)
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/addgrps.c
src/newgrp.c

index 630bff8c6dc00b5324442d32f85e24159f969738..70ccd5a455a04a1f35009a11b4a2edb8238b5755 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "alloc/malloc.h"
 #include "alloc/reallocf.h"
-#include "search/l/lfind.h"
+#include "search/l/lsearch.h"
 #include "shadowlog.h"
 
 #ident "$Id$"
@@ -35,10 +35,10 @@ int
 add_groups(const char *list)
 {
        GETGROUPS_T *grouplist;
-       int ngroups;
        char *g, *p;
        char buf[1024];
        FILE *shadow_logfd = log_get_logfd();
+       size_t  ngroups;
 
        if (strlen (list) >= sizeof (buf)) {
                errno = EINVAL;
@@ -72,11 +72,7 @@ add_groups(const char *list)
                if (grouplist == NULL)
                        return -1;
 
-               if (LFIND(&grp->gr_gid, grouplist, ngroups) != NULL)
-                       continue;
-
-               grouplist[ngroups] = grp->gr_gid;
-               ngroups++;
+               LSEARCH(&grp->gr_gid, grouplist, &ngroups);
        }
 
        if (setgroups(ngroups, grouplist) == -1) {
index 2b73ae01ae0886bb142f95e84ea1e9b00ada2222..ada65fb8121e48f9192a654fb51588bf9591fcc8 100644 (file)
@@ -25,6 +25,7 @@
 #include "getdef.h"
 #include "prototypes.h"
 #include "search/l/lfind.h"
+#include "search/l/lsearch.h"
 #include "shadowlog.h"
 #include "string/sprintf/snprintf.h"
 #include "string/strcmp/streq.h"
@@ -38,7 +39,7 @@ static const char *Prog;
 
 extern char **newenvp;
 
-static int ngroups;
+static size_t  ngroups;
 static /*@null@*/ /*@only@*/GETGROUPS_T *grouplist;
 
 static bool is_newgrp;
@@ -682,9 +683,7 @@ fail_gg:
         */
        grouplist = XREALLOC(grouplist, ngroups + 1, GETGROUPS_T);
 
-       if (LFIND(&gid, grouplist, ngroups) == NULL) {
-               grouplist[ngroups++] = gid;
-       }
+       LSEARCH(&gid, grouplist, &ngroups);
 
        if (setgroups(ngroups, grouplist) == -1)
                perror("setgroups");