Ejemplo n.º 1
0
 def _getPackageDpkg(self, path):
     """given a path it return the package which provide that 
     path if if finds one only debian system"""
     cmd1 = ['dpkg', '-S']
     cmd2 = ['dpkg-query', '--show', "-f='${Package} ${Version} ${Architecture}'", ]
     try:
         (package, returncode) = getOutputAsList(cmd1 + [path])
     except subprocess.CalledProcessError:
         #package not found
         return None
     except OSError:
         #cmd not found
         return None
     if returncode != 0 or len(package[0]) == 0:
         #the file is not tracked
         return None
     packageName = package[0].split(':')[0]
     try:
         (package, returncode) = getOutputAsList(cmd2 + [packageName])
         if returncode != 0:
             return None
         return package[0]
     except subprocess.CalledProcessError:
         #package not found
         return None
     except OSError:
         #cmd not found
         return None
Ejemplo n.º 2
0
    def _setDepsRequs(cls, swirlFile):
        """given a SwirlFile object it add to it all the dependency and all 
        the provides to it """

        #find deps
        for line in getOutputAsList(['bash', cls._RPM_FIND_DEPS], swirlFile.path)[0]:
            if len(line) > 0:
                newDep = Dependency( line )
                newDep.setPluginName( cls.pluginName )
                swirlFile.addDependency( newDep )
                #i need to take the parenthesis out of the game
                tempList = re.split('\(|\)',line)
                if len(tempList) > 3:
                    #set the 32/64 bits 
                    #probably unecessary
                    if tempList[3].find("64bit") >= 0 :
                        newDep.set64bits()
                    elif tempList[3].find("32bit") >= 0 :
                        #this should never happen
                        newDep.set32bits()
                else:
                    #no parenthesis aka 32 bit 
                    newDep.set32bits()
                p = cls.getPathToLibrary( newDep )
                if p:
                    newDep.pathList.append( p )
        
        #find provides
        for line in getOutputAsList(['bash', cls._RPM_FIND_PROV], swirlFile.path)[0]:
            if len(line) > 0 :
                newProv = Provide(line)
                newProv.setPluginName( cls.pluginName )
                swirlFile.addProvide(newProv)
Ejemplo n.º 3
0
 def _getPackageDpkg(self, path):
     """given a path it return the package which provide that 
     path if if finds one only debian system"""
     cmd1 = ['dpkg', '-S']
     cmd2 = [
         'dpkg-query',
         '--show',
         "-f=${Package}\ ${Version}\ ${Architecture}",
     ]
     try:
         (package, returncode) = getOutputAsList(cmd1 + [path])
     except subprocess.CalledProcessError:
         #package not found
         return None
     except OSError:
         #cmd not found
         return None
     if returncode != 0 or len(package[0]) == 0:
         #the file is not tracked
         return None
     packageName = package[0].split(':')[0]
     try:
         (package, returncode) = getOutputAsList(cmd2 + [packageName])
         if returncode != 0:
             return None
         return package[0]
     except subprocess.CalledProcessError:
         #package not found
         return None
     except OSError:
         #cmd not found
         return None
Ejemplo n.º 4
0
    def _setDepsRequs(cls, swirlFile, swirl):
        """
        given a SwirlFile object add all the dependency and all the provides
        to it

        :type swirlFile: :class:`FingerPrint.swirl.SwirlFile`
        :param swirlFile: the SwirlFile we need to find all the dependencies

        :type swirl: :class:`FingerPrint.swirl.Swirl`
        :param swirl: the Swirl that will be used to first lookup already
                          discovered dependencies
        """

        # find rpath first
        rpath = getOutputAsList([
            "bash", "-c",
            "objdump -x %s |grep RPATH|awk '{print $2}'" % swirlFile.path
        ])[0]
        if len(rpath) > 0:
            if "$ORIGIN" in rpath[0]:
                rpath[0] = string.replace(rpath[0], "$ORIGIN",
                                          os.path.dirname(swirlFile.path))
            swirlFile.rpaths = rpath[0].split(":")
