From 5212095b899db03bfb502e0c3b31160f536798b3 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Wed, 20 Nov 2024 20:51:20 +0100 Subject: [PATCH] EventManager: always close the connection filesystem closing the user filesystem is not enough here Signed-off-by: Nicola Murino --- internal/common/eventmanager.go | 17 +++++++++++++++++ internal/httpd/api_shares.go | 1 + 2 files changed, 18 insertions(+) diff --git a/internal/common/eventmanager.go b/internal/common/eventmanager.go index 93a62bf1..4da2c7bb 100644 --- a/internal/common/eventmanager.go +++ b/internal/common/eventmanager.go @@ -1370,6 +1370,9 @@ func getHTTPRuleActionBody(c *dataprovider.EventActionHTTPConfig, replacer *stri go func() { defer w.Close() defer user.CloseFs() //nolint:errcheck + if conn != nil { + defer conn.CloseFS() //nolint:errcheck + } for _, part := range c.Parts { h := make(textproto.MIMEHeader) @@ -1587,6 +1590,8 @@ func executeEmailRuleAction(c dataprovider.EventActionEmailConfig, params *Event return fmt.Errorf("error getting email attachments, unable to check root fs for user %q: %w", user.Username, err) } conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user) + defer conn.CloseFS() //nolint:errcheck + res, err := getMailAttachments(conn, fileAttachments, replacer) if err != nil { return err @@ -1648,6 +1653,8 @@ func executeDeleteFsActionForUser(deletes []string, replacer *strings.Replacer, return fmt.Errorf("delete error, unable to check root fs for user %q: %w", user.Username, err) } conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user) + defer conn.CloseFS() //nolint:errcheck + for _, item := range replacePathsPlaceholders(deletes, replacer) { info, err := conn.DoStat(item, 0, false) if err != nil { @@ -1716,6 +1723,8 @@ func executeMkDirsFsActionForUser(dirs []string, replacer *strings.Replacer, use return fmt.Errorf("mkdir error, unable to check root fs for user %q: %w", user.Username, err) } conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user) + defer conn.CloseFS() //nolint:errcheck + for _, item := range replacePathsPlaceholders(dirs, replacer) { if err = conn.CheckParentDirs(path.Dir(item)); err != nil { return fmt.Errorf("unable to check parent dirs for %q, user %q: %w", item, user.Username, err) @@ -1775,6 +1784,8 @@ func executeRenameFsActionForUser(renames []dataprovider.KeyValue, replacer *str return fmt.Errorf("rename error, unable to check root fs for user %q: %w", user.Username, err) } conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user) + defer conn.CloseFS() //nolint:errcheck + for _, item := range renames { source := util.CleanPath(replaceWithReplacer(item.Key, replacer)) target := util.CleanPath(replaceWithReplacer(item.Value, replacer)) @@ -1800,6 +1811,8 @@ func executeCopyFsActionForUser(keyVals []dataprovider.KeyValue, replacer *strin return fmt.Errorf("copy error, unable to check root fs for user %q: %w", user.Username, err) } conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user) + defer conn.CloseFS() //nolint:errcheck + for _, item := range keyVals { source := util.CleanPath(replaceWithReplacer(item.Key, replacer)) target := util.CleanPath(replaceWithReplacer(item.Value, replacer)) @@ -1831,6 +1844,8 @@ func executeExistFsActionForUser(exist []string, replacer *strings.Replacer, return fmt.Errorf("existence check error, unable to check root fs for user %q: %w", user.Username, err) } conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user) + defer conn.CloseFS() //nolint:errcheck + for _, item := range replacePathsPlaceholders(exist, replacer) { if _, err = conn.DoStat(item, 0, false); err != nil { return fmt.Errorf("error checking existence for path %q, user %q: %w", item, user.Username, err) @@ -1989,6 +2004,8 @@ func executeCompressFsActionForUser(c dataprovider.EventActionFsCompress, replac return fmt.Errorf("compress error, unable to check root fs for user %q: %w", user.Username, err) } conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user) + defer conn.CloseFS() //nolint:errcheck + name := util.CleanPath(replaceWithReplacer(c.Name, replacer)) conn.CheckParentDirs(path.Dir(name)) //nolint:errcheck paths := make([]string, 0, len(c.Paths)) diff --git a/internal/httpd/api_shares.go b/internal/httpd/api_shares.go index 73f85299..6704a515 100644 --- a/internal/httpd/api_shares.go +++ b/internal/httpd/api_shares.go @@ -562,6 +562,7 @@ func validateBrowsableShare(share dataprovider.Share, connection *Connection) er basePath := share.Paths[0] info, err := connection.Stat(basePath, 0) if err != nil { + connection.CloseFS() //nolint:errcheck return util.NewI18nError( fmt.Errorf("unable to check the share directory: %w", err), util.I18nErrorShareInvalidPath,