* passwd.cc (ChangePW): Add parameter to differ between called for

checking old password and called for changing password.  If called
	for checking old password, return non-zero only if password is surely
	incorrect.
	(main): Call ChangePW() with additional parameter.
This commit is contained in:
Corinna Vinschen 2002-01-30 11:57:16 +00:00
parent 8e2deb48d6
commit 9783296270
2 changed files with 14 additions and 4 deletions

View File

@ -1,3 +1,11 @@
2002-01-30 Corinna Vinschen <corinna@vinschen.de>
* passwd.cc (ChangePW): Add parameter to differ between called for
checking old password and called for changing password. If called
for checking old password, return non-zero only if password is surely
incorrect.
(main): Call ChangePW() with additional parameter.
2002-01-29 Christopher Faylor <cgf@redhat.com> 2002-01-29 Christopher Faylor <cgf@redhat.com>
* dump_setup.cc (parse_filename): Don't consider '_' part of the * dump_setup.cc (parse_filename): Don't consider '_' part of the

View File

@ -97,7 +97,7 @@ GetPW (const char *user)
} }
int int
ChangePW (const char *user, const char *oldpwd, const char *pwd) ChangePW (const char *user, const char *oldpwd, const char *pwd, int justcheck)
{ {
WCHAR name[512], oldpass[512], pass[512]; WCHAR name[512], oldpass[512], pass[512];
DWORD ret; DWORD ret;
@ -116,7 +116,9 @@ ChangePW (const char *user, const char *oldpwd, const char *pwd)
MultiByteToWideChar (CP_ACP, 0, oldpwd, -1, oldpass, 512); MultiByteToWideChar (CP_ACP, 0, oldpwd, -1, oldpass, 512);
ret = NetUserChangePassword (NULL, name, oldpass, pass); ret = NetUserChangePassword (NULL, name, oldpass, pass);
} }
if (! EvalRet (ret, user)) if (justcheck && ret != ERROR_INVALID_PASSWORD)
return 0;
if (! EvalRet (ret, user) && ! justcheck)
{ {
eprint (0, "Password changed."); eprint (0, "Password changed.");
} }
@ -334,7 +336,7 @@ main (int argc, char **argv)
if (li->usri3_priv != USER_PRIV_ADMIN) if (li->usri3_priv != USER_PRIV_ADMIN)
{ {
strcpy (oldpwd, getpass ("Old password: ")); strcpy (oldpwd, getpass ("Old password: "));
if (ChangePW (user, oldpwd, oldpwd)) if (ChangePW (user, oldpwd, oldpwd, 1))
return 1; return 1;
} }
@ -343,7 +345,7 @@ main (int argc, char **argv)
strcpy (newpwd, getpass ("New password: ")); strcpy (newpwd, getpass ("New password: "));
if (strcmp (newpwd, getpass ("Re-enter new password: "))) if (strcmp (newpwd, getpass ("Re-enter new password: ")))
eprint (0, "Password is not identical."); eprint (0, "Password is not identical.");
else if (! ChangePW (user, *oldpwd ? oldpwd : NULL, newpwd)) else if (! ChangePW (user, *oldpwd ? oldpwd : NULL, newpwd, 0))
ret = 1; ret = 1;
if (! ret && cnt < 2) if (! ret && cnt < 2)
eprint (0, "Try again."); eprint (0, "Try again.");