Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#
# http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
#
import codecs
import configparser as cfgparser
from pathlib import Path
import subprocess
from rpmlint.checks.AbstractCheck import AbstractFilesCheck
from rpmlint.helpers import ENGLISH_ENVIROMENT
STANDARD_BIN_DIRS = ('/bin', '/sbin', '/usr/bin', '/usr/sbin')
class MenuXDGCheck(AbstractFilesCheck):
"""
Check whether MenuXDG files installed by a package are valid.
"""
def __init__(self, config, output):
# desktop file need to be in $XDG_DATA_DIRS
# $ echo $XDG_DATA_DIRS/applications
# /var/lib/menu-xdg:/usr/share
super().__init__(config, output, r'/usr/share/applications/.*\.desktop$')
def parse_desktop_file(self, pkg, root, f, filename):
"""
Check the structure of a desktop file.
"""
cfp = cfgparser.RawConfigParser()
try:
with codecs.open(f, encoding='utf-8') as inputf:
import re
import stat
import time
from rpmlint.checks.AbstractCheck import AbstractFilesCheck
class BuildDateCheck(AbstractFilesCheck):
"""
Check that the file doesn't contain the current date or time.
If so, it causes the package to rebuild when it's not needed.
"""
def __init__(self, config, output):
super().__init__(config, output, r'.*')
self.looksliketime = re.compile('(2[0-3]|[01]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9])')
self.istoday = re.compile(time.strftime('%b %e %Y'))
def check_file(self, pkg, filename):
if filename.startswith('/usr/lib/debug') or pkg.is_source or \
not stat.S_ISREG(pkg.files[filename].mode):
return
grep_date = pkg.grep(self.istoday, filename)
import re
from pybeam import BeamFile
from rpm import expandMacro
from rpmlint.checks.AbstractCheck import AbstractFilesCheck
from rpmlint.helpers import byte_to_string
class ErlangCheck(AbstractFilesCheck):
def __init__(self, config, output):
super().__init__(config, output, r'.*?\.beam$')
build_dir = expandMacro('%_builddir')
self.source_re = re.compile(build_dir)
def check_file(self, pkg, filename):
beam = BeamFile(pkg.files[filename].path)
compile_state = byte_to_string(beam.compileinfo['source'].value)
if 'debug_info' not in beam.compileinfo['options']:
self.output.add_info('E', pkg, 'beam-compiled-without-debuginfo', filename)
# This can't be an error as builddir can be user specific and vary between users
# it could be error in OBS where all the builds are done by user abuild, not in
# general.
if not self.source_re.match(compile_state):
self.output.add_info('W', pkg, 'beam-was-not-recompiled', filename, compile_state)
import re
import stat
from rpmlint.checks.AbstractCheck import AbstractFilesCheck
class PkgConfigCheck(AbstractFilesCheck):
"""
Validate that .pc files are correct.
"""
suspicious_dir = re.compile(r'[=:](?:/usr/src/\w+/BUILD|/var/tmp|/tmp|/home)')
def __init__(self, config, output):
super().__init__(config, output, r'.*/pkgconfig/.*\.pc$')
def check(self, pkg):
# check for references to /lib when in lib64 mode and vice versa
if pkg.arch in ('x86_64', 'ppc64', 's390x', 'aarch64'):
self.wronglib_dir = re.compile(r'-L/usr/lib\b')
else:
self.wronglib_dir = re.compile(r'-L/usr/lib64\b')
AbstractFilesCheck.check(self, pkg)
#############################################################################
# Project : Mandriva Linux
# Module : rpmlint
# File : PamCheck.py
# Author : Michael Scherer
# Created On : 31/01/2006
# Purpose : Apply pam policy
#############################################################################
import re
from rpmlint.checks.AbstractCheck import AbstractFilesCheck
class PamCheck(AbstractFilesCheck):
pam_stack_re = re.compile(r'^\s*[^#].*pam_stack\.so\s*service')
def __init__(self, config, output):
super().__init__(config, output, r'/etc/pam\.d/.*')
def check_file(self, pkg, filename):
lines = pkg.grep(self.pam_stack_re, filename)
if lines:
self.output.add_info('E', pkg, 'use-old-pam-stack', filename,
'(line %s)' % ', '.join(lines))
def check(self, pkg):
# check for references to /lib when in lib64 mode and vice versa
if pkg.arch in ('x86_64', 'ppc64', 's390x', 'aarch64'):
self.wronglib_dir = re.compile(r'-L/usr/lib\b')
else:
self.wronglib_dir = re.compile(r'-L/usr/lib64\b')
AbstractFilesCheck.check(self, pkg)
import subprocess
from xml.etree import ElementTree
from rpmlint.checks.AbstractCheck import AbstractFilesCheck
from rpmlint.helpers import ENGLISH_ENVIROMENT
class AppDataCheck(AbstractFilesCheck):
"""
check appdata files for format violations
https://www.freedesktop.org/software/appstream/docs/
"""
# default command, split here so we can mock it later
cmd = 'appstream-util validate-relax --nonet '
def __init__(self, config, output):
super().__init__(config, output, r'/usr/share/appdata/.*\.(appdata|metainfo).xml$')
def check_file(self, pkg, filename):
root = pkg.dirName()
f = root + filename
cmd = self.cmd + f
validation_failed = False
import re
import stat
import rpm
from rpmlint.checks.AbstractCheck import AbstractFilesCheck
class BuildRootCheck(AbstractFilesCheck):
def __init__(self, config, output):
super().__init__(config, output, r'.*')
self.prepare_regex(rpm.expandMacro('%buildroot'))
def prepare_regex(self, buildroot):
for m in ('name', 'version', 'release', 'NAME', 'VERSION', 'RELEASE'):
buildroot = buildroot.replace('%%{%s}' % (m), r'[\w\!-\.]{1,20}')
self.build_root_re = re.compile(buildroot)
def check_file(self, pkg, filename):
if filename.startswith('/usr/lib/debug') or pkg.is_source:
return
if not stat.S_ISREG(pkg.files[filename].mode):
return
if pkg.grep(self.build_root_re, filename):
import stat
import subprocess
from rpmlint.checks.AbstractCheck import AbstractFilesCheck
from rpmlint.helpers import ENGLISH_ENVIROMENT
class BashismsCheck(AbstractFilesCheck):
def __init__(self, config, output):
super().__init__(config, output, r'.*')
def check_file(self, pkg, filename):
root = pkg.dirName()
pkgfile = pkg.files[filename]
filepath = root + filename
# We only care about the real files that state they are shell scripts
if not (stat.S_ISREG(pkgfile.mode) and
pkgfile.magic.startswith('POSIX shell script')):
return
self.check_bashisms(pkg, filepath, filename)
def check_bashisms(self, pkg, filepath, filename):