Skip to content
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

Handle the KeyError from record.get #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions ntdissector/ntds/ntds.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ def updateAttributeSchema(aid: int, cn_name: str, ldap_name: str):
self.attributeSchema["cn"][cn_name] = self.datatable_columns_mapping.get(aid)
self.attributeSchema["ldap"][ldap_name] = self.datatable_columns_mapping.get(aid)

def getRecordValue(record: Record, key: str):
"""Wraps the record.get method to silently fail the return value to None for when the table is missing the requested column"""
try:
return record.get(key)
except KeyError:
return None

seen = 0
OCLID_classSchema = 196621
OCLID_attributeSchema = 196622
Expand All @@ -271,12 +278,12 @@ def updateAttributeSchema(aid: int, cn_name: str, ldap_name: str):
_b_DNT = str(record.get("backlink_DNT"))
if _b_DNT not in self.links["to"]:
self.links["to"][_b_DNT] = []
self.links["to"][_b_DNT].append((record.get("link_DNT"), record.get("link_base"), record.get("link_deltime"), record.get("link_deactivetime"), record.get("link_data")))
self.links["to"][_b_DNT].append((record.get("link_DNT"), record.get("link_base"), record.get("link_deltime"), getRecordValue(record, "link_deactivetime"), record.get("link_data")))

_l_DNT = str(record.get("link_DNT"))
if _l_DNT not in self.links["from"]:
self.links["from"][_l_DNT] = []
self.links["from"][_l_DNT].append((record.get("backlink_DNT"), record.get("link_base"), record.get("link_deltime"), record.get("link_deactivetime"), record.get("link_data")))
self.links["from"][_l_DNT].append((record.get("backlink_DNT"), record.get("link_base"), record.get("link_deltime"), getRecordValue(record, "link_deactivetime"), record.get("link_data")))

logging.debug("Parsing the datatable")
for record in self.__datatable.records():
Expand Down