platform

package
v0.9.2-dev.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: GPL-3.0 Imports: 20 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 ErrIdentityMismatch = errors.New("private fs file identity mismatch")

ErrIdentityMismatch is returned when OpenReadChecked sees a different identity.

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 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 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 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 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 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.

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 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.

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 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 (*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 hardens logs/ or logs-export/ relative to the held root.

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) 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) 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 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.

Jump to

Keyboard shortcuts

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