aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Grosbein <eugen@FreeBSD.org>2022-11-28 14:22:39 +0000
committerEugene Grosbein <eugen@FreeBSD.org>2022-11-28 14:22:39 +0000
commit1cbe5012cfe10226dd365af325a01de5d4c15f5d (patch)
tree062049c3739f76ac371383ce9e25eeaf392dca00
parent0078721898754f6e71063e1f566c8671288a2218 (diff)
downloadsrc-1cbe5012cfe10226dd365af325a01de5d4c15f5d.tar.gz
src-1cbe5012cfe10226dd365af325a01de5d4c15f5d.zip
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
-rw-r--r--usr.sbin/pw/pw.88
-rw-r--r--usr.sbin/pw/pw_user.c11
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;
}