summaryrefslogtreecommitdiff
blob: e11f3d44b6495b1979422c8abde6259172bf9c79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/app-forensics/samhain/samhain-2.2.0.ebuild,v 1.2 2006/07/14 17:17:58 chtekk Exp $

KEYWORDS="~x86"
DESCRIPTION="Advanced file integrity and intrusion detection tool."
HOMEPAGE="http://la-samhna.de/samhain/"
SRC_URI="http://la-samhna.de/archive/samhain_signed-${PV}.tar.gz"
LICENSE="GPL-2"
SLOT="0"
IUSE="crypt debug login-watch mounts-check mysql netclient netserver postgres prelude static suidcheck userfiles xml"

RESTRICT="nostrip"

DEPEND="crypt? ( >=app-crypt/gnupg-1.2 )
		mysql? ( >=dev-db/mysql-3.23.26 )
		postgres? ( >=dev-db/postgresql-7.2 )
		prelude? ( >=dev-libs/libprelude-0.8.10 )
		>=sys-apps/sed-4
		app-arch/tar
		app-arch/gzip"

# Samhain stealth mode options
#
# If you would like to enable stealth mode, please set and uncomment the 
# following options or pass them as enviroment variables when emerging
# the package (like INSTALL_NAME="asd" emerge samhain).
# If you set the variables here, don't forget to redigest the ebuild by
# issuing 'ebuild samhain-2.1.1a.ebuild digest', also remember that with
# your next emerge sync, the changes to the ebuild will be lost!
#
# Read the Samhain manual for additional information.
#
# STEALTH should be set to either 'full' or 'micro' (mandatory)
#STEALTH=""
#
# XOR_VALUE should be a whole number from 128 to 255 (mandatory)
#XOR_VALUE=""
#
# INSTALL_NAME can be set to change the name of the Samhain binaries
# to the name you specify (optional)
#INSTALL_NAME=""

if [[ "${STEALTH}" == "full" ]] ; then
	RDEPEND="media-gfx/imagemagick"
fi

pkg_setup() {
	if use static ; then
		if use postgres || use prelude ; then
			ewarn "At the moment it isn't possible to build a static Samhain with"
			ewarn "Prelude and/or PostgreSQL support on Gentoo, the compilation"
			ewarn "fails during the linking process."
			echo
			ewarn "This will be looked at and fixed in the future, in the meantime,"
			ewarn "patches to fix this are always welcome and appreciated! ;)"
			ewarn "(Open a bug on bugs.gentoo.org for them or send them to"
			ewarn "the maintainer directly, thanks!)"
			die "Please turn the 'postgres' and/or 'prelude' USE flags off when building with 'static'"
		fi
	fi

	if use mysql && use postgres ; then
		ewarn "You cannot compile both database backends into Samhain at once,"
		ewarn "you need to choose between MySQL or PostgreSQL and disable the"
		ewarn "one you don't want to use."
		die "Please choose between 'mysql' or 'postgres' USE flags"
	fi
}

src_unpack() {
	unpack ${A}
	tar -xzf "samhain-${PV}.tar.gz"
}

src_compile() {
	local myconf

	if use crypt ; then
		myconf="${myconf} --with-gpg=/usr/bin/gpg --with-checksum=no"

		if [[ -n "${KEY_FPR}" ]] ; then
			einfo "Setting built-in key fingerprint to ${KEY_FPR}"
			FPR=`echo ${KEY_FPR} | sed "s/ //g"`
			myconf="${myconf} --with-fp=${FPR}"
		fi
	fi

	if [[ -n "${STEALTH}" ]] ; then
		[[ -z "${XOR_VALUE}" ]] && die "Variable XOR_VALUE must be set for stealth mode"
		echo
		einfo "Enabling stealth mode '${STEALTH}', setting XOR_VALUE to ${XOR_VALUE}"

		if [[ "${STEALTH}" == "full" ]] ; then
			myconf="${myconf} --enable-stealth=${XOR_VALUE}"
			sed -e "s:STEGIN=@stegin_prg@:STEGIN=:g" -i samhain-install.sh.in
		elif [[ "${STEALTH}" == "micro" ]] ; then
			myconf="${myconf} --enable-micro-stealth=${XOR_VALUE}"
		else
			die "STEALTH must be set to either 'full' or 'micro'"
		fi

		if [[ -n "${INSTALL_NAME}" ]] ; then
			echo
			einfo "Setting alternative samhain name to ${INSTALL_NAME}"
			echo
			myconf="${myconf} --enable-install-name=${INSTALL_NAME}"
		fi
	fi

	use mysql && myconf="${myconf} --with-database=mysql --enable-xml-log"
	use postgres && myconf="${myconf} --with-database=postgresql --enable-xml-log"
	use prelude && myconf="${myconf} --with-prelude --with-libprelude-prefix=/usr"
	use xml && myconf="${myconf} --enable-xml-log"
	use static && myconf="${myconf} --enable-static"
	use debug && myconf="${myconf} --enable-debug"

	use netclient && myconf="${myconf} --enable-network=client"
	use netserver && myconf="${myconf} --enable-network=server"

	use login-watch && myconf="${myconf} --enable-login-watch"
	use mounts-check && myconf="${myconf} --enable-mounts-check"
	use suidcheck && myconf="${myconf} --enable-suidcheck"
	use userfiles && myconf="${myconf} --enable-userfiles"

	myconf="${myconf} --localstatedir=/var"

	econf ${myconf} || die "configure failed"
	make || die "compile failed"
}