# check LD_LIBRARY_PATH
        ld_library = FingerPrint.utils.getLDLibraryPath(swirlFile.env)

        #find deps
        for line in getOutputAsList(['bash', cls._RPM_FIND_DEPS],
                                    swirlFile.path)[0]:
            if len(line) > 0:
                newDep = Dependency.fromString(line)
                swirlFile.addDependency(newDep)
                p = cls.getPathToLibrary(newDep,
                                         useCache=True,
                                         rpath=swirlFile.rpaths + ld_library)
                if not p:
                    # a dependency was not found complain loudly
                    logger.error("Unable to find library %s" % newDep)
                    continue
                if p and not swirl.isFileTracked(p):
                    # p not null and p is not already in swirl
                    cls.getSwirl(p, swirl, swirlFile.env)

        #find provides
        for line in getOutputAsList(['bash', cls._RPM_FIND_PROV],
                                    swirlFile.path)[0]:
            if len(line) > 0:
                newProv = Dependency.fromString(line)
                swirlFile.addProvide(newProv)
Ejemplo n.º 5
0
 def _checkMinor(cls, libPath, depName):
     """ check if libPath provides the depName (major and minor) """
     realProvider = os.path.realpath(libPath)
     for line in getOutputAsList(['bash', cls._RPM_FIND_PROV], realProvider)[0]:
         if len(line) > 0 and depName in line:
             return True
     return False
Ejemplo n.º 6
0
 def getPathToLibrary(cls, dependency):
     """ given a dependency it find the path of the library which provides 
     that dependency """
     soname = dependency.getBaseName()
     if dependency.depname in cls._pathCache :
         return cls._pathCache[dependency.depname]
     #for each library we have in the system
     for line in getOutputAsList(["/sbin/ldconfig","-p"])[0]:
         # if dependency is 64 and library is 64 of
         # dependency is 32 and library is 32:
         if len(line) > 0 and soname in line and \
             ( (dependency.is64bits() and cls._ldconfig_64bits in line) or \
             (dependency.is32bits() and not cls._ldconfig_64bits in line) ):
             temp = line.split('=>')
             if len(temp) == 2:
                 provider=temp[1].strip()
                 if cls._checkMinor(provider, dependency.depname):
                     cls._pathCache[dependency.depname] = provider
                     return provider
     pathToScan = cls.systemPath
     if "LD_LIBRARY_PATH" in os.environ:
         #we need to scan the LD_LIBRARY_PATH too
         pathToScan += os.environ["LD_LIBRARY_PATH"].split(':')
     for path in pathToScan:
         provider = path + '/' + soname
         if os.path.isfile(provider) and \
             cls._checkMinor(provider, dependency.depname):
             #we found the soname and minor are there return true
             cls._pathCache[dependency.depname] = provider
             return provider
     #the dependency could not be located
     return None
Ejemplo n.º 7
0
 def getDependeciesFromPath(cls, fileName):
     """given a file name it returns a Provide object with all the goodies in it
     """
     returnValue = []
     for line in getOutputAsList(['bash', cls._RPM_FIND_PROV], fileName)[0]:
         if len(line) == 0:
             continue
         newDep = Dependency( line )
         newDep.setPluginName( cls.pluginName )
         newDep.pathList.append( fileName )
         #i need to take the parenthesis out of the game
         tempList = re.split( '\(|\)', line )
         if len( tempList ) > 3:
             #set the 32/64 bits
             #probably unecessary
             if tempList[3].find( "64bit" ) >= 0 :
                 newDep.set64bits()
             elif tempList[3].find( "32bit" ) >= 0 :
                 #this should never happen
                 newDep.set32bits()
         else:
             #no parenthesis aka 32 bit
             newDep.set32bits()
         returnValue.append( newDep )
     return returnValue
Ejemplo n.º 8
0
 def _checkMinor(cls, libPath, depName):
     """ check if libPath provides the depName (major and minor) """
     realProvider = os.path.realpath(libPath)
     for line in getOutputAsList(['bash', cls._RPM_FIND_PROV],
                                 realProvider)[0]:
         if len(line) > 0 and depName in line:
             return True
     return False
Ejemplo n.º 9
0
    def _setDepsRequs(cls, swirlFile, swirl):
        """
        given a SwirlFile object add all the dependency and all the provides
        to it

        :type swirlFile: :class:`FingerPrint.swirl.SwirlFile`
        :param swirlFile: the SwirlFile we need to find all the dependencies

        :type swirl: :class:`FingerPrint.swirl.Swirl`
        :param swirl: the Swirl that will be used to first lookup already
                          discovered dependencies
        """

        # find rpath first
        rpath = getOutputAsList(["bash","-c", "objdump -x %s |grep RPATH|awk '{print $2}'" % swirlFile.path ])[0]
        if len( rpath ) > 0:
            if "$ORIGIN" in rpath[0]:
                rpath[0] = string.replace(rpath[0], "$ORIGIN", os.path.dirname(swirlFile.path))
            swirlFile.rpaths = rpath[0].split(":")
	# check LD_LIBRARY_PATH
	ld_library = FingerPrint.utils.getLDLibraryPath(swirlFile.env)

        #find deps
        for line in getOutputAsList(['bash', cls._RPM_FIND_DEPS], swirlFile.path)[0]:
            if len(line) > 0:
                newDep = Dependency.fromString( line )
                swirlFile.addDependency( newDep )
                p = cls.getPathToLibrary( newDep , useCache = True,
                        rpath = swirlFile.rpaths + ld_library)
                if not p:
                    # a dependency was not found complain loudly
                    logger.error("Unable to find library %s" % newDep)
                    continue
                if p and not swirl.isFileTracked(p):
                    # p not null and p is not already in swirl
                    cls.getSwirl(p, swirl, swirlFile.env)
        
        #find provides
        for line in getOutputAsList(['bash', cls._RPM_FIND_PROV], swirlFile.path)[0]:
            if len(line) > 0 :
                newProv = Dependency.fromString(line)
                swirlFile.addProvide(newProv)
Ejemplo n.º 10
0
 def _getPackageRpm(self, path):
     """given a path it return the package which provide that 
     path if if finds one
     only rpm based system"""
     cmd = ['rpm', '-qf']
     try:
         (package, returncode) = getOutputAsList(cmd + [path])
         if returncode != 0:
             return None
         return package[0]
     except subprocess.CalledProcessError:
         #package not found
         return None
     except OSError:
         #cmd not found
         return None
Ejemplo n.º 11
0
 def _getPackageRpm(self, path):
     """given a path it return the package which provide that 
     path if if finds one
     only rpm based system"""
     cmd = ['rpm', '-qf']
     try:
         (package, returncode) = getOutputAsList(cmd + [path])
         if returncode != 0:
             return None
         return package[0]
     except subprocess.CalledProcessError:
         #package not found
         return None
     except OSError:
         #cmd not found
         return None
Ejemplo n.º 12
0
 def setUp(self):
     """setup for your unittest"""
     import sys
     sys.path.append("../")
     self.files = ["/bin/ls", "/etc/passwd", "/etc/hosts"]
     temp = which("find")
     if temp:
         self.files.append(temp)
     temp = which("dbus-daemon")
     if temp:
         self.files.append(temp)
     self.files += glob.glob("/lib*/libcryptsetup.so.*")
     self.files += glob.glob("/lib*/libdmraid.so.*")
     self.files += glob.glob("/lib*/libnss_nis*")
     #a python file
     cmdFile = getOutputAsList(["python", "-c", "import urllib;print urllib.__file__"])[0][0]
     #print cmdFile
     if cmdFile.endswith(".pyc") or cmdFile.endswith(".pyo"):
         cmdFile = cmdFile[0:-1]
     self.files.append( cmdFile )
     #print "File list: ", self.files
     self.availablePlugin = 2
