Skip to content

Issue 6092 - passwordHistory is not updated with a pre-hashed password #6093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2024

Conversation

jchapma
Copy link
Contributor

@jchapma jchapma commented Feb 14, 2024

Bug description: passwordHistory is not updated with a pre-hashed password

Fix description: During a mod replace of the userpassword attribute, if an encoded password value is detected, both pw_history and allow_hashed_pw are enabled, get the present entry values which are used to uddate the password history.

Relates: #6092

Reviewed by:

Bug description: passwordHistory is not updated by with a pre-hashed password

Fix description: During a mod replace of the userpassword attribute, if an encoded
password value is detected, both pw_history and allow_hashed_pw are enabled, get
the present entry values which are used to uddate the password history.

Relates: 389ds#6092

Reviewed by:
Copy link
Contributor

@tbordaz tbordaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the fix works, I wonder if a better place to retrieve old_pwd is not

diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
index a20984e0b..0dde945af 100644
--- a/ldap/servers/slapd/modify.c
+++ b/ldap/servers/slapd/modify.c
@@ -1234,7 +1234,7 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
          * If this mod is being performed by a password administrator/rootDN,
          * just return success.
          */
-        if (pw_is_pwp_admin(pb, pwpolicy, PWP_ADMIN_OR_ROOTDN)) {
+        if (pw_is_pwp_admin(pb, pwpolicy, PWP_ADMIN_OR_ROOTDN) || config_get_allow_hashed_pw()) {
             if (!SLAPI_IS_MOD_DELETE(mod->mod_op) && pwpolicy->pw_history) {
                 /* Updating pw history, get the old password */
                 get_old_pw(pb, &sdn, old_pw);

@jchapma
Copy link
Contributor Author

jchapma commented Feb 15, 2024

Although the fix works, I wonder if a better place to retrieve old_pwd is not

diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
index a20984e0b..0dde945af 100644
--- a/ldap/servers/slapd/modify.c
+++ b/ldap/servers/slapd/modify.c
@@ -1234,7 +1234,7 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
          * If this mod is being performed by a password administrator/rootDN,
          * just return success.
          */
-        if (pw_is_pwp_admin(pb, pwpolicy, PWP_ADMIN_OR_ROOTDN)) {
+        if (pw_is_pwp_admin(pb, pwpolicy, PWP_ADMIN_OR_ROOTDN) || config_get_allow_hashed_pw()) {
             if (!SLAPI_IS_MOD_DELETE(mod->mod_op) && pwpolicy->pw_history) {
                 /* Updating pw history, get the old password */
                 get_old_pw(pb, &sdn, old_pw);

IIUC, in the scenario where a regular user is changing their password to a non hashed value. If we capture old_pw here, we return before we do any pw policy, min age or syntax checks.

Currently, when a regular user is changing their password to a non hashed value the old_pw is retrieved during syntax checking, after we do pw policy, min age checks.

In the case of a regular user changing their password to a hashed value, I thought it was best to follow the same sequence and capture old_pw during syntax checking, but only when an encoded password value is detected.

if (e == NULL) {
return -1;
}
attr = attrlist_find(e->e_attrs, SLAPI_USERPWD_ATTR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to use the same code as get_old_pw else it may crash (if there is userpassword or empty value)

/* We want to skip syntax checking since this is a pre-hashed password. But if the user
* has thrown caution to wind and allowed hashed passwords, we capture the history
*/
if (config_get_allow_hashed_pw() && pwpolicy->pw_history) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As old_pwd will be set (but may be not) you need to initialize it to NULL

@tbordaz
Copy link
Contributor

tbordaz commented Feb 15, 2024

Although the fix works, I wonder if a better place to retrieve old_pwd is not

diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
index a20984e0b..0dde945af 100644
--- a/ldap/servers/slapd/modify.c
+++ b/ldap/servers/slapd/modify.c
@@ -1234,7 +1234,7 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
          * If this mod is being performed by a password administrator/rootDN,
          * just return success.
          */
-        if (pw_is_pwp_admin(pb, pwpolicy, PWP_ADMIN_OR_ROOTDN)) {
+        if (pw_is_pwp_admin(pb, pwpolicy, PWP_ADMIN_OR_ROOTDN) || config_get_allow_hashed_pw()) {
             if (!SLAPI_IS_MOD_DELETE(mod->mod_op) && pwpolicy->pw_history) {
                 /* Updating pw history, get the old password */
                 get_old_pw(pb, &sdn, old_pw);

IIUC, in the scenario where a regular user is changing their password to a non hashed value. If we capture old_pw here, we return before we do any pw policy, min age or syntax checks.

Currently, when a regular user is changing their password to a non hashed value the old_pw is retrieved during syntax checking, after we do pw policy, min age checks.

In the case of a regular user changing their password to a hashed value, I thought it was best to follow the same sequence and capture old_pw during syntax checking, but only when an encoded password value is detected.

You are right. This suggestion was wrong !

Copy link
Contributor

@tbordaz tbordaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jchapma jchapma merged commit 91443ac into 389ds:main Feb 19, 2024
jchapma added a commit that referenced this pull request Apr 5, 2024
#6093)

Bug description: passwordHistory is not updated by with a pre-hashed password

Fix description: During a mod replace of the userpassword attribute, if an encoded
password value is detected and both pw_history and allow_hashed_pw are enabled, get
the present entry values which are used to update the password history.

Relates: #6092

Reviewed by: @tbordaz  (Thank you)
jchapma added a commit that referenced this pull request Apr 5, 2024
#6093)

Bug description: passwordHistory is not updated by with a pre-hashed password

Fix description: During a mod replace of the userpassword attribute, if an encoded
password value is detected and both pw_history and allow_hashed_pw are enabled, get
the present entry values which are used to update the password history.

Relates: #6092

Reviewed by: @tbordaz  (Thank you)
jchapma added a commit that referenced this pull request Apr 5, 2024
#6093)

Bug description: passwordHistory is not updated by with a pre-hashed password

Fix description: During a mod replace of the userpassword attribute, if an encoded
password value is detected and both pw_history and allow_hashed_pw are enabled, get
the present entry values which are used to update the password history.

Relates: #6092

Reviewed by: @tbordaz  (Thank you)
jchapma added a commit that referenced this pull request Apr 5, 2024
#6093)

Bug description: passwordHistory is not updated by with a pre-hashed password

Fix description: During a mod replace of the userpassword attribute, if an encoded
password value is detected and both pw_history and allow_hashed_pw are enabled, get
the present entry values which are used to update the password history.

Relates: #6092

Reviewed by: @tbordaz  (Thank you)
jchapma added a commit that referenced this pull request Apr 5, 2024
#6093)

Bug description: passwordHistory is not updated by with a pre-hashed password

Fix description: During a mod replace of the userpassword attribute, if an encoded
password value is detected and both pw_history and allow_hashed_pw are enabled, get
the present entry values which are used to update the password history.

Relates: #6092

Reviewed by: @tbordaz  (Thank you)
jchapma added a commit that referenced this pull request Apr 5, 2024
#6093)

Bug description: passwordHistory is not updated by with a pre-hashed password

Fix description: During a mod replace of the userpassword attribute, if an encoded
password value is detected and both pw_history and allow_hashed_pw are enabled, get
the present entry values which are used to update the password history.

Relates: #6092

Reviewed by: @tbordaz  (Thank you)
jchapma added a commit that referenced this pull request Apr 5, 2024
#6093)

Bug description: passwordHistory is not updated by with a pre-hashed password

Fix description: During a mod replace of the userpassword attribute, if an encoded
password value is detected and both pw_history and allow_hashed_pw are enabled, get
the present entry values which are used to update the password history.

Relates: #6092

Reviewed by: @tbordaz  (Thank you)
jchapma added a commit that referenced this pull request Apr 5, 2024
#6093)

Bug description: passwordHistory is not updated by with a pre-hashed password

Fix description: During a mod replace of the userpassword attribute, if an encoded
password value is detected and both pw_history and allow_hashed_pw are enabled, get
the present entry values which are used to update the password history.

Relates: #6092

Reviewed by: @tbordaz  (Thank you)
jchapma added a commit that referenced this pull request Apr 5, 2024
#6093)

Bug description: passwordHistory is not updated by with a pre-hashed password

Fix description: During a mod replace of the userpassword attribute, if an encoded
password value is detected and both pw_history and allow_hashed_pw are enabled, get
the present entry values which are used to update the password history.

Relates: #6092

Reviewed by: @tbordaz  (Thank you)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants