]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chfn: enable the use of the username or UID
authorChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Fri, 28 Nov 2025 02:56:05 +0000 (21:56 -0500)
committerChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Tue, 2 Dec 2025 05:45:47 +0000 (00:45 -0500)
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
login-utils/chfn.c

index 059432b3d28e4470177677a1b17901c4ed250e6c..8577916a2865cf4247585721aa4729544b7a9a1d 100644 (file)
@@ -44,6 +44,7 @@
 #include "logindefs.h"
 
 #include "ch-common.h"
+#include "pwdutils.h"
 
 #ifdef HAVE_LIBSELINUX
 # include <selinux/selinux.h>
@@ -88,7 +89,7 @@ static void __attribute__((__noreturn__)) usage(void)
 {
        FILE *fp = stdout;
        fputs(USAGE_HEADER, fp);
-       fprintf(fp, _(" %s [options] [<username>]\n"), program_invocation_short_name);
+       fprintf(fp, _(" %s [options] [<username>|<UID>]\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)))