-def search(query, connection=None):
- local_connection = False
- try:
- if not connection:
- local_connection = True
- connection = connect()
- post = ''
- if query:
- post = '*'
- filterstr = u'(|{0})'.format(
- u' '.join([u'({0}=*{1}{2})'.format(field, query, post)
- for field in CONFIG.get('query', 'search_fields').split()]))
- query_filter = CONFIG.get('query', 'filter')
- if query_filter:
- filterstr = u'(&({0}){1})'.format(query_filter, filterstr)
- r = connection.search_s(
- CONFIG.get('connection', 'basedn'),
- ldap.SCOPE_SUBTREE,
- filterstr.encode('utf-8'))
- finally:
- if local_connection and connection:
- connection.unbind()
- return r
+def search(query, connection):
+ post = ''
+ if query:
+ post = '*'
+ filterstr = u'(|{0})'.format(
+ u' '.join([u'({0}=*{1}{2})'.format(field, query, post)
+ for field in CONFIG.get('query', 'search_fields').split()]))
+ query_filter = CONFIG.get('query', 'filter')
+ if query_filter:
+ filterstr = u'(&({0}){1})'.format(query_filter, filterstr)
+ msg_id = connection.search(
+ CONFIG.get('connection', 'basedn'),
+ ldap.SCOPE_SUBTREE,
+ filterstr.encode('utf-8'))
+ return msg_id
+