Skip to content

Conversation

@smcgu
Copy link

@smcgu smcgu commented Mar 22, 2022

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 added 5 commits March 21, 2022 18:39
Not all instances of attribute types are being formatted as strings. Other methods, such as generateGrepList, fail when attempting to join attribute components returned by formatString that are not strings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant