Commit 42069016 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'improve_dn_checking' into 'master'

Add some additional checking for LDAP DNs in Group Sync

Based on https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/335#note_4827853, check for `uid` specifically.

cc/ @jacobvosmaer 

See merge request !339
parents cf7a38a2 9a68cad8
require 'net/ldap/dn'
module Gitlab
module LDAP
class GroupSync
......@@ -181,13 +183,17 @@ module Gitlab
# account for that. See gitlab-ee#442
def ensure_full_dns!(dns)
dns.map! do |dn|
# If there is more than one equal sign we must have a full DN
# Or at least the probability is higher.
return dn if dn.count('=') > 1
# If there is only one equal sign, we may only have a `uid`.
# In this case, strip the first part and look up full DN by UID
dn_for_uid(dn.split('=')[1])
parsed_dn = Net::LDAP::DN.new(dn).to_a
# If there is more than one key/value set we must have a full DN,
# or at least the probability is higher.
if parsed_dn.count > 2
dn
elsif parsed_dn[0] == 'uid'
dn_for_uid(parsed_dn[1])
else
logger.warn { "Found potentially malformed/incomplete DN: '#{dn}'" }
dn
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment