def setUp(self): super(TestSharedLibsOnlyIsalist, self).setUp() self.plc = fake_pkgstats_composer.PkgstatsListComposer('SunOS5.9', 'sparc') self.plc.AddPkgname('CSWbar') metadata_by_file_name = { '/opt/csw/lib/libfoo.so.1': representations.FileMetadata( path='/opt/csw/lib/libfoo.so.1', mime_type='application/x-sharedlib', machine_id=3, ), '/opt/csw/bin/bar': representations.FileMetadata( path='/opt/csw/bin/bar', mime_type='application/x-executable', machine_id=3, ), } pkgmap_entry_1 = representations.PkgmapEntry( line=None, class_=None, mode=None, owner=None, group=None, path='/opt/csw/lib/libfoo.so.1', target=None, type_=None, major=None, minor=None, size=None, cksum=None, modtime=None, pkgnames=[], ) pkgmap_entry_2 = representations.PkgmapEntry( line=None, class_=None, mode=None, owner=None, group=None, path='/opt/csw/bin/bar', target=None, type_=None, major=None, minor=None, size=None, cksum=None, modtime=None, pkgnames=[], ) binary_dump_info_1 = representations.BinaryDumpInfo( base_name='bar', needed_sonames=['libfoo.so.1'], path='opt/csw/bin/bar', rpath_set=True, runpath_rpath_the_same=True, runpath_set=True, runpath=('/opt/csw/lib/$ISALIST',), soname=None, ) binary_dump_info_2 = representations.BinaryDumpInfo( base_name='libfoo.so.1', needed_sonames=(), path='opt/csw/lib/libfoo.so.1', rpath_set=True, runpath_rpath_the_same=True, runpath_set=True, runpath=('/opt/csw/lib/$ISALIST',), soname=None, ) self.plc.AddFile('CSWbar', pkgmap_entry_1, metadata_by_file_name[pkgmap_entry_1.path], binary_dump_info_1, self.elfinfo_1) self.plc.AddFile('CSWbar', pkgmap_entry_2, metadata_by_file_name[pkgmap_entry_2.path], binary_dump_info_2, self.elfinfo_2)
def testByFilename(self): self.pkg_data = copy.deepcopy(tree_stats.pkgstats[0]) self.PrepareElfinfo(self.pkg_data) self.pkg_data['pkgmap'] = [ representations.PkgmapEntry(line='not important', class_='none', mode='0755', owner='root', group='bin', path='/opt/csw/apache2/bin/foo', target=None, type_='f', major=None, minor=None, size=None, cksum=None, modtime=None, pkgnames=None) ] self.error_mgr_mock.NeedPackage( u'CSWtree', u'CSWapache2', "found file(s) matching /opt/csw/apache2/, " "e.g. '/opt/csw/apache2/bin/foo'") self.mox.ReplayAll() result = dependency_checks.ByFilename(self.pkg_data, self.error_mgr_mock, self.logger_stub, self.messenger_stub, None, None) self.mox.VerifyAll()
def __init__(self, input, permissions=False, strip=None, basedir=""): self.paths = set() self.analyze_permissions = permissions self.entries = [] self.classes = None self.strip = strip self.basedir = basedir for line in input: entry, line_to_add = self._ParseLine(line) # Relocatable packages support if entry.path: entry = entry._asdict() entry["path"] = os.path.join(basedir, entry["path"]) # basedir here does not include the leading slash, but in pkgmap we # do need it. if not entry["path"].startswith("/"): entry["path"] = "/" + entry["path"] entry = representations.PkgmapEntry(**entry) self.entries.append(entry) if line_to_add: self.paths.add(line_to_add) self.entries_by_line = struct_util.IndexNamedtuplesBy( self.entries, "line") self.entries_by_type = struct_util.IndexNamedtuplesBy( self.entries, "type_") self.entries_by_class = struct_util.IndexNamedtuplesBy( self.entries, "class_") self.entries_by_path = struct_util.IndexNamedtuplesBy( self.entries, "path") self.entries = sorted(self.entries, key=lambda x: x.path)
def test_ParseLineSymlink(self): pm = pkgmap.Pkgmap(PKGMAP_2.splitlines()) line = ( '1 s none ' '/opt/csw/lib/postgresql/9.0/lib/sparcv9/libpq.so.5=libpq.so.5.3') # s none /opt/csw/lib/sparcv9/libpq.so.5=..//sparcv9/libpq.so.5 # s none /opt/csw/lib/sparcv9/libpq.so.5.3=..//sparcv9/libpq.so.5.3 line_to_add = ( '/opt/csw/lib/postgresql/9.0/lib/sparcv9/libpq.so.5 --> ' 'libpq.so.5.3') entry = representations.PkgmapEntry( cksum=None, class_='none', group=None, line=('1 s none /opt/csw/lib/postgresql/9.0/lib/sparcv9/' 'libpq.so.5=libpq.so.5.3'), major=None, minor=None, mode=None, modtime=None, owner=None, path='/opt/csw/lib/postgresql/9.0/lib/sparcv9/libpq.so.5', pkgnames=[], size=None, target='/opt/csw/lib/postgresql/9.0/lib/sparcv9/libpq.so.5.3', type_='s', ) self.assertEqual((entry, line_to_add), pm._ParseLine(line))
def _ParseIpsPkgContentsLine(self, line): """Parses one line of "pkg contents" output Returns: A dictionary of fields, or None. """ # we will map from IPS type to SVR4 type type_mapping = { "link": "s", "hardlink": "l", "file": "f", "dir": "d" } parts = re.split(configuration.WS_RE, line.strip()) if len(parts) < 4: raise ParsingError("Line does not have enough fields: %s" % repr(parts)) # paths are relative to "/" in pkg contents output f_path = "/" + parts[0] f_target = None try: f_type = type_mapping[parts[1]] except: raise ParsingError("Wrong file type: %s in %s" % (repr(parts[1]), repr(line))) f_mode = None f_owner = None f_group = None f_pkgname = None pkgnames = [ self._IpsNameToSrv4Name(parts[2]) ] if f_type in ("s", "l"): f_target = parts[3] else: (f_mode, f_owner, f_group) = parts[3:6] return representations.PkgmapEntry( line=line, class_=None, mode=f_mode, owner=f_owner, group=f_group, path=f_path, target=f_target, type_=f_type, major=None, minor=None, size=None, cksum=None, modtime=None, pkgnames=pkgnames, )
def test_ParseIpsPkgContentsLineFile(self): spi = system_pkgmap.Indexer() line = PKGCONTENT_LINE_4 expected = representations.PkgmapEntry( line=PKGCONTENT_LINE_4, class_=None, mode='0755', owner='root', group='bin', type_='f', major=None, minor=None, size=None, path='/lib/libc.so.1', target=None, cksum=None, modtime=None, pkgnames=['SUNWsystem-library'], ) self.assertEqual(expected, spi._ParseIpsPkgContentsLine(line))
def test_ParseIpsPkgContentsLineHardlink(self): spi = system_pkgmap.Indexer() line = PKGCONTENT_LINE_3 expected = representations.PkgmapEntry( line=PKGCONTENT_LINE_3, class_=None, mode=None, owner=None, group=None, type_='l', major=None, minor=None, size=None, path='/etc/svc/profile/platform_SUNW,UltraSPARC-IIe-NetraCT-40.xml', target='./platform_SUNW,UltraSPARC-IIi-Netract.xml', cksum=None, modtime=None, pkgnames=['SUNWsystem-core-os'], ) self.assertEqual(expected, spi._ParseIpsPkgContentsLine(line))
def test_ParseIpsPkgContentsLineDir(self): spi = system_pkgmap.Indexer() line = PKGCONTENT_LINE_2 expected = representations.PkgmapEntry( line=PKGCONTENT_LINE_2, class_=None, mode='0755', owner='root', group='sys', path='/dev', target=None, type_='d', major=None, minor=None, size=None, cksum=None, modtime=None, pkgnames=['SUNWsystem-core-os'], ) self.assertEqual(expected, spi._ParseIpsPkgContentsLine(line))
def test_ParseIpsPkgContentsLineLink(self): spi = system_pkgmap.Indexer() line = PKGCONTENT_LINE_1 expected = representations.PkgmapEntry( line=PKGCONTENT_LINE_1, class_=None, mode=None, owner=None, group=None, type_='s', major=None, minor=None, size=None, path='/bin', target='./usr/bin', cksum=None, modtime=None, pkgnames=['SUNWsystem-core-os'], ) self.assertEqual(expected, spi._ParseIpsPkgContentsLine(line))
def test_1(self): pm = pkgmap.Pkgmap(PKGMAP_1.splitlines()) entry = representations.PkgmapEntry( cksum=None, class_='cswcpsampleconf', group='bin', line=('1 f cswcpsampleconf /etc/opt/csw/cups/cupsd.conf.CSW ' '0644 root bin 4053 20987 1264420689'), major=None, minor=None, mode='0644', modtime=None, owner='root', path='/etc/opt/csw/cups/cupsd.conf.CSW', pkgnames=[], size=None, target=None, type_='f', ) self.assertEqual(1, len(pm.entries)) self.assertEqual(entry, pm.entries[0])
'pkgchk': {'return_code': 0, 'stderr_lines': [], 'stdout_lines': ['This is a fake package']}, 'pkginfo': {'ARCH': 'sparc', 'CATEGORY': 'fake-package', 'CLASSES': 'none', 'EMAIL': '*****@*****.**', 'HOTLINE': 'No hotline', 'NAME': 'A fake, autogenerated package', 'OPENCSW_CATALOGNAME': 'csw_bar', 'PKG': 'CSWbar', 'PSTAMP': 'fake@unknown-00000000000000', 'VENDOR': 'A fake package packaged for CSW by The Buildfarm', 'VERSION': 'fake_version'}, 'pkgmap': [representations.PkgmapEntry( line=None, class_=None, mode=None, owner=None, group=None, path='/opt/csw/lib/libfoo.so.1', target=None, type_=None, major=None, minor=None, size=None, cksum=None, modtime=None, pkgnames=[]), representations.PkgmapEntry( line=None, class_=None, mode=None, owner=None, group=None, path='/opt/csw/bin/bar', target=None, type_=None, major=None, minor=None, size=None, cksum=None, modtime=None, pkgnames=[])]}] class TestSharedLibsOnlyIsalist(unittest.TestCase): """/opt/csw/lib/$ISALIST in RPATH without the bare /opt/csw/lib.""" FUNCTION_NAME = 'SetCheckLibraries' # Contains only necessary bits. The data listed in full. elfinfo_1 = { 'version definition': [], 'version needed': [],
def _ParseLine(self, line): fields = re.split(r'\s+', line) if self.strip: strip_re = re.compile(r"^%s" % strip) fields = [re.sub(strip_re, "", x) for x in fields] line_to_add = None installed_path = None prototype_class = None line_type = fields[1] mode = None user = None group = None target = None if len(fields) < 2: return None elif line_type in ('f', 'd', 'p'): # Files and directories line_to_add = fields[3] installed_path = fields[3] prototype_class = fields[2] if self.analyze_permissions: line_to_add += " %s %s %s" % tuple(fields[4:7]) mode, user, group = fields[4:7] elif line_type in ('e'): # Editable files line_to_add = fields[3] installed_path = fields[3] prototype_class = fields[2] elif line_type in ('s', 'l'): # soft- and hardlinks # This breaks if PAX is broken. A rare case, but can happen. if "=" not in fields[3]: line_to_add = "broken link entry: %s" % fields[3] else: link_from, link_to = fields[3].split("=") installed_path = link_from line_to_add = "%s --> %s" % (link_from, link_to) target = struct_util.ResolveSymlink(link_from, link_to) prototype_class = fields[2] if line_to_add: self.paths.add(line_to_add) # entry = { # "line": line.strip(), # } # 'line, class_, mode, owner, group, path, target, type_, ' # 'major, minor, size, cksum, modtime, pkgnames') entry = representations.PkgmapEntry(line=line.strip(), class_=prototype_class, mode=mode, owner=user, group=group, path=installed_path, target=target, type_=line_type, major=None, minor=None, size=None, cksum=None, modtime=None, pkgnames=[]) return entry, line_to_add
def _ParseSrv4PkgmapLine(self, line): """Parses one line of /var/sadm/install/contents. Returns: A dictionary of fields, or None. """ if line.startswith("#"): return None parts = re.split(configuration.WS_RE, line.strip()) # logging.debug("_ParsePkgmapLine(): %s", parts) if len(parts) < 4: raise ParsingError("Line does not have enough fields: %s" % repr(parts)) file_type = parts[1] f_path = None f_target = None f_type = None f_class = None f_major = None f_minor = None f_mode = None f_owner = None f_group = None f_size = None f_cksum = None f_modtime = None f_pkgname = None pkgnames = [] if file_type == 's': # ftype s: path=rpath s class package # # Spotted in real life: # ['/opt/csw/man=share/man', 's', 'none', 'CSWschilybase', # 'CSWschilyutils', 'CSWstar', 'CSWcommon'] (f_path_rpath, f_type, f_class) = parts[:3] pkgnames.extend(parts[3:]) f_path, f_target = f_path_rpath.split("=") elif file_type == 'l': # ftype l: path l class package f_path, f_type, f_class, f_pkgname = parts elif file_type in ('d', 'x', 'p'): # ftype d: path d class mode owner group package(s) # ftype x: path x class mode owner group package f_path, f_type, f_class, f_mode, f_owner, f_group = parts[:6] pkgnames.extend(parts[6:]) elif file_type == '?': # Does not follow the specfication. A specimen: # /opt/csw/gcc3/lib/gcc/sparc-sun-solaris2.8/3.4.6/include # ? none CSWgcc3g77 CSWgcc3core logging.warning("File type of %s is '?', assuming it's a directory.", parts[0]) f_type = 'd' f_path, unused_type, f_class = parts[:3] pkgnames.extend(parts[3:]) elif file_type in ('b', 'c'): # ftype b: path b class major minor mode owner group package # ftype c: path c class major minor mode owner group package (f_path, f_type, f_class, f_major, f_minor, f_mode, f_owner, f_group, f_pkgname) = parts elif file_type in ('f', 'v', 'e'): # ftype f: path f class mode owner group size cksum modtime package # ftype v: path v class mode owner group size cksum modtime package # ftype e: path e class mode owner group size cksum modtime package # # Spotted in real life: # ['/etc/.java/.systemPrefs/.system.lock', 'e', 'preserve', # '0644', 'root', 'bin', '0', '0', '1265116929', 'SUNWj6cfg', # 'SUNWj5cfg'] (f_path, f_type, f_class, f_mode, f_owner, f_group, f_size, f_cksum, f_modtime) = parts[:9] pkgnames.extend(parts[9:]) else: raise ParsingError("Wrong file type: %s in %s" % (repr(file_type), repr(line))) if f_pkgname: pkgnames.append(f_pkgname) static_parts = parts[:9] dynamic_parts = parts[9:] # ['/usr/lib/sparcv9/libpthread.so.1', 'f', 'none', '0755', 'root', # 'bin', '41296', '28258', '1018129099', 'SUNWcslx'] # line, class_, mode, owner, group, path, target, type_, # major, minor, size, cksum, modtime, pkgnames return representations.PkgmapEntry( line=line, class_=f_class, mode=f_mode, owner=f_owner, group=f_group, path=f_path, target=f_target, type_=f_type, major=f_major, minor=f_minor, size=f_size, cksum=f_cksum, modtime=f_modtime, pkgnames=pkgnames, )
'HOTLINE': 'No hotline', 'NAME': 'A fake, autogenerated package', 'OPENCSW_CATALOGNAME': 'sunw_exa1', 'PKG': 'SUNWexa1', 'PSTAMP': 'fake@unknown-00000000000000', 'VENDOR': 'A fake package packaged for CSW by The Buildfarm', 'VERSION': 'fake_version' }, 'pkgmap': [ representations.PkgmapEntry(line='does not matter here', class_='none', mode='0755', owner='root', group='bin', path='/boot/grub/bin/grub', target=None, type_='f', major=None, minor=None, size=None, cksum=None, modtime=None, pkgnames=['SUNWexa1']), representations.PkgmapEntry(line='does not matter here', class_='none', mode='0644', owner='root', group='other', path='/etc/example/file', target=None, type_='f', major=None,