Skip to content
This repository has been archived by the owner on Oct 5, 2019. It is now read-only.

adds binaries in path to collection #158

Merged
merged 3 commits into from
Oct 13, 2017
Merged
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions osxcollector/osxcollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,8 @@ def __enter__(self):
def __exit__(self, type, value, traceback):
del Logger.Extra.extras[self.key]

PATH_ENVIRONMENT_NAME = "PATH"


class Collector(object):

Expand Down Expand Up @@ -913,6 +915,7 @@ def collect(self, section_list=None):
('safari', self._collect_safari),
('accounts', self._collect_accounts),
('mail', self._collect_mail),
('executables', self._collect_binary_names_in_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a missing , at the end of this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++ I missed this copy pasting between different checkouts

('full_hash', self._collect_full_hash)
]

Expand Down Expand Up @@ -1205,6 +1208,22 @@ def _collect_system_info(self):
}
Logger.log_dict(record)

def _collect_binary_names_in_path(self):
"""Collect the names of executable binaries in the PATH environment"""
exe_files = []

def is_exe(fpath):
return os.path.isfile(fpath) and os.path.exists(fpath) and os.access(fpath, os.X_OK)
Copy link
Contributor

Choose a reason for hiding this comment

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

os.path.isfile always implies os.path.exists, so the latter seems redundant. You could also have a directory mislabelled as an executable which would probably further encourage just using os.path.isfile and os.access alone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto


if PATH_ENVIRONMENT_NAME in os.environ:
for bin_dir in os.environ[PATH_ENVIRONMENT_NAME].split(":"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Super small nit and probably unnecessary since OS X uses colon as path separator by default, but maybe using os.pathsep for more readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense @leeren, I'll update it.

for root_dir, dirs, files in os.walk(bin_dir):
for the_file in files:
file_path = os.path.join(root_dir, the_file)
if is_exe(file_path):
exe_files.append(file_path)
Logger.log_dict({"executable_files": exe_files})

def _collect_startup(self):
"""Log the different LauchAgents and LaunchDaemons"""

Expand Down