dissect.target.filesystems.config
#
Module Contents#
Classes#
A special |
|
A Special filesystem entry. |
Attributes#
- dissect.target.filesystems.config.log#
- class dissect.target.filesystems.config.ConfigurationFilesystem(target: dissect.target.Target, path: str, **kwargs)#
Bases:
dissect.target.filesystem.VirtualFilesystem
A special
Filesystem
class that allows you to browse and interact with configuration files asdirectories
andfiles
by parsing the file into key/value pairs.- Depending on the
value
of a configuration file’skey
, it will act like adirectory
orfile
: When the
key
contains sub-values (dictionary), it will act like adirectory
.Otherwise it will act like a
file
.
Examples
>>> fs = ConfigurationFilesystem(target, "/etc") >>> entry = fs.get("xattr.conf") <ConfigurationEntry path=/etc/xattr.conf value=<dissect.target.helpers.configutil.Default object at 0x115683280> >>> entry.listdir() # listed entries are the keys in the configuration file [... 'system.posix_acl_access', 'system.posix_acl_default', 'trusted.SGI_ACL_DEFAULT', 'trusted.SGI_ACL_FILE', ...] >>> entry.get("system.posix_acl_access") # returns the value of the key <ConfigurationEntry path=/etc/xattr.conf/system.posix_acl_access value=permissions> >>> entry.get("system.posix_acl_access").open().read() # returns the raw value of the key b'permissions\n'
- __type__: str = 'META:configuration'#
- get(path: str, relentry: dissect.target.filesystem.FilesystemEntry | None = None, *args, **kwargs) dissect.target.filesystem.FilesystemEntry | ConfigurationEntry #
Retrieve a
ConfigurationEntry
orFilesystemEntry
relative to the root orrelentry
.- Raises:
FileNotFoundError – if it could not find the entry.
- Depending on the
- class dissect.target.filesystems.config.ConfigurationEntry(fs: dissect.target.filesystem.Filesystem, path: str, entry: dissect.target.filesystem.FilesystemEntry, parser_items: dict | dissect.target.helpers.configutil.ConfigurationParser | str | list | None = None)#
Bases:
dissect.target.filesystem.FilesystemEntry
A Special filesystem entry.
Behaves like a
directory
whenparser_items
is aConfigurationParser
or adict
. Behaves like afile
otherwise.- parser_items#
A dict-like object containing all configuration entries and values. In most cases this is either a
ConfigurationParser
ordict
. Otherwise, its the entry’s value
Examples
>>> fs = ConfigurationFilesystem(target, "/etc") >>> entry = fs.get("xattr.conf") <ConfigurationEntry path=/etc/xattr.conf value=<dissect.target.helpers.configutil.Default object at 0x115683280> >>> entry.listdir() # listed entries are the keys in the configuration file [... 'system.posix_acl_access', 'system.posix_acl_default', 'trusted.SGI_ACL_DEFAULT', 'trusted.SGI_ACL_FILE', ...] >>> entry.as_dict() { ... "system.posix_acl_access" : "...", ... } >>> entry.get("system.posix_acl_access") # returns the value of the key <ConfigurationEntry path=/etc/xattr.conf/system.posix_acl_access value=permissions> >>> entry.get("system.posix_acl_access").open().read() # returns the raw value of the key b'permissions\n'
- __getitem__(item: str) ConfigurationEntry #
- __repr__() str #
Return repr(self).
- get(key, default: Any | None = None) ConfigurationEntry | Any | None #
Gets the dictionary key that belongs to this entry using
key
. Behaves likedictionary.get()
.- Parameters:
key – A dictionary key that is inside
parser_items
.default – The default value to return if
key
is not inside this entry.
- Returns:
a
ConfigurationEntry
whenkey
is present, otherwise itsdefault
.
- open() BinaryIO #
Open this
ConfigurationEntry
.If
parser_items
is aConfigurationParser
, it willopen
the underlying entry.- Returns:
A file-like object holding a byte representation of
parser_items
.
- iterdir() Iterator[str] #
Iterate over the contents of a directory, return them as strings.
- Returns:
An iterator of directory entries as path strings.
- scandir() Iterator[ConfigurationEntry] #
Return the items inside
parser_items
asConfigurationEntries
.
- 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, returnFalse
otherwise. Iffollow_symlinks
isFalse
, returnTrue
only if the entry is a file (without following symlinks).
- is_dir(follow_symlinks: bool = True) bool #
Returns whether this
ConfigurationEntry
can be considered a directory.
- is_symlink() bool #
Return whether this
ConfigurationEntry
is a symlink or not.- Returns:
False, as
ConfigurationEntries
are never symlinks.
- exists(key: str) bool #
Return whether the underlying
FilesystemEntry
entry
and suppliedkey
exists inside thisConfigurationEntry
.- Returns:
Whether the
entry
andkey
exists
- stat(follow_symlinks: bool = True) dissect.target.helpers.fsutil.stat_result #
Returns the stat from the underlying
FilesystemEntry
entry
.
- lstat() dissect.target.helpers.fsutil.stat_result #
Returns the lstat from the underlying
FilesystemEntry
entry
.
- as_dict() dict #
Returns
parser_items
as a dictionary.