From cc48c12d8f16dcb10b21972f7bfd631c5d15be48 Mon Sep 17 00:00:00 2001 From: zeripath Date: Thu, 7 Feb 2019 02:38:28 +0000 Subject: [PATCH] Fix empty ssh key importing in ldap (#5984) --- models/user.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/models/user.go b/models/user.go index 5eb9db1e5ef..e50385d4113 100644 --- a/models/user.go +++ b/models/user.go @@ -1501,9 +1501,12 @@ func synchronizeLdapSSHPublicKeys(usr *User, s *LoginSource, SSHPublicKeys []str // Get Public Keys from LDAP and skip duplicate keys var ldapKeys []string for _, v := range SSHPublicKeys { - ldapKey := strings.Join(strings.Split(v, " ")[:2], " ") - if !util.ExistsInSlice(ldapKey, ldapKeys) { - ldapKeys = append(ldapKeys, ldapKey) + sshKeySplit := strings.Split(v, " ") + if len(sshKeySplit) > 1 { + ldapKey := strings.Join(sshKeySplit[:2], " ") + if !util.ExistsInSlice(ldapKey, ldapKeys) { + ldapKeys = append(ldapKeys, ldapKey) + } } }