예제 #1
0
  def Parse(self, stat, file_object, knowledge_base):
    """Parse the sshd configuration.

    Process each of the lines in the configuration file.

    Assembes an sshd_config file into a dictionary with the configuration
    keyword as the key, and the configuration settings as value(s).

    Args:
      stat: unused
      file_object: An open configuration file object.
      knowledge_base: unused

    Yields:
      The configuration as an rdfvalue.
    """
    _, _ = stat, knowledge_base
    # Clean out any residual state.
    self.Flush()
    # for line in file_object:
    lines = [l.strip() for l in file_object.read(100000).splitlines()]
    for line in lines:
      # Remove comments (will break if it includes a quoted/escaped #)
      line = line.split("#")[0].strip()
      if line:
        self.ParseLine(line)
    matches = []
    for match in self.matches:
      criterion, config = match["criterion"], match["config"]
      block = rdf_config_file.SshdMatchBlock(criterion=criterion, config=config)
      matches.append(block)
    yield rdf_config_file.SshdConfig(config=self.config, matches=matches)
예제 #2
0
 def GenerateResults(self):
   matches = []
   for match in self.matches:
     criterion, config = match["criterion"], match["config"]
     block = rdf_config_file.SshdMatchBlock(criterion=criterion, config=config)
     matches.append(block)
   yield rdf_config_file.SshdConfig(config=self.config, matches=matches)
예제 #3
0
 def testRdfFormatterAttributedDict(self):
     sshd = rdf_config_file.SshdConfig()
     sshd.config = rdf_protodict.AttributedDict(skynet="operational")
     template = "{config.skynet}"
     hinter = hints.Hinter(template=template)
     expected = "operational"
     result = hinter.Render(sshd)
     self.assertEqual(expected, result)