From nobody Mon Dec 12 03:42:32 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NVnWX3tDfz4jb7Q; Mon, 12 Dec 2022 03:42:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NVnWX3Fd8z4dJS; Mon, 12 Dec 2022 03:42:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670816552; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=57BbXSplPNRAOfemuT9aZZJGDSFU1asbDBm8alwAmPU=; b=Q3H0St5/gxXix0R/r5K+CO7sqdbCwOD4PLe0jn53Fs4FyPouPwEd9sRUMhE/LHve9j+IZu xs2daDBseB/lU/foXV93f6b2nklzeHgYuZfJbOteHOm+jlPIm1x21Z246GL0EUwOQWNQHg vDj8UX46J06CVr66x6keJHdYDXdmJm4RqrStpFGgXsQ9snTF1OFexXu73vw26DIEAAI9mp b4/9cjKiQuQ/noHiN4c5GvnzdXFhC6HotIfWL7/JuTt9C9Qh+M67yQILMNAYw2UaDSqq1B VrP0od2mqtqax71r/nHHglKgYx/0S59ifQU7fJHVw9pmgCc00zTBt2HIVjg/SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670816552; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=57BbXSplPNRAOfemuT9aZZJGDSFU1asbDBm8alwAmPU=; b=qlhrpNtbK+N6bcBsnQ8EWCpy+nUVQPfxj3Hr9VVvEziA6CaRQX22VwevkCQ/4uQP41+q8c 6x6cvfSCBCo2+fi8FXJzPQVxdJ+QuKZim1qyiDhbIcZh5FS+Bh8Iy42k5yzTSaydNNBvlf XnJA2TVfZqfqcwYK/IPreIZWSdcsYEpcZFy7/XQ5aRu2IbtMmsr7Vw1NfJGrgFcqinHFN7 a8Awhu2j7jUWhABk0wbsDIvfcrdgaEqlVsXGn5Q0Ts79UJo6DYcY6JWfq2xoR5IXLlBEfo HuCwXJRasaoxOVgiqfDKv2MOW+4kup2GLXN0W9Fx8GJsclsCSWI1wYS13aUE1Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670816552; a=rsa-sha256; cv=none; b=aLTZwPhwbsX6KuXUpz2b7nw7FtkGXSje1Dqs+W73eet4J9RQSEcAzPGl4Grp1OhRudV+BU S86TMUUgJ+n4sc5Yov2z7QpdrenChlOQgH/jK6iNSKUpN+I1+Cs2kkzRrQmpbJ2vXz+x3z jVKyrtUrhsSudZcyXKV/Xh2UuFibqjc5k2AX9qJVduiNHLtdGdGpeIV//zDqLjBJ3suNHJ P29LgYrmK8r7E+Ps3uMYt6RdOztUjc2jVPR7H6Y/lUYyfgzKN+fcgA91tzPqRK3QcI/JrF jKA0ANOVNzEJMzIHqcg3VWbIYCd/2ij9h6/YquLQTB4Iz8vbbG72Oqprm2tyMw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NVnWX2J91zKvH; Mon, 12 Dec 2022 03:42:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2BC3gW0s041449; Mon, 12 Dec 2022 03:42:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BC3gWCp041448; Mon, 12 Dec 2022 03:42:32 GMT (envelope-from git) Date: Mon, 12 Dec 2022 03:42:32 GMT Message-Id: <202212120342.2BC3gWCp041448@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Eugene Grosbein Subject: git: af959792908b - stable/12 - MFC: pw(8): fix combination of modes -N and -w random List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: eugen X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: af959792908b20209506560307904b50f5f8b3a0 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=af959792908b20209506560307904b50f5f8b3a0 commit af959792908b20209506560307904b50f5f8b3a0 Author: Eugene Grosbein AuthorDate: 2022-11-28 14:22:39 +0000 Commit: Eugene Grosbein CommitDate: 2022-12-12 03:42:14 +0000 MFC: pw(8): fix combination of modes -N and -w random The command "pw usermod nobody -Nw random" (or useradd) generates random password and prints it in encrypted form but skips choosen random string that makes not much sense and contradicts the manual page pw.8 Fix it by showing random password in plain text with -N and without it equally. Add yet another example of how to generate pw-style random password. (cherry picked from commit 1cbe5012cfe10226dd365af325a01de5d4c15f5d) --- usr.sbin/pw/pw.8 | 8 +++++++- usr.sbin/pw/pw_user.c | 11 +++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/usr.sbin/pw/pw.8 b/usr.sbin/pw/pw.8 index d9072872bc2b..d305d9b2b79e 100644 --- a/usr.sbin/pw/pw.8 +++ b/usr.sbin/pw/pw.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 3, 2022 +.Dd November 28, 2022 .Dt PW 8 .Os .Sh NAME @@ -988,6 +988,12 @@ in addition to the other groups jsmith is already a member of. .Bd -literal -offset indent pw groupmod wheel -m jsmith .Ed +.Pp +Generate random password and show it in both plain text and +encrypted form not modifying any database. +.Bd -literal -offset indent +pw usermod nobody -Nw random +.Ed .Sh EXIT STATUS The .Nm diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index 2eec317b5e5b..21a4c5a0c26e 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -80,8 +80,7 @@ static uid_t pw_gidpolicy(struct userconf *cnf, char *grname, char *nam, static char *pw_homepolicy(struct userconf * cnf, char *homedir, const char *user); static char *pw_shellpolicy(struct userconf * cnf); -static char *pw_password(struct userconf * cnf, char const * user, - bool dryrun); +static char *pw_password(struct userconf * cnf, char const * user); static char *shell_path(char const * path, char *shells[], char *sh); static void rmat(uid_t uid); static void rmopie(char const * name); @@ -511,7 +510,7 @@ pw_pwcrypt(char *password) } static char * -pw_password(struct userconf * cnf, char const * user, bool dryrun) +pw_password(struct userconf * cnf, char const * user) { int i, l; char pwbuf[32]; @@ -528,7 +527,7 @@ pw_password(struct userconf * cnf, char const * user, bool dryrun) /* * We give this information back to the user */ - if (conf.fd == -1 && !dryrun) { + if (conf.fd == -1) { if (isatty(STDOUT_FILENO)) printf("Password for '%s' is: ", user); printf("%s\n", pwbuf); @@ -1398,7 +1397,7 @@ pw_user_add(int argc, char **argv, char *arg1) if (lc == NULL || login_setcryptfmt(lc, "sha512", NULL) == NULL) warn("setting crypt(3) format"); login_close(lc); - pwd->pw_passwd = pw_password(cmdcnf, pwd->pw_name, dryrun); + pwd->pw_passwd = pw_password(cmdcnf, pwd->pw_name); if (pwd->pw_uid == 0 && strcmp(pwd->pw_name, "root") != 0) warnx("WARNING: new account `%s' has a uid of 0 " "(superuser access!)", pwd->pw_name); @@ -1745,7 +1744,7 @@ pw_user_mod(int argc, char **argv, char *arg1) login_close(lc); cnf->default_password = passwd_val(passwd, cnf->default_password); - pwd->pw_passwd = pw_password(cnf, pwd->pw_name, dryrun); + pwd->pw_passwd = pw_password(cnf, pwd->pw_name); edited = true; }