]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: find_new_sub_[ug]ids(): Report errors through errno
authorAlejandro Colomar <alx@kernel.org>
Sun, 15 Mar 2026 14:09:18 +0000 (15:09 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 10 Apr 2026 03:20:34 +0000 (22:20 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/find_new_sub_gids.c
lib/find_new_sub_uids.c
src/newusers.c
src/useradd.c
src/usermod.c

index 082bd07b4a20134a0c5a425a947bc1ebdfa28749..e4ee7e908a0cc88f5392982ce04299f9e5df91ba 100644 (file)
@@ -39,19 +39,13 @@ int find_new_sub_gids (id_t *range_start, unsigned long *range_count)
        count = getdef_ulong ("SUB_GID_COUNT", 65536);
 
        if (min > max || count >= max || (min + count - 1) > max) {
-               (void) fprintf (log_get_logfd(),
-                               _("%s: Invalid configuration: SUB_GID_MIN (%lu),"
-                                 " SUB_GID_MAX (%lu), SUB_GID_COUNT (%lu)\n"),
-                       log_get_progname(), min, max, count);
+               errno = ERANGE;
                return -1;
        }
 
        start = sub_gid_find_free_range(min, max, count);
        if (start == (id_t)-1) {
-               fprintf (log_get_logfd(),
-                        _("%s: Can't get unique subordinate GID range\n"),
-                        log_get_progname());
-               SYSLOG(LOG_WARN, "no more available subordinate GIDs on the system");
+               errno = EUSERS;
                return -1;
        }
        *range_start = start;
index 1d4e08b732dc38f3526876b606d19aae607fe580..50c3c830bc8e782273233d78f4511bee78196ed8 100644 (file)
@@ -39,19 +39,13 @@ int find_new_sub_uids (id_t *range_start, unsigned long *range_count)
        count = getdef_ulong ("SUB_UID_COUNT", 65536);
 
        if (min > max || count >= max || (min + count - 1) > max) {
-               (void) fprintf (log_get_logfd(),
-                               _("%s: Invalid configuration: SUB_UID_MIN (%lu),"
-                                 " SUB_UID_MAX (%lu), SUB_UID_COUNT (%lu)\n"),
-                       log_get_progname(), min, max, count);
+               errno = ERANGE;
                return -1;
        }
 
        start = sub_uid_find_free_range(min, max, count);
        if (start == (id_t)-1) {
-               fprintf (log_get_logfd(),
-                        _("%s: Can't get unique subordinate UID range\n"),
-                        log_get_progname());
-               SYSLOG(LOG_WARN, "no more available subordinate UIDs on the system");
+               errno = EUSERS;
                return -1;
        }
        *range_start = start;
index 25f0841eba64be80ae161f496b92037878608b6e..6e61dd76d59c2890907d79dbcc2e0855e8659a1c 100644 (file)
@@ -1183,8 +1183,10 @@ int main (int argc, char **argv)
                        if (find_new_sub_uids(&sub_uid_start, &sub_uid_count) != 0)
                        {
                                fprintf (stderr,
-                                       _("%s: can't find subordinate user range\n"),
-                                       Prog);
+                                       _("%s: can't find subordinate user range: %s\n"),
+                                       Prog, strerrno());
+                               SYSLOG(LOG_WARN, "can't find subordinate user range: %s\n",
+                                      strerrno());
                                fail_exit (EXIT_FAILURE, process_selinux);
                        }
                        if (sub_uid_add(fields[0], sub_uid_start, sub_uid_count) == 0)
@@ -1204,8 +1206,10 @@ int main (int argc, char **argv)
                        unsigned long sub_gid_count = 0;
                        if (find_new_sub_gids(&sub_gid_start, &sub_gid_count) != 0) {
                                fprintf (stderr,
-                                       _("%s: can't find subordinate group range\n"),
-                                       Prog);
+                                       _("%s: can't find subordinate group range: %s\n"),
+                                       Prog, strerrno());
+                               SYSLOG(LOG_WARN, "can't find subordinate group range: %s\n",
+                                      strerrno());
                                fail_exit (EXIT_FAILURE, process_selinux);
                        }
                        if (sub_gid_add(fields[0], sub_gid_start, sub_gid_count) == 0) {
index 41ef0769168d7b471e2383e157f1555f6161de15..02ab3dc1b7d32f5b5639cda425dc83e96ee0070c 100644 (file)
@@ -2657,16 +2657,20 @@ int main (int argc, char **argv)
        if (is_sub_uid && subuid_count != 0) {
                if (find_new_sub_uids(&sub_uid_start, &subuid_count) < 0) {
                        fprintf (stderr,
-                                _("%s: can't create subordinate user IDs\n"),
-                                Prog);
+                                _("%s: can't create subordinate user IDs: %s\n"),
+                                Prog, strerrno());
+                       SYSLOG(LOG_WARN, "can't create subordinate user IDs: %s\n",
+                              strerrno());
                        fail_exit(E_SUB_UID_UPDATE, process_selinux);
                }
        }
        if (is_sub_gid && subgid_count != 0) {
                if (find_new_sub_gids(&sub_gid_start, &subgid_count) < 0) {
                        fprintf (stderr,
-                                _("%s: can't create subordinate group IDs\n"),
-                                Prog);
+                                _("%s: can't create subordinate group IDs: %s\n"),
+                                Prog, strerrno());
+                       SYSLOG(LOG_WARN, "can't create subordinate group IDs: %s\n",
+                              strerrno());
                        fail_exit(E_SUB_GID_UPDATE, process_selinux);
                }
        }
index ba01186227803239c57fb68ab6607636ba129308..108a60adbda8843a11f82b991f98db8353c88548 100644 (file)
@@ -2250,14 +2250,18 @@ int main (int argc, char **argv)
        if (Sflg) {
                if (find_range (&add_sub_uids, find_new_sub_uids) == 0) {
                        fprintf (stderr,
-                               _("%s: unable to find new subordinate uid range\n"),
-                               Prog);
+                               _("%s: unable to find new subordinate uid range: %s\n"),
+                               Prog, strerrno());
+                       SYSLOG(LOG_WARN, "unable to find new subordinate uid range: %s\n",
+                              strerrno());
                        fail_exit (E_SUB_UID_UPDATE, process_selinux);
                }
                if (find_range (&add_sub_gids, find_new_sub_gids) == 0) {
                        fprintf (stderr,
-                               _("%s: unable to find new subordinate gid range\n"),
-                               Prog);
+                               _("%s: unable to find new subordinate gid range: %s\n"),
+                               Prog, strerrno());
+                       SYSLOG(LOG_WARN, "unable to find new subordinate gid range: %s\n",
+                              strerrno());
                        fail_exit (E_SUB_GID_UPDATE, process_selinux);
                }
        }