diff --git a/config/config.go b/config/config.go index cd07acd9..44a35be4 100644 --- a/config/config.go +++ b/config/config.go @@ -401,7 +401,6 @@ func LoadConfig(configDir, configFile string) error { } // viper only supports slice of strings from env vars, so we use our custom method loadBindingsFromEnv() - checkCommonParamsCompatibility() if strings.TrimSpace(globalConf.SFTPD.Banner) == "" { globalConf.SFTPD.Banner = defaultSFTPDBanner } @@ -440,53 +439,10 @@ func LoadConfig(configDir, configFile string) error { logger.Warn(logSender, "", "Configuration error: %v", warn) logger.WarnToConsole("Configuration error: %v", warn) } - checkHostKeyCompatibility() logger.Debug(logSender, "", "config file used: '%#v', config loaded: %+v", viper.ConfigFileUsed(), getRedactedGlobalConf()) return nil } -func checkHostKeyCompatibility() { - // we copy deprecated fields to new ones to keep backward compatibility so lint is disabled - if len(globalConf.SFTPD.Keys) > 0 && len(globalConf.SFTPD.HostKeys) == 0 { //nolint:staticcheck - logger.Warn(logSender, "", "keys is deprecated, please use host_keys") - logger.WarnToConsole("keys is deprecated, please use host_keys") - for _, k := range globalConf.SFTPD.Keys { //nolint:staticcheck - globalConf.SFTPD.HostKeys = append(globalConf.SFTPD.HostKeys, k.PrivateKey) - } - } -} - -func checkCommonParamsCompatibility() { - // we copy deprecated fields to new ones to keep backward compatibility so lint is disabled - if globalConf.SFTPD.IdleTimeout > 0 { //nolint:staticcheck - logger.Warn(logSender, "", "sftpd.idle_timeout is deprecated, please use common.idle_timeout") - logger.WarnToConsole("sftpd.idle_timeout is deprecated, please use common.idle_timeout") - globalConf.Common.IdleTimeout = globalConf.SFTPD.IdleTimeout //nolint:staticcheck - } - if globalConf.SFTPD.Actions.Hook != "" && len(globalConf.Common.Actions.Hook) == 0 { //nolint:staticcheck - logger.Warn(logSender, "", "sftpd.actions is deprecated, please use common.actions") - logger.WarnToConsole("sftpd.actions is deprecated, please use common.actions") - globalConf.Common.Actions.ExecuteOn = globalConf.SFTPD.Actions.ExecuteOn //nolint:staticcheck - globalConf.Common.Actions.Hook = globalConf.SFTPD.Actions.Hook //nolint:staticcheck - } - if globalConf.SFTPD.SetstatMode > 0 && globalConf.Common.SetstatMode == 0 { //nolint:staticcheck - logger.Warn(logSender, "", "sftpd.setstat_mode is deprecated, please use common.setstat_mode") - logger.WarnToConsole("sftpd.setstat_mode is deprecated, please use common.setstat_mode") - globalConf.Common.SetstatMode = globalConf.SFTPD.SetstatMode //nolint:staticcheck - } - if globalConf.SFTPD.UploadMode > 0 && globalConf.Common.UploadMode == 0 { //nolint:staticcheck - logger.Warn(logSender, "", "sftpd.upload_mode is deprecated, please use common.upload_mode") - logger.WarnToConsole("sftpd.upload_mode is deprecated, please use common.upload_mode") - globalConf.Common.UploadMode = globalConf.SFTPD.UploadMode //nolint:staticcheck - } - if globalConf.SFTPD.ProxyProtocol > 0 && globalConf.Common.ProxyProtocol == 0 { //nolint:staticcheck - logger.Warn(logSender, "", "sftpd.proxy_protocol is deprecated, please use common.proxy_protocol") - logger.WarnToConsole("sftpd.proxy_protocol is deprecated, please use common.proxy_protocol") - globalConf.Common.ProxyProtocol = globalConf.SFTPD.ProxyProtocol //nolint:staticcheck - globalConf.Common.ProxyAllowed = globalConf.SFTPD.ProxyAllowed //nolint:staticcheck - } -} - func checkSFTPDBindingsCompatibility() { if globalConf.SFTPD.BindPort == 0 { //nolint:staticcheck return diff --git a/config/config_test.go b/config/config_test.go index 5774538b..245601ae 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -19,7 +19,6 @@ import ( "github.com/drakkan/sftpgo/httpclient" "github.com/drakkan/sftpgo/httpd" "github.com/drakkan/sftpgo/sftpd" - "github.com/drakkan/sftpgo/utils" "github.com/drakkan/sftpgo/webdavd" ) @@ -218,76 +217,6 @@ func TestInvalidUsersBaseDir(t *testing.T) { assert.NoError(t, err) } -func TestCommonParamsCompatibility(t *testing.T) { - reset() - - configDir := ".." - confName := tempConfigName + ".json" - configFilePath := filepath.Join(configDir, confName) - err := config.LoadConfig(configDir, "") - assert.NoError(t, err) - sftpdConf := config.GetSFTPDConfig() - sftpdConf.IdleTimeout = 21 //nolint:staticcheck - sftpdConf.Actions.Hook = "http://hook" - sftpdConf.Actions.ExecuteOn = []string{"upload"} - sftpdConf.SetstatMode = 1 //nolint:staticcheck - sftpdConf.UploadMode = common.UploadModeAtomicWithResume //nolint:staticcheck - sftpdConf.ProxyProtocol = 1 //nolint:staticcheck - sftpdConf.ProxyAllowed = []string{"192.168.1.1"} //nolint:staticcheck - c := make(map[string]sftpd.Configuration) - c["sftpd"] = sftpdConf - jsonConf, err := json.Marshal(c) - assert.NoError(t, err) - err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) - assert.NoError(t, err) - err = config.LoadConfig(configDir, confName) - assert.NoError(t, err) - commonConf := config.GetCommonConfig() - assert.Equal(t, 21, commonConf.IdleTimeout) - assert.Equal(t, "http://hook", commonConf.Actions.Hook) - assert.Len(t, commonConf.Actions.ExecuteOn, 1) - assert.True(t, utils.IsStringInSlice("upload", commonConf.Actions.ExecuteOn)) - assert.Equal(t, 1, commonConf.SetstatMode) - assert.Equal(t, 1, commonConf.ProxyProtocol) - assert.Len(t, commonConf.ProxyAllowed, 1) - assert.True(t, utils.IsStringInSlice("192.168.1.1", commonConf.ProxyAllowed)) - err = os.Remove(configFilePath) - assert.NoError(t, err) -} - -func TestHostKeyCompatibility(t *testing.T) { - reset() - - configDir := ".." - confName := tempConfigName + ".json" - configFilePath := filepath.Join(configDir, confName) - err := config.LoadConfig(configDir, "") - assert.NoError(t, err) - sftpdConf := config.GetSFTPDConfig() - sftpdConf.Keys = []sftpd.Key{ //nolint:staticcheck - { - PrivateKey: "rsa", - }, - { - PrivateKey: "ecdsa", - }, - } - c := make(map[string]sftpd.Configuration) - c["sftpd"] = sftpdConf - jsonConf, err := json.Marshal(c) - assert.NoError(t, err) - err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) - assert.NoError(t, err) - err = config.LoadConfig(configDir, confName) - assert.NoError(t, err) - sftpdConf = config.GetSFTPDConfig() - assert.Equal(t, 2, len(sftpdConf.HostKeys)) - assert.True(t, utils.IsStringInSlice("rsa", sftpdConf.HostKeys)) - assert.True(t, utils.IsStringInSlice("ecdsa", sftpdConf.HostKeys)) - err = os.Remove(configFilePath) - assert.NoError(t, err) -} - func TestSetGetConfig(t *testing.T) { reset() diff --git a/vfs/gcsfs.go b/vfs/gcsfs.go index 8927fc83..0f5832a5 100644 --- a/vfs/gcsfs.go +++ b/vfs/gcsfs.go @@ -5,6 +5,7 @@ package vfs import ( "context" "encoding/json" + "errors" "fmt" "io" "io/ioutil" @@ -127,24 +128,13 @@ func (fs *GCSFs) Stat(name string) (os.FileInfo, error) { } // now check if this is a prefix (virtual directory) hasContents, err := fs.hasContents(name) - if err == nil && hasContents { - return NewFileInfo(name, true, 0, time.Now(), false), nil - } else if err != nil { + if err != nil { return nil, err } - // search a dir ending with "/" for backward compatibility - return fs.getStatCompat(name) -} - -func (fs *GCSFs) getStatCompat(name string) (os.FileInfo, error) { - var result *FileInfo - attrs, err := fs.headObject(name + "/") - if err != nil { - return result, err + if hasContents { + return NewFileInfo(name, true, 0, time.Now(), false), nil } - objSize := attrs.Size - objectModTime := attrs.Updated - return NewFileInfo(name, true, objSize, objectModTime, false), nil + return nil, errors.New("404 no such file or directory") } // Lstat returns a FileInfo describing the named file