]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: get_gid(): Use the usual -1 as an error code
authorAlejandro Colomar <alx@kernel.org>
Fri, 1 Dec 2023 23:23:06 +0000 (00:23 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 5 Jan 2024 22:54:55 +0000 (16:54 -0600)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/get_gid.c
lib/sgetgrent.c
lib/sgetpwent.c
src/groupadd.c
src/groupmod.c
src/newusers.c

index c9dcd1d0c2d165e0791dee5df4ae21651d35ea36..2c5030be37ff265b84e292bd5fcc29adbcda602e 100644 (file)
@@ -4,6 +4,7 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
+
 #include <config.h>
 
 #ident "$Id$"
@@ -11,7 +12,9 @@
 #include "prototypes.h"
 #include "defines.h"
 
-int get_gid (const char *gidstr, gid_t *gid)
+
+int
+get_gid(const char *gidstr, gid_t *gid)
 {
        long long  val;
        char *endptr;
@@ -22,10 +25,10 @@ int get_gid (const char *gidstr, gid_t *gid)
            || ('\0' != *endptr)
            || (0 != errno)
            || (/*@+longintegral@*/val != (gid_t)val)/*@=longintegral@*/) {
-               return 0;
+               return -1;
        }
 
        *gid = val;
-       return 1;
+       return 0;
 }
 
index dde755810ef2cd5070d659d826d864d8c6fd5fd4..77587c43334065e271e1e74a1b5b038d4c796515 100644 (file)
@@ -105,7 +105,7 @@ struct group *sgetgrent (const char *buf)
        }
        grent.gr_name = grpfields[0];
        grent.gr_passwd = grpfields[1];
-       if (get_gid (grpfields[2], &grent.gr_gid) == 0) {
+       if (get_gid(grpfields[2], &grent.gr_gid) == -1) {
                return NULL;
        }
        grent.gr_mem = list (grpfields[3]);
index 1c8c63e0c676a853f777b0c178f702937a1a4a6b..5dc60bc6f2726976b2df4a165cfe539dc7e6a29b 100644 (file)
@@ -97,7 +97,7 @@ struct passwd *sgetpwent (const char *buf)
        if (get_uid (fields[2], &pwent.pw_uid) == 0) {
                return NULL;
        }
-       if (get_gid (fields[3], &pwent.pw_gid) == 0) {
+       if (get_gid(fields[3], &pwent.pw_gid) == -1) {
                return NULL;
        }
        pwent.pw_gecos = fields[4];
index d06c3241036e4811a47316f89284f4b88732bc44..c285258d627ff48ca5f77da4ec17502982f62192 100644 (file)
@@ -403,7 +403,7 @@ static void process_flags (int argc, char **argv)
                        break;
                case 'g':
                        gflg = true;
-                       if (   (get_gid (optarg, &group_id) == 0)
+                       if (   (get_gid(optarg, &group_id) == -1)
                            || (group_id == (gid_t)-1)) {
                                fprintf (stderr,
                                         _("%s: invalid group ID '%s'\n"),
index 084c5d56103d809bb8fddd1642c3940a03ac05b9..7c48dd4d54543d9d482fc01b38ca9e30e67aee82 100644 (file)
@@ -414,7 +414,7 @@ static void process_flags (int argc, char **argv)
                        break;
                case 'g':
                        gflg = true;
-                       if (   (get_gid (optarg, &group_newid) == 0)
+                       if (   (get_gid(optarg, &group_newid) == -1)
                            || (group_newid == (gid_t)-1)) {
                                fprintf (stderr,
                                         _("%s: invalid group ID '%s'\n"),
index 6eb3350552f50b3d3aa63cf1951392b7a0e6a510..0ed7a3e0953d0de30e41e4ec0f2f0c7a169448f8 100644 (file)
@@ -239,7 +239,7 @@ static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid)
                 * new group, or an existing group.
                 */
 
-               if (get_gid (gid, &grent.gr_gid) == 0) {
+               if (get_gid(gid, &grent.gr_gid) == -1) {
                        fprintf (stderr,
                                 _("%s: invalid group ID '%s'\n"),
                                 Prog, gid);