ldapdomaindump icon indicating copy to clipboard operation
ldapdomaindump copied to clipboard

Ensure formatString returns a string

Open smcgu opened this issue 2 years ago • 0 comments

In a recent assessment, a multi-line account description was being returned as a list. This broke the generateGrepList method that was attempting to join the account attributes. The root of the issue appears to be that formatString does not guarantee that all returned values will be str. I refactored formatString:

  • always return a str value
  • use isinstance for type checks
  • simplified the return path to a single statement
  • added formatString handling of list values with a ', '.join (this could potentially clash with self.config.grepsplitchar)

Copy of stack trace:

Traceback (most recent call last):
  File "/usr/local/bin/ldapdomaindump", line 3, in <module>
    ldapdomaindump.main()
  File "/usr/lib/python3/dist-packages/ldapdomaindump/__init__.py", line 944, in main
    dd.domainDump()
  File "/usr/lib/python3/dist-packages/ldapdomaindump/__init__.py", line 422, in domainDump
    rw.generateUsersReport(self)
  File "/usr/lib/python3/dist-packages/ldapdomaindump/__init__.py", line 797, in generateUsersReport
    grepout = self.generateGrepList(dd.users, self.userattributes)
  File "/usr/lib/python3/dist-packages/ldapdomaindump/__init__.py", line 735, in generateGrepList
    out.append(self.config.grepsplitchar.join(eo))
TypeError: sequence item 11: expected str instance, list found 

Redacted output data from pdb:

[snip]
    description: description line one
                 description line two
                 description line three
    displayName: Redacted User
[snip]

entry['description']
description: description line one
                 description line two
                 description line three

self.formatGrepAttribute(entry['description'])
['description line one', 'description line two', 'description line three']

[type(val) for val in eo]
[<class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'list'>]

smcgu avatar Mar 22 '22 02:03 smcgu