diff options
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/models/user.go b/models/user.go index 2cef2e5dec..0454158de6 100644 --- a/models/user.go +++ b/models/user.go @@ -7,6 +7,7 @@ package models import ( "container/list" + "context" "crypto/md5" "crypto/sha256" "crypto/subtle" @@ -1695,7 +1696,7 @@ func synchronizeLdapSSHPublicKeys(usr *User, s *LoginSource, sshPublicKeys []str } // SyncExternalUsers is used to synchronize users with external authorization source -func SyncExternalUsers() { +func SyncExternalUsers(ctx context.Context) { log.Trace("Doing: SyncExternalUsers") ls, err := LoginSources() @@ -1710,6 +1711,12 @@ func SyncExternalUsers() { if !s.IsActived || !s.IsSyncEnabled { continue } + select { + case <-ctx.Done(): + log.Warn("SyncExternalUsers: Aborted due to shutdown before update of %s", s.Name) + return + default: + } if s.IsLDAP() { log.Trace("Doing: SyncExternalUsers[%s]", s.Name) @@ -1727,6 +1734,12 @@ func SyncExternalUsers() { log.Error("SyncExternalUsers: %v", err) return } + select { + case <-ctx.Done(): + log.Warn("SyncExternalUsers: Aborted due to shutdown before update of %s", s.Name) + return + default: + } sr, err := s.LDAP().SearchEntries() if err != nil { @@ -1735,6 +1748,19 @@ func SyncExternalUsers() { } for _, su := range sr { + select { + case <-ctx.Done(): + log.Warn("SyncExternalUsers: Aborted due to shutdown at update of %s before completed update of users", s.Name) + // Rewrite authorized_keys file if LDAP Public SSH Key attribute is set and any key was added or removed + if sshKeysNeedUpdate { + err = RewriteAllPublicKeys() + if err != nil { + log.Error("RewriteAllPublicKeys: %v", err) + } + } + return + default: + } if len(su.Username) == 0 { continue } @@ -1819,6 +1845,13 @@ func SyncExternalUsers() { } } + select { + case <-ctx.Done(): + log.Warn("SyncExternalUsers: Aborted due to shutdown at update of %s before delete users", s.Name) + return + default: + } + // Deactivate users not present in LDAP if updateExisting { for _, usr := range users { |