Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse hostname from /proc/sys/kernel/hostname #704

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CinisSec
Copy link

Adds the /proc/sys/kernel/hostname path to the paths mentioned in issue 606

@CinisSec CinisSec marked this pull request as ready for review May 13, 2024 19:49
@Miauwkeru Miauwkeru linked an issue May 14, 2024 that may be closed by this pull request
@Miauwkeru
Copy link
Contributor

Could you change the title of the PR and your commit message according to our commit style guidelines?

https://docs.dissect.tools/en/latest/contributing/style-guide.html#commit-message-style-and-formatting

@@ -149,7 +149,7 @@ def _parse_hostname_string(self, paths: Optional[list[str]] = None) -> Optional[
paths (list): list of paths
"""
redhat_legacy_path = "/etc/sysconfig/network"
paths = paths or ["/etc/hostname", "/etc/HOSTNAME", redhat_legacy_path]
paths = paths or ["/etc/hostname", "/etc/HOSTNAME", "/proc/sys/kernel/hostname", redhat_legacy_path]
Copy link
Contributor

@Paradoxis Paradoxis May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always want to add the file, or only when a user doesn't specify their own paths? If we always want to include the file you're better off cloning the paths, and merging these four hostname paths together:

If the list order doesn't matter you can combine the two and cast it to a set to make the values unique:

paths = set(paths + ["/etc/hostname", "/etc/HOSTNAME", "/proc/sys/kernel/hostname", redhat_legacy_path])

If the list order does matter, just create a copy and add each unique item to it:

paths = paths.copy()  # ensures that we don't modify the existing list in-place
for path in ["/etc/hostname", "/etc/HOSTNAME", "/proc/sys/kernel/hostname", redhat_legacy_path]:
    if path not in paths:
        paths.append(path)

@Horofic Horofic changed the title adding "/proc/sys/kernel/hostname" to paths in _parse_hostname_string Parse hostname from /proc/sys/kernel/hostname Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse hostname from /proc/sys/kernel/hostname for Unix
3 participants