platform

package
v0.9.8-dev.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: GPL-3.0 Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInstallControlReadOnly reports a mutation attempted through an
	// inspection-only installation-control capability.
	ErrInstallControlReadOnly = errors.New("installation control is read-only")
	// ErrInstallControlUninitialized reports an existing control directory
	// whose fixed state or lock files are absent.
	ErrInstallControlUninitialized = errors.New("installation control is uninitialized")
	// ErrInstallStateChanged reports that the name-bound state no longer has
	// the identity or digest observed by the caller.
	ErrInstallStateChanged = errors.New("installation state changed")
	// ErrInstallStateTooLarge reports a raw state document beyond the fixed
	// installation-record bound.
	ErrInstallStateTooLarge = errors.New("installation state exceeds 64 KiB")
	// ErrInstallControlBusy reports that the permanent operation or startup
	// lock is already held.
	ErrInstallControlBusy = errors.New("installation control lock is already held")
)
View Source
var (
	// ErrLaunchdRuntimeUninitialized reports an existing runtime directory whose
	// fixed state or permanent lock file is absent.
	ErrLaunchdRuntimeUninitialized = errors.New("launchd runtime control is uninitialized")
	// ErrLaunchdRuntimeStateTooLarge reports a raw runtime record above 4 KiB.
	ErrLaunchdRuntimeStateTooLarge = errors.New("launchd runtime state exceeds 4 KiB")
	// ErrLaunchdRuntimeNotDurable prevents the app-store adapter from accepting
	// a publication whose namespace visibility was not followed by durability.
	ErrLaunchdRuntimeNotDurable = errors.New("launchd runtime publication is not durable")
)
View Source
var ErrControlData = errors.New("invalid control credential data")

ErrControlData identifies invalid credential size or an incomplete read.

View Source
var ErrIdentityMismatch = errors.New("private fs file identity mismatch")

ErrIdentityMismatch is returned when OpenReadChecked sees a different identity.

View Source
var ErrLeaseConflict = errors.New("lease already held")

ErrLeaseConflict reports another holder of a data, install or endpoint lock.

View Source
var ErrPublishCleanupIncomplete = errors.New("publish cleanup incomplete")

ErrPublishCleanupIncomplete marks a failed cleanup attempt, even when a later held-workspace cleanup succeeds. Callers should report their sanitized warning.

View Source
var ErrPublishDirectoryChanged = errors.New("publish directory changed")

ErrPublishDirectoryChanged reports that the visible path no longer names the held publish directory.

View Source
var ErrUnsafeComponent = fmt.Errorf("unsafe filesystem component: %w", os.ErrPermission)

ErrUnsafeComponent identifies a non-directory, symlink or multiply linked file. It also matches os.ErrPermission for control API permission-denied mapping.

Functions

func AbsoluteDataRoot

func AbsoluteDataRoot() (string, error)

AbsoluteDataRoot returns DefaultDataRoot as a cleaned absolute path. Used when installing the OS service so LocalSystem/root inherits a fixed path instead of resolving systemprofile or /root home.

func AbsoluteInstallRoot

func AbsoluteInstallRoot() (string, error)

AbsoluteInstallRoot returns InstallRoot as a cleaned absolute path.

func AbsoluteInstalledBinaryPath

func AbsoluteInstalledBinaryPath() (string, error)

AbsoluteInstalledBinaryPath returns the absolute path of the installed binary.

func ChannelDataRoot added in v0.9.0

func ChannelDataRoot() (string, error)

ChannelDataRoot returns the data root used only for Mihari channel I/O. MIHARI_DATA wins. Unlike DefaultDataRoot, Unix elevated processes honor SUDO_USER.

func ChannelPath added in v0.9.0

func ChannelPath() (string, error)

ChannelPath returns the sidecar path for the Mihari release channel.

func CleanupReplacedBinary added in v0.9.6

func CleanupReplacedBinary(context.Context, string) error

CleanupReplacedBinary is a no-op: Unix replacement unlinks the old image atomically and leaves no named .old-* copies to collect.

func DefaultDataRoot

func DefaultDataRoot() string

DefaultDataRoot returns MIHARI_DATA when set, otherwise the platform default data root under the current user's home directory ($HOME/.mihari / %USERPROFILE%\.mihari).

func ElevationRevealsListener added in v0.9.7

func ElevationRevealsListener() bool

ElevationRevealsListener reports that root can name a listener an ordinary user cannot see.

func FileURI added in v0.9.7

func FileURI(path string) (string, error)

FileURI returns a canonical URI for an absolute native file path or file URI.

func FileURIPath added in v0.9.7

func FileURIPath(raw string) (string, error)

FileURIPath converts a file URI to an absolute native path without IO.

func InitializeInstallControlForUpdate added in v0.9.3

func InitializeInstallControlForUpdate(ctx context.Context, lease *OwnedInstallLease, initial []byte) (_ *InstallControl, publication InstallPublication, err error)

InitializeInstallControlForUpdate atomically publishes K with both permanent locks and the caller-supplied initial raw state.

func InstallRoot

func InstallRoot() string

