2014-07-08 18:28:55 +00:00
|
|
|
#!/usr/bin/env python
|
2017-08-05 19:55:35 +00:00
|
|
|
from __future__ import print_function
|
2015-06-03 17:33:11 +00:00
|
|
|
import glob
|
2014-07-08 18:28:55 +00:00
|
|
|
from setuptools import setup
|
2014-10-29 16:03:44 +00:00
|
|
|
import distutils.log as log
|
2014-10-25 01:00:24 +00:00
|
|
|
from distutils.core import Extension
|
2014-10-29 16:03:44 +00:00
|
|
|
from distutils.cmd import Command
|
2015-06-15 14:31:12 +00:00
|
|
|
from distutils.unixccompiler import UnixCCompiler
|
2014-10-29 16:03:44 +00:00
|
|
|
from setuptools.command.build_ext import build_ext
|
|
|
|
import subprocess
|
2015-02-05 18:23:27 +00:00
|
|
|
import sys
|
2015-06-15 14:31:12 +00:00
|
|
|
import os
|
2015-02-05 18:23:27 +00:00
|
|
|
from os.path import join
|
2014-10-29 16:03:44 +00:00
|
|
|
|
|
|
|
|
2016-04-19 19:59:56 +00:00
|
|
|
class QtHelpCommand(Command):
|
|
|
|
description = "Build Qt help files."
|
|
|
|
user_options = []
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def run(self):
|
2017-02-15 20:28:06 +00:00
|
|
|
command = ['qcollectiongenerator', 'qhc/apol.qhcp']
|
2016-04-19 19:59:56 +00:00
|
|
|
self.announce("Building Qt help files", level=log.INFO)
|
|
|
|
self.announce(' '.join(command), level=log.INFO)
|
|
|
|
subprocess.check_call(command)
|
2017-02-15 20:28:06 +00:00
|
|
|
self.announce("Moving Qt help files to setoolsgui/apol")
|
|
|
|
os.rename('qhc/apol.qhc', 'setoolsgui/apol/apol.qhc')
|
|
|
|
os.rename('qhc/apol.qch', 'setoolsgui/apol/apol.qch')
|
2016-04-19 19:59:56 +00:00
|
|
|
|
|
|
|
|
2014-10-29 16:03:44 +00:00
|
|
|
class YaccCommand(Command):
|
|
|
|
description = "Build yacc parsers."
|
|
|
|
user_options = []
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def run(self):
|
2014-10-29 16:04:53 +00:00
|
|
|
command = ['bison', '-y', '-d', 'libqpol/policy_parse.y',
|
|
|
|
'-o', 'libqpol/policy_parse.c']
|
|
|
|
self.announce("Generating parser", level=log.INFO)
|
2014-10-29 16:03:44 +00:00
|
|
|
self.announce(' '.join(command), level=log.INFO)
|
|
|
|
subprocess.check_call(command)
|
|
|
|
|
2014-10-29 16:04:53 +00:00
|
|
|
|
2014-10-29 16:03:44 +00:00
|
|
|
class LexCommand(Command):
|
|
|
|
description = "Build lex scanners."
|
|
|
|
user_options = []
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def run(self):
|
2014-10-29 16:04:53 +00:00
|
|
|
command = [
|
|
|
|
'flex', '-o', 'libqpol/policy_scan.c', 'libqpol/policy_scan.l']
|
|
|
|
self.announce("Generating scanner", level=log.INFO)
|
2014-10-29 16:03:44 +00:00
|
|
|
self.announce(' '.join(command), level=log.INFO)
|
|
|
|
subprocess.check_call(command)
|
|
|
|
|
2014-10-29 16:04:53 +00:00
|
|
|
|
2014-10-29 16:03:44 +00:00
|
|
|
class BuildExtCommand(build_ext):
|
2014-10-29 16:04:53 +00:00
|
|
|
|
2014-10-29 16:03:44 +00:00
|
|
|
def run(self):
|
|
|
|
self.run_command('build_yacc')
|
|
|
|
self.run_command('build_lex')
|
|
|
|
build_ext.run(self)
|
2014-10-25 01:00:24 +00:00
|
|
|
|
2015-06-15 14:31:12 +00:00
|
|
|
|
2017-01-23 23:27:22 +00:00
|
|
|
base_lib_dirs = ['.', '/usr/lib64', '/usr/lib', '/usr/local/lib']
|
2016-11-11 23:21:48 +00:00
|
|
|
include_dirs = ['libqpol', 'libqpol/include']
|
|
|
|
|
|
|
|
try:
|
|
|
|
base_lib_dirs.insert(0, os.environ["SEPOL_SRC"] + "/src")
|
|
|
|
include_dirs.append(os.environ["SEPOL_SRC"] + "/include")
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
2015-06-15 14:31:12 +00:00
|
|
|
try:
|
2015-12-16 14:40:49 +00:00
|
|
|
static_sepol = os.environ['SEPOL']
|
2015-06-15 14:31:12 +00:00
|
|
|
except KeyError:
|
|
|
|
# try to find libsepol.a. The find_library_file function
|
|
|
|
# chooses dynamic libraries over static ones, so
|
|
|
|
# this assumes that the static lib is in the same directory
|
|
|
|
# as the dynamic lib.
|
2016-11-11 23:21:48 +00:00
|
|
|
dynamic_sepol = UnixCCompiler().find_library_file(base_lib_dirs, 'sepol')
|
2016-05-10 18:16:53 +00:00
|
|
|
|
|
|
|
if dynamic_sepol is None:
|
|
|
|
print('Unable to find a libsepol.so on your system!')
|
2017-08-05 19:55:35 +00:00
|
|
|
print("Looked in the following directories:\n{}".format("\n".join(base_lib_dirs)))
|
|
|
|
print('Please set the SEPOL or SEPOL_SRC environment variables. Exiting.')
|
2016-05-10 18:16:53 +00:00
|
|
|
exit(1)
|
|
|
|
|
2015-06-15 14:31:12 +00:00
|
|
|
static_sepol = dynamic_sepol.replace(".so", ".a")
|
|
|
|
|
2016-04-22 01:37:30 +00:00
|
|
|
if sys.platform.startswith('darwin'):
|
|
|
|
macros=[('DARWIN',1)]
|
|
|
|
else:
|
|
|
|
macros=[]
|
|
|
|
|
2014-10-29 16:04:53 +00:00
|
|
|
ext_py_mods = [Extension('setools.policyrep._qpol',
|
|
|
|
['setools/policyrep/qpol.i',
|
|
|
|
'libqpol/avrule_query.c',
|
|
|
|
'libqpol/bool_query.c',
|
|
|
|
'libqpol/bounds_query.c',
|
|
|
|
'libqpol/class_perm_query.c',
|
|
|
|
'libqpol/cond_query.c',
|
|
|
|
'libqpol/constraint_query.c',
|
|
|
|
'libqpol/context_query.c',
|
|
|
|
'libqpol/default_object_query.c',
|
|
|
|
'libqpol/expand.c',
|
|
|
|
'libqpol/fs_use_query.c',
|
|
|
|
'libqpol/ftrule_query.c',
|
|
|
|
'libqpol/genfscon_query.c',
|
|
|
|
'libqpol/isid_query.c',
|
|
|
|
'libqpol/iterator.c',
|
|
|
|
'libqpol/mls_query.c',
|
|
|
|
'libqpol/mlsrule_query.c',
|
|
|
|
'libqpol/module.c',
|
|
|
|
'libqpol/module_compiler.c',
|
|
|
|
'libqpol/netifcon_query.c',
|
|
|
|
'libqpol/nodecon_query.c',
|
|
|
|
'libqpol/permissive_query.c',
|
|
|
|
'libqpol/polcap_query.c',
|
|
|
|
'libqpol/policy.c',
|
|
|
|
'libqpol/policy_define.c',
|
|
|
|
'libqpol/policy_extend.c',
|
|
|
|
'libqpol/portcon_query.c',
|
|
|
|
'libqpol/queue.c',
|
|
|
|
'libqpol/rbacrule_query.c',
|
|
|
|
'libqpol/role_query.c',
|
|
|
|
'libqpol/terule_query.c',
|
|
|
|
'libqpol/type_query.c',
|
|
|
|
'libqpol/user_query.c',
|
|
|
|
'libqpol/policy_parse.c',
|
2015-12-16 16:35:36 +00:00
|
|
|
'libqpol/policy_scan.c',
|
2016-03-01 22:27:33 +00:00
|
|
|
'libqpol/xen_query.c'],
|
2016-11-11 23:21:48 +00:00
|
|
|
include_dirs=include_dirs,
|
2015-02-05 15:52:42 +00:00
|
|
|
extra_compile_args=['-Werror', '-Wextra',
|
2014-11-02 18:38:41 +00:00
|
|
|
'-Waggregate-return',
|
|
|
|
'-Wfloat-equal',
|
|
|
|
'-Wformat', '-Wformat=2',
|
2017-08-05 19:55:35 +00:00
|
|
|
'-Winit-self',
|
2014-11-02 18:38:41 +00:00
|
|
|
'-Wmissing-format-attribute',
|
|
|
|
'-Wmissing-include-dirs',
|
|
|
|
'-Wnested-externs',
|
|
|
|
'-Wold-style-definition',
|
|
|
|
'-Wpointer-arith',
|
|
|
|
'-Wredundant-decls',
|
|
|
|
'-Wstrict-prototypes',
|
|
|
|
'-Wunknown-pragmas',
|
|
|
|
'-Wwrite-strings',
|
|
|
|
'-Wno-missing-field-initializers', # SWIG 3.0.2 generates partially-initialized structs
|
|
|
|
'-Wno-unused-parameter', # SWIG generates functions with unused parameters
|
2016-04-22 01:37:30 +00:00
|
|
|
'-Wno-cast-qual', # libsepol uses const-to-nonconst casts
|
2014-11-02 18:38:41 +00:00
|
|
|
'-Wno-shadow', # SWIG generates shadow variables
|
2016-05-09 15:02:21 +00:00
|
|
|
'-Wno-unreachable-code', # Bison generates unreachable code
|
2014-11-02 18:38:41 +00:00
|
|
|
'-fno-exceptions'],
|
2016-04-22 01:37:30 +00:00
|
|
|
swig_opts=['-Ilibqpol/include'],
|
|
|
|
define_macros=macros,
|
|
|
|
extra_objects=[static_sepol])]
|
2014-07-08 18:28:55 +00:00
|
|
|
|
|
|
|
setup(name='setools',
|
2017-09-16 18:17:51 +00:00
|
|
|
version='4.2-dev',
|
2014-10-29 16:04:53 +00:00
|
|
|
description='SELinux Policy tools.',
|
|
|
|
author='Tresys Technology, LLC',
|
|
|
|
author_email='setools@tresys.com',
|
|
|
|
url='https://github.com/TresysTechnology/setools',
|
|
|
|
cmdclass={'build_yacc': YaccCommand,
|
|
|
|
'build_lex': LexCommand,
|
2016-04-19 19:59:56 +00:00
|
|
|
'build_ext': BuildExtCommand,
|
2016-04-20 13:50:23 +00:00
|
|
|
'build_qhc': QtHelpCommand},
|
2016-01-07 19:48:50 +00:00
|
|
|
packages=['setools', 'setools.diff', 'setools.policyrep', 'setoolsgui', 'setoolsgui.apol'],
|
|
|
|
scripts=['apol', 'sediff', 'seinfo', 'seinfoflow', 'sesearch', 'sedta'],
|
2016-11-12 16:13:21 +00:00
|
|
|
data_files=[(join(sys.prefix, 'share/man/man1'), glob.glob("man/*.1"))],
|
2017-02-15 20:28:06 +00:00
|
|
|
package_data={'': ['*.ui', '*.qhc', '*.qch'], 'setools': ['perm_map']},
|
2014-10-29 16:04:53 +00:00
|
|
|
ext_modules=ext_py_mods,
|
|
|
|
test_suite='tests',
|
|
|
|
license='GPLv2+, LGPLv2.1+',
|
|
|
|
classifiers=[
|
|
|
|
'Environment :: Console',
|
2015-06-03 17:33:11 +00:00
|
|
|
'Environment :: X11 Applications :: Qt',
|
2014-10-29 16:04:53 +00:00
|
|
|
'Intended Audience :: Information Technology',
|
|
|
|
'Topic :: Security',
|
|
|
|
'Topic :: Utilities',
|
|
|
|
],
|
|
|
|
)
|