Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions app/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,6 @@ class User:
"homedirectory": "homeDirectory",
}

def get_upn_prefix(self) -> str:
return self.user_principal_name.split("@")[0]

def is_expired(self) -> bool:
if self.account_exp is None:
return False
Expand Down
2 changes: 1 addition & 1 deletion app/extra/scripts/principal_block_user_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def principal_block_sync(

if "@" in user.user_principal_name:
principal_postfix = user.user_principal_name.split("@")[1].upper()
principal_name = f"{user.get_upn_prefix()}@{principal_postfix}"
principal_name = f"{user.sam_account_name}@{principal_postfix}"
else:
continue

Expand Down
2 changes: 1 addition & 1 deletion app/extra/scripts/uac_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def disable_accounts(
) # fmt: skip

async for user in users:
await kadmin.lock_principal(user.get_upn_prefix())
await kadmin.lock_principal(user.sam_account_name)

await add_lock_and_expire_attributes(
session,
Expand Down
2 changes: 1 addition & 1 deletion app/ldap_protocol/auth/auth_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ async def _update_password(

if include_krb:
await self._kadmin.create_or_update_principal_pw(
user.get_upn_prefix(),
user.sam_account_name,
new_password,
)

Expand Down
31 changes: 17 additions & 14 deletions app/ldap_protocol/ldap_requests/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,7 @@ async def handle( # noqa: C901
# in the attributes
if (
attr_name in Directory.ro_fields
or attr_name
in (
"userpassword",
"unicodepwd",
)
or attr_name in ("userpassword", "unicodepwd")
or attr_name == new_dir.rdname
):
continue
Expand Down Expand Up @@ -342,11 +338,11 @@ async def handle( # noqa: C901
),
)

for uattr, value in {
"loginShell": "/bin/bash",
"uidNumber": str(create_integer_hash(user.sam_account_name)),
"homeDirectory": f"/home/{user.sam_account_name}",
}.items():
for uattr, value in (
("loginShell", "/bin/bash"),
("uidNumber", str(create_integer_hash(user.sam_account_name))),
("homeDirectory", f"/home/{user.sam_account_name}"),
):
if uattr in user_attributes:
value = user_attributes[uattr]
del user_attributes[uattr]
Expand Down Expand Up @@ -421,6 +417,15 @@ async def handle( # noqa: C901
),
)

if is_computer:
attributes.append(
Attribute(
name="sAMAccountName",
value=f"{new_dir.name}",
directory_id=new_dir.id,
),
)

if not ctx.attribute_value_validator.is_directory_attributes_valid(
entity_type.name if entity_type else "",
attributes,
Expand Down Expand Up @@ -461,16 +466,14 @@ async def handle( # noqa: C901
KRBAPIDeletePrincipalError,
KRBAPIPrincipalNotFoundError,
):
await ctx.kadmin.del_principal(
user.get_upn_prefix(),
)
await ctx.kadmin.del_principal(user.sam_account_name)

pw = (
self.password.get_secret_value()
if self.password
else None
)
await ctx.kadmin.add_principal(user.get_upn_prefix(), pw)
await ctx.kadmin.add_principal(user.sam_account_name, pw)

elif is_computer:
await ctx.kadmin.add_principal(
Expand Down
2 changes: 1 addition & 1 deletion app/ldap_protocol/ldap_requests/bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async def handle(
KRBAPIConnectionError,
):
await ctx.kadmin.add_principal(
user.get_upn_prefix(),
user.sam_account_name,
self.authentication_choice.password.get_secret_value(),
0.1,
)
Expand Down
2 changes: 1 addition & 1 deletion app/ldap_protocol/ldap_requests/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async def handle( # noqa: C901
await ctx.session_storage.clear_user_sessions(
directory.user.id,
)
await ctx.kadmin.del_principal(directory.user.get_upn_prefix())
await ctx.kadmin.del_principal(directory.user.sam_account_name)

if await is_computer(directory.id, ctx.session):
await ctx.kadmin.del_principal(directory.host_principal)
Expand Down
2 changes: 1 addition & 1 deletion app/ldap_protocol/ldap_requests/extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ async def handle(
):
try:
await ctx.kadmin.create_or_update_principal_pw(
user.get_upn_prefix(),
user.sam_account_name,
new_password,
)
except (
Expand Down
Loading