@@ -247,11 +247,17 @@ func (ls *Source) SearchEntry(name, passwd string, directBind bool) *SearchResul
247
247
return nil
248
248
}
249
249
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
+
250
257
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 )
251
258
search := ldap .NewSearchRequest (
252
259
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 )
255
261
256
262
sr , err := l .Search (search )
257
263
if err != nil {
@@ -267,11 +273,15 @@ func (ls *Source) SearchEntry(name, passwd string, directBind bool) *SearchResul
267
273
return nil
268
274
}
269
275
276
+ var sshPublicKey []string
277
+
270
278
username := sr .Entries [0 ].GetAttributeValue (ls .AttributeUsername )
271
279
firstname := sr .Entries [0 ].GetAttributeValue (ls .AttributeName )
272
280
surname := sr .Entries [0 ].GetAttributeValue (ls .AttributeSurname )
273
281
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
+ }
275
285
isAdmin := checkAdmin (l , ls , userDN )
276
286
277
287
if ! directBind && ls .AttributesInBind {
@@ -320,11 +330,17 @@ func (ls *Source) SearchEntries() []*SearchResult {
320
330
321
331
userFilter := fmt .Sprintf (ls .Filter , "*" )
322
332
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
+
323
340
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 )
324
341
search := ldap .NewSearchRequest (
325
342
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 )
328
344
329
345
var sr * ldap.SearchResult
330
346
if ls .UsePagedSearch () {
@@ -341,12 +357,14 @@ func (ls *Source) SearchEntries() []*SearchResult {
341
357
342
358
for i , v := range sr .Entries {
343
359
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 )
350
368
}
351
369
}
352
370
0 commit comments