Skip to content

Commit 8d432a5

Browse files
committed
Small fixes: use format strings and built-in open(), lint unused variables
1 parent 3d3b41d commit 8d432a5

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

nxc/modules/daclread.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import binascii
2-
import codecs
32
import json
43
import datetime
54
from enum import Enum
@@ -278,11 +277,9 @@ def options(self, context, module_options):
278277
self.rights_guid = None
279278

280279
def on_login(self, context, connection):
281-
self.context = context
282280
"""On a successful LDAP login we perform a search for the targets' SID, their Security Descriptors and the principal's SID if there is one specified"""
283281
context.log.highlight("Be careful, this module cannot read the DACLS recursively.")
284-
self.baseDN = connection.ldap_connection._baseDN
285-
self.ldap_session = connection.ldap_connection
282+
self.context = context
286283
self.connection = connection
287284

288285
# Searching for the principal SID
@@ -339,11 +336,9 @@ def backup(self, target, target_principal_dn, principal_raw_security_descriptor)
339336
backup["sd"] = binascii.hexlify(principal_raw_security_descriptor).decode("latin-1")
340337
backup["dn"] = str(target_principal_dn)
341338

342-
filename = "dacledit-{}-{}.bak".format(
343-
datetime.datetime.now().strftime("%Y%m%d-%H%M%S"),
344-
target,
345-
)
346-
with codecs.open(filename, "w", "latin-1") as outfile:
339+
timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
340+
filename = f"dacledit-{timestamp}-{target}.bak"
341+
with open(filename, "w", encoding="latin-1") as outfile:
347342
json.dump(backup, outfile)
348343
self.context.log.highlight(f"DACL backed up to {filename}")
349344

@@ -427,10 +422,7 @@ def parse_ace(self, ace):
427422
except KeyError:
428423
parsed_ace["Inherited type (GUID)"] = f"UNKNOWN ({inh_obj_type})"
429424
# Extract the Trustee SID (the object that has the right over the DACL bearer)
430-
parsed_ace["Trustee (SID)"] = "{} ({})".format(
431-
self.resolveSID(ace["Ace"]["Sid"].formatCanonical()) or "UNKNOWN",
432-
ace["Ace"]["Sid"].formatCanonical(),
433-
)
425+
parsed_ace["Trustee (SID)"] = f"{self.resolveSID(ace['Ace']['Sid'].formatCanonical()) or 'UNKNOWN'} ({ace['Ace']['Sid'].formatCanonical()})"
434426
else: # if the ACE is not an access allowed
435427
self.context.log.debug(f"ACE Type ({ace['TypeName']}) unsupported for parsing yet, feel free to contribute")
436428
_ace_flags = [FLAG.name for FLAG in ACE_FLAGS if ace.hasFlag(FLAG.value)]

0 commit comments

Comments
 (0)