6c187fced25c5aca5c272fdca614f67bf2710ee8
[AGL/meta-agl.git] / meta-security / recipes-security / cynara / cynara_0.14.10.bb
1 DESCRIPTION = "Cynara service with client libraries"
2 LICENSE = "Apache-2.0"
3 LIC_FILES_CHKSUM = "file://LICENSE;md5=86d3f3a95c324c9479bd8986968f4327;beginline=3"
4
5 PV = "0.14.10+git${SRCPV}"
6 SRCREV = "be455dcaf1400bec0272a6ce90852b9147393a60"
7 SRC_URI = "git://github.com/Samsung/cynara.git"
8 S = "${WORKDIR}/git"
9
10 SRC_URI += " \
11   file://cynara-db-migration-abort-on-errors.patch \
12   file://0001-Add-fallthrough-tags.patch \
13   file://0002-gcc-7-requires-include-functional-for-std-function.patch \
14   file://0003-Avoid-warning-when-compiling-without-smack.patch \
15   file://0004-Fix-mode-of-sockets.patch \
16   file://0005-Allow-to-tune-sockets.patch \
17   file://0006-Install-socket-activation-by-default.patch \
18 "
19
20 DEPENDS = " \
21 glib-2.0 \
22 systemd \
23 zip \
24 "
25
26 PACKAGECONFIG ??= ""
27 # Use debug mode to increase logging. Beware, also compiles with less optimization
28 # and thus has to disable FORTIFY_SOURCE below.
29 PACKAGECONFIG[debug] = "-DCMAKE_BUILD_TYPE=DEBUG,-DCMAKE_BUILD_TYPE=RELEASE,libunwind elfutils"
30
31 inherit cmake
32
33 EXTRA_OECMAKE += " \
34   -DCMAKE_VERBOSE_MAKEFILE=ON \
35   -DBUILD_WITH_SYSTEMD_DAEMON=ON \
36   -DBUILD_WITH_SYSTEMD_JOURNAL=ON \
37   -DSYSTEMD_UNIT_DIR=${systemd_system_unitdir} \
38   -DSOCKET_DIR=/run/cynara \
39   -DBUILD_COMMONS=ON \
40   -DBUILD_SERVICE=ON \
41   -DBUILD_DBUS=OFF \
42   -DCYNARA_ADMIN_SOCKET_GROUP=cynara \
43 "
44
45 # Explicitly package empty directory. Otherwise Cynara prints warnings
46 # at runtime:
47 # cyad[198]: Couldn't scan for plugins in </usr/lib/cynara/plugin/service/> : <No such file or directory>
48 FILES_${PN}_append = " \
49 ${libdir}/cynara/plugin/service \
50 ${libdir}/cynara/plugin/client \
51 "
52
53 inherit useradd
54 USERADD_PACKAGES = "${PN}"
55 GROUPADD_PARAM_${PN} = "-r cynara"
56 USERADD_PARAM_${PN} = "\
57 --system --home ${localstatedir}/lib/empty \
58 --no-create-home --shell /bin/false \
59 --gid cynara cynara \
60 "
61
62 # Causes deadlock during booting, see workaround in postinst below.
63 #inherit systemd
64 #SYSTEMD_SERVICE_${PN} = "cynara.service"
65
66 #do_install_append () {
67 #   chmod a+rx ${D}/${sbindir}/cynara-db-migration
68 #
69 #   install -d ${D}${sysconfdir}/cynara/
70 #   install -m 644 ${S}/conf/creds.conf ${D}/${sysconfdir}/cynara/creds.conf
71 #
72 #   # No need to create empty directories except for those which
73 #   # Cynara expects to find.
74 #   # install -d ${D}${localstatedir}/cynara/
75 #   # install -d ${D}${prefix}/share/cynara/tests/empty_db
76 #   install -d ${D}${libdir}/cynara/plugin/client
77 #   install -d ${D}${libdir}/cynara/plugin/service
78 #
79 #   # install db* ${D}${prefix}/share/cynara/tests/
80 #
81 #   install -d ${D}${systemd_system_unitdir}/sockets.target.wants
82 #   ln -s ../cynara.socket ${D}${systemd_system_unitdir}/sockets.target.wants/cynara.socket
83 #   ln -s ../cynara-admin.socket ${D}${systemd_system_unitdir}/sockets.target.wants/cynara-admin.socket
84 #   ln -s ../cynara-agent.socket ${D}${systemd_system_unitdir}/sockets.target.wants/cynara-agent.socket
85 #}
86
87 FILES_${PN} += "${systemd_system_unitdir}"
88
89 # Cynara itself has no dependency on Smack. Only its installation
90 # is Smack-aware in the sense that it sets Smack labels. Do not
91 # depend on smack userspace unless we really need Smack labels.
92 #
93 # The Tizen .spec file calls cynara-db-migration in a %pre section.
94 # That only works when cynara-db-migration is packaged separately
95 # (overly complex) and does not seem necessary: perhaps there is a
96 # time window where cynara might already get activated before
97 # the postinst completes, but that is a general problem. It gets
98 # avoided entirely when calling this script while building the
99 # rootfs.
100 DEPENDS_append_with-lsm-smack = " smack smack-native"
101 EXTRA_OECMAKE_append_with-lsm-smack = " -DDB_FILES_SMACK_LABEL=System"
102 CHSMACK_with-lsm-smack = "chsmack"
103 CHSMACK = "true"
104 pkg_postinst_${PN} () {
105    # Fail on error.
106    set -e
107
108    # It would be nice to run the code below while building an image,
109    # but currently the calls to cynara-db-chsgen (a binary) in
110    # cynara-db-migration (a script) prevent that. Rely instead
111    # on OE's support for running failed postinst scripts at first boot.
112    if [ x"$D" != "x" ]; then
113       exit 1
114    fi
115
116    mkdir -p $D${sysconfdir}/cynara
117    ${CHSMACK} -a System $D${sysconfdir}/cynara
118
119    # Strip git patch level information, the version comparison code
120    # in cynara-db-migration only expect major.minor.patch version numbers.
121    VERSION=${@d.getVar('PV',d,1).split('+git')[0]}
122    if [ -d $D${localstatedir}/cynara ] ; then
123       # upgrade
124       echo "NOTE: updating cynara DB to version $VERSION"
125       $D${sbindir}/cynara-db-migration upgrade -f 0.0.0 -t $VERSION
126    else
127       # install
128       echo "NOTE: creating cynara DB for version $VERSION"
129       mkdir -p $D${localstatedir}/cynara
130       ${CHSMACK} -a System $D${localstatedir}/cynara
131       $D${sbindir}/cynara-db-migration install -t $VERSION
132    fi
133
134    # Workaround for systemd.bbclass issue: it would call
135    # "systemctl start" without "--no-block", but because
136    # the service is not ready to run at the time when
137    # this scripts gets executed by run-postinsts.service,
138    # booting deadlocks.
139    echo "NOTE: enabling and starting cynara service"
140    systemctl enable cynara
141    systemctl start --no-block cynara
142 }
143
144 # Testing depends on gmock and gtest. They can be found in meta-oe
145 # and are not necessarily available, so this feature is off by default.
146 # If gmock from meta-oe is used, then a workaround is needed to avoid
147 # a link error (libgmock.a calls pthread functions without libpthread
148 # being listed in the .pc file).
149 DEPENDS_append = "${@bb.utils.contains('PACKAGECONFIG', 'tests', ' gmock', '', d)}"
150 LDFLAGS_append = "${@bb.utils.contains('PACKAGECONFIG', 'tests', ' -lpthread', '', d)}"
151 SRC_URI_append = "${@bb.utils.contains('PACKAGECONFIG', 'tests', ' file://run-ptest', '', d)}"
152 PACKAGECONFIG[tests] = "-DBUILD_TESTS:BOOL=ON,-DBUILD_TESTS:BOOL=OFF,gmock gtest,"
153
154 # Will be empty if no tests were built.
155 inherit ptest
156 FILES_${PN}-ptest += "${bindir}/cynara-tests ${bindir}/cynara-db-migration-tests ${datadir}/cynara/tests"
157 do_install_ptest () {
158     if ${@bb.utils.contains('PACKAGECONFIG', 'tests', 'true', 'false', d)}; then
159         mkdir -p ${D}/${datadir}/cynara/tests
160         cp -r ${S}/test/db/* ${D}/${datadir}/cynara/tests
161     fi
162 }
163