MCPcopy
hub / github.com/larksuite/cli / checkOwnerUID

Function checkOwnerUID

internal/binding/audit_unix.go:17–31  ·  view source on GitHub ↗

checkOwnerUID verifies the file is owned by the current user.

(path, label string)

Source from the content-addressed store, hash-verified

15
16// checkOwnerUID verifies the file is owned by the current user.
17func checkOwnerUID(path, label string) error {
18 stat, err := vfs.Stat(path)
19 if err != nil {
20 return fmt.Errorf("%s: cannot stat %q: %w", label, path, err)
21 }
22 sysStat, ok := stat.Sys().(*syscall.Stat_t)
23 if !ok {
24 return fmt.Errorf("%s: cannot retrieve file owner for %q", label, path)
25 }
26 if sysStat.Uid != uint32(os.Getuid()) {
27 return fmt.Errorf("%s: path %q is owned by uid %d, expected %d",
28 label, path, sysStat.Uid, os.Getuid())
29 }
30 return nil
31}
32
33// auditFilePermissions rejects world/group-writable modes (always) and
34// world/group-readable modes (unless allowReadableByOthers is true, which

Callers 1

AssertSecurePathFunction · 0.70

Calls 1

StatFunction · 0.92

Tested by

no test coverage detected