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
|
||||||
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']
|
mlmmj_basepath = @configuration['mlmmj']['basepath']
|
||||||
|
user_basetree = @configuration['ldap']['users']['basetree']
|
||||||
list = "#{mlmmj_basepath}/#{list_name}@#{@configuration['domain']}"
|
list = "#{mlmmj_basepath}/#{list_name}@#{@configuration['domain']}"
|
||||||
|
|
||||||
ldap_members = ldap_group_entry.memberuid.map do |uid|
|
ldap_members = ldap_group_entry.memberuid.map do |uid|
|
||||||
filter = Net::LDAP::Filter.eq('uid', 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?
|
if matched_ldap_users.nil? || matched_ldap_users.empty?
|
||||||
""
|
""
|
||||||
else
|
else
|
||||||
matched_ldap_users.first.mail
|
matched_ldap_users.first.mail.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -149,10 +150,9 @@ def main
|
||||||
# Parse configuration, bind to LDAP server
|
# Parse configuration, bind to LDAP server
|
||||||
configuration_file = ARGV[0] ? ARGV[0] : @configuration_file
|
configuration_file = ARGV[0] ? ARGV[0] : @configuration_file
|
||||||
@configuration = read_configuration(configuration_file)
|
@configuration = read_configuration(configuration_file)
|
||||||
conn = connect_ldap
|
ldap_conn = connect_ldap
|
||||||
|
|
||||||
domain = @configuration['domain']
|
domain = @configuration['domain']
|
||||||
user_basetree = @configuration['ldap']['user']['basetree']
|
|
||||||
list_basetree = @configuration['ldap']['lists']['basetree']
|
list_basetree = @configuration['ldap']['lists']['basetree']
|
||||||
lists = (@configuration['lists_add'] + @configuration['lists_remove']).uniq
|
lists = (@configuration['lists_add'] + @configuration['lists_remove']).uniq
|
||||||
|
|
||||||
|
@ -162,14 +162,14 @@ def main
|
||||||
print 'Searching LDAP... '
|
print 'Searching LDAP... '
|
||||||
|
|
||||||
filter = Net::LDAP::Filter.eq('cn', list_name)
|
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?
|
if matched_ldap_groups.nil? || matched_ldap_groups.empty?
|
||||||
# Could not find matching LDAP group
|
# Could not find matching LDAP group
|
||||||
puts 'NOT FOUND'
|
puts 'NOT FOUND'
|
||||||
else
|
else
|
||||||
puts 'OK'
|
puts 'OK'
|
||||||
ldap_group_entry = matched_ldap_groups.first
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue