跳到主要内容

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

浏览文件

cloud_windows.go

61 行 · 1.8 KB历史下载
1package reversesshfs
2
3import (
4 "os"
5 "path/filepath"
6 "strings"
7
8 "golang.org/x/sys/windows"
9)
10
11// Open an absolute local drive path from its volume root. DONT_REPARSE applies
12// to all remaining components, so junctions cannot redirect the grant.
13func openCloudRoot(directory string) (rootedSys, error) {
14 dir := filepath.Clean(directory)
15 drive := filepath.VolumeName(dir)
16 if len(drive) != 2 || drive[1] != ':' {
17 return rootedSys{}, errDenied
18 }
19 base, err := openRootedSys(drive + `\`)
20 if err != nil {
21 return rootedSys{}, err
22 }
23 defer base.close()
24 h, err := ntCreate(base.rootHandle, strings.TrimPrefix(dir[len(drive):], `\`), fileDirectoryAccess, 0, windows.FILE_OPEN, windows.FILE_DIRECTORY_FILE, windows.OBJ_DONT_REPARSE)
25 if err != nil {
26 return rootedSys{}, err
27 }
28 name, err := normalizedName(h)
29 if err != nil {
30 windows.CloseHandle(h)
31 return rootedSys{}, errDenied
32 }
33 return rootedSys{localPath: dir, rootHandle: h, rootName: name}, nil
34}
35
36func (h *rootedHandlers) cloudOpenRead(rel string) (*os.File, error) {
37 var fh windows.Handle
38 var err error
39 if rel == "." {
40 self := windows.CurrentProcess()
41 err = windows.DuplicateHandle(self, h.rootHandle, self, &fh, 0, false, windows.DUPLICATE_SAME_ACCESS)
42 } else {
43 fh, err = ntCreate(h.rootHandle, filepath.FromSlash(rel), windows.FILE_GENERIC_READ, 0, windows.FILE_OPEN, 0, windows.OBJ_DONT_REPARSE)
44 }
45 if err != nil {
46 return nil, err
47 }
48 err = h.checkHandle(fh)
49 var fi windows.ByHandleFileInformation
50 if err == nil {
51 err = windows.GetFileInformationByHandle(fh, &fi)
52 }
53 if err == nil && (fi.FileAttributes&(windows.FILE_ATTRIBUTE_REPARSE_POINT|windows.FILE_ATTRIBUTE_DEVICE) != 0 || (fi.FileAttributes&windows.FILE_ATTRIBUTE_DIRECTORY == 0 && fi.NumberOfLinks != 1)) {
54 err = errDenied
55 }
56 if err != nil {
57 windows.CloseHandle(fh)
58 return nil, err
59 }
60 return os.NewFile(uintptr(fh), rel), nil
61}