Small Change to chpass.c
Giorgos Keramidas
keramida at ceid.upatras.gr
Wed Dec 10 22:32:34 PST 2008
On Wed, 10 Dec 2008 18:00:25 -0800, "Sheldon Givens" <sheldon at sigsegv.ca> wrote:
> Hi guys,
>
> When I was doing some user management today I noticed that chpass, and
> all the utilities that use chpass.c, only give one attempt to
> authenticate to make the change. After I messed this up once or twice
> (and after doing 4-5 minutes of editing only to have it lost when I
> typo'd the password) I wrote this little change in to chpass.c.
This seems useful, thanks for submitting the patch :)
> ---snip---
> --- /usr/src/usr.bin/chpass.c 2008-12-11 01:55:27.000000000 -0800
> +++ /usr/src/usr.bin/chpass.c 2008-12-11 01:57:09.000000000 -0800
> @@ -80,10 +80,11 @@
> {
> enum { NEWSH, LOADENTRY, EDITENTRY, NEWPW, NEWEXP } op;
> struct passwd lpw, *old_pw, *pw;
> - int ch, pfd, tfd;
> + int ch, pfd, tfd, itr, auth;
> const char *password;
> char *arg = NULL;
> uid_t uid;
> + int max_retries = 3;
> #ifdef YP
> struct ypclnt *ypclnt;
> const char *yp_domain = NULL, *yp_host = NULL;
> @@ -227,9 +228,16 @@
> }
>
> if (old_pw && !master_mode) {
> - password = getpass("Password: ");
> - if (strcmp(crypt(password, old_pw->pw_passwd),
> - old_pw->pw_passwd) != 0)
> + auth = 0;
> + for(itr=0;itr<max_retries;itr++) {
> + password = getpass("Password:");
> + if(strcmp(crypt(password, old_pw->pw_passwd),
> + old_pw->pw_passwd) == 0) {
> + auth=1;
> + break;
> + }
> + }
> + if (!auth)
> baduser();
> } else {
> password = "";
> ---snip---
You can probably do away with `auth' and reset password to NULL when
strcmp() fails (note that we also use whitespace in for statements to
separate everything more clearly):
if (old_pw && !master_mode) {
for (itr = 0; itr < max_retries; itr++) {
password = getpass("Password:");
if (strcmp(crypt(password, old_pw->pw_passwd),
old_pw->pw_passwd) != 0)
break;
password = NULL;
}
if (password == NULL)
baduser();
} else {
password = "";
More information about the freebsd-hackers
mailing list