Skip to content
This repository was archived by the owner on Feb 25, 2021. It is now read-only.

Commit

Permalink
Send SSH_FX_QUOTA_EXCEEDED if out of disk space
Browse files Browse the repository at this point in the history
  • Loading branch information
DaneEveritt committed Jul 3, 2020
1 parent 0112541 commit 368abf5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
19 changes: 19 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sftp_server

type fxerr uint32

const (
// Extends the default SFTP server to return a quota exceeded error to the client.
//
// @see https://tools.ietf.org/id/draft-ietf-secsh-filexfer-13.txt
ErrSshQuotaExceeded = fxerr(15)
)

func (e fxerr) Error() string {
switch e {
case ErrSshQuotaExceeded:
return "Quota Exceeded"
default:
return "Failure"
}
}
17 changes: 8 additions & 9 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
)

type FileSystem struct {
UUID string
Permissions []string
ReadOnly bool
User SftpUser
Cache *cache.Cache
UUID string
Permissions []string
ReadOnly bool
User SftpUser
Cache *cache.Cache

PathValidator func(fs FileSystem, p string) (string, error)
HasDiskSpace func(fs FileSystem) bool
HasDiskSpace func(fs FileSystem) bool

logger *zap.SugaredLogger
lock sync.Mutex
Expand All @@ -30,7 +30,7 @@ func (fs FileSystem) buildPath(p string) (string, error) {
}

const (
PermissionFileRead = "file.read"
PermissionFileRead = "file.read"
PermissionFileCreate = "file.create"
PermissionFileUpdate = "file.update"
PermissionFileDelete = "file.delete"
Expand Down Expand Up @@ -80,8 +80,7 @@ func (fs FileSystem) Filewrite(request *sftp.Request) (io.WriterAt, error) {
// If the user doesn't have enough space left on the server it should respond with an
// error since we won't be letting them write this file to the disk.
if !fs.HasDiskSpace(fs) {
fs.logger.Infow("denying file write due to space limit", zap.String("server", fs.UUID))
return nil, sftp.ErrSshFxFailure
return nil, ErrSshQuotaExceeded
}

fs.lock.Lock()
Expand Down

0 comments on commit 368abf5

Please sign in to comment.