MCPcopy Index your code
hub / github.com/1Panel-dev/1Panel / prepareMasterSocketDir

Function prepareMasterSocketDir

agent/server/server.go:44–67  ·  view source on GitHub ↗
(dir string)

Source from the content-addressed store, hash-verified

42)
43
44func prepareMasterSocketDir(dir string) error {
45 if err := os.MkdirAll(dir, masterSocketDirPerm); err != nil {
46 return fmt.Errorf("create master socket dir %s failed: %w", dir, err)
47 }
48 if err := os.Chmod(dir, masterSocketDirPerm); err != nil {
49 return fmt.Errorf("chmod master socket dir %s failed: %w", dir, err)
50 }
51 info, err := os.Stat(dir)
52 if err != nil {
53 return fmt.Errorf("stat master socket dir %s failed: %w", dir, err)
54 }
55 if info.Mode().Perm()&masterSocketDirPermMask != 0 {
56 return fmt.Errorf("master socket dir %s permission %#o is too permissive", dir, info.Mode().Perm())
57 }
58 if stat, ok := info.Sys().(*syscall.Stat_t); ok {
59 if int(stat.Uid) != os.Geteuid() {
60 return fmt.Errorf(
61 "master socket dir %s owner uid %d does not match current process uid %d",
62 dir, stat.Uid, os.Geteuid(),
63 )
64 }
65 }
66 return nil
67}
68
69func secureMasterSocket(sockPath string) error {
70 if err := os.Chmod(sockPath, masterSocketFilePerm); err != nil {

Callers 1

StartFunction · 0.85

Calls 4

MkdirAllMethod · 0.80
ModeMethod · 0.80
SysMethod · 0.80
StatMethod · 0.45

Tested by

no test coverage detected