def test_call_setgroups(binariescheck): output, test = binariescheck with FakePkg('fake') as pkg: pkgfile = PkgFile('/bin/call-setgroups') pkgfile.path = get_full_path('call-setgroups') pkg.files[pkgfile.name] = pkgfile run_elf_checks(test, pkg, pkgfile) out = output.print_results(output.results) assert 'E: missing-call-to-setgroups-before-setuid /bin/call-setgroups' in out
def add_file_with_content(self, name, content): """ Add file to the FakePkg and fill the file with provided string content. """ basename = name.replace(os.path.sep, '_') path = os.path.join(self.dirName(), basename) with open(path, 'w') as out: out.write(content) pkg_file = PkgFile(name) pkg_file.path = path self.files[name] = pkg_file
def add_file_with_content(self, name, content, **flags): """ Add file to the FakePkg and fill the file with provided string content. """ basename = name.replace(os.path.sep, '_') path = os.path.join(self.dir_name(), basename) with open(path, 'w') as out: out.write(content) pkg_file = PkgFile(name) pkg_file.path = path for key, value in flags.items(): setattr(pkg_file, key, value) self.files[name] = pkg_file
def _gatherFilesInfo(self): ret = {} flags = self.header[rpm.RPMTAG_FILEFLAGS] modes = self.header[rpm.RPMTAG_FILEMODES] users = self.header[rpm.RPMTAG_FILEUSERNAME] groups = self.header[rpm.RPMTAG_FILEGROUPNAME] links = [byte_to_string(x) for x in self.header[rpm.RPMTAG_FILELINKTOS]] sizes = self.header[rpm.RPMTAG_FILESIZES] md5s = self.header[rpm.RPMTAG_FILEMD5S] mtimes = self.header[rpm.RPMTAG_FILEMTIMES] rdevs = self.header[rpm.RPMTAG_FILERDEVS] langs = self.header[rpm.RPMTAG_FILELANGS] inodes = self.header[rpm.RPMTAG_FILEINODES] requires = [byte_to_string(x) for x in self.header[rpm.RPMTAG_FILEREQUIRE]] provides = [byte_to_string(x) for x in self.header[rpm.RPMTAG_FILEPROVIDE]] files = [byte_to_string(x) for x in self.header[rpm.RPMTAG_FILENAMES]] magics = [byte_to_string(x) for x in self.header[rpm.RPMTAG_FILECLASS]] try: # rpm >= 4.7.0 filecaps = self.header[rpm.RPMTAG_FILECAPS] except AttributeError: filecaps = None # rpm-python < 4.6 does not return a list for this (or FILEDEVICES, # FWIW) for packages containing exactly one file if not isinstance(inodes, list): inodes = [inodes] if files: for idx in range(0, len(files)): pkgfile = PkgFile(files[idx]) pkgfile.path = os.path.normpath(os.path.join( self.dirName() or '/', pkgfile.name.lstrip('/'))) pkgfile.flags = flags[idx] pkgfile.mode = modes[idx] pkgfile.user = byte_to_string(users[idx]) pkgfile.group = byte_to_string(groups[idx]) pkgfile.linkto = links[idx] and os.path.normpath(links[idx]) pkgfile.size = sizes[idx] pkgfile.md5 = md5s[idx] pkgfile.mtime = mtimes[idx] pkgfile.rdev = rdevs[idx] pkgfile.inode = inodes[idx] pkgfile.requires = parse_deps(requires[idx]) pkgfile.provides = parse_deps(provides[idx]) pkgfile.lang = byte_to_string(langs[idx]) pkgfile.magic = magics[idx] if not pkgfile.magic: if stat.S_ISDIR(pkgfile.mode): pkgfile.magic = 'directory' elif stat.S_ISLNK(pkgfile.mode): pkgfile.magic = "symbolic link to `%s'" % pkgfile.linkto elif not pkgfile.size: pkgfile.magic = 'empty' if (not pkgfile.magic and not pkgfile.is_ghost and _magic): # file() method evaluates every file twice with python2, # use descriptor() method instead try: fd = os.open(pkgfile.path, os.O_RDONLY) pkgfile.magic = byte_to_string(_magic.descriptor(fd)) os.close(fd) except OSError: pass if pkgfile.magic is None: pkgfile.magic = '' elif Pkg._magic_from_compressed_re.search(pkgfile.magic): # Discard magic from inside compressed files ('file -z') # until PkgFile gets decompression support. We may get # such magic strings from package headers already now; # for example Fedora's rpmbuild as of F-11's 4.7.1 is # patched so it generates them. pkgfile.magic = '' if filecaps: pkgfile.filecaps = filecaps[idx] ret[pkgfile.name] = pkgfile return ret
def add_file(self, path, name): pkgfile = PkgFile(name) pkgfile.path = path self.files[name] = pkgfile return pkgfile