Пример #1
0
 def _run(self):
     # process systemd service startup file
     f_path = '/etc/systemd/system/multi-user.target.wants/postgresql-' + self._version + '.service'
     if not hutils.path_exists(f_path):
         self._log('Package ' + self._package_name + ' is installed but service not started. ' 
                   + f_path + ' not found.')
         return
     f = hutils.path_rehydrate(f_path)
     # find the ExecStart line
     s = re.search(r'^ExecStart=.+', f, re.M).group(0)
     # look for a -D switch
     m = re.search(r'-D\s+',s)
     if m == None:
         self._log('Postgresql data directory not specified in service definition')
         return
     # find the argument for the -D switch
     s = m.group(0).split()[1]
     if not s[0] == '$':
         # argument is not an environment variable
         self._mark_as_content(s)
     else:
         # Else argument is an environment variable - extract it's name
         # Assume format is ${v_name}
         v_name = s[2:-1]
         # Find Environment statement that assigns a value to that name
         d = re.search(r'^Environment='+v_name+'=.+',f,re.M).group(0).split('=')[2]
         self._mark_as_content(d)
Пример #2
0
    def _run(self):
        # process main conf file
        conf_path = '/etc/nginx/nginx.conf'
        if not hutils.path_exists(conf_path):
            self._log('Package ' + self._package_name + ' is installed. ' 
                      + conf_path + ' not found.')
            return
        conf_file = hutils.path_rehydrate(conf_path)
        include_paths = hutils.conf_file_fields(conf_file, 'include')
        for p in include_paths:
            if not p == '/etc/nginx/conf.d/*.conf': # the default include
                # The value has to resolve to a file, i.e. you
                # can't Include a directory. You CAN use wildcards.
                # So...if we see '/*' then take everything before that
                # as a directory. If we don't, then we are referencing
                # a single file.
                m = re.search(r'/\*',p) 
                if not m == None:
                    # path ends in wildcard - we'll grab the whole directory
                    p = m.string[:m.start()]
                self._mark_as_content(p)
            
        # We can have multiple document paths, if there are
        # virtual hosts
        doc_paths = hutils.conf_file_fields(conf_file, 'root')
        for p in doc_paths:
            self._mark_as_content(p)

        # We can have multiple Alias paths, if there are
        # virtual hosts (or even without virtual hosts)
        alias_paths = hutils.conf_file_fields(conf_file,'alias')
        for p in alias_paths:
            # These must be fully qualified.
            self._mark_as_content(p)
Пример #3
0
 def _run(self):
     eph_dirs = [
         '/dev', '/proc', '/run', '/tmp', '/var/account', '/var/adm',
         '/var/cache', '/var/crash', '/var/empty', '/var/gopher',
         '/var/lock', '/var/log', '/var/mail', '/var/preserve', '/var/run',
         '/var/spool', '/var/lib/misc', '/usr/tmp'
     ]
     for d in eph_dirs:
         if hutils.path_exists(d):
             self._mark_as_ephemeral(d)
Пример #4
0
    def _process_service_def(self, path_spec):
        # We assume that path_spec points to file, and file exists
        self._log('Found possible user-defined service ' + path_spec)
        svc_file = hutils.path_rehydrate(path_spec)
        # find the ExecStart
        m = re.search(r'^ExecStart=.+', svc_file, re.M)
        if m == None:
            self._log('Error - file did not contain ExecStart line')
            return
        el = m.group(0)[10:]  # after 'ExecStart='
        es = el.split()  # split fields by whitespace

        for field in es:
            # if it looks like a path
            if hutils.path_exists(field):
                if hutils.origin_unknown(field):
                    # The first field may be something like /bin/python,
                    # so the origin_unknown check should keep us from sweeping
                    # that up.
                    self._mark_as_other_exe(field)
