Files
zero/internal/peermsg/private_dir_other.go
Anandan f922cb378e Add cross-session messaging (#884)
* Add cross-session messaging

* Harden cross-session messaging

Authenticate sender metadata against live registry records, bound peer lifecycle state, preserve records across transient discovery failures, and make receipt delivery direct and bounded.

Also serialize TUI peer approvals, harden platform runtime paths and transport deadlines, widen session references, and add regression coverage for identity spoofing, queue limits, path boundaries, and tool failures.

* Support canonical macOS socket paths

Resolve Unix transport directories to their physical path before applying strict no-symlink traversal, allowing the standard /var to /private/var macOS alias without weakening runtime-directory validation.

* Fix macOS socket path regression test

Create the canonicalization fixture beneath a guaranteed short Unix path so it exercises the primary endpoint on macOS, and report temporary-directory cleanup failures.

* Harden peer messaging lifecycle

* Fix Windows peer directory traversal

* Handle Windows token-owned peer directories

* Accept equivalent Windows ACL masks

* Build Windows peer ACL explicitly

* Pin Windows ACL trustee SIDs

* Validate Windows peer ACL semantics

* Propagate Windows peer handle cleanup errors

* Use null handle for Windows close failure test

* Test held-message eviction callback
2026-08-09 18:12:09 +05:30

41 lines
970 B
Go

//go:build !unix && !windows
package peermsg
import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
)
func ensurePrivateDir(path string) error {
abs, err := filepath.Abs(path)
if err != nil {
return err
}
volume := filepath.VolumeName(abs)
current := volume + string(filepath.Separator)
for _, component := range strings.Split(strings.TrimPrefix(abs[len(volume):], string(filepath.Separator)), string(filepath.Separator)) {
if component == "" {
continue
}
current = filepath.Join(current, component)
info, statErr := os.Lstat(current)
if errors.Is(statErr, os.ErrNotExist) {
if err := os.Mkdir(current, 0o700); err != nil && !errors.Is(err, os.ErrExist) {
return err
}
info, statErr = os.Lstat(current)
}
if statErr != nil {
return statErr
}
if !info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
return fmt.Errorf("refusing non-directory or symlink runtime path %q", current)
}
}
return os.Chmod(abs, 0o700)
}