1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
6 inherit eutils user flag-o-matic multilib autotools pam systemd versionator
8 # Make it more portable between straight releases
12 HPN_PATCH="${PN}-6.7p1-hpnssh14v5.tar.xz"
13 LDAP_PATCH="${PN}-lpk-6.7p1-0.3.14.patch.xz"
14 #X509_VER="8.1" X509_PATCH="${PARCH/6.7/6.6}+x509-${X509_VER}.diff.gz"
16 DESCRIPTION="Port of OpenBSD's free SSH release"
17 HOMEPAGE="http://www.openssh.org/"
18 SRC_URI="mirror://openbsd/OpenSSH/portable/${PARCH}.tar.gz
19 mirror://gentoo/${P}-sctp.patch.xz
21 mirror://gentoo/${HPN_PATCH}
22 https://dev.gentoo.org/~vapier/dist/${HPN_PATCH}
23 mirror://sourceforge/hpnssh/${HPN_PATCH}
25 ${LDAP_PATCH:+ldap? ( mirror://gentoo/${LDAP_PATCH} )}
26 ${X509_PATCH:+X509? ( http://roumenpetrov.info/openssh/x509-${X509_VER}/${X509_PATCH} )}
31 KEYWORDS="alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 s390 sh sparc x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd ~arm-linux ~x86-linux"
32 IUSE="bindist ${HPN_PATCH:++}hpn kerberos ldap ldns libedit pam +pie sctp selinux skey static X X509"
33 REQUIRED_USE="pie? ( !static )"
35 LIB_DEPEND="sctp? ( net-misc/lksctp-tools[static-libs(+)] )
36 selinux? ( >=sys-libs/libselinux-1.28[static-libs(+)] )
37 skey? ( >=sys-auth/skey-1.1.5-r1[static-libs(+)] )
38 libedit? ( dev-libs/libedit[static-libs(+)] )
39 >=dev-libs/openssl-0.9.6d:0[bindist=]
40 dev-libs/openssl[static-libs(+)]
41 >=sys-libs/zlib-1.2.3[static-libs(+)]"
44 ${LIB_DEPEND//\[static-libs(+)]}
46 !bindist? ( net-libs/ldns[ecdsa,ssl] )
47 bindist? ( net-libs/ldns[-ecdsa,ssl] )
51 kerberos? ( virtual/krb5 )
52 ldap? ( net-nds/openldap )"
57 !bindist? ( net-libs/ldns[ecdsa,ssl,static-libs(+)] )
58 bindist? ( net-libs/ldns[-ecdsa,ssl,static-libs(+)] )
65 pam? ( >=sys-auth/pambase-20081028 )
66 userland_GNU? ( virtual/shadow )
67 X? ( x11-apps/xauth )"
72 # this sucks, but i'd rather have people unable to `emerge -u openssh`
73 # than not be able to log in to their server any more
74 maybe_fail() { [[ -z ${!2} ]] && echo "$1" ; }
76 $(use X509 && maybe_fail X509 X509_PATCH)
77 $(use ldap && maybe_fail ldap LDAP_PATCH)
78 $(use hpn && maybe_fail hpn HPN_PATCH)
81 if [[ -n ${fail} ]] ; then
82 eerror "Sorry, but this version does not yet support features"
83 eerror "that you requested: ${fail}"
84 eerror "Please mask ${PF} for now and check back later:"
85 eerror " # echo '=${CATEGORY}/${PF}' >> /etc/portage/package.mask"
91 # version.h patch conflict avoidence
92 mv version.h version.h.$1
93 cp -f version.h.pristine version.h
98 -e "/_PATH_XAUTH/s:/usr/X11R6/bin/xauth:${EPREFIX}/usr/bin/xauth:" \
100 # keep this as we need it to avoid the conflict between LPK and HPN changing
102 cp version.h version.h.pristine
104 # don't break .ssh/authorized_keys2 for fun
105 sed -i '/^AuthorizedKeysFile/s:^:#:' sshd_config || die
107 epatch "${FILESDIR}"/${PN}-6.7_p1-sshd-gssapi-multihomed.patch #378361
110 epatch "${FILESDIR}"/${PN}-6.6.1_p1-x509-glue.patch
111 use hpn && epatch "${FILESDIR}"/${PN}-6.6.1_p1-x509-hpn14v5-glue.patch
113 epatch "${WORKDIR}"/${X509_PATCH%.*}
114 epatch "${FILESDIR}"/${PN}-6.3_p1-x509-hpn14v2-glue.patch
118 if [[ -n ${LDAP_PATCH} ]] && use ldap ; then
119 epatch "${WORKDIR}"/${LDAP_PATCH%.*}
123 use ldap && ewarn "Sorry, X509 and LDAP conflict internally, disabling LDAP"
125 epatch "${FILESDIR}"/${PN}-4.7_p1-GSSAPI-dns.patch #165444 integrated into gsskex
126 epatch "${FILESDIR}"/${PN}-6.7_p1-openssl-ignore-status.patch
127 epatch "${WORKDIR}"/${PN}-6.7_p1-sctp.patch
128 if [[ -n ${HPN_PATCH} ]] && use hpn; then
129 epatch "${WORKDIR}"/${HPN_PATCH%.*}/*
135 -e "s:-lcrypto:$(${PKG_CONFIG} --libs openssl):"
136 # Disable PATH reset, trust what portage gives us #254615
137 -e 's:^PATH=/:#PATH=/:'
138 # Disable fortify flags ... our gcc does this for us
139 -e 's:-D_FORTIFY_SOURCE=2::'
141 # The -ftrapv flag ICEs on hppa #505182
142 use hppa && sed_args+=(
143 -e '/CFLAGS/s:-ftrapv:-fdisable-this-test:'
144 -e '/OSSH_CHECK_CFLAG_LINK.*-ftrapv/d'
146 sed -i "${sed_args[@]}" configure{.ac,} || die
150 # Now we can build a sane merged version.h
152 sed '/^#define SSH_RELEASE/d' version.h.* | sort -u
154 for p in HPN LPK X509 ; do [ -e version.h.${p} ] && macros+=( SSH_${p} ) ; done
155 printf '#define SSH_RELEASE SSH_VERSION SSH_PORTABLE %s\n' "${macros}"
163 if use static && use ${flag} ; then
164 ewarn "Disabling '${flag}' support because of USE='static'"
165 # rebuild args so that we invert the first one (USE flag)
166 # but otherwise leave everything else working so we can
167 # just leverage use_with
169 [[ -z $1 ]] && flag="${flag} ${flag}"
178 addpredict /etc/skey/skeykeys #skey configure code triggers this
180 use static && append-ldflags -static
182 # Special settings for Gentoo/FreeBSD 9.0 or later (see bug #391011)
183 if use elibc_FreeBSD && version_is_at_least 9.0 "$(uname -r|sed 's/\(.\..\).*/\1/')" ; then
184 myconf+=( --disable-utmp --disable-wtmp --disable-wtmpx )
185 append-ldflags -lutil
189 --with-ldflags="${LDFLAGS}" \
191 --with-pid-dir="${EPREFIX}"/var/run \
192 --sysconfdir="${EPREFIX}"/etc/ssh \
193 --libexecdir="${EPREFIX}"/usr/$(get_libdir)/misc \
194 --datadir="${EPREFIX}"/usr/share/openssh \
195 --with-privsep-path="${EPREFIX}"/var/empty \
196 --with-privsep-user=sshd \
197 --with-md5-passwords \
199 $(static_use_with pam) \
200 $(static_use_with kerberos kerberos5 "${EPREFIX}"/usr) \
201 ${LDAP_PATCH:+$(use X509 || ( use ldap && use_with ldap ))} \
203 $(use_with libedit) \
206 $(use_with selinux) \
212 emake install-nokeys DESTDIR="${D}"
213 fperms 600 /etc/ssh/sshd_config
214 dobin contrib/ssh-copy-id
215 newinitd "${FILESDIR}"/sshd.rc6.4 sshd
216 newconfd "${FILESDIR}"/sshd.confd sshd
219 # not all openssl installs support ecc, or are functional #352645
220 if ! grep -q '#define OPENSSL_HAS_ECC 1' config.h ; then
221 elog "dev-libs/openssl was built with 'bindist' - disabling ecdsa support"
222 sed -i 's:&& gen_key ecdsa::' "${ED}"/etc/init.d/sshd || die
225 newpamd "${FILESDIR}"/sshd.pam_include.2 sshd
228 -e "/^#UsePAM /s:.*:UsePAM yes:" \
229 -e "/^#PasswordAuthentication /s:.*:PasswordAuthentication no:" \
230 -e "/^#PrintMotd /s:.*:PrintMotd no:" \
231 -e "/^#PrintLastLog /s:.*:PrintLastLog no:" \
232 "${ED}"/etc/ssh/sshd_config || die "sed of configuration file failed"
235 # Gentoo tweaks to default config files
236 cat <<-EOF >> "${ED}"/etc/ssh/sshd_config
238 # Allow client to pass locale environment variables #367017
241 cat <<-EOF >> "${ED}"/etc/ssh/ssh_config
243 # Send locale environment variables #367017
247 # This instruction is from the HPN webpage,
248 # Used for the server logging functionality
249 if [[ -n ${HPN_PATCH} ]] && use hpn ; then
250 keepdir /var/empty/dev
253 if ! use X509 && [[ -n ${LDAP_PATCH} ]] && use ldap ; then
254 insinto /etc/openldap/schema/
255 newins openssh-lpk_openldap.schema openssh-lpk.schema
258 doman contrib/ssh-copy-id.1
259 dodoc ChangeLog CREDITS OVERVIEW README* TODO sshd_config
264 systemd_dounit "${FILESDIR}"/sshd.{service,socket}
265 systemd_newunit "${FILESDIR}"/sshd_at.service 'sshd@.service'
269 local t tests skipped failed passed shell
270 tests="interop-tests compat-tests"
272 shell=$(egetshell ${UID})
273 if [[ ${shell} == */nologin ]] || [[ ${shell} == */false ]] ; then
274 elog "Running the full OpenSSH testsuite"
275 elog "requires a usable shell for the 'portage'"
276 elog "user, so we will run a subset only."
277 skipped="${skipped} tests"
279 tests="${tests} tests"
281 # It will also attempt to write to the homedir .ssh
282 local sshhome=${T}/homedir
283 mkdir -p "${sshhome}"/.ssh
284 for t in ${tests} ; do
285 # Some tests read from stdin ...
286 HOMEDIR="${sshhome}" \
287 emake -k -j1 ${t} </dev/null \
288 && passed="${passed}${t} " \
289 || failed="${failed}${t} "
291 einfo "Passed tests: ${passed}"
292 ewarn "Skipped tests: ${skipped}"
293 if [[ -n ${failed} ]] ; then
294 ewarn "Failed tests: ${failed}"
295 die "Some tests failed: ${failed}"
297 einfo "Failed tests: ${failed}"
304 enewuser sshd 22 -1 /var/empty sshd
308 if has_version "<${CATEGORY}/${PN}-5.8_p1" ; then
309 elog "Starting with openssh-5.8p1, the server will default to a newer key"
310 elog "algorithm (ECDSA). You are encouraged to manually update your stored"
311 elog "keys list as servers update theirs. See ssh-keyscan(1) for more info."
313 ewarn "Remember to merge your config files in /etc/ssh/ and then"
314 ewarn "reload sshd: '/etc/init.d/sshd reload'."
315 # This instruction is from the HPN webpage,
316 # Used for the server logging functionality
317 if [[ -n ${HPN_PATCH} ]] && use hpn ; then
318 einfo "For the HPN server logging patch, you must ensure that"
319 einfo "your syslog application also listens at /var/empty/dev/log."
321 elog "Note: openssh-6.7 versions no longer support USE=tcpd as upstream has"
322 elog " dropped it. Make sure to update any configs that you might have."