-
Notifications
You must be signed in to change notification settings - Fork 0
/
quota-ldap.py
38 lines (29 loc) · 1016 Bytes
/
quota-ldap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/env python3
import json
import sys
from ldap3 import Connection, Server, SUBTREE
import lm_auth
def main():
for ou, origin in lm_auth.ad_ou_tree.items():
if ou == 'all':
continue
get_information(origin[0], origin[1])
def get_information(origin, group_name):
connection = lm_auth.active_derectory_connector()
connection.search(origin,
'(&(mail=*)(objectCategory=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))',
SUBTREE, attributes=['sAMAccountName', 'division', 'mail'])
print('')
print(group_name)
print('++++++++++++++++')
for entry in connection.entries:
# print(entry)
#dn = (json.loads(entry.entry_to_json())['dn'])
login = entry.sAMAccountName
division = entry.division
mail = entry.mail
if division != "2G" and division != "2g":
print(login, mail, division)
connection.unbind()
if __name__ == "__main__":
sys.exit(main())