Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anodos325 committed Sep 6, 2024
1 parent 37a1e9a commit be0086f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/middlewared/middlewared/utils/user_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
PAM_TDB_FILE = os.path.join(PAM_TDB_DIR, 'pam_tdb.tdb')
PAM_TDB_DIR_MODE = 0o700
PAM_TDB_VERSION = 1
PAM_TDB_MAX_TOKENS = 10 # Max number of tokens per user
PAM_TDB_MAX_KEYS = 10 # Max number of keys per user

PAM_TDB_OPTIONS = TDBOptions(TDBPathType.CUSTOM, TDBDataType.BYTES)

Expand Down Expand Up @@ -45,7 +45,7 @@ def _pack_user_auth_key(api_key: UserApiKey) -> bytes:
integer, and the userhash converted into a pascal string.
"""
if not isinstance(api_key, UserApiKey):
raise TypeError(f'{type(token)}: not a UserAuthToken')
raise TypeError(f'{type(api_key)}: not a UserAuthToken')

userhash = api_key.userhash.encode() + b'\x00'
return pack(f'<q{len(userhash)}p', api_key.expiry, userhash)
Expand All @@ -63,13 +63,13 @@ def write_entry(hdl: TDBHandle, entry: PamTdbEntry) -> None:
raise TypeError(f'{type(entry)}: expected UserAuthToken')

key_cnt = len(entry.keys)
if token_cnt > PAM_TDB_MAX_TOKENS:
raise ValueError(f'{token_cnt}: count of entries exceeds maximum')
if key_cnt > PAM_TDB_MAX_KEYS:
raise ValueError(f'{key_cnt}: count of entries exceeds maximum')

entry_bytes = pack('<II', PAM_TDB_VERSION, len(entry.keys))
parsed_cnt = 0
for key in entry.keys:
entry_bytes += _pack_user_auth_token(key)
entry_bytes += _pack_user_auth_key(key)
parsed_cnt += 1

# since we've already packed struct with array length
Expand Down

0 comments on commit be0086f

Please sign in to comment.