Documentation
¶
Overview ¶
Package fs provides a virtual filesystem interface for SCALIBR scans and related helper functions.
Index ¶
- func GetRealPath(root *ScanRoot, path string, reader io.Reader) (string, error)
- func NewReaderAt(ioReader io.Reader) (io.ReaderAt, error)
- func OpenOSFile(root *ScanRoot, path string, reader io.Reader) (*os.File, func() error, error)
- func OpenOSPath(root *ScanRoot, path string, reader io.Reader) (string, func() error, error)
- func SQLiteReadOnlyURI(osPath string) string
- type FS
- type ScanRoot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRealPath ¶ added in v0.3.1
GetRealPath copies the file into an isolated temporary directory on the scanning host's filesystem and returns its absolute path. It is up to the caller to delete the temporary directory (filepath.Dir(realPath)) once they are done using it.
Prefer OpenOSPath or OpenOSFile when an isolated copy is not always required.
Sample code to delete the directory: ``` realPath := GetRealPath(...) dir := filepath.Dir(realPath)
if err := os.RemoveAll(dir); err != nil {
log.Errorf("os.RemoveAll(%q): %v", dir, err)
}
func NewReaderAt ¶ added in v0.1.6
NewReaderAt converts an io.Reader into an io.ReaderAt.
func OpenOSFile ¶ added in v0.5.4
OpenOSFile returns an *os.File handle for the target file along with a cleanup function that closes the file and removes any temporary copy that had to be created. On real filesystems, it returns the *os.File opened directly from root.FS without copying the file to a temporary directory.
func OpenOSPath ¶ added in v0.5.4
OpenOSPath returns a host filesystem path for the target file along with a cleanup function that removes any temporary copy that had to be created. On unconfined real filesystems (os.DirFS), it returns the in-place file path without copying; on confined or virtual filesystems, it copies the file into an isolated temporary directory so database engines cannot follow sibling (-wal/-journal/-shm) symlinks.
func SQLiteReadOnlyURI ¶ added in v0.5.4
SQLiteReadOnlyURI encodes a host filesystem path as a read-only, immutable SQLite file: URI. Escaping prevents special characters in host paths (such as '?') from injecting SQLite URI query parameters (e.g. _pragma), and immutable=1 allows reading WAL-mode databases in read-only or unprivileged directories without creating -wal/-shm sidecar files.
Types ¶
type FS ¶
FS is a filesystem interface that allows the opening of files, reading of directories, and performing stat on files.
FS implementations may return ErrNotImplemented for `Open`, `ReadDir` and `Stat`. Extractor implementations must decide whether the error is fatal or can be ignored.
FS implementations MUST implement io.ReaderAt for opened files to enable random access.
func DirFS ¶
DirFS returns an FS implementation that accesses the real filesystem at the given root, confined to root via os.Root. The underlying os.Root handle is opened lazily on first access and can be released via Close.
func Sub ¶ added in v0.5.4
Sub returns an FS corresponding to the subtree rooted at dir within fsys. This is analogous to io/fs.Sub but preserves the scalibr FS interface (ReadDir and Stat). dir must be a slash-separated, relative path. The returned FS performs no validation of the names it is given, so it should only be used with trusted paths.
type ScanRoot ¶
type ScanRoot struct {
// A virtual filesystem for file access, rooted at the scan root.
FS FS
// The path of the scan root. Empty if this is a virtual filesystem and the
// scanning environment doesn't support the DirectFS requirement.
Path string
}
ScanRoot defines a root directory to start a scan from. mounted to a local dir.
func RealFSScanRoot ¶
RealFSScanRoot returns a ScanRoot array the given root path on the real filesystem SCALIBR is running on.
func RealFSScanRoots ¶
RealFSScanRoots returns a one-element ScanRoot array representing the given root path on the real filesystem SCALIBR is running on.
func (*ScanRoot) IsVirtual ¶
IsVirtual returns true if the scan root represents the root of a virtual filesystem, i.e. one with no real location on the disk of the scanned host.
func (*ScanRoot) WithAbsolutePath ¶
WithAbsolutePath returns a copy of the ScanRoot with the Path set an absolute path.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package diriterate provides a utility for iterating over the contents of a directory without loading all of it into memory at once.
|
Package diriterate provides a utility for iterating over the contents of a directory without loading all of it into memory at once. |