add mailLocalAddress to each record (#30)
Closes #26. Co-authored-by: Max Erenberg <> Reviewed-on: #30 Co-authored-by: Max Erenberg <merenber@csclub.uwaterloo.ca> Co-committed-by: Max Erenberg <merenber@csclub.uwaterloo.ca>pull/32/head
parent
23f40c74f9
commit
ac573039da
@ -0,0 +1,31 @@ |
||||
#!/usr/bin/env python3 |
||||
""" |
||||
This is a script which adds the mailLocalAddress to all members. |
||||
|
||||
GSSAPI is used for LDAP authentication, so make sure to run `kinit` first. |
||||
Also, make sure to run this script from the top-level of the git directory |
||||
(see the sys.path hack below). |
||||
""" |
||||
import ldap3 |
||||
|
||||
# modify as necessary |
||||
BASE_DOMAIN = "csclub.uwaterloo.ca" |
||||
LDAP_URI = "ldaps://auth1.csclub.uwaterloo.ca" |
||||
LDAP_MEMBERS_BASE = "ou=People,dc=csclub,dc=uwaterloo,dc=ca" |
||||
|
||||
conn = ldap3.Connection( |
||||
LDAP_URI, authentication=ldap3.SASL, sasl_mechanism=ldap3.KERBEROS, |
||||
auto_bind=True, raise_exceptions=True) |
||||
conn.search(LDAP_MEMBERS_BASE, '(&(objectClass=member)(!(mailLocalAddress=*)))', |
||||
attributes=['uid', 'objectClass']) |
||||
total_records_updated = 0 |
||||
for entry in conn.entries: |
||||
uid = entry.uid.value |
||||
address = f'{uid}@{BASE_DOMAIN}' |
||||
changes = {'mailLocalAddress': [(ldap3.MODIFY_REPLACE, [address])]} |
||||
if 'inetLocalMailRecipient' not in entry.objectClass.values: |
||||
changes['objectClass'] = [(ldap3.MODIFY_ADD, ['inetLocalMailRecipient'])] |
||||
conn.modify(entry.entry_dn, changes) |
||||
print('Modified %s' % entry.uid.value) |
||||
total_records_updated += 1 |
||||
print('Total records updated: %d' % total_records_updated) |
Loading…
Reference in new issue