@@ -247,11 +247,17 @@ func (ls *Source) SearchEntry(name, passwd string, directBind bool) *SearchResul
247247 return nil
248248 }
249249
250+ var isAttributeSSHPublicKeySet = len (strings .TrimSpace (ls .AttributeSSHPublicKey )) > 0
251+
252+ attribs := []string {ls .AttributeUsername , ls .AttributeName , ls .AttributeSurname , ls .AttributeMail }
253+ if isAttributeSSHPublicKeySet {
254+ attribs = append (attribs , ls .AttributeSSHPublicKey )
255+ }
256+
250257 log .Trace ("Fetching attributes '%v', '%v', '%v', '%v', '%v' with filter %s and base %s" , ls .AttributeUsername , ls .AttributeName , ls .AttributeSurname , ls .AttributeMail , ls .AttributeSSHPublicKey , userFilter , userDN )
251258 search := ldap .NewSearchRequest (
252259 userDN , ldap .ScopeWholeSubtree , ldap .NeverDerefAliases , 0 , 0 , false , userFilter ,
253- []string {ls .AttributeUsername , ls .AttributeName , ls .AttributeSurname , ls .AttributeMail , ls .AttributeSSHPublicKey },
254- nil )
260+ attribs , nil )
255261
256262 sr , err := l .Search (search )
257263 if err != nil {
@@ -267,11 +273,15 @@ func (ls *Source) SearchEntry(name, passwd string, directBind bool) *SearchResul
267273 return nil
268274 }
269275
276+ var sshPublicKey []string
277+
270278 username := sr .Entries [0 ].GetAttributeValue (ls .AttributeUsername )
271279 firstname := sr .Entries [0 ].GetAttributeValue (ls .AttributeName )
272280 surname := sr .Entries [0 ].GetAttributeValue (ls .AttributeSurname )
273281 mail := sr .Entries [0 ].GetAttributeValue (ls .AttributeMail )
274- sshPublicKey := sr .Entries [0 ].GetAttributeValues (ls .AttributeSSHPublicKey )
282+ if isAttributeSSHPublicKeySet {
283+ sshPublicKey = sr .Entries [0 ].GetAttributeValues (ls .AttributeSSHPublicKey )
284+ }
275285 isAdmin := checkAdmin (l , ls , userDN )
276286
277287 if ! directBind && ls .AttributesInBind {
@@ -320,11 +330,17 @@ func (ls *Source) SearchEntries() []*SearchResult {
320330
321331 userFilter := fmt .Sprintf (ls .Filter , "*" )
322332
333+ var isAttributeSSHPublicKeySet = len (strings .TrimSpace (ls .AttributeSSHPublicKey )) > 0
334+
335+ attribs := []string {ls .AttributeUsername , ls .AttributeName , ls .AttributeSurname , ls .AttributeMail }
336+ if isAttributeSSHPublicKeySet {
337+ attribs = append (attribs , ls .AttributeSSHPublicKey )
338+ }
339+
323340 log .Trace ("Fetching attributes '%v', '%v', '%v', '%v', '%v' with filter %s and base %s" , ls .AttributeUsername , ls .AttributeName , ls .AttributeSurname , ls .AttributeMail , ls .AttributeSSHPublicKey , userFilter , ls .UserBase )
324341 search := ldap .NewSearchRequest (
325342 ls .UserBase , ldap .ScopeWholeSubtree , ldap .NeverDerefAliases , 0 , 0 , false , userFilter ,
326- []string {ls .AttributeUsername , ls .AttributeName , ls .AttributeSurname , ls .AttributeMail , ls .AttributeSSHPublicKey },
327- nil )
343+ attribs , nil )
328344
329345 var sr * ldap.SearchResult
330346 if ls .UsePagedSearch () {
@@ -341,12 +357,14 @@ func (ls *Source) SearchEntries() []*SearchResult {
341357
342358 for i , v := range sr .Entries {
343359 result [i ] = & SearchResult {
344- Username : v .GetAttributeValue (ls .AttributeUsername ),
345- Name : v .GetAttributeValue (ls .AttributeName ),
346- Surname : v .GetAttributeValue (ls .AttributeSurname ),
347- Mail : v .GetAttributeValue (ls .AttributeMail ),
348- SSHPublicKey : v .GetAttributeValues (ls .AttributeSSHPublicKey ),
349- IsAdmin : checkAdmin (l , ls , v .DN ),
360+ Username : v .GetAttributeValue (ls .AttributeUsername ),
361+ Name : v .GetAttributeValue (ls .AttributeName ),
362+ Surname : v .GetAttributeValue (ls .AttributeSurname ),
363+ Mail : v .GetAttributeValue (ls .AttributeMail ),
364+ IsAdmin : checkAdmin (l , ls , v .DN ),
365+ }
366+ if isAttributeSSHPublicKeySet {
367+ result [i ].SSHPublicKey = v .GetAttributeValues (ls .AttributeSSHPublicKey )
350368 }
351369 }
352370
0 commit comments