From nobody Mon Dec 12 03:11:56 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 4NVmrD38jvz4jW9F; Mon, 12 Dec 2022 03:11:56 +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 4NVmrD2h6lz4Ynv; Mon, 12 Dec 2022 03:11:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670814716; 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=xSlqqrnk72IP+yX+C71Ga4b9cQjkaI/GGGUtgtebh70=; b=ZxjWuwdeUyUdGSGIWqJvp8GU2zqUR1ugDz9CSvtbjeynpK3ZuuM10/1F6hU6SXf6G1ML+5 NWd0Tj6WcMyqPiLRjIZk8MlnrKb4bMDvNZvscPWP5asq/veKHVlpCb5z0w6EZDD1yOyQuf fTJ4siyTWGdGaUf2J8C7efnYfuQ5dPnSXcQbLJipBiGdNwo4puZdbKOkxJJKAnzx9Oh8eN ExKL3F9AAZr7ESY05IfK6xQ5Jtfeo9eRd4o7TQB9yw7CVjcCEeoaQUouO5HpMSnkvejQKu 4DGtVn9hpfLaiMY1+j7+OjNjTa27KjPBr79xhARxvZ7RhPqPllvE/5uRX7iDRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670814716; 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=xSlqqrnk72IP+yX+C71Ga4b9cQjkaI/GGGUtgtebh70=; b=hAP2iayBiy5awdK7yFaCPRCpBuR6F9LZ08ZerGMLKNYwXyXvCqcWcMjbmtJapapyy7DSLn 6klgXqbp80QW+fy02TMpnKVEQKsv6/D1ydjZqRMnfCVwcqDmaUxtqsc1D3r0mtym+/bule 0XCExYYtjACgx5jpLxwDo+vefzULmWPcQ92/8gQKNmlcb66Fc5TjmLMOZx53vGCMz4ZkbP Sc4K+b/XExUjZjuiFyxlav6967TDZ15dKztdRcxaeUQtqcqI8OLkYo0NfK41z7lnBhue0X qcWjzrtLYVYhApACa+gHno3ObbfK7DMYxN0prEf50j+k9RKRWsxNZ8XFTZhbTg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670814716; a=rsa-sha256; cv=none; b=rr/GoEqT8l1/tP6LRD5sJU7ZZUPWOJXYyXIMwUHBaesSQ+TRkdon1P+HwS80Z8gQ2tyzHa HAYD4afHMjk3BoZMRINc6E27nCq0vaRJc3wGx3s8MDQNG9nhqxmySQhzmyyMLZ2mZ1HidI J69UZE5wNy3NlZ2dzu48xhPtCaD9gvYzocQBVxu1L4BW01mj5yXzbjrjp6qk/DAHQR/Jy/ qYIptKwTc8MvBi+3FErIiU/IqE7cEo0mdM66+DVkv6Rnf5XvPJSigymk5TV5aFZ7URALyz sdv/a4XmZMiXe33o0UuELas7NqYhiNIyTcVv5AZjOvSAAn1wZEXXxz0gNUcmWA== 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 4NVmrD1lXQzJhQ; Mon, 12 Dec 2022 03:11:56 +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 2BC3Buqb095126; Mon, 12 Dec 2022 03:11:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BC3Bude095125; Mon, 12 Dec 2022 03:11:56 GMT (envelope-from git) Date: Mon, 12 Dec 2022 03:11:56 GMT Message-Id: <202212120311.2BC3Bude095125@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: 293ff98462a7 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 293ff98462a74ca16638f70c24bee36b42da6aa4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=293ff98462a74ca16638f70c24bee36b42da6aa4 commit 293ff98462a74ca16638f70c24bee36b42da6aa4 Author: Eugene Grosbein AuthorDate: 2022-11-28 14:22:39 +0000 Commit: Eugene Grosbein CommitDate: 2022-12-12 03:11:20 +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 f218ebdf8c13..b16faaf52bdb 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); @@ -1410,7 +1409,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); @@ -1759,7 +1758,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; }