From nobody Mon Nov 28 14:28:41 2022 X-Original-To: dev-commits-src-main@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 4NLSWZ1T2bz4j3m1; Mon, 28 Nov 2022 14:28:42 +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 4NLSWZ12SJz3m61; Mon, 28 Nov 2022 14:28:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669645722; 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=7CN+BMSJ25WecE5TMceEEKlRc/bHDeubRPBMH7CKYOk=; b=eV84Me9SP19M8ohTsQM1Q1ckRnGIHtN3MpmJswWtCzFSTekzQXFC75q1nvLOtOHE9ZJNKk ntrgutX6VSfN6FNy9bC+ZB8ag/52EPRQBuxbJQk5oLrOnW8eM9QHMgzxK4lSDRKlgot60r H5uOOcDo+WE79oMiu73n0PNld9l64HeUBNXI4ggnbn5O8bP+smTLoKXbK9ZGch+8MZxXtd /VbVEoZDi7KQEfe2DjV38fWI6BmY+r267JIZaN6CvnrTZoBz0vu+H6DOD0DCF6jzLoZORZ nDR6P3GmDFDY7W9jS0gaBVe6rzE/YJyYLEkbtPh/+pGME8QGwL3S4rPP+LA1XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669645722; 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=7CN+BMSJ25WecE5TMceEEKlRc/bHDeubRPBMH7CKYOk=; b=hXQ2SjZDxp6MrNwg2wd9xzRelCyIJNXa9frJZ/HtwLImzD/oTw0u0Dp08Zp6IEj2JhrcqO KqRkuTbhb98d+CsrMleF5RmFfhCtm1St9H9hv8W94bFZDZjKH1nDXWqUaB4L52URkcLJwA TWFD/MCcXhSDBFs0jFQ4jhSykatvWT0flwFW8CJdR2T6sm2d4y3gDEE5pwJF+gWo24GKhv z5R6ZCcL9GTPUGD3PR9h25hsBBtz31x74Y7YRm4mh/Mlf00tvyA8Xha+R+YTSYs1Frg/pQ rzmjuLzDbLOW5yOxoUq/jctw4Kj7KwxLAKvfvOHJ6NWLze4Nzf1++n0rBY9rRA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669645722; a=rsa-sha256; cv=none; b=cB6M2CfWvlzFr+d31/7v3r0Dgm9O1sXQt7G87VPVujGHWhcjzIPBOnLcuwIHyG+F5vmqZ5 KbAtcS/PBOjiOsjFUF4OLKpTApyMXv0CM69aM3tJSd+LT4vO/EIuo6k/S0K6wdokJDBsLl HCA6/qHI1JEbppg5gnS8AbVjRUKrZcXZtFpFr9M5V7+3lUNGYg0v1H6Ugo9D4jlHLSeSHl 0tCQ/T2NOD+ZwezLvnmRKPPrjW4rdZ+B9g5/N7d8EoHrslcwNzx5b66fF7FotZAQLDPavy qqyh2Qk53OtHXQUhMde9/M39YUenBjXE3Fwr+TycctkECXAtu9EvfxRM55wLgw== 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 4NLSWY73pKzgxp; Mon, 28 Nov 2022 14:28:41 +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 2ASESf7q025849; Mon, 28 Nov 2022 14:28:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2ASESfb8025848; Mon, 28 Nov 2022 14:28:41 GMT (envelope-from git) Date: Mon, 28 Nov 2022 14:28:41 GMT Message-Id: <202211281428.2ASESfb8025848@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Eugene Grosbein Subject: git: 1cbe5012cfe1 - main - pw(8): fix combination of modes -N and -w random List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 1cbe5012cfe10226dd365af325a01de5d4c15f5d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=1cbe5012cfe10226dd365af325a01de5d4c15f5d commit 1cbe5012cfe10226dd365af325a01de5d4c15f5d Author: Eugene Grosbein AuthorDate: 2022-11-28 14:22:39 +0000 Commit: Eugene Grosbein CommitDate: 2022-11-28 14:22:39 +0000 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. MFC after: 2 weeks --- 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 64c22ce49848..5997728b363e 100644 --- a/usr.sbin/pw/pw.8 +++ b/usr.sbin/pw/pw.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 21, 2022 +.Dd November 28, 2022 .Dt PW 8 .Os .Sh NAME @@ -993,6 +993,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 7dd84d468f1f..00f290f72c97 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); @@ -510,7 +509,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]; @@ -527,7 +526,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); @@ -1375,7 +1374,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); @@ -1724,7 +1723,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; }