Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 1 | SUMMARY = "A full platform to monitor and control your systems" |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 2 | LICENSE = "GPL-2.0-only" |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 3 | LIC_FILES_CHKSUM = "file://LICENSE;md5=d625d1520b5e38faefb81cf9772badc9" |
| 4 | |
| 5 | |
| 6 | DEPENDS = "openssl libpcre2 zlib libevent" |
Patrick Williams | 53961c2 | 2022-01-20 11:06:23 -0600 | [diff] [blame] | 7 | SRC_URI = "git://github.com/ossec/ossec-hids;branch=master;protocol=https \ |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 8 | file://0001-Makefile-drop-running-scrips-install.patch \ |
| 9 | file://0002-Makefile-don-t-set-uid-gid.patch \ |
| 10 | " |
| 11 | |
Andrew Geissler | dc9d614 | 2023-05-19 09:38:37 -0500 | [diff] [blame] | 12 | SRCREV = "bf797c759994015274f3bc31fe2bed278cce67ee" |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 13 | |
William A. Kennington III | ee32beb | 2021-06-02 12:48:35 -0700 | [diff] [blame] | 14 | UPSTREAM_CHECK_COMMITS = "1" |
| 15 | |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 16 | inherit autotools-brokensep useradd |
| 17 | |
| 18 | S = "${WORKDIR}/git" |
| 19 | |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 20 | |
| 21 | OSSEC_DIR="/var/ossec" |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 22 | OSSEC_UID ?= "ossec" |
| 23 | OSSEC_RUID ?= "ossecr" |
| 24 | OSSEC_GID ?= "ossec" |
| 25 | OSSEC_EMAIL ?= "ossecm" |
| 26 | |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 27 | USERADD_PACKAGES = "${PN}" |
| 28 | GROUPADD_PARAM:${PN} = "--system ${OSSEC_UID}" |
| 29 | USERADD_PARAM:${PN} = "--system -g ${OSSEC_GID} --home-dir \ |
| 30 | ${OSSEC_DIR} --no-create-home \ |
| 31 | --shell /sbin/nologin ${BPN}" |
| 32 | |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 33 | do_configure[noexec] = "1" |
| 34 | |
| 35 | do_compile() { |
| 36 | cd ${S}/src |
| 37 | make PREFIX=${prefix} TARGET=local USE_SYSTEMD=No build |
| 38 | } |
| 39 | |
| 40 | do_install(){ |
| 41 | install -d ${D}${sysconfdir} |
| 42 | install -d ${D}/var/ossec/${sysconfdir} |
| 43 | |
| 44 | cd ${S}/src |
| 45 | make TARGET=local PREFIX=${D}/var/ossec install |
| 46 | |
| 47 | echo "DIRECTORY=\"/var/ossec\"" > ${D}/${sysconfdir}/ossec-init.conf |
| 48 | echo "VERSION=\"${PV}\"" >> ${D}/${sysconfdir}/ossec-init.conf |
| 49 | echo "DATE=\"`date`\"" >> ${D}/${sysconfdir}/ossec-init.conf |
| 50 | echo "TYPE=\"local\"" >> ${D}/${sysconfdir}/ossec-init.conf |
| 51 | chmod 600 ${D}/${sysconfdir}/ossec-init.conf |
| 52 | install -m 640 ${D}/${sysconfdir}/ossec-init.conf ${D}/var/ossec/${sysconfdir}/ossec-init.conf |
| 53 | } |
| 54 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 55 | pkg_postinst_ontarget:${PN} () { |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 56 | |
| 57 | # Default for all directories |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 58 | chmod -R 550 ${OSSEC_DIR} |
| 59 | chown -R root:${OSSEC_GID} ${OSSEC_DIR} |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 60 | |
| 61 | # To the ossec queue (default for agentd to read) |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 62 | chown -R ${OSSEC_UUID}:${OSSEC_GID} ${OSSEC_DIR}/queue/ossec |
| 63 | chmod -R 770 ${OSSEC_DIR}/queue/ossec |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 64 | |
| 65 | # For the logging user |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 66 | chown -R ${OSSEC_UUID}:${OSSEC_GID} ${OSSEC_DIR}/logs |
| 67 | chmod -R 750 ${OSSEC_DIR}/logs |
| 68 | chmod -R 775 ${OSSEC_DIR}/queue/rids |
| 69 | touch ${OSSEC_DIR}/logs/ossec.log |
| 70 | chown ${OSSEC_UUID}:${OSSEC_GID} ${OSSEC_DIR}/logs/ossec.log |
| 71 | chmod 664 ${OSSEC_DIR}/logs/ossec.log |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 72 | |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 73 | chown -R ${OSSEC_UUID}:${OSSEC_GID} ${OSSEC_DIR}/queue/diff |
| 74 | chmod -R 750 ${OSSEC_DIR}/queue/diff |
| 75 | chmod 740 ${OSSEC_DIR}/queue/diff/* > /dev/null 2>&1 || true |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 76 | |
| 77 | # For the etc dir |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 78 | chmod 550 ${OSSEC_DIR}/etc |
| 79 | chown -R root:${OSSEC_GID} ${OSSEC_DIR}/etc |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 80 | if [ -f /etc/localtime ]; then |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 81 | cp -pL /etc/localtime ${OSSEC_DIR}/etc/; |
| 82 | chmod 555 ${OSSEC_DIR}/etc/localtime |
| 83 | chown root:${OSSEC_GID} ${OSSEC_DIR}/etc/localtime |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 84 | fi |
| 85 | |
| 86 | if [ -f /etc/TIMEZONE ]; then |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 87 | cp -p /etc/TIMEZONE ${OSSEC_DIR}/etc/; |
| 88 | chmod 555 ${OSSEC_DIR}/etc/TIMEZONE |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 89 | fi |
| 90 | |
| 91 | # More files |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 92 | chown root:${OSSEC_GID} ${OSSEC_DIR}/etc/internal_options.conf |
| 93 | chown root:${OSSEC_GID} ${OSSEC_DIR}/etc/local_internal_options.conf >/dev/null 2>&1 || true |
| 94 | chown root:${OSSEC_GID} ${OSSEC_DIR}/etc/client.keys >/dev/null 2>&1 || true |
| 95 | chown root:${OSSEC_GID} ${OSSEC_DIR}/agentless/* |
| 96 | chown ${OSSEC_UUID}:${OSSEC_GID} ${OSSEC_DIR}/.ssh |
| 97 | chown root:${OSSEC_GID} ${OSSEC_DIR}/etc/shared/* |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 98 | |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 99 | chmod 550 ${OSSEC_DIR}/etc |
| 100 | chmod 440 ${OSSEC_DIR}/etc/internal_options.conf |
| 101 | chmod 660 ${OSSEC_DIR}/etc/local_internal_options.conf >/dev/null 2>&1 || true |
| 102 | chmod 440 ${OSSEC_DIR}/etc/client.keys >/dev/null 2>&1 || true |
| 103 | chmod 550 ${OSSEC_DIR}/agentless/* |
| 104 | chmod 700 ${OSSEC_DIR}/.ssh |
| 105 | chmod 770 ${OSSEC_DIR}/etc/shared |
| 106 | chmod 660 ${OSSEC_DIR}/etc/shared/* |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 107 | |
| 108 | # For the /var/run |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 109 | chmod 770 ${OSSEC_DIR}/var/run |
| 110 | chown root:${OSSEC_GID} ${OSSEC_DIR}/var/run |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 111 | |
| 112 | # For util.sh |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 113 | chown root:${OSSEC_GID} ${OSSEC_DIR}/bin/util.sh |
| 114 | chmod +x ${OSSEC_DIR}/bin/util.sh |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 115 | |
| 116 | # For binaries and active response |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 117 | chmod 755 ${OSSEC_DIR}/active-response/bin/* |
| 118 | chown root:${OSSEC_GID} ${OSSEC_DIR}/active-response/bin/* |
| 119 | chown root:${OSSEC_GID} ${OSSEC_DIR}/bin/* |
| 120 | chmod 550 ${OSSEC_DIR}/bin/* |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 121 | |
| 122 | # For ossec.conf |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 123 | chown root:${OSSEC_GID} ${OSSEC_DIR}/etc/ossec.conf |
| 124 | chmod 660 ${OSSEC_DIR}/etc/ossec.conf |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 125 | |
| 126 | # Debconf |
| 127 | . /usr/share/debconf/confmodule |
| 128 | db_input high ossec-hids-agent/server-ip || true |
| 129 | db_go |
| 130 | |
| 131 | db_get ossec-hids-agent/server-ip |
| 132 | SERVER_IP=$RET |
| 133 | |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 134 | sed -i "s/<server-ip>[^<]\+<\/server-ip>/<server-ip>${SERVER_IP}<\/server-ip>/" ${OSSEC_DIR}/etc/ossec.conf |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 135 | db_stop |
| 136 | |
| 137 | # ossec-init.conf |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 138 | if [ -e ${OSSEC_DIR}/etc/ossec-init.conf ] && [ -d /etc/ ]; then |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 139 | if [ -e /etc/ossec-init.conf ]; then |
| 140 | rm -f /etc/ossec-init.conf |
| 141 | fi |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 142 | ln -s ${OSSEC_DIR}/etc/ossec-init.conf /etc/ossec-init.conf |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 143 | fi |
| 144 | |
| 145 | # init.d/ossec file |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 146 | if [ -x ${OSSEC_DIR}/etc/init.d/ossec ] && [ -d /etc/init.d/ ]; then |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 147 | if [ -e /etc/init.d/ossec ]; then |
| 148 | rm -f /etc/init.d/ossec |
| 149 | fi |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 150 | ln -s ${OSSEC_DIR}/etc/init.d/ossec /etc/init.d/ossec |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 151 | fi |
| 152 | |
| 153 | # Service |
| 154 | if [ -x /etc/init.d/ossec ]; then |
| 155 | update-rc.d -f ossec defaults |
| 156 | fi |
| 157 | |
| 158 | # Delete tmp directory |
| 159 | if [ -d ${OSSEC_HIDS_TMP_DIR} ]; then |
| 160 | rm -r ${OSSEC_HIDS_TMP_DIR} |
| 161 | fi |
| 162 | } |
| 163 | |
| 164 | USERADD_PACKAGES = "${PN}" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 165 | USERADD_PARAM:${PN} = "--system --home-dir /var/ossec -g ossec --shell /bin/false ossec" |
| 166 | GROUPADD_PARAM:${PN} = "--system ossec" |
Andrew Geissler | 5e7fd51 | 2021-05-07 16:09:00 -0500 | [diff] [blame] | 167 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 168 | RDEPENDS:${PN} = "openssl bash" |
Andrew Geissler | a1a6aef | 2021-06-25 14:23:58 -0500 | [diff] [blame] | 169 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 170 | COMPATIBLE_HOST:libc-musl = "null" |