Пример #5
0
    def _run(self):
        self._log_start()

        mu_dir_path = '/etc/systemd/system/multi-user.target.wants'

        # services we expect to see from OS install in mu_dir_path
        expected_services = [
            'auditd.service', 'crond.service', 'firewalld.service',
            'irqbalance.service', 'kdump.service', 'NetworkManager.service',
            'postfix.service', 'rhel-configure.service', 'rsyslog.service',
            'sshd.service', 'tuned.service'
        ]

        # services that we might see, but these are covered by package
        # rules
        package_services = [
            'nginx.service',
            'postgresql-9.4.service',
        ]
        known_services = expected_services + package_services

        if not hutils.path_exists(mu_dir_path):
            self._log('multi-user.target.wants directory does not exist')
            self._log_stop()
            return

        d = hutils.get_directory_contents(mu_dir_path)  # list of FileDetail
        # strip out non-service files
        s = []
        for f in d:
            if f.file_location[-8:] == '.service':
                s.append(f.file_location.rpartition('/')[2])

        for f in s:
            if not f in known_services:
                self._process_service_def(mu_dir_path + '/' + f)

        self._log_complete()
Пример #6
0
def test_path_not_exists(test_database):
    assert not heuristic_utils.path_exists("/etc/profiles")
Пример #7
0
    def _run(self):
        # process main conf file
        conf_path = '/etc/httpd/conf/httpd.conf'
        if not hutils.path_exists(conf_path):
            self._log('Package ' + self._package_name + ' is installed. ' +
                      conf_path + ' not found.')
            return
        conf_file = hutils.path_rehydrate(conf_path)
        server_root = hutils.conf_file_field(conf_file, 'ServerRoot')
        if not server_root == '/etc/httpd':
            self._log('UNUSUAL! httpd ServerRoot is ' + server_root)

        include_paths = hutils.conf_file_fields(conf_file, 'Include')
        for p in include_paths:
            if not p == 'conf.modules.d/*.conf':  # the default includes
                # The value has to resolve to a file, i.e. you
                # can't Include a directory. You CAN use wildcards.
                # So...if we see '/*' then take everything before that
                # as a directory. If we don't, then we are referencing
                # a single file.
                p = self._httpd_path_mangle(p, server_root)
                m = re.search(r'/\*', p)
                if not m == None:
                    # path ends in wildcard - we'll grab the whole directory
                    p = m.string[:m.start()]
                self._mark_as_content(p)

        # We can have multiple document paths, if there are
        # virtual hosts
        doc_paths = hutils.conf_file_fields(conf_file, 'DocumentRoot')
        for p in doc_paths:
            # mangling this path is a 'just in case' - it should
            # be a fully qualified path
            p = self._httpd_path_mangle(p, server_root)
            self._mark_as_content(p)

        # We can have multiple Alias paths, if there are
        # virtual hosts (or even without virtual hosts)
        alias_paths = hutils.conf_file_fields(conf_file, 'Alias')
        for p in alias_paths:
            # These must be fully qualified.
            self._mark_as_content(p)

        # We can have multiple script alias paths, if there are
        # virtual hosts
        script_alias_paths = hutils.conf_file_fields(conf_file, 'ScriptAlias')
        for p in script_alias_paths:
            mp = self._httpd_path_mangle(p, server_root)
            # These must be fully qualified.
            self._mark_as_content(mp)

        # Process standard conf.d files
        # autoindex.conf
        conf_file_path = server_root + 'conf.d/autoindex.conf'
        if hutils.path_exists(conf_file_path):
            conf_file = hutils.path_rehydrate(conf_file_path)
            icon_path = hutils.conf_file_field(conf_file, 'Alias')
            if not icon_path == '"/usr/share/httpd/icons/"':
                self._mark_as_content(icon_path)

        # fcgid.conf - Fast CGI - nothing for us there
        # manual.conf - going to skip this.
        # ssl.conf
        conf_file_path = server_root + 'conf.d/ssl.conf'
        if hutils.path_exists(conf_file_path):
            conf_file = hutils.path_rehydrate(conf_file_path)
            pass_phrase_dialog = hutils.conf_file_field(
                conf_file, 'SSLPassPhraseDialog')
            if not pass_phrase_dialog == 'exec:/usr/libexec/httpd-ssl-pass-dialog':
                #strip leading "exec:"
                p = pass_phrase_dialog[5:]
                self._mark_as_content(p)