Agent: Move `pwd`'s import statement to avoid using try/except

This commit is contained in:
Shreya Malviya 2022-02-22 17:49:08 +05:30
parent e47239f81c
commit f0679ebb26
1 changed files with 2 additions and 5 deletions

View File

@ -1,11 +1,6 @@
import glob
import logging
import os
try: # can't import on Windows
import pwd
except ModuleNotFoundError:
pass
from typing import Dict, Iterable
from common.utils.attack_utils import ScanStatus
@ -34,6 +29,8 @@ def get_ssh_info(telemetry_messenger: ITelemetryMessenger) -> Iterable[Dict]:
def _get_home_dirs() -> Iterable[Dict]:
import pwd
root_dir = _get_ssh_struct("root", "")
home_dirs = [
_get_ssh_struct(x.pw_name, x.pw_dir) for x in pwd.getpwall() if x.pw_dir.startswith("/home")