Skip to content

Commit

Permalink
Fix logs permission
Browse files Browse the repository at this point in the history
  • Loading branch information
D3vil0p3r committed Nov 11, 2024
1 parent 8f41087 commit 3518de0
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions empire/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ def setup_logging(args):
log_level = logging.getLevelName(empire_config.logging.level.upper())

log_dir = empire_config.logging.directory
log_dir.mkdir(parents=True, exist_ok=True)

try:
log_dir.mkdir(parents=True, exist_ok=True)
except PermissionError:
user_home = Path.home()
log_dir = user_home / ".empire" / "server" / "downloads" / "logs"
log.debug(f"Permission denied to create logs in the directory specified in the configuration file. Logs will be stored in {log_dir}")
log_dir.mkdir(parents=True, exist_ok=True)

root_log_file = log_dir / "empire_server.log"
root_logger = logging.getLogger()
# If this isn't set to DEBUG, then we won't see debug messages from the listeners.
Expand All @@ -52,19 +60,6 @@ def setup_logging(args):
root_logger_stream_handler.setLevel(log_level)
root_logger.addHandler(root_logger_stream_handler)

try:
user = os.getenv("SUDO_USER")
if user:
user_info = pwd.getpwnam(user)
os.chown(root_log_file, user_info.pw_uid, user_info.pw_gid)
log.debug(f"Log file owner changed to {user}.")
else:
log.warning("Log file owner not changed. SUDO_USER not found.")
except KeyError:
log.error("User not found. Log file owner not changed.")
except PermissionError:
log.error("Permission denied. You need root privileges to change file owner.")


CSHARP_DIR_BASE = os.path.join(os.path.dirname(__file__), "csharp/Covenant")
INVOKE_OBFS_SRC_DIR_BASE = os.path.join(
Expand Down

0 comments on commit 3518de0

Please sign in to comment.