From: Christian Goeschel Ndjomouo Date: Fri, 28 Nov 2025 02:56:05 +0000 (-0500) Subject: chfn: enable the use of the username or UID X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=384840b432cde849cbdb3d5c0e88ca5959a4ca96;p=thirdparty%2Futil-linux.git chfn: enable the use of the username or UID Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/login-utils/chfn.c b/login-utils/chfn.c index 059432b3d..8577916a2 100644 --- a/login-utils/chfn.c +++ b/login-utils/chfn.c @@ -44,6 +44,7 @@ #include "logindefs.h" #include "ch-common.h" +#include "pwdutils.h" #ifdef HAVE_LIBSELINUX # include @@ -88,7 +89,7 @@ static void __attribute__((__noreturn__)) usage(void) { FILE *fp = stdout; fputs(USAGE_HEADER, fp); - fprintf(fp, _(" %s [options] []\n"), program_invocation_short_name); + fprintf(fp, _(" %s [options] [|]\n"), program_invocation_short_name); fputs(USAGE_SEPARATOR, fp); fputs(_("Change your finger information.\n"), fp); @@ -186,7 +187,7 @@ static void parse_argv(struct chfn_control *ctl, int argc, char **argv) /* done parsing arguments. check for a username. */ if (optind < argc) { if (optind + 1 < argc) { - warnx(_("cannot handle multiple usernames")); + warnx(_("cannot handle multiple usernames or UIDs")); errtryhelp(EXIT_FAILURE); } ctl->username = argv[optind]; @@ -417,13 +418,13 @@ int main(int argc, char **argv) if (!ctl.pw) errx(EXIT_FAILURE, _("you (user %d) don't exist."), uid); - ctl.username = ctl.pw->pw_name; } else { - ctl.pw = getpwnam(ctl.username); + ctl.pw = ul_getuserpw_str(ctl.username); if (!ctl.pw) errx(EXIT_FAILURE, _("user \"%s\" does not exist."), ctl.username); } + ctl.username = ctl.pw->pw_name; parse_passwd(&ctl); #ifndef HAVE_LIBUSER if (!(is_local(ctl.username)))