InstallRoot returns the machine-local directory that holds the OS-managed mihari binary (separate from the data root and from any download location). Override with MIHARI_INSTALL_ROOT (absolute preferred; relative is Abs'd by callers).

func InstalledBinaryName

func InstalledBinaryName() string

InstalledBinaryName is mihari.exe on Windows and mihari elsewhere.

func InstalledBinaryPath

func InstalledBinaryPath() string

InstalledBinaryPath is InstallRoot()/InstalledBinaryName().

func LegacyRootSourcePresent added in v0.9.3

func LegacyRootSourcePresent(ctx context.Context) (bool, error)

LegacyRootSourcePresent is a conservative bootstrap blocker only. It never selects migration data; source authority belongs to explicit install input.

func OpenBrowser

func OpenBrowser(url string) error

OpenBrowser launches the OS default browser for a local URL. Callers must not log the URL when it may contain one-shot access tokens.

func OpenSnapshot added in v0.9.2

func OpenSnapshot(fs *PrivateFS, path string, expected FileIdentity) (*os.File, error)

OpenSnapshot opens a no-follow read handle whose identity must match expected.

func OwnChannelWrite added in v0.9.0

func OwnChannelWrite(path string, newParent bool) error

OwnChannelWrite chowns the sidecar to the SUDO_USER owner when Unix euid is 0. newParent chowns the immediate data-root directory only when this write created it. It is a no-op on Windows.

func PortInUse added in v0.9.4

func PortInUse(err error) bool

PortInUse identifies a socket address conflict without matching error text.

func ReadControlCredential added in v0.9.3

func ReadControlCredential(ctx context.Context, locator ControlLocator) ([]byte, error)

ReadControlCredential returns bounded, verified bytes without creating C. The credential package owns hexadecimal and optional newline validation.

func ReadInstallChannel added in v0.9.3

func ReadInstallChannel(ctx context.Context, layout ResolvedLayout) ([]byte, error)

ReadInstallChannel reads only the selected root-owned channel sidecar through the same search-only, no-follow namespace proof as control discovery. It never opens B for directory listing and does not create application paths.

func Relaunch added in v0.4.0

func Relaunch(binary string, args, env []string) error

Relaunch replaces the current process with the updated Mihari binary.

func StageInstalledBinary

func StageInstalledBinary(source string) (string, error)

StageInstalledBinary copies source into the install directory and returns the absolute installed path. The OS service ImagePath must always use this path, never a download folder or developer workspace path.

If source already resolves to the install path, no copy is performed.

func UninstallControlRoot added in v0.9.3

func UninstallControlRoot() (string, error)

UninstallControlRoot returns no separate control root on Unix because the fixed install-control directory is an entry of the selected system base root.

func WithControlEndpoint added in v0.9.3

func WithControlEndpoint(ctx context.Context, locator ControlLocator, fn func(string) error) error

WithControlEndpoint retains a read-only namespace proof throughout fn.

Types

type AdvisoryLock added in v0.9.2

type AdvisoryLock interface {
	Lock(context.Context, LockMode) error
	Unlock() error
	Close() error
}

AdvisoryLock is a closeable OS advisory lock on a lock file.

func OpenAdvisoryLock added in v0.9.2

func OpenAdvisoryLock(fs *PrivateFS, path string) (AdvisoryLock, error)

OpenAdvisoryLock opens path via fs.OpenAppend and returns an advisory lock.

type BorrowedDaemonLease added in v0.9.3

type BorrowedDaemonLease struct {
	// contains filtered or unexported fields
}

BorrowedDaemonLease provides endpoint operations without release authority.

func (BorrowedDaemonLease) Validate added in v0.9.3

func (l BorrowedDaemonLease) Validate(ctx context.Context, layout ResolvedLayout) error

Validate proves that the view still names the requested data and endpoint.

func (BorrowedDaemonLease) WithCredential added in v0.9.3

func (l BorrowedDaemonLease) WithCredential(ctx context.Context, layout ResolvedLayout, fn func(*ControlCredentialFile) error) error

WithCredential borrows the daemon lease without reacquiring filesystem locks.

func (BorrowedDaemonLease) WithEndpoint added in v0.9.3

func (l BorrowedDaemonLease) WithEndpoint(ctx context.Context, layout ResolvedLayout, fn func(string) error) error

WithEndpoint borrows the owner's operation scope without reacquiring locks.

type ControlCredentialFile added in v0.9.3

type ControlCredentialFile struct {
	// contains filtered or unexported fields
}

ControlCredentialFile is a daemon-only scoped capability for the selected C. It cannot be used after its WithCredential callback returns.

func (*ControlCredentialFile) Create added in v0.9.3

func (c *ControlCredentialFile) Create(ctx context.Context, raw []byte) error

Create publishes C without replacing any existing inode.

func (*ControlCredentialFile) Read added in v0.9.3

func (c *ControlCredentialFile) Read(ctx context.Context) (_ []byte, err error)

Read returns bounded, verified bytes without creating or repairing C.

type ControlLocator added in v0.9.3

type ControlLocator struct {
	Mode          LayoutMode
	BaseDir       string
	Endpoint      string
	Credential    string
	ExpectedOwner uint32
}

ControlLocator identifies the local control endpoint and credential owner.

type DirectoryIdentity added in v0.9.2

type DirectoryIdentity struct {
	// contains filtered or unexported fields
}

DirectoryIdentity is a closeable capability over a held directory handle.

func (*DirectoryIdentity) Close added in v0.9.2

func (d *DirectoryIdentity) Close() error

Close releases the duplicated directory handle. Repeat calls return nil.

type FileEntry added in v0.9.2

type FileEntry struct {
	Name     string
	Mode     os.FileMode
	Identity FileIdentity
}

FileEntry is a no-follow directory listing record.

type FileIdentity added in v0.9.2

type FileIdentity struct {
	// contains filtered or unexported fields
}

FileIdentity is an opaque platform identity for a directory entry or open handle.

func (FileIdentity) Key added in v0.9.3

func (id FileIdentity) Key() string

Key returns an opaque observation suitable for a same-boot journal identity. It cannot be parsed back into a FileIdentity authorization.

type InstallControl added in v0.9.3

type InstallControl struct {
	// contains filtered or unexported fields
}

InstallControl is a closeable capability over the fixed machine installation-control directory. Do not copy after first use.

func OpenInstallControlForUpdate added in v0.9.3

func OpenInstallControlForUpdate(ctx context.Context, lease *OwnedInstallLease) (_ *InstallControl, err error)

OpenInstallControlForUpdate opens fixed K using evidence from the already held global install lease. The lease must remain valid through mutations.

func OpenInstallControlReadOnly added in v0.9.3

func OpenInstallControlReadOnly(ctx context.Context) (_ *InstallControl, err error)

OpenInstallControlReadOnly opens fixed K without creating files or directories. It can inspect operation.lock and hold startup.lock.

func (*InstallControl) ArchiveState added in v0.9.3

func (c *InstallControl) ArchiveState(ctx context.Context, expectedSHA256 string) error

ArchiveState stores exactly the currently held state as the single bounded previous-state record. It never restores or changes state.json.

func (*InstallControl) Close added in v0.9.3

func (c *InstallControl) Close() error

Close releases the directory, held state, and any platform resources owned by the control capability. Independently returned locks remain caller-owned.

func (*InstallControl) ConfirmState added in v0.9.3

func (c *InstallControl) ConfirmState(ctx context.Context, expectedSHA256 string) error

ConfirmState proves durability of the matching version held by this capability and then re-reads its digest. It does not modify state.json.

func (*InstallControl) LockOperation added in v0.9.3

func (c *InstallControl) LockOperation(ctx context.Context) (*InstallControlLock, error)

LockOperation takes the permanent machine installation-operation lock.

func (*InstallControl) LockStartup added in v0.9.3

func (c *InstallControl) LockStartup(ctx context.Context) (*InstallControlLock, error)

LockStartup takes the permanent startup gate.

func (*InstallControl) ProbeOperation added in v0.9.3

func (c *InstallControl) ProbeOperation(ctx context.Context) (bool, error)

ProbeOperation reports whether another process holds operation.lock. The probe opens only the permanent existing file and releases its test lock.

func (*InstallControl) PublishState added in v0.9.3

func (c *InstallControl) PublishState(ctx context.Context, previousSHA256 string, next []byte) (InstallPublication, error)

PublishState conditionally replaces state.json when previousSHA256 still identifies the name-bound predecessor. Initial absence is handled only by atomic control-directory initialization.

func (*InstallControl) ReadState added in v0.9.3

func (c *InstallControl) ReadState(ctx context.Context) ([]byte, string, error)

ReadState reads the raw state bytes and their lowercase SHA-256 digest.

type InstallControlLock added in v0.9.3

type InstallControlLock struct {
	// contains filtered or unexported fields
}

InstallControlLock is a held permanent-file lock. Closing it releases the lock but never deletes its fixed lock file. Do not copy after first use.

func (*InstallControlLock) CheckWindowsStartupGate added in v0.9.3

func (l *InstallControlLock) CheckWindowsStartupGate() error

CheckWindowsStartupGate verifies that this is a live, held startup.lock capability. Windows service-state backends use it before registry mutation.

func (*InstallControlLock) Close added in v0.9.3

func (l *InstallControlLock) Close() error

Close releases the held byte-range lock. It is idempotent.

type InstallPublication added in v0.9.3

type InstallPublication struct {
	Published bool
	Durable   bool
}

InstallPublication separates namespace visibility from proven durability. Callers must not treat Published as Durable.

type LaunchdRuntimeControl added in v0.9.3

type LaunchdRuntimeControl struct {
	// contains filtered or unexported fields
}

LaunchdRuntimeControl is a closeable capability over the fixed global launchd-runtime record and its permanent startup gate. Do not copy after use.

func (*LaunchdRuntimeControl) Close added in v0.9.3

func (c *LaunchdRuntimeControl) Close() error

Close releases resources owned by the control. A returned gate remains caller-owned and held until its own Close.

func (*LaunchdRuntimeControl) ConfirmState added in v0.9.3

func (c *LaunchdRuntimeControl) ConfirmState(ctx context.Context, expectedSHA256 string) error

ConfirmState syncs and re-reads the matching held state without modifying it.

func (*LaunchdRuntimeControl) LockStartup added in v0.9.3

LockStartup takes the permanent nonblocking launchd runtime startup gate.

func (*LaunchdRuntimeControl) Publish added in v0.9.3

func (c *LaunchdRuntimeControl) Publish(ctx context.Context, previousSHA256 string, next []byte) error

Publish implements the app runtime-store adapter and succeeds only after a conditional publication is proven durable.

func (*LaunchdRuntimeControl) PublishState added in v0.9.3

func (c *LaunchdRuntimeControl) PublishState(ctx context.Context, previousSHA256 string, next []byte) (InstallPublication, error)

PublishState conditionally replaces state.json. The caller must hold this control's own live start.lock capability.

func (*LaunchdRuntimeControl) Read added in v0.9.3

Read returns the raw state bytes and their lowercase SHA-256 digest.

type LaunchdRuntimeGate added in v0.9.3

type LaunchdRuntimeGate struct {
	// contains filtered or unexported fields
}

LaunchdRuntimeGate is a held permanent start.lock capability. Closing it releases the lock without deleting the file. Do not copy after use.

func (*LaunchdRuntimeGate) Close added in v0.9.3

func (g *LaunchdRuntimeGate) Close() error

Close releases the held start.lock and is idempotent.

type LayoutDefaults added in v0.9.3

type LayoutDefaults struct {
	OS          string
	BaseDir     string
	InstallRoot string
	TrustedHome string
	SocketLimit int
}

LayoutDefaults contains trusted target-platform defaults.

func SystemLayoutDefaults added in v0.9.3

func SystemLayoutDefaults() LayoutDefaults

SystemLayoutDefaults returns the current platform's fixed machine defaults. It performs no IO and does not select a process mode.

type LayoutInput added in v0.9.3

type LayoutInput struct {
	CWD         string
	Data        string
	Endpoint    string
	Credential  string
	InstallRoot string
	Home        string
	XDGState    string
	EUID        uint32
}

LayoutInput contains process-captured values used to resolve a layout.

type LayoutMode added in v0.9.3

type LayoutMode string

LayoutMode identifies the ownership and discovery rules for a resolved layout.

const (
	SystemMode  LayoutMode = "system"
	PrivateMode LayoutMode = "private"
	WindowsMode LayoutMode = "windows"
)

type LockMode added in v0.9.2

type LockMode uint8

LockMode selects a shared or exclusive advisory lock.

const (
	// LockShared allows concurrent shared holders.
	LockShared LockMode = iota
	// LockExclusive denies concurrent holders.
	LockExclusive
)

type NetworkInterface added in v0.9.6

type NetworkInterface struct {
	Name         string
	Kind         string
	Availability string
	Addresses    []string
	// Description is the OS device description when it differs from Name.
	Description string
}

NetworkInterface contains local adapter identity and link state, not reachability.

func NetworkInterfaces added in v0.9.6

func NetworkInterfaces(ctx context.Context) ([]NetworkInterface, error)

NetworkInterfaces enumerates all adapters, including disabled and disconnected ones.

type OwnedBinaryLease added in v0.9.3

type OwnedBinaryLease struct {
	// contains filtered or unexported fields
}

OwnedBinaryLease owns only the verified binary-parent update lock.

func AcquireBinaryLease added in v0.9.3

func AcquireBinaryLease(ctx context.Context, parentPath string) (*OwnedBinaryLease, error)

AcquireBinaryLease locks an existing binary parent without acquiring service, private-data or daemon locks. The caller must separately verify its binary.

func (*OwnedBinaryLease) Close added in v0.9.3

func (l *OwnedBinaryLease) Close() error

Close releases the binary update lock and its retained parent.

func (*OwnedBinaryLease) Validate added in v0.9.3

func (l *OwnedBinaryLease) Validate(ctx context.Context, parentPath string) error

Validate checks the requested binary-parent scope and every retained identity.

type OwnedDaemonLease added in v0.9.3

type OwnedDaemonLease struct {
	// contains filtered or unexported fields
}

OwnedDaemonLease owns data and endpoint locks. Do not copy after use.

func AcquireDaemonLease added in v0.9.3

func AcquireDaemonLease(ctx context.Context, layout ResolvedLayout) (*OwnedDaemonLease, error)

AcquireDaemonLease obtains the data lock before the endpoint lock.

func (*OwnedDaemonLease) Borrow added in v0.9.3

Borrow returns a view that cannot close or unlock the owner.

func (*OwnedDaemonLease) Close added in v0.9.3

func (l *OwnedDaemonLease) Close() error

Close releases endpoint before data, after any borrowed operation finishes.

func (*OwnedDaemonLease) WithEndpoint added in v0.9.3

func (l *OwnedDaemonLease) WithEndpoint(ctx context.Context, layout ResolvedLayout, fn func(string) error) error

WithEndpoint validates the held namespace before and after a socket operation. The callback receives a pathname only; it must not retain the borrowed scope.

type OwnedInstallLease added in v0.9.3

type OwnedInstallLease struct {
	// contains filtered or unexported fields
}

OwnedInstallLease owns service-install locks. Do not copy after use.

func AcquireChannelLease added in v0.9.3

func AcquireChannelLease(ctx context.Context, layout ResolvedLayout) (*OwnedInstallLease, error)

AcquireChannelLease serializes fixed channel metadata with installations. Private maintenance owns only P/install.lock, including when invoked as root. It grants no data/endpoint or named-service lifecycle authority.

func AcquireInstallLease added in v0.9.3

func AcquireInstallLease(ctx context.Context, layout ResolvedLayout) (*OwnedInstallLease, error)

AcquireInstallLease obtains B then P for root private services, B for system services, or P alone for unprivileged private maintenance.

func AcquirePrivateBootstrapLease added in v0.9.3

func AcquirePrivateBootstrapLease(ctx context.Context, layout ResolvedLayout) (_ *OwnedInstallLease, err error)

AcquirePrivateBootstrapLease locks only P for a root foreground instance. This capability cannot authorize named system-service operations.

func (*OwnedInstallLease) BindInstallLayout added in v0.9.3

func (l *OwnedInstallLease) BindInstallLayout(ctx context.Context, layout ResolvedLayout) error

BindInstallLayout keeps the already held global lease while recovery resolves its private P from a verified private backup. It never reacquires B or releases an earlier P; all added locks remain owned by this same outer lease.

func (*OwnedInstallLease) Close added in v0.9.3

func (l *OwnedInstallLease) Close() error

Close releases endpoint/data/install locks in reverse acquisition order.

func (*OwnedInstallLease) Validate added in v0.9.3

func (l *OwnedInstallLease) Validate(ctx context.Context, layout ResolvedLayout, requireGlobal bool) error

Validate verifies install scope and retained identities. requireGlobal rejects an unprivileged maintenance lease when a system-service action is requested.

type Paths

type Paths struct {
	Root                string
	ControlToken        string
	Bin                 string
	CoreBinary          string
	RuntimeConfig       string
	Settings            string
	Onboarding          string
	LogDir              string
	DaemonLog           string
	TUILog              string
	MihomoLog           string
	LogExportDir        string
	Staging             string
	Subscriptions       string
	SubscriptionCatalog string
	SubscriptionCache   string
	SubscriptionStaging string
	TUIPreferences      string
	GeoIPCountry        string
	GeoIPASN            string
	GeoIPStaging        string
	WebRoot             string
	WebActive           string
	WebCredential       string
	PanelStaging        string
}

Paths is the on-disk layout under a single data root (default: $HOME/.mihari).

func DefaultPaths

func DefaultPaths() Paths

DefaultPaths returns the layout under DefaultDataRoot.

func NewPaths

func NewPaths(root string) Paths

NewPaths builds the standard layout under root.

func (Paths) Absolute added in v0.9.2

func (p Paths) Absolute() (Paths, error)

Absolute resolves Root with filepath.Abs/Clean and rebuilds every derived field via NewPaths. It does not EvalSymlinks; callers that need a trusted data-root identity must open NewPrivateFS on the absolute Root before EnsureDirs or default token IO. --help/--version must not call Absolute. root/LocalSystem missing-root failures fail closed with zero directory IO and must not be written into CLI SetupError; TUI may continue with PrivateFS=nil, daemon must not continue directory IO. Callers reuse one process-level PrivateFS and must not call NewPrivateFS again after EnsureDirs/Settings.

func (Paths) EnsureDirs

func (p Paths) EnsureDirs() error

EnsureDirs creates the durable directories under this layout. It may pre-create LogDir with MkdirAll but does not harden permissions or reject intermediate symlinks, and it does not create LogExportDir. Callers that need a local data root must establish NewPrivateFS(absolutePaths.Root) before EnsureDirs or default token IO; EnsureDirs is not the root create or harden entrypoint. The process-level PrivateFS from that call is reused by daemon/TUI; do not call NewPrivateFS again after EnsureDirs/Settings.

type PrivateFS added in v0.9.2

type PrivateFS struct {
	// contains filtered or unexported fields
}

PrivateFS is a closeable capability over a verified data-root directory.

func NewPrivateFS added in v0.9.2

func NewPrivateFS(dataRoot string) (*PrivateFS, error)

NewPrivateFS opens or creates an absolute data root and holds its identity.

func NewPrivateFSFromRoot added in v0.9.3

func NewPrivateFSFromRoot(root *TrustedRoot) (*PrivateFS, error)

NewPrivateFSFromRoot transfers a verified 0700 application root and all its retained ancestry into a logging capability. Failure leaves ownership with the caller; success makes the original root closed without releasing its fds.

func OpenClientLogFS added in v0.9.3

func OpenClientLogFS(ctx context.Context, layout ResolvedLayout) (result *PrivateFS, err error)

OpenClientLogFS owns only the current user's diagnostic tree. Existing user ancestors are verified without chmod; missing descendants are created only below a verified, current-user-owned anchor. Failure never falls back to D.

func (*PrivateFS) Close added in v0.9.2

func (fs *PrivateFS) Close() error

Close releases held directory handles. Repeat calls return nil.

func (*PrivateFS) CreateTemp added in v0.9.2

func (fs *PrivateFS) CreateTemp(dir, pattern string) (*os.File, error)

CreateTemp creates an exclusive temporary file in logs/ or logs-export/.

func (*PrivateFS) EnsureDir added in v0.9.2

func (fs *PrivateFS) EnsureDir(path string) error

EnsureDir creates or verifies logs/ or logs-export/ relative to the held root. Legacy path-based adapters may also repair their private access policy.

func (*PrivateFS) OpenAppend added in v0.9.2

func (fs *PrivateFS) OpenAppend(path string) (*os.File, error)

OpenAppend opens a log or export file for append-create, no-follow.

func (*PrivateFS) OpenDirIdentity added in v0.9.2

func (fs *PrivateFS) OpenDirIdentity(path string) (*DirectoryIdentity, error)

OpenDirIdentity duplicates a held logs/ or logs-export/ directory capability.

func (*PrivateFS) OpenPublishDir added in v0.9.2

func (fs *PrivateFS) OpenPublishDir(path string) (*PublishDir, error)

OpenPublishDir opens one of PrivateFS's verified child directories as a held publish capability.

func (*PrivateFS) OpenReadChecked added in v0.9.2

func (fs *PrivateFS) OpenReadChecked(path string, expected FileIdentity) (*os.File, error)

OpenReadChecked opens a file no-follow and requires the handle identity to match.

func (*PrivateFS) ReadDir added in v0.9.2

func (fs *PrivateFS) ReadDir(path string) ([]FileEntry, error)

ReadDir lists no-follow entries of logs/ or logs-export/.

func (*PrivateFS) Remove added in v0.9.2

func (fs *PrivateFS) Remove(path string) error

Remove unlinks a file in logs/ or logs-export/.

func (*PrivateFS) Rename added in v0.9.2

func (fs *PrivateFS) Rename(oldpath, newpath string) error

Rename renames a file within the same verified logs/ or logs-export/ directory.

func (*PrivateFS) RepairAccessChecked added in v0.9.2

func (fs *PrivateFS) RepairAccessChecked(path string, expected FileIdentity) error

RepairAccessChecked restores an existing file's private access policy after verifying its identity. It never creates or rewrites file content.

func (*PrivateFS) ReplaceEmpty added in v0.9.2

func (fs *PrivateFS) ReplaceEmpty(path string) error

ReplaceEmpty replaces path with a new empty inode. The caller must close its write handle first.

type PublishDir added in v0.9.2

type PublishDir struct {
	// contains filtered or unexported fields
}

PublishDir is a closeable capability over a held output directory.

func OpenPublishDir added in v0.9.2

func OpenPublishDir(path string) (*PublishDir, error)

OpenPublishDir opens an existing absolute directory. The selected path may resolve through a symlink or junction once; later operations use the held directory capability.

func (*PublishDir) Close added in v0.9.2

func (d *PublishDir) Close() error

Close releases the held publish directory. Repeated calls return nil.

func (*PublishDir) CreateWorkspace added in v0.9.2

func (d *PublishDir) CreateWorkspace() (*PublishWorkspace, error)

CreateWorkspace creates and holds a private child directory.

func (*PublishDir) Exists added in v0.9.2

func (d *PublishDir) Exists(name string) (bool, error)

Exists reports whether name exists in the held directory without following the directory's visible path.

func (*PublishDir) IsWithin added in v0.9.2

func (d *PublishDir) IsWithin(ancestor *DirectoryIdentity) (bool, error)

IsWithin reports whether the held publish directory is the held ancestor or one of its descendants.

func (*PublishDir) Path added in v0.9.2

func (d *PublishDir) Path() string

Path returns the immutable canonical absolute path captured at open time. It remains available after Close.

func (*PublishDir) PublishNoReplace added in v0.9.2

func (d *PublishDir) PublishNoReplace(workspace *PublishWorkspace, tempName, targetName string, onWarning func(error)) error

PublishNoReplace atomically publishes tempName into the held directory. It never replaces targetName. Once the target exists, later cleanup or sync failures are delivered to onWarning and success remains committed.

type PublishWorkspace added in v0.9.2

type PublishWorkspace struct {
	// contains filtered or unexported fields
}

PublishWorkspace is a private child directory held by identity.

func (*PublishWorkspace) Close added in v0.9.2

func (w *PublishWorkspace) Close() error

Close cleans held workspace contents and removes the directory only when its namespace is proved safe. All handles are closed even if cleanup fails. Repeated calls return nil.

func (*PublishWorkspace) CreateTemp added in v0.9.2

func (w *PublishWorkspace) CreateTemp(pattern string) (*os.File, string, error)

CreateTemp creates a private, exclusive temporary file relative to the held workspace and returns its single-segment basename.

func (*PublishWorkspace) Remove added in v0.9.2

func (w *PublishWorkspace) Remove(name string) error

Remove removes a non-reparse file relative to the held workspace.

type ReadOnlySource added in v0.9.3

type ReadOnlySource struct {
	// contains filtered or unexported fields
}

ReadOnlySource retains the source namespace and offers no mutation methods. Unlike TrustedRoot it permits user-owned ancestors: source bytes must still pass the installer's typed validation and independent executable verification.

func OpenReadOnlySource added in v0.9.3

func OpenReadOnlySource(ctx context.Context, path string) (_ *ReadOnlySource, err error)

OpenReadOnlySource anchors an existing local source without following links. Mount transitions are allowed before the anchor; descendants cannot cross one.

func (*ReadOnlySource) Close added in v0.9.3

func (r *ReadOnlySource) Close() error

Close waits for owned reads before releasing all retained source descriptors.

func (*ReadOnlySource) ContainsTrustedRoot added in v0.9.3

func (r *ReadOnlySource) ContainsTrustedRoot(ctx context.Context, target *TrustedRoot) (bool, error)

ContainsTrustedRoot checks whether target is the source itself or below it. This allows checking an absent migration target's retained creation parent without rejecting an unrelated source below that same parent.

func (*ReadOnlySource) ListNames added in v0.9.3

func (r *ReadOnlySource) ListNames(ctx context.Context, rel string) (names []string, err error)

ListNames lists bounded names beneath the anchor; entries are still untrusted.

func (*ReadOnlySource) OverlapsTrustedRoot added in v0.9.3

func (r *ReadOnlySource) OverlapsTrustedRoot(ctx context.Context, target *TrustedRoot) (bool, error)

OverlapsTrustedRoot compares the retained source and target ancestry after revalidating both namespaces. Device/inode identity deliberately ignores mount IDs, so alternate bind-mount names cannot hide a shared source/target tree.

func (*ReadOnlySource) Read added in v0.9.3

func (r *ReadOnlySource) Read(ctx context.Context, rel string, limit int64) (entry SourceEntry, raw []byte, err error)

Read observes one regular, single-link file and reads it with a strict bound. Metadata is checked again after IO so concurrent rewrites cannot become a snapshot.

func (*ReadOnlySource) Snapshot added in v0.9.3

func (r *ReadOnlySource) Snapshot(ctx context.Context) (string, string, error)

Snapshot returns the retained source identity after namespace revalidation.

func (*ReadOnlySource) Stat added in v0.9.3

func (r *ReadOnlySource) Stat(ctx context.Context, rel string, limit int64) (SourceEntry, error)

Stat observes metadata and hashes a bounded file without retaining its bytes. It applies the same namespace, identity and mutation checks as Read.

type ReplacementFile added in v0.9.3

type ReplacementFile struct {
	Path       string
	FileID     string
	SHA256     string
	Exists     bool
	MayExecute bool
}

ReplacementFile binds a replacement target to its observed contents and identity. Lack of execution trust does not imply absence.

func ObserveReplacementFile added in v0.9.3

func ObserveReplacementFile(ctx context.Context, path string) (out ReplacementFile, err error)

ObserveReplacementFile observes an absolute replacement target without writing it.

type ResolvedLayout added in v0.9.3

type ResolvedLayout struct {
	Mode            LayoutMode
	BaseDir         string
	Data            Paths
	ControlEndpoint string
	CredentialPath  string
	ChannelPath     string
	InstallRoot     string
	ClientLogs      Paths // zero value means diagnostics must remain in memory
}

ResolvedLayout is the pure, absolute path model consumed by later platform capabilities.

func CaptureLayout added in v0.9.3

func CaptureLayout(ctx context.Context) (ResolvedLayout, uint32, error)

CaptureLayout captures native process inputs once. It never creates business or diagnostic directories. An untrusted user home disables file diagnostics.

func ResolveLayout added in v0.9.3

func ResolveLayout(input LayoutInput, defaults LayoutDefaults) (ResolvedLayout, error)

ResolveLayout resolves process-captured inputs without filesystem access.

func (ResolvedLayout) Locator added in v0.9.3

func (l ResolvedLayout) Locator(euid uint32) (ControlLocator, error)

Locator derives the Unix control locator for a resolved layout.

type RootPolicy added in v0.9.3

type RootPolicy struct {
	Owner       uint32
	Mode        uint32
	AllowCreate bool
}

RootPolicy specifies the owner and exact permissions of an application directory. AllowCreate permits creation of only the final component.

type ServiceEntry added in v0.9.3

type ServiceEntry struct {
	Present     bool
	Link        string
	Bytes       []byte
	Mode, Owner uint32
	// contains filtered or unexported fields
}

ServiceEntry is an opaque retained observation for the narrow Unix service definition symlink exception. Its identity cannot be constructed by callers.

func (ServiceEntry) Key added in v0.9.3

func (s ServiceEntry) Key() string

Key returns observed identity for a durable backup record, not write authority.

type SourceEntry added in v0.9.3

type SourceEntry struct {
	Name, Kind, Identity, Mount, SHA256 string
	Size, Mtime, Ctime                  int64
	Nlink                               uint64
}

SourceEntry is an untrusted read-only migration observation. It grants no authority to publish a file or execute its bytes.

type TCPOccupant added in v0.7.3

type TCPOccupant struct {
	PID     int
	Process string
}

TCPOccupant is the process holding a local TCP listen address.

func LookupTCPOccupant added in v0.7.3

func LookupTCPOccupant(address string) (TCPOccupant, bool)

LookupTCPOccupant reports the process listening on address (host:port). Lookup failures return ok=false.

type TrustedRoot added in v0.9.3

type TrustedRoot struct {
	// contains filtered or unexported fields
}

TrustedRoot owns a directory descriptor and its verified namespace ancestry. A zero value is closed and cannot authorize IO. Do not copy after first use.

func OpenTrustedParent added in v0.9.3

func OpenTrustedParent(ctx context.Context, path string, owner uint32) (*TrustedRoot, error)

OpenTrustedParent opens an existing owner-controlled creation parent. It preserves its mode and verifies ancestry, filesystem and creation ACLs.

func OpenTrustedRoot added in v0.9.3

func OpenTrustedRoot(ctx context.Context, path string, policy RootPolicy) (*TrustedRoot, error)

OpenTrustedRoot opens a directory without following application symlinks.

func (*TrustedRoot) Close added in v0.9.3

func (r *TrustedRoot) Close() error

Close releases the retained descriptors. Repeated calls are harmless.

func (*TrustedRoot) ExchangeServiceEntryWith added in v0.9.3

func (r *TrustedRoot) ExchangeServiceEntryWith(ctx context.Context, name string, candidate ServiceEntry, to *TrustedRoot, target string, expected ServiceEntry) (published bool, err error)

ExchangeServiceEntryWith swaps two verified service objects atomically, keeping both recorded inodes available for a later recovery. Published remains true if either parent synchronization fails after the exchange.

func (*TrustedRoot) MoveDirTo added in v0.9.3

func (r *TrustedRoot) MoveDirTo(ctx context.Context, name string, child *TrustedRoot, to *TrustedRoot, target string) (published bool, err error)

MoveDirTo atomically publishes a held private staging directory. Destination must be absent. Both parent directories are synced and child ownership stays with the caller, which must close its old namespace capability after success.

func (*TrustedRoot) MoveFileTo added in v0.9.3

func (r *TrustedRoot) MoveFileTo(ctx context.Context, name string, id FileIdentity, to *TrustedRoot, target string, mode uint32, expected *FileIdentity) error

MoveFileTo publishes a held source inode into a held directory, including a same-parent backup using the same capability. Both roots remain owned by the caller; expected=nil requires absence. Callers serialize cross-directory moves under their lifecycle/transaction lease.

func (*TrustedRoot) MoveFileToPublished added in v0.9.3

func (r *TrustedRoot) MoveFileToPublished(ctx context.Context, name string, id FileIdentity, to *TrustedRoot, target string, mode uint32, expected *FileIdentity) (published bool, err error)

MoveFileToPublished reports the single rename commit even if parent sync fails.

func (*TrustedRoot) MoveServiceEntryTo added in v0.9.3

func (r *TrustedRoot) MoveServiceEntryTo(ctx context.Context, name string, candidate ServiceEntry, to *TrustedRoot, target string, expected ServiceEntry) error

MoveServiceEntryTo publishes an already private-staged service object while preserving its recorded inode. Both directory capabilities remain caller-owned.

func (*TrustedRoot) OpenDir added in v0.9.3

func (r *TrustedRoot) OpenDir(ctx context.Context, name string, p RootPolicy) (_ *TrustedRoot, err error)

OpenDir acquires one child beneath this anchor, rejecting nested mounts. The child owns independent retained descriptors and has the same owner.

func (*TrustedRoot) OpenFile added in v0.9.3

func (r *TrustedRoot) OpenFile(ctx context.Context, name string, maxMode uint32) (_ *os.File, _ FileIdentity, err error)

OpenFile opens one read-only regular file. maxMode is a permission ceiling.

func (*TrustedRoot) ReadNames added in v0.9.3

func (r *TrustedRoot) ReadNames(ctx context.Context) (names []string, err error)

ReadNames lists at most 4096 immediate names through the held directory. Names are observations only; callers must open children through this root.

func (*TrustedRoot) ReadServiceEntry added in v0.9.3

func (r *TrustedRoot) ReadServiceEntry(ctx context.Context, name string) (out ServiceEntry, err error)

ReadServiceEntry reads a unit/plist or a root-owned service link without following the link. The trusted parent remains owned by the caller.

func (*TrustedRoot) RemoveEmptyDir added in v0.9.3

func (r *TrustedRoot) RemoveEmptyDir(ctx context.Context, name string) (err error)

RemoveEmptyDir removes only a freshly verified, empty private child directory.

func (*TrustedRoot) RemoveFile added in v0.9.3

func (r *TrustedRoot) RemoveFile(ctx context.Context, name string, mode uint32, expected FileIdentity) error

RemoveFile unlinks only the exact previously opened regular inode.

func (*TrustedRoot) RemoveServiceEntry added in v0.9.3

func (r *TrustedRoot) RemoveServiceEntry(ctx context.Context, name string, expected ServiceEntry) error

RemoveServiceEntry removes only an exact held unit/plist/link observation.

func (*TrustedRoot) Snapshot added in v0.9.3

func (r *TrustedRoot) Snapshot(ctx context.Context) (path, identity string, owner, mode uint32, err error)

Snapshot returns freshly verified display/identity metadata, not a writable descriptor or authority setter. Ownership stays with the root capability.

func (*TrustedRoot) Sync added in v0.9.3

func (r *TrustedRoot) Sync(ctx context.Context) error

Sync makes the held directory durable after checking its namespace.

func (*TrustedRoot) WriteFile added in v0.9.3

func (r *TrustedRoot) WriteFile(ctx context.Context, name string, data []byte, mode uint32, expected *FileIdentity) error

WriteFile atomically publishes bytes through an exclusive 0600 temporary inode. A nil expected identity requests no-replace publication; a non-nil identity authorizes replacement of exactly that previously observed inode.

func (*TrustedRoot) WriteFileWithIdentity added in v0.9.3

func (r *TrustedRoot) WriteFileWithIdentity(ctx context.Context, name string, data []byte, mode uint32, expected *FileIdentity) (identity *FileIdentity, err error)

WriteFileWithIdentity also reports the published inode when a later sync or descriptor-close operation fails. A nil identity means no publication occurred.

func (*TrustedRoot) WriteServiceEntry added in v0.9.3

func (r *TrustedRoot) WriteServiceEntry(ctx context.Context, name string, body []byte, link string, mode uint32, expected ServiceEntry) (err error)

WriteServiceEntry atomically replaces exactly the observed unit/plist/link. Link publication is reserved for service masks and enable links; application data writers continue using WriteFile, which rejects symlinks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL