跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

0003-append-fix.patch

114 行 · 4.0 KB历史下载
1diff --git a/pkg/reversesshfs/rooted.go b/pkg/reversesshfs/rooted.go
2index fb39721..f97c31f 100644
3--- a/pkg/reversesshfs/rooted.go
4+++ b/pkg/reversesshfs/rooted.go
5@@ -3,6 +3,7 @@
6 package reversesshfs
7
8 import (
9+ "encoding/binary"
10 "errors"
11 "io"
12 "os"
13@@ -168,6 +169,17 @@ func (h *rootedHandlers) OpenFile(r *sftp.Request) (sftp.WriterAtReaderAt, error
14 return h.openFile(r)
15 }
16
17+// openMode returns the permissions sent with an Open request.
18+// For Open, pkg/sftp puts the open flags in r.Flags and drops the attribute flags,
19+// so r.AttrFlags and r.Attributes must not be used: SSH_FXF_APPEND reads as permissions.
20+// Permissions alone are the only 4-byte attributes, which is what sshfs always sends.
21+func openMode(r *sftp.Request) (uint32, bool) {
22+ if len(r.Attrs) != 4 {
23+ return 0, false
24+ }
25+ return binary.BigEndian.Uint32(r.Attrs) & 0o7777, true
26+}
27+
28 // Filecmd implements sftp.FileCmder.
29 func (h *rootedHandlers) Filecmd(r *sftp.Request) error {
30 switch r.Method {
31diff --git a/pkg/reversesshfs/rooted_test.go b/pkg/reversesshfs/rooted_test.go
32index bfd630e..d6a186f 100644
33--- a/pkg/reversesshfs/rooted_test.go
34+++ b/pkg/reversesshfs/rooted_test.go
35@@ -208,6 +208,51 @@ func TestRootedChmodWithoutReadPermission(t *testing.T) {
36 }
37 }
38
39+// SSH_FXF_APPEND has the bit of SSH_FILEXFER_ATTR_PERMISSIONS: an append open used to
40+// panic the server, and with it the process serving the mount.
41+func TestRootedOpenAppend(t *testing.T) {
42+ c, root := setupRooted(t, false)
43+ for _, s := range []string{"src/main.go", "src/new.go"} {
44+ f, err := c.OpenFile(filepath.Join(root, s), os.O_WRONLY|os.O_APPEND|os.O_CREATE)
45+ if err != nil {
46+ t.Fatalf("%s: %v", s, err)
47+ }
48+ // The server ignores SSH_FXF_APPEND: the client sends the offset, as sshfs does.
49+ if _, err := f.Seek(0, io.SeekEnd); err != nil {
50+ t.Fatalf("%s: %v", s, err)
51+ }
52+ if _, err := f.Write([]byte("+")); err != nil {
53+ t.Fatalf("%s: %v", s, err)
54+ }
55+ f.Close()
56+ }
57+ for s, want := range map[string]string{"src/main.go": "orig+", "src/new.go": "+"} {
58+ if b, err := os.ReadFile(filepath.Join(root, s)); err != nil || string(b) != want {
59+ t.Fatalf("%s: %q, %v", s, b, err)
60+ }
61+ }
62+}
63+
64+// sshfs sends its open flags with the permissions alone as attributes.
65+func TestRootedOpenMode(t *testing.T) {
66+ if runtime.GOOS == "windows" {
67+ t.Skip("mode bits other than the owner write bit are not supported on Windows")
68+ }
69+ _, root, h := setupRootedHandlers(t, false)
70+ const write, appendFlag, creat = 0x2, 0x4, 0x8
71+ r := sftp.NewRequest("Put", filepath.Join(root, "src", "run.sh"))
72+ r.Flags = write | appendFlag | creat
73+ r.Attrs = []byte{0, 0, 0o1, 0o355} // 0o755
74+ f, err := h.openFile(r)
75+ if err != nil {
76+ t.Fatal(err)
77+ }
78+ f.Close()
79+ if fi, err := os.Stat(filepath.Join(root, "src", "run.sh")); err != nil || fi.Mode().Perm() != 0o755 {
80+ t.Fatalf("%v, %v", fi, err)
81+ }
82+}
83+
84 func TestRootedDeniesProtectedWrites(t *testing.T) {
85 type env struct {
86 c *sftp.Client
87diff --git a/pkg/reversesshfs/rooted_unix.go b/pkg/reversesshfs/rooted_unix.go
88index f6d757d..81eb662 100644
89--- a/pkg/reversesshfs/rooted_unix.go
90+++ b/pkg/reversesshfs/rooted_unix.go
91@@ -104,8 +104,8 @@ func (h *rootedHandlers) openFile(r *sftp.Request) (*os.File, error) {
92 flags |= unix.O_EXCL
93 }
94 var mode uint32 = 0o644
95- if r.AttrFlags().Permissions {
96- mode = r.Attributes().Mode & 0o7777
97+ if m, ok := openMode(r); ok {
98+ mode = m
99 }
100 dirfd, base, err := h.openParent(rel)
101 if err != nil {
102diff --git a/pkg/reversesshfs/rooted_windows.go b/pkg/reversesshfs/rooted_windows.go
103index 3d95be4..eb2dece 100644
104--- a/pkg/reversesshfs/rooted_windows.go
105+++ b/pkg/reversesshfs/rooted_windows.go
106@@ -248,7 +248,7 @@ func (h *rootedHandlers) openFile(r *sftp.Request) (*os.File, error) {
107 disposition = windows.FILE_OPEN_IF
108 }
109 var attrs uint32 = fileAttributeNormal
110- if r.AttrFlags().Permissions && r.Attributes().Mode&0o200 == 0 {
111+ if m, ok := openMode(r); ok && m&0o200 == 0 {
112 attrs = fileAttributeReadonly
113 }
114 fh, err := ntCreate(parent, base, access, attrs, disposition, options, windows.OBJ_DONT_REPARSE)