diff --git a/mlmmj-ldap-sync b/mlmmj-ldap-sync index 261b5f1..c114256 100755 --- a/mlmmj-ldap-sync +++ b/mlmmj-ldap-sync @@ -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