810106d75c36c2cb6d6a44ea1e3a10108a70cbd3
[AGL/meta-agl.git] / meta-security / recipes-security / security-manager / security-manager.inc
1 DESCRIPTION = "Security manager and utilities"
2 LICENSE = "Apache-2.0"
3 LIC_FILES_CHKSUM = "file://LICENSE;md5=86d3f3a95c324c9479bd8986968f4327;beginline=3"
4
5 inherit cmake
6
7 # Out-of-tree build is broken ("sqlite3 .security-manager.db <db.sql" where db.sql is in $S/db).
8 B = "${S}"
9
10 DEPENDS = " \
11 attr \
12 boost \
13 cynara \
14 icu \
15 libcap \
16 smack \
17 sqlite3 \
18 sqlite3-native \
19 systemd \
20 "
21
22 PACKAGECONFIG ??= ""
23 PACKAGECONFIG[debug] = "-DCMAKE_BUILD_TYPE=DEBUG,-DCMAKE_BUILD_TYPE=RELEASE"
24
25 TZ_SYS_DB = "/var/local/db/security-manager"
26
27 EXTRA_OECMAKE = " \
28 -DCMAKE_VERBOSE_MAKEFILE=ON \
29 -DVERSION=${PV} \
30 -DSYSTEMD_INSTALL_DIR=${systemd_unitdir}/system \
31 -DBIN_INSTALL_DIR=${bindir} \
32 -DDB_INSTALL_DIR=${TZ_SYS_DB} \
33 -DLIB_INSTALL_DIR=${libdir} \
34 -DSHARE_INSTALL_PREFIX=${datadir} \
35 -DINCLUDE_INSTALL_DIR=${includedir} \
36 "
37
38 inherit systemd
39 SYSTEMD_SERVICE_${PN} = "security-manager.service"
40
41 inherit distro_features_check
42 REQUIRED_DISTRO_FEATURES += "smack"
43
44 # The upstream source code contains the Tizen-specific policy configuration files.
45 # To replace them, create a security-manager.bbappend and set the following variable to a
46 # space-separated list of policy file names (not URIs!), for example:
47 # SECURITY_MANAGER_POLICY = "privilege-group.list usertype-system.profile"
48 #
49 # Leave it empty to use the upstream Tizen policy.
50 SECURITY_MANAGER_POLICY ?= ""
51 SRC_URI_append = " ${@' '.join(['file://' + x for x in d.getVar('SECURITY_MANAGER_POLICY', True).split()])}"
52 python do_patch_append () {
53     import os
54     import shutil
55     import glob
56     files = d.getVar('SECURITY_MANAGER_POLICY', True).split()
57     if files:
58         s = d.getVar('S', True)
59         workdir = d.getVar('WORKDIR', True)
60         for pattern in ['*.profile', '*.list']:
61             for old_file in glob.glob(s + '/policy/' + pattern):
62                 os.unlink(old_file)
63         for file in files:
64             shutil.copy(file, s + '/policy')
65 }
66
67 do_install_append () {
68    install -d ${D}/${systemd_unitdir}/system/multi-user.target.wants
69    ln -s ../security-manager.service ${D}/${systemd_unitdir}/system/multi-user.target.wants/security-manager.service
70    install -d ${D}/${systemd_unitdir}/system/sockets.target.wants
71    ln -s ../security-manager.socket ${D}/${systemd_unitdir}/system/sockets.target.wants/security-manager.socket
72 }
73
74 RDEPENDS_${PN} += "smack"
75 pkg_postinst_${PN} () {
76    set -e
77    chsmack -a System $D${TZ_SYS_DB}/.security-manager.db
78    chsmack -a System $D${TZ_SYS_DB}/.security-manager.db-journal
79 }
80
81 FILES_${PN} += " \
82 ${systemd_unitdir} \
83 ${TZ_SYS_DB} \
84 "
85
86 PACKAGES =+ "${PN}-policy"
87 FILES_${PN}-policy = " \
88    ${datadir}/${PN} \
89    ${bindir}/security-manager-policy-reload \
90 "
91 RDEPENDS_${PN}-policy += "sqlite3 cynara"
92 pkg_postinst_${PN}-policy () {
93    if [ x"$D" = "x" ] && ${bindir}/security-manager-policy-reload; then
94        exit 0
95    else
96        exit 1
97    fi
98 }