dissect.target.filesystems.nfs

Module Contents

Classes

NfsFilesystem

Filesystem implementation of a NFS share

NfsFilesystemEntry

Base class for filesystem entries.

NfsStream

Basic buffered stream that provides aligned reads.

Attributes

dissect.target.filesystems.nfs.ConCredentials
dissect.target.filesystems.nfs.ConVerifier
dissect.target.filesystems.nfs.ClientFactory
dissect.target.filesystems.nfs.AuthSetter
exception dissect.target.filesystems.nfs.AuthFlavorNotSupported(supported_flavors: list[int], provided_flavor: int)

Bases: Exception

Common base class for all non-exit exceptions.

supported
provided
__str__() str

Return str(self).

class dissect.target.filesystems.nfs.NfsFilesystem(client_factory: ClientFactory, root_handle: dissect.target.helpers.nfs.nfs3.FileHandle)

Bases: dissect.target.filesystem.Filesystem

Filesystem implementation of a NFS share

The connection is lazily established to not waste resources. Use the connect method to conveniently create a new instance.

__type__ = 'nfs'

A short string identifying the type of filesystem.

classmethod connect(address: str, exported_dir: str, auth: dissect.target.helpers.sunrpc.client.AuthScheme[ConCredentials, ConVerifier] | AuthSetter, local_port: int | dissect.target.helpers.sunrpc.client.LocalPortPolicy = 0, timeout_in_seconds: float | None = 5.0) typing_extensions.Self

Utility function to setup a connection to a NFS share.

Parameters:
  • hostname – The remote hostname.

  • port – The remote port.

  • auth – The authentication scheme.

  • local_port – The local port to bind to. If equal to LocalPortPolicy.PRIVILEGED or -1, bind to the first free privileged port. If equal to LocalPortPolicy.ANY or 0, bind to any free port. Otherwise, bind to the specified port.

  • timeout_in_seconds – The timeout for making the connection.

static detect(_: BinaryIO) bool

Detect whether the fh file-handle is supported by this Filesystem implementation.

The position of fh will be restored before returning.

Parameters:

fh – A file-like object, usually a disk or partition.

Returns:

True if fh is supported, False otherwise.

get(path: str, relentry: NfsFilesystemEntry | None = None) NfsFilesystemEntry

Get a filesystem entry.

Parameters:
  • path – The path to the entry. The path is relative to relentry, if provided.

  • relentry – The relative entry to start from. If not provided, the root entry is used.

class dissect.target.filesystems.nfs.NfsFilesystemEntry(fs: NfsFilesystem, path: str, file_handle: dissect.target.helpers.nfs.nfs3.FileHandle, attributes: dissect.target.helpers.nfs.nfs3.FileAttributes | None = None)

Bases: dissect.target.filesystem.FilesystemEntry

Base class for filesystem entries.

fs: NfsFilesystem
entry: dissect.target.helpers.nfs.nfs3.FileHandle
get(path: str) NfsFilesystemEntry

Get a new filesystem entry relative to this entry

is_file(follow_symlinks: bool = True) bool

Determine if this entry is a file.

Parameters:

follow_symlinks – Whether to resolve the entry if it is a symbolic link.

Returns:

True if the entry is a file or a symbolic link to a file, return False otherwise. If follow_symlinks is False, return True only if the entry is a file (without following symlinks).

is_dir(follow_symlinks: bool = True) bool

Determine if this entry is a directory.

Parameters:

follow_symlinks – Whether to resolve the entry if it is a symbolic link.

Returns:

True if the entry is a directory or a symbolic link to a directory, return False otherwise. If follow_symlinks is False, return True only if the entry is a directory (without following symlinks).

Determine whether this entry is a symlink.

Returns:

True if the entry is a symbolic link, False otherwise.

Read the link where this entry points to, return the resulting path as string.

If it is a symlink and returns the entry that corresponds to that path. This means it follows the path a link points to, it tries to do it recursively.

Returns:

The path the link points to.

Read the link where this entry points to, return the resulting path as FilesystemEntry.

If it is a symlink and returns the string that corresponds to that path. This means it follows the path a link points to, it tries to do it recursively.

Returns:

The filesystem entry the link points to.

iterdir() collections.abc.Iterator[str]

Iterate over the contents of a directory, return them as strings.

Returns:

An iterator of directory entries as path strings.

scandir() collections.abc.Iterator[dissect.target.filesystem.FilesystemEntry]

Iterate over the contents of a directory, yields FilesystemEntry.

Returns:

An iterator of FilesystemEntry.

open() NfsStream

Open this filesystem entry.

Returns:

A file-like object. Resolves symlinks when possible

stat(follow_symlinks: bool = True) dissect.target.helpers.fsutil.stat_result

Determine the stat information of this entry.

If the entry is a symlink and follow_symlinks is True, it gets resolved, attempting to stat the path where it points to.

Parameters:

follow_symlinks – Whether to resolve the symbolic link if this entry is a symbolic link.

Returns:

The stat information of this entry.

lstat() dissect.target.helpers.fsutil.stat_result

Determine the stat information of this entry, without resolving the symlinks.

When it detects a symlink, it will stat the information of the symlink, not the path it points to.

Returns:

The stat information of this entry.

class dissect.target.filesystems.nfs.NfsStream(client: dissect.target.helpers.nfs.client.nfs.Client, file_handle: dissect.target.helpers.nfs.nfs3.FileHandle, size: int | None)

Bases: dissect.util.stream.AlignedStream

Basic buffered stream that provides aligned reads.

Must be subclassed for various stream implementations. Subclasses can implement:
  • _read()

  • _seek()

The offset and length for _read are guaranteed to be aligned for streams of a known size. If your stream has an unknown size (i.e. size == None), reads of length -1 (i.e. read until EOF) will be passed through to your implementation of _read. The only time that overriding _seek would make sense is if there’s no known size of your stream, but still want to provide SEEK_END functionality.

Most subclasses of AlignedStream take one or more file-like objects as source. Operations on these subclasses, like reading, will modify the source file-like object as a side effect.

Parameters:
  • size – The size of the stream. This is used in read and seek operations. None if unknown.

  • align – The alignment size. Read operations are aligned on this boundary. Also determines buffer size.

_read(offset: int, size: int) bytes

Read method that backs this aligned stream.

_seek(pos: int, whence: int = 0) int

Calculate and return the new stream position after a seek.