src_install() {
	make DESTDIR="${D}" install || die "make install failed"

	rm -Rf "${D}/var/log"
	rm -Rf "${D}/var/run"
	rm -Rf "${D}/var/state"

	if [[ -n "${STEALTH}" ]] ; then
		rm -Rf "${D}/usr/share"
	else
		dodoc COPYING LICENSE docs/BUGS docs/MANUAL* docs/README* docs/TODO docs/*.txt
		dohtml docs/*.html
		docinto scripts
		dodoc scripts/*
		insinto /etc
		insopts -m0600
		newins samhainrc.linux samhainrc
		exeinto /etc/init.d
		newexe init/samhain.startGentoo samhain
		keepdir "/var/lib/samhain"
	fi

	if use netserver ; then
		keepdir "/var/lib/yule"
		chown daemon:daemon "${D}/var/lib/yule"
		keepdir "/var/log/yule"
		chown daemon:daemon "${D}/var/log/yule"
	fi
}

pkg_postinst() {
	if [[ -n "${STEALTH}" ]] ; then
		echo
		einfo "Manual pages, documentation, and init script were NOT installed in order to"
		einfo "obscure Samhain's presence. You should also remove samhain's installation"
		einfo "traces from ${ROOT}/var/cache/edb/world and ${ROOT}/var/db/pkg."
	fi

	if [[ "${STEALTH}" == "full" ]] ; then
		echo
		einfo "In stealth mode, the configuration file must be steganographically hidden"
		einfo "in a postscript image file. The sample config has been created this way by"
		einfo "the installation process. Use the samhain_stealth utility to modify or"
		einfo "create your own configuration file."
	fi

	if [[ -z "${KEY_FPR}" ]] ; then
		echo
		ewarn "GnuPG support has been enabled, but fingerprint verification will be"
		ewarn "ignored. To enable fingerprint verification (strongly recommended),"
		ewarn "you must re-emerge this package with the KEY_FPR variable set to"
		ewarn "your default signing key fingerprint."
		ewarn "Please read the Samhain manual for more details."
		echo
		einfo "Enabling GnuPG support in Samhain requires that you sign your configuration"
		einfo "and and database files. Please run the following commands as root:"
		einfo
		einfo "    gpg -a --clearsign --not-dash-escaped ${ROOT}/etc/samhainrc"
		einfo "    mv ${ROOT}/etc/samhainrc.asc ${ROOT}/etc/samhainrc"
		einfo "    chmod 600 ${ROOT}/etc/samhainrc"
		einfo
		einfo "Run the same commands on ${ROOT}/var/lib/samhain/samhain_file after initialization."
	fi

	echo
	einfo "Be sure to check your settings in ${ROOT}/etc/samhainrc. When ready, run:"
	einfo "    samhain -t init"
	einfo "to initialize Samhain."

	echo
	einfo "Samhain stealth-mode options are also available. Please view the comments"
	einfo "in the Samhain ebuild for further configuration instructions."

	echo
	ewarn "Please be sure to read the Samhain manual to understand and correctly"
	ewarn "configure the Samhain utility."
	ewarn "HTML version available for viewing at http://la-samhna.de/samhain/manual/ ."
}