Documentation
¶
Index ¶
- Variables
- func AbsoluteDataRoot() (string, error)
- func AbsoluteInstallRoot() (string, error)
- func AbsoluteInstalledBinaryPath() (string, error)
- func ChannelDataRoot() (string, error)
- func ChannelPath() (string, error)
- func DefaultDataRoot() string
- func InstallRoot() string
- func InstalledBinaryName() string
- func InstalledBinaryPath() string
- func OpenBrowser(url string) error
- func OpenSnapshot(fs *PrivateFS, path string, expected FileIdentity) (*os.File, error)
- func OwnChannelWrite(path string, newParent bool) error
- func Relaunch(binary string, args, env []string) error
- func StageInstalledBinary(source string) (string, error)
- type AdvisoryLock
- type DirectoryIdentity
- type FileEntry
- type FileIdentity
- type LockMode
- type Paths
- type PrivateFS
- func (fs *PrivateFS) Close() error
- func (fs *PrivateFS) CreateTemp(dir, pattern string) (*os.File, error)
- func (fs *PrivateFS) EnsureDir(path string) error
- func (fs *PrivateFS) OpenAppend(path string) (*os.File, error)
- func (fs *PrivateFS) OpenDirIdentity(path string) (*DirectoryIdentity, error)
- func (fs *PrivateFS) OpenPublishDir(path string) (*PublishDir, error)
- func (fs *PrivateFS) OpenReadChecked(path string, expected FileIdentity) (*os.File, error)
- func (fs *PrivateFS) ReadDir(path string) ([]FileEntry, error)
- func (fs *PrivateFS) Remove(path string) error
- func (fs *PrivateFS) Rename(oldpath, newpath string) error
- func (fs *PrivateFS) ReplaceEmpty(path string) error
- type PublishDir
- func (d *PublishDir) Close() error
- func (d *PublishDir) CreateWorkspace() (*PublishWorkspace, error)
- func (d *PublishDir) Exists(name string) (bool, error)
- func (d *PublishDir) IsWithin(ancestor *DirectoryIdentity) (bool, error)
- func (d *PublishDir) Path() string
- func (d *PublishDir) PublishNoReplace(workspace *PublishWorkspace, tempName, targetName string, ...) error
- type PublishWorkspace
- type TCPOccupant
Constants ¶
This section is empty.
Variables ¶
var ErrIdentityMismatch = errors.New("private fs file identity mismatch")
ErrIdentityMismatch is returned when OpenReadChecked sees a different identity.
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.
var ErrPublishDirectoryChanged = errors.New("publish directory changed")
ErrPublishDirectoryChanged reports that the visible path no longer names the held publish directory.
Functions ¶
func AbsoluteDataRoot ¶
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 ¶
AbsoluteInstallRoot returns InstallRoot as a cleaned absolute path.
func AbsoluteInstalledBinaryPath ¶
AbsoluteInstalledBinaryPath returns the absolute path of the installed binary.
func ChannelDataRoot ¶ added in v0.9.0
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
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 ¶
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
OpenSnapshot opens a no-follow read handle whose identity must match expected.
func OwnChannelWrite ¶ added in v0.9.0
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
Relaunch replaces the current process with the updated Mihari binary.
func StageInstalledBinary ¶
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
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.
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 (Paths) Absolute ¶ added in v0.9.2
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 ¶
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
NewPrivateFS opens or creates an absolute data root and holds its identity.
func (*PrivateFS) Close ¶ added in v0.9.2
Close releases held directory handles. Repeat calls return nil.
func (*PrivateFS) CreateTemp ¶ added in v0.9.2
CreateTemp creates an exclusive temporary file in logs/ or logs-export/.
func (*PrivateFS) EnsureDir ¶ added in v0.9.2
EnsureDir creates or hardens logs/ or logs-export/ relative to the held root.
func (*PrivateFS) OpenAppend ¶ added in v0.9.2
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
OpenReadChecked opens a file no-follow and requires the handle identity to match.
func (*PrivateFS) ReadDir ¶ added in v0.9.2
ReadDir lists no-follow entries of logs/ or logs-export/.
func (*PrivateFS) Rename ¶ added in v0.9.2
Rename renames a file within the same verified logs/ or logs-export/ directory.
func (*PrivateFS) ReplaceEmpty ¶ added in v0.9.2
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
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 TCPOccupant ¶ added in v0.7.3
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.