Compare commits

...
Author SHA1 Message Date
Chris LuandClaude Opus 5.5 c52e2b9d51 sftp: refuse a setstat that two open uploads of its path could mean
Sending it to the stored entry instead could still apply a size the client
meant for its buffered upload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 14:57:56 -08:00
Chris LuandClaude Opus 5.5 ba31775360 sftp: fail the close when an upload's queued attributes are not stored
The setstat already answered success, so a failed post-upload update was
only logged and "put -p" lost the times without the client knowing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 14:50:40 -08:00
Chris LuandClaude Opus 5.5 4a43a9f014 sftp: leave a setstat alone when two uploads share its path
A setstat carries only the path, so with two uploads of one path open in a
session it went to whichever opened last, and a size cut the other upload's
bytes. Route it to an upload only when that upload is the only one open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 14:45:25 -08:00
Chris LuandClaude Opus 5.5 e1aca2255c sftp: set the attributes queued on an upload in its post-upload update
A new file can be under its bucket's default retention as soon as the PUT
stores it, and a setstat after that is refused, so "put -p" into such a
bucket stored the file and then failed the close. Apply the queued
attributes in the update that already sets the owner after the upload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 14:45:12 -08:00
Chris LuandClaude Opus 5.5 ad4015eecd sftp: clear the sub-second part of an mtime a setstat replaces
SFTP times are whole seconds, but the stored nanoseconds of the old mtime
stayed, so a touched or "put -p" file showed a time the client never set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 14:33:21 -08:00
Chris LuandClaude Opus 5.5 d001a706fb sftp: apply an fsetstat sent while an upload is still buffering
"put -p" sets the mode and times on the open handle before closing it, but
the upload only reaches the filer on close, so the setstat found no entry and
the client failed with "No such file or directory". Keep such attributes on
the open upload: a size cuts the buffered bytes, the mode goes on the PUT,
and the rest is set once the file is stored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 14:33:08 -08:00
Chris LuandClaude Opus 5.5 ce7a80ca9f sftp: keep an existing file's mode when an upload overwrites it
An overwrite went through the same PUT as a new file, so a 0600 file came
back with the default mode. Send the stored mode instead, as open(2) on an
existing file keeps it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 14:26:27 -08:00
Chris LuandClaude Opus 5.5 a4fae5a244 sftp: create uploaded files with mode 0644
The upload writer carried a 0644 mode that never reached the filer, so the
PUT fell back to the filer default of 0660. Pass the mode on the PUT, as
OpenSSH's sftp-server creates new files 0666 minus a 022 umask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 14:25:35 -08:00
6 changed files with 307 additions and 39 deletions

No files matched your search

