fix connection limits

an SFTP client can start multiple transfers on a single connection

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2024-10-26 21:18:19 +02:00
parent c69fbe6bf9
commit ae1487d733
24 changed files with 707 additions and 7 deletions

View File

@@ -227,6 +227,12 @@ func (c *scpCommand) getUploadFileData(sizeToRead int64, transfer *transfer) err
}
func (c *scpCommand) handleUploadFile(fs vfs.Fs, resolvedPath, filePath string, sizeToRead int64, isNewFile bool, fileSize int64, requestPath string) error {
if err := common.Connections.IsNewTransferAllowed(c.connection.User.Username); err != nil {
err := fmt.Errorf("denying file write due to transfer count limits")
c.connection.Log(logger.LevelInfo, "denying file write due to transfer count limits")
c.sendErrorMessage(nil, err)
return err
}
diskQuota, transferQuota := c.connection.HasSpace(isNewFile, false, requestPath)
if !diskQuota.HasSpace || !transferQuota.HasUploadSpace() {
err := fmt.Errorf("denying file write due to quota limits")
@@ -501,6 +507,13 @@ func (c *scpCommand) sendDownloadFileData(fs vfs.Fs, filePath string, stat os.Fi
func (c *scpCommand) handleDownload(filePath string) error {
c.connection.UpdateLastActivity()
if err := common.Connections.IsNewTransferAllowed(c.connection.User.Username); err != nil {
err := fmt.Errorf("denying file read due to transfer count limits")
c.connection.Log(logger.LevelInfo, "denying file read due to transfer count limits")
c.sendErrorMessage(nil, err)
return err
}
transferQuota := c.connection.GetTransferQuota()
if !transferQuota.HasDownloadSpace() {
c.connection.Log(logger.LevelInfo, "denying file read due to quota limits")