Ejemplo n.º 13
0
 def setUp(self):
     """setup for your unittest"""
     import sys
     sys.path.append("../")
     self.files = ["/bin/ls", "/etc/passwd", "/etc/hosts"]
     temp = which("find")
     if temp:
         self.files.append(temp)
     temp = which("dbus-daemon")
     if temp:
         self.files.append(temp)
     self.files += glob.glob("/lib*/libcryptsetup.so.*")
     self.files += glob.glob("/lib*/libdmraid.so.*")
     self.files += glob.glob("/lib*/libnss_nis*")
     #a python file
     cmdFile = getOutputAsList(["python", "-c", "import urllib;print urllib.__file__"])[0][0]
     #print cmdFile
     if cmdFile.endswith(".pyc") or cmdFile.endswith(".pyo"):
         cmdFile = cmdFile[0:-1]
     self.files.append( cmdFile )
     #print "File list: ", self.files
     self.availablePlugin = 1
Ejemplo n.º 14
0
 def getPathToLibrary(cls, dependency, useCache=True, rpath=[]):
     """ given a dependency it find the path of the library which provides 
     that dependency """
     soname = dependency.getMajor()
     if useCache and dependency.getName() in cls._pathCache:
         return cls._pathCache[dependency.getName()]
     #for each library we have in the system
     pathToScan = cls.systemPath[:] + rpath
     if "LD_LIBRARY_PATH" in os.environ:
         #we need to scan the LD_LIBRARY_PATH too
         pathToScan += os.environ["LD_LIBRARY_PATH"].split(':')
     # remove duplicate
     pathToScan = list(set(pathToScan))
     for path in pathToScan:
         path = os.path.normpath(path)
         provider = path + '/' + soname
         if os.path.isfile(provider) and \
             cls._checkMinor(provider, dependency.getName()):
             #we found the soname and minor are there return true
             cls._pathCache[dependency.getName()] = provider
             return provider
     for line in getOutputAsList(["/sbin/ldconfig", "-p"])[0]:
         # TODO it needs to handle in a better way the hwcap field
         # if dependency is 64 and library is 64 or
         # dependency is 32 and library is 32:
         if len(line) > 0 and soname in line and 'hwcap' not in line and \
             ( (dependency.is64bits() and cls._ldconfig_64bits in line) or \
             (dependency.is32bits() and not cls._ldconfig_64bits in line) ):
             temp = line.split('=>')
             if len(temp) == 2:
                 provider = temp[1].strip()
                 if cls._checkMinor(provider, dependency.getName()):
                     cls._pathCache[dependency.getName()] = provider
                     return provider
     #the dependency could not be located
     return None
Ejemplo n.º 15
0
 def getPathToLibrary(cls, dependency, useCache = True, rpath = []):
     """ given a dependency it find the path of the library which provides 
     that dependency """
     soname = dependency.getMajor()
     if useCache and dependency.getName() in cls._pathCache :
         return cls._pathCache[dependency.getName()]
     #for each library we have in the system
     pathToScan = cls.systemPath[:] + rpath
     if "LD_LIBRARY_PATH" in os.environ:
         #we need to scan the LD_LIBRARY_PATH too
         pathToScan += os.environ["LD_LIBRARY_PATH"].split(':')
     # remove duplicate
     pathToScan = list(set(pathToScan))
     for path in pathToScan:
         path = os.path.normpath(path)
         provider = path + '/' + soname
         if os.path.isfile(provider) and \
             cls._checkMinor(provider, dependency.getName()):
             #we found the soname and minor are there return true
             cls._pathCache[dependency.getName()] = provider
             return provider
     for line in getOutputAsList(["/sbin/ldconfig","-p"])[0]:
         # TODO it needs to handle in a better way the hwcap field
         # if dependency is 64 and library is 64 or
         # dependency is 32 and library is 32:
         if len(line) > 0 and soname in line and 'hwcap' not in line and \
             ( (dependency.is64bits() and cls._ldconfig_64bits in line) or \
             (dependency.is32bits() and not cls._ldconfig_64bits in line) ):
             temp = line.split('=>')
             if len(temp) == 2:
                 provider=temp[1].strip()
                 if cls._checkMinor(provider, dependency.getName()):
                     cls._pathCache[dependency.getName()] = provider
                     return provider
     #the dependency could not be located
     return None