Fix nt_hash use in pdbedit.create (convert to string)

This commit is contained in:
Marius Hoch 2022-09-13 14:10:41 +02:00 committed by Megan Wilhite
parent bbe4cab183
commit dcdafc3954
3 changed files with 23 additions and 1 deletions

1
changelog/62670.fixed Normal file
View file

@ -0,0 +1 @@
Fixed pdbedit.create trying to use a bytes-like hash as string.

View file

@ -203,7 +203,7 @@ def create(login, password, password_hashed=False, machine_account=False):
password_hash = password.upper()
password = "" # wipe password
else:
password_hash = generate_nt_hash(password)
password_hash = generate_nt_hash(password).decode("ascii")
# create user
if login not in list_users(False):

View file

@ -1,3 +1,4 @@
import hashlib
from textwrap import dedent
import pytest
@ -5,6 +6,12 @@ import pytest
import salt.modules.pdbedit as pdbedit
from tests.support.mock import MagicMock, patch
try:
hashlib.new("md4", "".encode("utf-16le"))
MD4_SUPPORTED = True
except ValueError:
MD4_SUPPORTED = False
@pytest.fixture
def configure_loader_modules():
@ -134,3 +141,17 @@ def test_when_verbose_and_multiple_records_present_data_should_be_correctly_pars
):
actual_data = pdbedit.list_users(verbose=True)
assert actual_data == expected_data
@pytest.mark.skipif(not MD4_SUPPORTED, reason="Requires md4")
def test_create_with_existing_user_updates_password():
with patch(
"salt.modules.pdbedit.list_users", MagicMock(return_value=["Foo"])
), patch(
"salt.modules.pdbedit.get_user",
MagicMock(return_value={"nt hash": "old value"}),
), patch.dict(
pdbedit.__salt__, {"cmd.run_all": MagicMock(return_value={"retcode": 0})}
):
ret = pdbedit.create("Foo", "secret")
assert {"Foo": "updated"} == ret