Fix LDAP user/mail resolution
This commit is contained in:
parent
ad221c1d33
commit
bcd855df3c
1 changed files with 7 additions and 7 deletions
|
@ -108,17 +108,18 @@ def remove_subscriber_from(list_name, list, addr)
|
|||
end
|
||||
end
|
||||
|
||||
def sync_list(list_name, ldap_group_entry, user_basetree)
|
||||
def sync_list(list_name, ldap_group_entry, ldap_conn)
|
||||
mlmmj_basepath = @configuration['mlmmj']['basepath']
|
||||
user_basetree = @configuration['ldap']['users']['basetree']
|
||||
list = "#{mlmmj_basepath}/#{list_name}@#{@configuration['domain']}"
|
||||
|
||||
ldap_members = ldap_group_entry.memberuid.map do |uid|
|
||||
filter = Net::LDAP::Filter.eq('uid', uid)
|
||||
matched_ldap_users = conn.search(base: user_basetree, filter: filter)
|
||||
matched_ldap_users = ldap_conn.search(base: user_basetree, filter: filter)
|
||||
if matched_ldap_users.nil? || matched_ldap_users.empty?
|
||||
""
|
||||
else
|
||||
matched_ldap_users.first.mail
|
||||
matched_ldap_users.first.mail.first
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -149,10 +150,9 @@ def main
|
|||
# Parse configuration, bind to LDAP server
|
||||
configuration_file = ARGV[0] ? ARGV[0] : @configuration_file
|
||||
@configuration = read_configuration(configuration_file)
|
||||
conn = connect_ldap
|
||||
ldap_conn = connect_ldap
|
||||
|
||||
domain = @configuration['domain']
|
||||
user_basetree = @configuration['ldap']['user']['basetree']
|
||||
list_basetree = @configuration['ldap']['lists']['basetree']
|
||||
lists = (@configuration['lists_add'] + @configuration['lists_remove']).uniq
|
||||
|
||||
|
@ -162,14 +162,14 @@ def main
|
|||
print 'Searching LDAP... '
|
||||
|
||||
filter = Net::LDAP::Filter.eq('cn', list_name)
|
||||
matched_ldap_groups = conn.search(base: list_basetree, filter: filter)
|
||||
matched_ldap_groups = ldap_conn.search(base: list_basetree, filter: filter)
|
||||
if matched_ldap_groups.nil? || matched_ldap_groups.empty?
|
||||
# Could not find matching LDAP group
|
||||
puts 'NOT FOUND'
|
||||
else
|
||||
puts 'OK'
|
||||
ldap_group_entry = matched_ldap_groups.first
|
||||
sync_list(list_name, ldap_group_entry, user_basetree)
|
||||
sync_list(list_name, ldap_group_entry, ldap_conn)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue