From: Christian Goeschel Ndjomouo Date: Wed, 8 Apr 2026 05:20:53 +0000 (-0400) Subject: treewide: use err() instead of errx() where ul_get{userpw,grp}_str() fails X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=3fb7a428fbf477e92ee938d8dc851b3c44d4351b;p=thirdparty%2Futil-linux.git treewide: use err() instead of errx() where ul_get{userpw,grp}_str() fails Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/login-utils/chfn.c b/login-utils/chfn.c index 76895887a..efc58159e 100644 --- a/login-utils/chfn.c +++ b/login-utils/chfn.c @@ -448,9 +448,10 @@ int main(int argc, char **argv) errx(EXIT_FAILURE, _("your user %u does not exist"), uid); } else { + errno = 0; ctl.pw = ul_getuserpw_str(ctl.username, NULL); if (!ctl.pw) - errx(EXIT_FAILURE, _("user \"%s\" does not exist"), + err(EXIT_FAILURE, _("user \"%s\" does not exist"), ctl.username); } ctl.username = ctl.pw->pw_name; diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c index 17c58e55e..fa352d814 100644 --- a/login-utils/newgrp.c +++ b/login-utils/newgrp.c @@ -218,20 +218,22 @@ int main(int argc, char *argv[]) errtryhelp(EXIT_FAILURE); } - if (!(pw_entry = getpwuid(getuid()))) - err(EXIT_FAILURE, _("who are you?")); + errno = 0; + pw_entry = getpwuid(getuid()); + if (!pw_entry) { + if (!errno) + errno = EINVAL; + err(EXIT_FAILURE, _("failed to look up current user")); + } if (argc <= optind) { if (setgid(pw_entry->pw_gid) < 0) err(EXIT_FAILURE, _("setgid() failed")); } else { errno = 0; - if (!(gr_entry = ul_getgrp_str(argv[optind++], NULL))) { - if (errno) - err(EXIT_FAILURE, _("no such group")); - else - errx(EXIT_FAILURE, _("no such group")); - } + gr_entry = ul_getgrp_str(argv[optind++], NULL); + if (!gr_entry) + err(EXIT_FAILURE, _("no such group")); if (!allow_setgid(pw_entry, gr_entry)) errx(EXIT_FAILURE, _("permission denied")); if (setgid(gr_entry->gr_gid) < 0) diff --git a/login-utils/su-common.c b/login-utils/su-common.c index 57651ea9e..6f361e65a 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -978,9 +978,10 @@ static gid_t add_supp_group(const char *name, gid_t **groups, size_t *ngroups) "specifying more than %d supplemental groups is not possible", NGROUPS_MAX - 1), NGROUPS_MAX - 1); + errno = 0; gr = ul_getgrp_str(name, NULL); if (!gr) - errx(EXIT_FAILURE, _("group %s does not exist"), name); + err(EXIT_FAILURE, _("group %s does not exist"), name); DBG(MISC, ul_debug("add %s group [name=%s, GID=%d]", name, gr->gr_name, (int) gr->gr_gid)); diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c index fd2768064..8f0380bf4 100644 --- a/sys-utils/unshare.c +++ b/sys-utils/unshare.c @@ -327,8 +327,9 @@ static uid_t get_user(const char *s) { uid_t uid; + errno = 0; if (!ul_getuserpw_str(s, &uid) && uid == (uid_t) -1) - errx(EXIT_FAILURE, _("failed to parse uid '%s'"), s); + err(EXIT_FAILURE, _("failed to parse uid '%s'"), s); return uid; } @@ -336,8 +337,9 @@ static gid_t get_group(const char *s) { gid_t gid; + errno = 0; if (!ul_getgrp_str(s, &gid) && gid == (gid_t) -1) - errx(EXIT_FAILURE, _("failed to parse gid '%s'"), s); + err(EXIT_FAILURE, _("failed to parse gid '%s'"), s); return gid; }