示例#1
0
def parsedirs (directory, regex, depth, debian_release):
  """ Recursive search directory for DSA files contain postfix in their names.

    For this files called oval.parser.dsa.parseFile() for extracting DSA information.
  """

  global ovals
  debian_version = DEBIAN_VERSION[debian_release]

  if depth == 0:
    logging.log(logging.DEBUG, "Maximum depth reached at directory " + directory)
    return (0)
  
  for fileName in os.listdir (directory):
    
    path = "%s/%s" % (directory, fileName)
    
    logging.log (logging.DEBUG, "Checking %s (for %s at %s)" % (fileName, regex, depth))
    
    if os.access(path, os.R_OK) and os.path.isdir (path) and not os.path.islink (path) and fileName[0] != '.':
      logging.log(logging.DEBUG, "Entering directory " + path)
      parsedirs (path, regex, depth-1, debian_release)

    #Parse fileNames
    if os.access(path, os.R_OK) and regex.search(fileName) and fileName[0] != '.' and fileName[0] != '#':
      result = dsa.parseFile(path)
      if result:
        cve = result[0]
        if ovals.has_key(cve):
          for (k, v) in result[1].iteritems():
            ovals[cve][k] = v
        else:
          ovals[cve] = result[1]

        dsaRef = fileName[:-5].upper() # remove .data part
        
        # also parse corresponding wml file
        wmlResult = wml.parseFile(path.replace('.data', '.wml'), DEBIAN_VERSION)
        if wmlResult:
          data, releases = wmlResult
        # skip if the wml file does not contain the debian release
          if not debian_version in releases:
              continue
          for (k, v) in data.iteritems():
            if k == "moreinfo":
              if not "moreinfo" in ovals[cve]:
                ovals[cve]["moreinfo"] = "\n"
              # aggregate all advisories
              ovals[cve][k] += "%s%s\n" % (dsaRef, v)
            elif k in ('description'): # some keys shouldn't be clobbered
              if not k in ovals[cve]:
                ovals[cve][k] = v
            else:
              ovals[cve][k] = v
          if not "release" in ovals[cve]:
            ovals[cve]["release"] = {}
          ovals[cve]['release'].update({debian_version: releases[debian_version]})

  return 0
示例#2
0
def parsedirs (directory, regex, depth):
  """ Recursive search directory for DSA files contain postfix in their names.

    For this files called oval.parser.dsa.parseFile() for extracting DSA information.
  """

  global ovals

  if depth == 0:
    logging.log(logging.DEBUG, "Maximum depth reached at directory " + directory)
    return (0)
  
  for fileName in os.listdir (directory):
    
    path = "%s/%s" % (directory, fileName)
    
    logging.log (logging.DEBUG, "Checking %s (for %s at %s)" % (fileName, regex, depth))
    
    if os.access(path, os.R_OK) and os.path.isdir (path) and not os.path.islink (path) and fileName[0] != '.':
      logging.log(logging.DEBUG, "Entering directory " + path)
      parsedirs (path, regex, depth-1)

    #Parse fileNames
    if os.access(path, os.R_OK) and regex.search(fileName) and fileName[0] != '.' and fileName[0] != '#':
      result = dsa.parseFile(path)
      if result:
        cve = result[0]
        if ovals.has_key(cve):
          for (k, v) in result[1].iteritems():
            ovals[cve][k] = v
        else:
          ovals[cve] = result[1]

        dsaRef = fileName[:-5].upper() # remove .data part
        
        # also parse corresponding wml file
        wmlResult = wml.parseFile(path.replace('.data', '.wml'), DEBIAN_VERSION)
        if wmlResult:
          data, releases = wmlResult
          for (k, v) in data.iteritems():
            if k == "moreinfo":
              if not "moreinfo" in ovals[cve]:
                ovals[cve]["moreinfo"] = "\n"
              # aggregate all advisories
              ovals[cve][k] += "%s%s\n" % (dsaRef, v)
            elif k in ('description'): # some keys shouldn't be clobbered
              if not k in ovals[cve]:
                ovals[cve][k] = v
            else:
              ovals[cve][k] = v
          if not "release" in ovals[cve]:
            ovals[cve]["release"] = {}
          ovals[cve]['release'].update(releases)

  return 0
示例#3
0
def parsedirs(directory, postfix, depth):
    """ Recursive search directory for DSA files contain postfix in their names.

		For this files called oval.parser.dsa.parseFile() for extracting DSA information.
	"""

    if depth == 0:
        logging.log(logging.DEBUG,
                    "Maximum depth reached at directory " + directory)
        return (0)

    for file in os.listdir(directory):

        path = "%s/%s" % (directory, file)

        logging.log(logging.DEBUG,
                    "Checking %s (for %s at %s)" % (file, postfix, depth))

        if os.access(path, os.R_OK) and os.path.isdir(
                path) and not os.path.islink(path) and file[0] != '.':
            logging.log(logging.DEBUG, "Entering directory " + path)
            parsedirs(path, postfix, depth - 1)

#Parse DSA data files
        if os.access(path, os.R_OK) and file.endswith(
                postfix) and file[0] != '.' and file[0] != '#':
            result = dsa.parseFile(path)
            if result:
                if dsaref.has_key(result[0]):
                    for (k, v) in result[1].iteritems():
                        dsaref[result[0]][k] = v
                else:
                    dsaref[result[0]] = result[1]

#Parse DSA wml descriptions
        if os.access(path, os.R_OK) and file.endswith(
                ".wml") and file[0] != '.' and file[0] != '#':
            result = wml.parseFile(path)
            if result:
                if dsaref.has_key(result[0]):
                    for (k, v) in result[1].iteritems():
                        dsaref[result[0]][k] = v
                else:
                    dsaref[result[0]] = result[1]

    return 0
示例#4
0
def parsedirs(directory, postfix, depth):
    """ Recursive search directory for DSA files contain postfix in their names.

		For this files called oval.parser.dsa.parseFile() for extracting DSA information.
	"""

    if depth == 0:
        logging.log(logging.DEBUG, "Maximum depth reached at directory " + directory)
        return 0

    for file in os.listdir(directory):

        path = "%s/%s" % (directory, file)

        logging.log(logging.DEBUG, "Checking %s (for %s at %s)" % (file, postfix, depth))

        if os.access(path, os.R_OK) and os.path.isdir(path) and not os.path.islink(path) and file[0] != ".":
            logging.log(logging.DEBUG, "Entering directory " + path)
            parsedirs(path, postfix, depth - 1)

            # Parse DSA data files
        if os.access(path, os.R_OK) and file.endswith(postfix) and file[0] != "." and file[0] != "#":
            result = dsa.parseFile(path)
            if result:
                if dsaref.has_key(result[0]):
                    for (k, v) in result[1].iteritems():
                        dsaref[result[0]][k] = v
                else:
                    dsaref[result[0]] = result[1]

                    # Parse DSA wml descriptions
        if os.access(path, os.R_OK) and file.endswith(".wml") and file[0] != "." and file[0] != "#":
            result = wml.parseFile(path)
            if result:
                if dsaref.has_key(result[0]):
                    for (k, v) in result[1].iteritems():
                        dsaref[result[0]][k] = v
                else:
                    dsaref[result[0]] = result[1]

    return 0