ocf / ocflib

Python libraries for account and server management
https://pypi.python.org/pypi/ocflib
Other
15 stars 32 forks source link

ocflib.account.search.users_by_filter can KeyError #27

Closed chriskuehl closed 8 years ago

chriskuehl commented 8 years ago
Traceback (most recent call last):
  File "staff/acct/guess-passwords", line 47, in <module>
    exit(main())
  File "staff/acct/guess-passwords", line 36, in main
    usernames = unsorried_users()
  File "staff/acct/guess-passwords", line 18, in unsorried_users
    return users_by_filter('(!(loginShell={}))'.format(SORRIED_SHELL))
  File "/usr/lib/python3/dist-packages/ocflib/account/search.py", line 12, in users_by_filter
    return [entry['attributes']['uid'][0] for entry in c.response]
  File "/usr/lib/python3/dist-packages/ocflib/account/search.py", line 12, in <listcomp>
    return [entry['attributes']['uid'][0] for entry in c.response]
KeyError: 'uid'

Debugging:

(Pdb) p len(c.response)
24679
(Pdb) derp = [user for user in c.response if 'uid' not in user['attributes']]                                    
(Pdb) p derp
[{'type': 'searchResEntry', 'raw_attributes': {}, 'attributes': {}, 'dn': 'ou=People,dc=OCF,dc=Berkeley,dc=EDU'}]
jvperrin commented 8 years ago

This is the same error I got using ldap3 with tuples in utils. I think using a list for attributes worked to fix it for me. Not sure why this would be a problem though, since ldap3 should be able to use tuples for attributes with no problems...

chriskuehl commented 8 years ago

I don't think there is any relation to tuples here. The OU object itself is being returned; we probably just need to search at a different scope.

jvperrin commented 8 years ago

Hmm, maybe that's the same problem I had with utils then, since I had the same error, it was already searching at single level though, so I'm not sure on that...