2008-12-15 15:05:00 +01:00
|
|
|
# vim:sw=4:et
|
|
|
|
#############################################################################
|
|
|
|
# File : CheckPolkitPrivs.py
|
|
|
|
# Package : rpmlint
|
|
|
|
# Author : Ludwig Nussel
|
|
|
|
# Purpose : Check for /etc/polkit-default-privs violations
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
from Filter import *
|
|
|
|
import AbstractCheck
|
2010-02-26 01:10:53 +01:00
|
|
|
import Config
|
2008-12-15 15:05:00 +01:00
|
|
|
import re
|
|
|
|
import os
|
|
|
|
from xml.dom.minidom import parse
|
|
|
|
|
2010-02-26 01:10:53 +01:00
|
|
|
POLKIT_PRIVS_WHITELIST = Config.getOption('PolkitPrivsWhiteList', ()) # set of file names
|
|
|
|
POLKIT_PRIVS_FILES = Config.getOption('PolkitPrivsFiles', [ "/etc/polkit-default-privs.standard" ])
|
2008-12-15 15:05:00 +01:00
|
|
|
|
|
|
|
class PolkitCheck(AbstractCheck.AbstractCheck):
|
|
|
|
def __init__(self):
|
|
|
|
AbstractCheck.AbstractCheck.__init__(self, "CheckPolkitPrivs")
|
|
|
|
self.privs = {}
|
|
|
|
|
2011-08-19 18:36:40 +02:00
|
|
|
for filename in POLKIT_PRIVS_FILES:
|
|
|
|
if os.path.exists(filename):
|
|
|
|
self._parsefile(filename)
|
2008-12-15 15:05:00 +01:00
|
|
|
|
2011-08-19 18:36:40 +02:00
|
|
|
def _parsefile(self,filename):
|
|
|
|
for line in file(filename):
|
2008-12-15 15:05:00 +01:00
|
|
|
line = line.split('#')[0].split('\n')[0]
|
|
|
|
if len(line):
|
|
|
|
line = re.split(r'\s+', line)
|
|
|
|
priv = line[0]
|
|
|
|
value = line[1]
|
|
|
|
|
|
|
|
self.privs[priv] = value
|
|
|
|
|
|
|
|
def check(self, pkg):
|
|
|
|
|
|
|
|
if pkg.isSource():
|
|
|
|
return
|
|
|
|
|
|
|
|
files = pkg.files()
|
|
|
|
|
|
|
|
permfiles = {}
|
|
|
|
# first pass, find additional files
|
|
|
|
for f in files:
|
|
|
|
if f in pkg.ghostFiles():
|
|
|
|
continue
|
|
|
|
|
|
|
|
if f.startswith("/etc/polkit-default-privs.d/"):
|
|
|
|
|
|
|
|
bn = f[28:]
|
2010-02-26 01:10:53 +01:00
|
|
|
if not bn in POLKIT_PRIVS_WHITELIST:
|
2008-12-15 15:05:00 +01:00
|
|
|
printError(pkg, "polkit-unauthorized-file", f)
|
|
|
|
|
2011-08-19 18:36:40 +02:00
|
|
|
if bn.endswith(".restrictive") or bn.endswith(".standard") or bn.endswith(".relaxed"):
|
|
|
|
bn = bn.split('.')[0]
|
|
|
|
|
2008-12-15 15:05:00 +01:00
|
|
|
if not bn in permfiles:
|
|
|
|
permfiles[bn] = 1
|
|
|
|
|
|
|
|
for f in permfiles:
|
|
|
|
f = pkg.dirName() + "/etc/polkit-default-privs.d/" + f
|
2011-08-19 18:36:40 +02:00
|
|
|
|
2008-12-15 15:05:00 +01:00
|
|
|
if os.path.exists(f+".restrictive"):
|
|
|
|
self._parsefile(f + ".restrictive")
|
|
|
|
elif os.path.exists(f+".standard"):
|
|
|
|
self._parsefile(f + ".standard")
|
|
|
|
elif os.path.exists(f+".relaxed"):
|
|
|
|
self._parsefile(f + ".relaxed")
|
|
|
|
else:
|
|
|
|
self._parsefile(f)
|
|
|
|
|
2011-08-19 18:36:40 +02:00
|
|
|
|
2008-12-15 15:05:00 +01:00
|
|
|
for f in files:
|
|
|
|
if f in pkg.ghostFiles():
|
|
|
|
continue
|
|
|
|
|
|
|
|
# catch xml exceptions
|
|
|
|
try:
|
2010-02-26 01:10:53 +01:00
|
|
|
if f.startswith("/usr/share/PolicyKit/policy/")\
|
|
|
|
or f.startswith("/usr/share/polkit-1/actions/"):
|
2011-06-07 17:11:55 +02:00
|
|
|
xml = parse(pkg.dirName() + f)
|
2008-12-15 15:05:00 +01:00
|
|
|
for a in xml.getElementsByTagName("action"):
|
|
|
|
action = a.getAttribute('id')
|
|
|
|
if not action in self.privs:
|
|
|
|
iserr = 0
|
|
|
|
foundno = 0
|
2011-06-07 17:11:55 +02:00
|
|
|
foundundef = 0
|
|
|
|
settings = {}
|
2008-12-15 15:05:00 +01:00
|
|
|
try:
|
|
|
|
defaults = a.getElementsByTagName("defaults")[0]
|
|
|
|
for i in defaults.childNodes:
|
|
|
|
if not i.nodeType == i.ELEMENT_NODE:
|
|
|
|
continue
|
2011-06-07 17:11:55 +02:00
|
|
|
|
|
|
|
if i.nodeName in ('allow_any', 'allow_inactive', 'allow_active'):
|
|
|
|
settings[i.nodeName] = i.firstChild.data
|
|
|
|
|
2008-12-15 15:05:00 +01:00
|
|
|
except:
|
|
|
|
iserr = 1
|
|
|
|
|
2011-06-07 17:11:55 +02:00
|
|
|
for i in ('allow_any', 'allow_inactive', 'allow_active'):
|
|
|
|
if not i in settings:
|
|
|
|
foundundef = 1
|
|
|
|
settings[i] = '??'
|
|
|
|
elif settings[i].find("auth_admin") != 0:
|
|
|
|
if settings[i] == 'no':
|
|
|
|
foundno = 1
|
|
|
|
else:
|
|
|
|
iserr = 1
|
|
|
|
|
2008-12-15 15:05:00 +01:00
|
|
|
if iserr:
|
2011-06-07 17:11:55 +02:00
|
|
|
printError(pkg, 'polkit-unauthorized-privilege', '%s (%s:%s:%s)' % (action, \
|
|
|
|
settings['allow_any'], settings['allow_inactive'], settings['allow_active']))
|
2008-12-15 15:05:00 +01:00
|
|
|
else:
|
2011-06-07 17:11:55 +02:00
|
|
|
printInfo(pkg, 'polkit-untracked-privilege', '%s (%s:%s:%s)' % (action, \
|
|
|
|
settings['allow_any'], settings['allow_inactive'], settings['allow_active']))
|
|
|
|
|
|
|
|
if foundno or foundundef:
|
|
|
|
printInfo(pkg,
|
|
|
|
'polkit-cant-acquire-privilege', '%s (%s:%s:%s)' % (action, \
|
|
|
|
settings['allow_any'], settings['allow_inactive'], settings['allow_active']))
|
2008-12-15 15:05:00 +01:00
|
|
|
|
2011-06-07 17:11:55 +02:00
|
|
|
except Exception, x:
|
|
|
|
printError(pkg, 'rpmlint-exception', "%(file)s raised an exception: %(x)s" % {'file':f, 'x':x})
|
2008-12-15 15:05:00 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
check=PolkitCheck()
|
|
|
|
|
|
|
|
if Config.info:
|
|
|
|
addDetails(
|
|
|
|
'polkit-unauthorized-file',
|
2010-10-28 13:38:59 +02:00
|
|
|
"""If the package is intended for inclusion in any SUSE product
|
|
|
|
please open a bug report to request review of the package by the
|
|
|
|
security team""",
|
2008-12-15 15:05:00 +01:00
|
|
|
'polkit-unauthorized-privilege',
|
2011-06-07 17:11:55 +02:00
|
|
|
"""The package allows unprivileged users to carry out privileged
|
|
|
|
operations without authentication. This could cause security
|
|
|
|
problems if not done carefully. If the package is intended for
|
|
|
|
inclusion in any SUSE product please open a bug report to request
|
|
|
|
review of the package by the security team""",
|
|
|
|
'polkit-untracked-privilege',
|
|
|
|
"""The privilege is not listed in /etc/polkit-default-privs.*
|
|
|
|
which makes it harder for admins to find. If the package is intended
|
|
|
|
for inclusion in any SUSE product please open a bug report to
|
|
|
|
request review of the package by the security team""",
|
2008-12-15 15:05:00 +01:00
|
|
|
'polkit-cant-acquire-privilege',
|
|
|
|
"""Usability can be improved by allowing users to acquire privileges
|
|
|
|
via authentication. Use e.g. 'auth_admin' instead of 'no' and make
|
2011-06-07 17:11:55 +02:00
|
|
|
sure to define 'allow_any'. This is an issue only if the privilege
|
|
|
|
is not listed in /etc/polkit-default-privs.*""")
|