From: Alejandro Colomar Date: Sun, 15 Mar 2026 14:09:18 +0000 (+0100) Subject: lib/, src/: find_new_sub_[ug]ids(): Report errors through errno X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=7c7042e06e9acc5485d4ba4787da51676c6086c3;p=thirdparty%2Fshadow.git lib/, src/: find_new_sub_[ug]ids(): Report errors through errno Signed-off-by: Alejandro Colomar --- diff --git a/lib/find_new_sub_gids.c b/lib/find_new_sub_gids.c index 082bd07b4..e4ee7e908 100644 --- a/lib/find_new_sub_gids.c +++ b/lib/find_new_sub_gids.c @@ -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; diff --git a/lib/find_new_sub_uids.c b/lib/find_new_sub_uids.c index 1d4e08b73..50c3c830b 100644 --- a/lib/find_new_sub_uids.c +++ b/lib/find_new_sub_uids.c @@ -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; diff --git a/src/newusers.c b/src/newusers.c index 25f0841eb..6e61dd76d 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -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) { diff --git a/src/useradd.c b/src/useradd.c index 41ef07691..02ab3dc1b 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -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); } } diff --git a/src/usermod.c b/src/usermod.c index ba0118622..108a60adb 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -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); } }