:py:mod:`dissect.target.filesystems.nfs` ======================================== .. py:module:: dissect.target.filesystems.nfs Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: dissect.target.filesystems.nfs.NfsFilesystem dissect.target.filesystems.nfs.NfsDirEntry dissect.target.filesystems.nfs.NfsFilesystemEntry dissect.target.filesystems.nfs.NfsStream Attributes ~~~~~~~~~~ .. autoapisummary:: dissect.target.filesystems.nfs.ConCredentials dissect.target.filesystems.nfs.ConVerifier dissect.target.filesystems.nfs.ClientFactory dissect.target.filesystems.nfs.AuthSetter .. py:data:: ConCredentials .. py:data:: ConVerifier .. py:data:: ClientFactory .. py:data:: AuthSetter .. py:exception:: AuthFlavorNotSupported(supported_flavors: list[int], provided_flavor: int) Bases: :py:obj:`Exception` Common base class for all non-exit exceptions. .. py:attribute:: supported .. py:attribute:: provided .. py:method:: __str__() -> str Return str(self). .. py:class:: NfsFilesystem(client_factory: ClientFactory, root_handle: dissect.target.helpers.nfs.nfs3.FileHandle) Bases: :py:obj:`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. .. py:attribute:: __type__ :value: 'nfs' A short string identifying the type of filesystem. .. py:method:: 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) -> Self :classmethod: Utility function to setup a connection to a NFS share. :param hostname: The remote hostname. :param port: The remote port. :param auth: The authentication scheme. :param 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. :param timeout_in_seconds: The timeout for making the connection. .. py:method:: detect(_: BinaryIO) -> bool :staticmethod: Detect whether the ``fh`` file-handle is supported by this ``Filesystem`` implementation. The position of ``fh`` will be restored before returning. :param fh: A file-like object, usually a disk or partition. :returns: ``True`` if ``fh`` is supported, ``False`` otherwise. .. py:method:: get(path: str, relentry: NfsFilesystemEntry | None = None) -> NfsFilesystemEntry Get a filesystem entry. :param path: The path to the entry. The path is relative to ``relentry``, if provided. :param relentry: The relative entry to start from. If not provided, the root entry is used. .. py:class:: NfsDirEntry(fs: Filesystem, path: str, name: str, entry: Any) Bases: :py:obj:`dissect.target.filesystem.DirEntry` Directory entry base class. Closely models ``os.DirEntry``. Filesystem implementations are encouraged to subclass this class to provide efficient implementations of the various methods. :param fs: The filesystem the entry belongs to. :param path: The path of the parent directory. :param name: The name of the entry. :param entry: The raw entry backing this directory entry. .. py:attribute:: fs :type: NfsFilesystem The filesystem the entry belongs to. .. py:attribute:: entry :type: dissect.target.helpers.nfs.nfs3.EntryPlus The raw entry backing this directory entry. .. py:method:: get() -> NfsFilesystemEntry Retrieve the :class:`FilesystemEntry` this directory entry points to. Subclasses should override this method to provide an efficient implementation. .. py:method:: stat(*, follow_symlinks: bool = True) -> dissect.target.helpers.fsutil.stat_result .. py:class:: NfsFilesystemEntry(fs: NfsFilesystem, path: str, file_handle: dissect.target.helpers.nfs.nfs3.FileHandle, attributes: dissect.target.helpers.nfs.nfs3.FileAttributes | None = None) Bases: :py:obj:`dissect.target.filesystem.FilesystemEntry` Base class for filesystem entries. .. py:attribute:: fs :type: NfsFilesystem .. py:attribute:: entry :type: dissect.target.helpers.nfs.nfs3.FileHandle .. py:method:: get(path: str) -> NfsFilesystemEntry Get a new filesystem entry relative to this entry .. py:method:: is_file(follow_symlinks: bool = True) -> bool Determine if this entry is a file. :param 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). .. py:method:: is_dir(follow_symlinks: bool = True) -> bool Determine if this entry is a directory. :param 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). .. py:method:: is_symlink() -> bool Determine whether this entry is a symlink. :returns: ``True`` if the entry is a symbolic link, ``False`` otherwise. .. py:method:: readlink() -> str 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. .. py:method:: readlink_ext() -> NfsFilesystemEntry Read the link where this entry points to, return the resulting path as :class:`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. .. py:method:: scandir() -> collections.abc.Iterator[NfsDirEntry] Iterate over the contents of a directory, yields :class:`FilesystemEntry`. :returns: An iterator of :class:`FilesystemEntry`. .. py:method:: open() -> NfsStream Open this filesystem entry. :returns: A file-like object. Resolves symlinks when possible .. py:method:: 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. :param follow_symlinks: Whether to resolve the symbolic link if this entry is a symbolic link. :returns: The stat information of this entry. .. py:method:: 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. .. py:class:: NfsStream(client: dissect.target.helpers.nfs.client.nfs.Client, file_handle: dissect.target.helpers.nfs.nfs3.FileHandle, size: int | None) Bases: :py:obj:`dissect.util.stream.AlignedStream` Basic buffered stream that provides aligned reads. Must be subclassed for various stream implementations. Subclasses can implement: - :meth:`~AlignedStream._read` - :meth:`~AlignedStream._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. :param size: The size of the stream. This is used in read and seek operations. ``None`` if unknown. :param align: The alignment size. Read operations are aligned on this boundary. Also determines buffer size. .. automethod:: _read .. automethod:: _seek