sftpd: add support for chmod/chown

added matching permissions too and a new setting "setstat_mode".
Setting setstat_mode to 1 you can keep the previous behaviour that
silently ignore setstat requests
This commit is contained in:
Nicola Murino
2019-11-15 12:15:07 +01:00
parent 206799ff1c
commit bb37a1c1ce
13 changed files with 291 additions and 101 deletions

View File

@@ -191,11 +191,39 @@ func TestSFTPCmdTargetPath(t *testing.T) {
User: u,
}
_, err := connection.getSFTPCmdTargetPath("invalid_path")
if err != sftp.ErrSSHFxOpUnsupported {
if err != sftp.ErrSSHFxNoSuchFile {
t.Errorf("getSFTPCmdTargetPath must fal with the expected error: %v", err)
}
}
func TestGetSFTPErrorFromOSError(t *testing.T) {
err := os.ErrNotExist
err = getSFTPErrorFromOSError(err)
if err != sftp.ErrSSHFxNoSuchFile {
t.Errorf("unexpected error: %v", err)
}
err = os.ErrPermission
err = getSFTPErrorFromOSError(err)
if err != sftp.ErrSSHFxPermissionDenied {
t.Errorf("unexpected error: %v", err)
}
err = getSFTPErrorFromOSError(nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
}
func TestSetstatModeIgnore(t *testing.T) {
originalMode := setstatMode
setstatMode = 1
connection := Connection{}
err := connection.handleSFTPSetstat("invalid", nil)
if err != nil {
t.Errorf("unexpected error: %v setstat should be silently ignore in mode 1", err)
}
setstatMode = originalMode
}
func TestSFTPGetUsedQuota(t *testing.T) {
u := dataprovider.User{}
u.HomeDir = "home_rel_path"