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

Chown when Scapy is run with sudo #4566

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion scapy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,38 @@ def _read_config_file(cf, _globals=globals(), _locals=locals(),
return
# We have a default ! set it
try:
cf_path.parent.mkdir(parents=True, exist_ok=True)
if not cf_path.parent.exists():
cf_path.parent.mkdir(parents=True, exist_ok=True)
if (
not WINDOWS and
"SUDO_UID" in os.environ and
"SUDO_GID" in os.environ
):
# Was started with sudo. Still, chown to the user.
try:
os.chown(
cf_path.parent,
int(os.environ["SUDO_UID"]),
int(os.environ["SUDO_GID"]),
)
except Exception:
pass
with cf_path.open("w") as fd:
fd.write(default)
if (
not WINDOWS and
"SUDO_UID" in os.environ and
"SUDO_GID" in os.environ
):
# Was started with sudo. Still, chown to the user.
try:
os.chown(
cf_path,
int(os.environ["SUDO_UID"]),
int(os.environ["SUDO_GID"]),
)
except Exception:
pass
log_loading.debug("Config file [%s] created with default.", cf)
except OSError:
log_loading.warning("Config file [%s] could not be created.", cf,
Expand Down
Loading