+1 -1
View File
@@ -192,7 +192,7 @@ func TestSetstatSizeClearsMd5(t *testing.T) {
req := sftp.NewRequest("Setstat", "/b/f")
req.Flags = 1 // SSH_FILEXFER_ATTR_SIZE
req.Attrs = binary.BigEndian.AppendUint64(nil, size)
if err := fs.setFileStatWithRequest("/buckets/b/f", req); err != nil {
if err := fs.setFileStat("/buckets/b/f", req.AttrFlags(), req.Attributes()); err != nil {
t.Fatalf("setstat size %d: %v", size, err)
}
got := fake.lastUpdate.Entry.Attributes
+81 -3
View File
@@ -2,8 +2,10 @@
package sftpd
import (
"fmt"
"io"
"os"
"slices"
"sync"
"time"
@@ -48,7 +50,7 @@ func (l listerat) ListAt(ls []os.FileInfo, offset int64) (int, error) {
// SeaweedSftpFileWriter buffers writes and flushes on Close.
type SeaweedSftpFileWriter struct {
fs SftpServer
fs *SftpServer
req *sftp.Request
absPath string // Absolute path after HomeDir translation
mu sync.Mutex
@@ -57,6 +59,68 @@ type SeaweedSftpFileWriter struct {
uid uint32
gid uint32
offset int64
closed bool
setStats []fileStat // attributes set while the upload buffered
}
type fileStat struct {
flags sftp.FileAttrFlags
attrs *sftp.FileStat
}
func (fs *SftpServer) trackUpload(w *SeaweedSftpFileWriter) {
fs.uploadsMu.Lock()
defer fs.uploadsMu.Unlock()
if fs.uploads == nil {
fs.uploads = make(map[string][]*SeaweedSftpFileWriter)
}
fs.uploads[w.absPath] = append(fs.uploads[w.absPath], w)
}
func (fs *SftpServer) untrackUpload(w *SeaweedSftpFileWriter) {
fs.uploadsMu.Lock()
defer fs.uploadsMu.Unlock()
open := slices.DeleteFunc(fs.uploads[w.absPath], func(o *SeaweedSftpFileWriter) bool { return o == w })
if len(open) == 0 {
delete(fs.uploads, w.absPath)
} else {
fs.uploads[w.absPath] = open
}
}
// openUpload returns the upload open on absPath, or nil. A setstat names only
// the path, so with several uploads open there it cannot tell which one it is
// for and is refused.
func (fs *SftpServer) openUpload(absPath string) (*SeaweedSftpFileWriter, error) {
fs.uploadsMu.Lock()
defer fs.uploadsMu.Unlock()
switch open := fs.uploads[absPath]; len(open) {
case 0:
return nil, nil
case 1:
return open[0], nil
default:
return nil, fmt.Errorf("%s has %d uploads open: %w", absPath, len(open), sftp.ErrSSHFxFailure)
}
}
// setStat takes an fsetstat on the handle of a buffering upload, whose entry
// may not exist yet: a size cuts the buffered bytes, the rest is applied once
// the upload is stored. It does not handle it once the upload has closed.
func (w *SeaweedSftpFileWriter) setStat(flags sftp.FileAttrFlags, attrs *sftp.FileStat) (handled bool, err error) {
w.mu.Lock()
defer w.mu.Unlock()
if w.closed {
return false, nil
}
if flags.Size {
if err := w.tmpFile.Truncate(int64(attrs.Size)); err != nil {
return true, err
}
flags.Size = false
}
w.setStats = append(w.setStats, fileStat{flags: flags, attrs: attrs})
return true, nil
}
func (w *SeaweedSftpFileWriter) Write(p []byte) (int, error) {
@@ -77,6 +141,8 @@ func (w *SeaweedSftpFileWriter) Close() error {
w.mu.Lock()
defer w.mu.Unlock()
defer w.fs.untrackUpload(w)
w.closed = true
defer os.Remove(w.tmpFile.Name()) // Clean up temp file
defer w.tmpFile.Close()
@@ -88,10 +154,22 @@ func (w *SeaweedSftpFileWriter) Close() error {
if err := w.fs.requireParentDir(w.absPath); err != nil {
return err
}
if err := w.fs.checkWritable(w.absPath); err != nil {
existing, err := w.fs.checkWritable(w.absPath)
if err != nil {
return err
}
// Like open(2) on an existing file, an overwrite keeps the file's mode;
// a zero mode is an entry written without one.
mode := w.permissions
if perm := os.FileMode(existing.GetAttributes().GetFileMode()).Perm(); perm != 0 {
mode = perm
}
for _, st := range w.setStats {
if st.flags.Permissions {
mode = st.attrs.FileMode().Perm()
}
}
// Stream the file to the absolute path (after HomeDir translation)
return w.fs.putFile(w.absPath, w.tmpFile, w.fs.user)
return w.fs.putFile(w.absPath, w.tmpFile, w.fs.user, mode, w.setStats)
}
+55 -30
View File
@@ -127,7 +127,16 @@ func (fs *SftpServer) dispatchCmd(r *sftp.Request) error {
case "Rmdir":
return fs.removeDir(absPath)
case "Setstat":
return fs.setFileStatWithRequest(absPath, r)
w, err := fs.openUpload(absPath)
if err != nil {
return err
}
if w != nil {
if handled, err := w.setStat(r.AttrFlags(), r.Attributes()); handled {
return err
}
}
return fs.setFileStat(absPath, r.AttrFlags(), r.Attributes())
default:
return fmt.Errorf("unsupported: %s", r.Method)
}
@@ -162,7 +171,7 @@ func (fs *SftpServer) newFileWriter(r *sftp.Request) (io.WriterAt, error) {
if err := fs.requireParentDir(absPath); err != nil {
return nil, err
}
if err := fs.checkWritable(absPath); err != nil {
if _, err := fs.checkWritable(absPath); err != nil {
return nil, err
}
// Create a temporary file to buffer writes
@@ -179,8 +188,8 @@ func (fs *SftpServer) newFileWriter(r *sftp.Request) (io.WriterAt, error) {
}
}
return &SeaweedSftpFileWriter{
fs: *fs,
w := &SeaweedSftpFileWriter{
fs: fs,
req: r,
absPath: absPath,
tmpFile: tmpFile,
@@ -188,23 +197,26 @@ func (fs *SftpServer) newFileWriter(r *sftp.Request) (io.WriterAt, error) {
uid: fs.user.Uid,
gid: fs.user.Gid,
offset: 0,
}, nil
}
fs.trackUpload(w)
return w, nil
}
// checkWritable refuses an upload onto a directory, which the filer would
// redirect to a child, or onto a protected entry.
func (fs *SftpServer) checkWritable(absPath string) error {
// redirect to a child, or onto a protected entry. It returns the existing
// file, or nil when there is none.
func (fs *SftpServer) checkWritable(absPath string) (*filer_pb.Entry, error) {
entry, err := fs.getEntry(absPath)
if errors.Is(err, os.ErrNotExist) {
return nil
return nil, nil
}
if err != nil {
return err
return nil, err
}
if entry.IsDirectory {
return fmt.Errorf("%s is a directory", absPath)
return nil, fmt.Errorf("%s is a directory", absPath)
}
return fs.checkEntryProtected(absPath, entry)
return entry, fs.checkEntryProtected(absPath, entry)
}
func (fs *SftpServer) copyExistingContent(absPath string, dst io.Writer) error {
@@ -457,7 +469,7 @@ func (fs *SftpServer) checkRenameKeepsAcl(absPath, absTarget string) error {
return nil
}
func (fs *SftpServer) setFileStatWithRequest(absPath string, r *sftp.Request) error {
func (fs *SftpServer) setFileStat(absPath string, flags sftp.FileAttrFlags, attrs *sftp.FileStat) error {
if err := fs.checkFilePermission(absPath, "write"); err != nil {
return err
}
@@ -469,25 +481,29 @@ func (fs *SftpServer) setFileStatWithRequest(absPath string, r *sftp.Request) er
return err
}
dir, _ := util.FullPath(absPath).DirAndName()
// apply attrs
if r.AttrFlags().Permissions {
entry.Attributes.FileMode = uint32(r.Attributes().FileMode())
applyFileStat(entry, flags, attrs)
return fs.updateEntry(dir, entry)
}
func applyFileStat(entry *filer_pb.Entry, flags sftp.FileAttrFlags, attrs *sftp.FileStat) {
if flags.Permissions {
entry.Attributes.FileMode = uint32(attrs.FileMode())
}
if r.AttrFlags().UidGid {
entry.Attributes.Uid = uint32(r.Attributes().UID)
entry.Attributes.Gid = uint32(r.Attributes().GID)
if flags.UidGid {
entry.Attributes.Uid = uint32(attrs.UID)
entry.Attributes.Gid = uint32(attrs.GID)
}
if r.AttrFlags().Acmodtime {
entry.Attributes.Mtime = int64(r.Attributes().Mtime)
if flags.Acmodtime {
entry.Attributes.Mtime = int64(attrs.Mtime)
entry.Attributes.MtimeNs = 0
}
if r.AttrFlags().Size {
if size := uint64(r.Attributes().Size); size != entry.Attributes.FileSize {
if flags.Size {
if size := uint64(attrs.Size); size != entry.Attributes.FileSize {
entry.Attributes.FileSize = size
// the stored MD5 described the old content
entry.Attributes.Md5 = nil
}
}
return fs.updateEntry(dir, entry)
}
// ==================== Directory Operations ====================
@@ -647,10 +663,13 @@ func (fs *SftpServer) requireEntry(absPath string, isDir bool) error {
return nil
}
func (fs *SftpServer) putFile(filepath string, reader io.Reader, user *user.User) error {
// putFile uploads the file, then sets the owner to user and applies stats,
// the attributes a client set while the upload buffered.
func (fs *SftpServer) putFile(filepath string, reader io.Reader, user *user.User, mode os.FileMode, stats []fileStat) error {
dir, filename := util.FullPath(filepath).DirAndName()
// Escape the path so a "?" in the filename cannot inject filer query commands like cp.from/mv.from.
uploadUrl := (&url.URL{Scheme: "http", Host: fs.filerAddr.ToHttpAddress(), Path: filepath}).String()
query := url.Values{"mode": {strconv.FormatUint(uint64(mode.Perm()), 8)}}
uploadUrl := (&url.URL{Scheme: "http", Host: fs.filerAddr.ToHttpAddress(), Path: filepath, RawQuery: query.Encode()}).String()
// Let the global HTTP client normalize the scheme to https:// when TLS is configured
normalizedUrl, err := util_http.NormalizeUrl(uploadUrl)
if err != nil {
@@ -702,8 +721,7 @@ func (fs *SftpServer) putFile(filepath string, reader io.Reader, user *user.User
if result.Error != "" {
return fmt.Errorf("filer error: %s", result.Error)
}
// Update file ownership using the same pattern as other functions
if user != nil {
if user != nil || len(stats) > 0 {
err := fs.callWithClient(false, func(ctx context.Context, client filer_pb.SeaweedFilerClient) error {
// Look up the file to get its current entry
lookupResp, err := client.LookupDirectoryEntry(ctx, &filer_pb.LookupDirectoryEntryRequest{
@@ -718,10 +736,14 @@ func (fs *SftpServer) putFile(filepath string, reader io.Reader, user *user.User
return fmt.Errorf("file not found after upload: %s/%s", dir, filename)
}
// Update the entry with new uid/gid
entry := lookupResp.Entry
entry.Attributes.Uid = user.Uid
entry.Attributes.Gid = user.Gid
if user != nil {
entry.Attributes.Uid = user.Uid
entry.Attributes.Gid = user.Gid
}
for _, st := range stats {
applyFileStat(entry, st.flags, st.attrs)
}
// Update the entry in the filer
_, err = client.UpdateEntry(ctx, &filer_pb.UpdateEntryRequest{
@@ -731,6 +753,9 @@ func (fs *SftpServer) putFile(filepath string, reader io.Reader, user *user.User
return err
})
if err != nil && len(stats) > 0 {
return fmt.Errorf("set attributes of %s: %w", filepath, err)
}
if err != nil {
// Log the error but don't fail the whole operation
glog.Errorf("Failed to update file ownership for %s: %v", filepath, err)
+159 -2
View File
@@ -3,12 +3,16 @@ package sftpd
import (
"context"
"crypto/rand"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"io"
"net"
"net/http"
"net/http/httptest"
"os"
"path"
"strings"
"testing"
"time"
@@ -16,6 +20,7 @@ import (
"github.com/pkg/sftp"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
"github.com/seaweedfs/seaweedfs/weed/security"
"github.com/seaweedfs/seaweedfs/weed/sftpd/user"
"google.golang.org/grpc"
@@ -42,11 +47,11 @@ func TestPutFileEscapesQueryInjection(t *testing.T) {
fs := &SftpServer{filerAddr: pb.ServerAddress(strings.TrimPrefix(ts.URL, "http://"))}
malicious := "/home/alice/steal?cp.from=/home/bob/secret.txt"
if err := fs.putFile(malicious, strings.NewReader("dummy"), nil); err != nil {
if err := fs.putFile(malicious, strings.NewReader("dummy"), nil, 0644, nil); err != nil {
t.Fatalf("putFile: %v", err)
}
if gotRawQuery != "" {
if gotRawQuery != "mode=644" {
t.Errorf("filename leaked into query string: RawQuery=%q", gotRawQuery)
}
if gotPath != malicious {
@@ -272,3 +277,155 @@ func TestListAllPagesMissingDirectory(t *testing.T) {
t.Fatalf("directory: got %d entries, want a.txt", n)
}
}
func TestUploadFileMode(t *testing.T) {
fs, _ := newLockTestServer(t, map[string]*filer_pb.Entry{
"/buckets/plain": {Name: "plain", IsDirectory: true},
"/buckets/plain/private": {Name: "private", Attributes: &filer_pb.FuseAttributes{FileMode: 0600}},
"/buckets/plain/shared": {Name: "shared", Attributes: &filer_pb.FuseAttributes{FileMode: 0664}},
"/buckets/plain/unset": {Name: "unset", Attributes: &filer_pb.FuseAttributes{}},
})
var gotMode string
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotMode = r.URL.Query().Get("mode")
_, _ = w.Write([]byte(`{}`))
}))
t.Cleanup(ts.Close)
_, grpcPort, _ := net.SplitHostPort(fs.filerAddr.ToGrpcAddress())
fs.filerAddr = pb.ServerAddress(strings.TrimPrefix(ts.URL, "http://") + "." + grpcPort)
tests := []struct {
name string
req *sftp.Request
want string
}{
{"default", sftp.NewRequest("Put", "/plain/new"), "644"},
{"overwrite keeps private mode", sftp.NewRequest("Put", "/plain/private"), "600"},
{"overwrite keeps shared mode", sftp.NewRequest("Put", "/plain/shared"), "664"},
{"overwrite of a file without a mode", sftp.NewRequest("Put", "/plain/unset"), "644"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.req.Flags |= 0x1a // write, create, truncate
gotMode = ""
w, err := fs.newFileWriter(tt.req)
if err != nil {
t.Fatalf("newFileWriter: %v", err)
}
if _, err := w.WriteAt([]byte("data"), 0); err != nil {
t.Fatalf("write: %v", err)
}
if err := w.(io.Closer).Close(); err != nil {
t.Fatalf("close: %v", err)
}
if gotMode != tt.want {
t.Errorf("mode = %q, want %q", gotMode, tt.want)
}
})
}
}
// An fsetstat on an upload's handle, as "put -p" sends before closing, finds
// no entry yet: it has to wait for the upload and apply then, even when the
// upload took the bucket's default retention.
func TestSetstatOnBufferingUpload(t *testing.T) {
fs, fake := newLockTestServer(t, map[string]*filer_pb.Entry{
"/buckets/plain": {Name: "plain", IsDirectory: true},
})
var gotMode, gotBody string
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
gotMode, gotBody = r.URL.Query().Get("mode"), string(body)
fake.mu.Lock()
entry := lockedEntry(path.Base(r.URL.Path), map[string]string{s3_constants.ExtObjectLockModeKey: s3_constants.RetentionModeCompliance, s3_constants.ExtRetentionUntilDateKey: retainUntil(time.Hour)})
entry.Attributes = &filer_pb.FuseAttributes{FileMode: 0644, FileSize: uint64(len(body)), MtimeNs: 123}
fake.entries[r.URL.Path] = entry
fake.mu.Unlock()
_, _ = w.Write([]byte(`{}`))
}))
t.Cleanup(ts.Close)
_, grpcPort, _ := net.SplitHostPort(fs.filerAddr.ToGrpcAddress())
fs.filerAddr = pb.ServerAddress(strings.TrimPrefix(ts.URL, "http://") + "." + grpcPort)
open := sftp.NewRequest("Put", "/plain/new")
open.Flags = 0x1a // write, create, truncate
w, err := fs.newFileWriter(open)
if err != nil {
t.Fatalf("newFileWriter: %v", err)
}
if _, err := w.WriteAt([]byte("hello world"), 0); err != nil {
t.Fatalf("write: %v", err)
}
const mtime = 1700000000
setstat := sftp.NewRequest("Setstat", "/plain/new")
setstat.Flags = 0x1 | 0x4 | 0x8 // size, permissions, times
setstat.Attrs = binary.BigEndian.AppendUint64(nil, 5)
setstat.Attrs = binary.BigEndian.AppendUint32(setstat.Attrs, 0100600)
setstat.Attrs = binary.BigEndian.AppendUint32(setstat.Attrs, mtime)
setstat.Attrs = binary.BigEndian.AppendUint32(setstat.Attrs, mtime)
if err := fs.dispatchCmd(setstat); err != nil {
t.Fatalf("setstat before close: %v", err)
}
if err := w.(io.Closer).Close(); err != nil {
t.Fatalf("close: %v", err)
}
if gotMode != "600" || gotBody != "hello" {
t.Errorf("uploaded mode %q body %q, want 600 and the body cut to 5 bytes", gotMode, gotBody)
}
got := fake.lastUpdate.GetEntry().GetAttributes()
if got.GetMtime() != mtime || got.GetMtimeNs() != 0 || os.FileMode(got.GetFileMode()).Perm() != 0600 {
t.Errorf("stored mtime %d.%09d mode %o, want %d.000000000 and 600", got.GetMtime(), got.GetMtimeNs(), got.GetFileMode(), mtime)
}
if w, _ := fs.openUpload("/buckets/plain/new"); w != nil {
t.Error("closed upload is still tracked")
}
// The client was told the setstat worked, so losing it must fail the close.
fake.mu.Lock()
fake.updateErr = errors.New("update refused")
fake.mu.Unlock()
open.Filepath, setstat.Filepath = "/plain/other", "/plain/other"
w, err = fs.newFileWriter(open)
if err != nil {
t.Fatalf("newFileWriter: %v", err)
}
if err := fs.dispatchCmd(setstat); err != nil {
t.Fatalf("setstat before close: %v", err)
}
if err := w.(io.Closer).Close(); err == nil {
t.Error("close succeeded although the queued attributes were not stored")
}
}
// A setstat names only the path, so it can't pick between two uploads open
// on the same one, and changing the stored entry instead would be wrong too.
func TestSetstatWithTwoUploadsOnOnePath(t *testing.T) {
fs, fake := newLockTestServer(t, map[string]*filer_pb.Entry{
"/buckets/plain": {Name: "plain", IsDirectory: true},
"/buckets/plain/new": {Name: "new", Attributes: &filer_pb.FuseAttributes{FileMode: 0644, FileSize: 10}},
})
open := func() io.WriteCloser {
req := sftp.NewRequest("Put", "/plain/new")
req.Flags = 0x1a // write, create, truncate
w, err := fs.newFileWriter(req)
if err != nil {
t.Fatalf("newFileWriter: %v", err)
}
return w.(io.WriteCloser)
}
first, second := open(), open()
setstat := sftp.NewRequest("Setstat", "/plain/new")
setstat.Flags = 0x1 // size
setstat.Attrs = binary.BigEndian.AppendUint64(nil, 0)
if err := fs.dispatchCmd(setstat); err == nil {
t.Error("setstat with two uploads open succeeded")
}
if fake.lastUpdate != nil {
t.Errorf("setstat changed the stored entry: %v", fake.lastUpdate.Entry.Attributes)
}
_ = second.Close()
if got, err := fs.openUpload("/buckets/plain/new"); got != first || err != nil {
t.Fatalf("open upload = %p, %v, want the remaining one %p", got, err, first)
}
_ = first.Close()
}
+7 -3
View File
@@ -37,6 +37,7 @@ type lockTestFiler struct {
volume string
lastUpdate *filer_pb.UpdateEntryRequest
updateErr error
}
func (f *lockTestFiler) LookupDirectoryEntry(_ context.Context, req *filer_pb.LookupDirectoryEntryRequest) (*filer_pb.LookupDirectoryEntryResponse, error) {
@@ -228,6 +229,9 @@ func TestRenameRefusesProtectedSourceAndTarget(t *testing.T) {
func (f *lockTestFiler) UpdateEntry(_ context.Context, req *filer_pb.UpdateEntryRequest) (*filer_pb.UpdateEntryResponse, error) {
f.mu.Lock()
defer f.mu.Unlock()
if f.updateErr != nil {
return nil, f.updateErr
}
f.updates++
f.lastUpdate = req
return &filer_pb.UpdateEntryResponse{}, nil
@@ -250,14 +254,14 @@ func TestWriteAndSetstatRefuseProtectedEntries(t *testing.T) {
}
t.Fatalf("overwrite of %s: got %v, want os.ErrPermission", p, err)
}
if err := fs.setFileStatWithRequest("/buckets"+p, sftp.NewRequest("Setstat", p)); !errors.Is(err, os.ErrPermission) {
if err := fs.setFileStat("/buckets"+p, sftp.FileAttrFlags{}, &sftp.FileStat{}); !errors.Is(err, os.ErrPermission) {
t.Fatalf("setstat of %s: got %v, want os.ErrPermission", p, err)
}
}
if fake.updates != 0 {
t.Fatalf("setstat of a protected entry reached the filer")
}
if err := fs.setFileStatWithRequest("/buckets/b/unlocked", sftp.NewRequest("Setstat", "/b/unlocked")); err != nil {
if err := fs.setFileStat("/buckets/b/unlocked", sftp.FileAttrFlags{}, &sftp.FileStat{}); err != nil {
t.Fatalf("setstat of an unprotected entry: %v", err)
}
if _, ok := fake.lastUpdate.ExpectedExtended[s3_constants.ExtLegalHoldKey]; !ok {
@@ -423,7 +427,7 @@ func TestPutFileAppliesBucketDefaultRetention(t *testing.T) {
fs.bucketsDir = bucketsDir
for _, tt := range tests {
gotHeader = nil
if err := fs.putFile(tt.path, strings.NewReader("data"), nil); err != nil {
if err := fs.putFile(tt.path, strings.NewReader("data"), nil, 0644, nil); err != nil {
t.Fatalf("putFile %s: %v", tt.path, err)
}
mode := gotHeader[s3_constants.ExtObjectLockModeKey]
+4
View File
@@ -8,6 +8,7 @@ import (
"os"
"path"
"strings"
"sync"
"time"
"unicode/utf8"
@@ -29,6 +30,9 @@ type SftpServer struct {
filerSigningKey []byte
filerSigningExpiresAfter int
bucketsDir string
uploadsMu sync.Mutex
uploads map[string][]*SeaweedSftpFileWriter
}
// NewSftpServer constructs the server.