1 # Copyright 1999-2015 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.2" X509_PATCH="${PARCH}+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 kernel_linux 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}"/${P}-x509-glue.patch
111 epatch "${FILESDIR}"/${P}-sctp-x509-glue.patch
113 epatch "${WORKDIR}"/${X509_PATCH%.*}
114 epatch "${FILESDIR}"/${PN}-6.3_p1-x509-hpn14v2-glue.patch
115 epatch "${FILESDIR}"/${PN}-6.7_p1-xmalloc-include.patch
119 if [[ -n ${LDAP_PATCH} ]] && use ldap ; then
120 epatch "${WORKDIR}"/${LDAP_PATCH%.*}
124 use ldap && ewarn "Sorry, X509 and LDAP conflict internally, disabling LDAP"
126 epatch "${FILESDIR}"/${PN}-4.7_p1-GSSAPI-dns.patch #165444 integrated into gsskex
127 epatch "${FILESDIR}"/${PN}-6.7_p1-openssl-ignore-status.patch
128 epatch "${WORKDIR}"/${PN}-6.7_p1-sctp.patch
129 if [[ -n ${HPN_PATCH} ]] && use hpn; then
130 epatch "${WORKDIR}"/${HPN_PATCH%.*}/*
136 -e "s:-lcrypto:$(${PKG_CONFIG} --libs openssl):"
137 # Disable PATH reset, trust what portage gives us #254615
138 -e 's:^PATH=/:#PATH=/:'
139 # Disable fortify flags ... our gcc does this for us
140 -e 's:-D_FORTIFY_SOURCE=2::'
142 # The -ftrapv flag ICEs on hppa #505182
143 use hppa && sed_args+=(
144 -e '/CFLAGS/s:-ftrapv:-fdisable-this-test:'
145 -e '/OSSH_CHECK_CFLAG_LINK.*-ftrapv/d'
147 sed -i "${sed_args[@]}" configure{.ac,} || die
151 # Now we can build a sane merged version.h
153 sed '/^#define SSH_RELEASE/d' version.h.* | sort -u
155 for p in HPN LPK X509 ; do [ -e version.h.${p} ] && macros+=( SSH_${p} ) ; done
156 printf '#define SSH_RELEASE SSH_VERSION SSH_PORTABLE %s\n' "${macros}"
164 if use static && use ${flag} ; then
165 ewarn "Disabling '${flag}' support because of USE='static'"
166 # rebuild args so that we invert the first one (USE flag)
167 # but otherwise leave everything else working so we can
168 # just leverage use_with
170 [[ -z $1 ]] && flag="${flag} ${flag}"
179 addpredict /etc/skey/skeykeys #skey configure code triggers this
181 use static && append-ldflags -static
183 # Special settings for Gentoo/FreeBSD 9.0 or later (see bug #391011)
184 if use elibc_FreeBSD && version_is_at_least 9.0 "$(uname -r|sed 's/\(.\..\).*/\1/')" ; then
185 myconf+=( --disable-utmp --disable-wtmp --disable-wtmpx )
186 append-ldflags -lutil
190 --with-ldflags="${LDFLAGS}" \
192 --with-pid-dir="${EPREFIX}"$(usex kernel_linux '' '/var')/run \
193 --sysconfdir="${EPREFIX}"/etc/ssh \
194 --libexecdir="${EPREFIX}"/usr/$(get_libdir)/misc \
195 --datadir="${EPREFIX}"/usr/share/openssh \
196 --with-privsep-path="${EPREFIX}"/var/empty \
197 --with-privsep-user=sshd \
198 --with-md5-passwords \
200 $(static_use_with pam) \
201 $(static_use_with kerberos kerberos5 "${EPREFIX}"/usr) \
202 ${LDAP_PATCH:+$(use X509 || ( use ldap && use_with ldap ))} \
204 $(use_with libedit) \
207 $(use_with selinux) \
213 emake install-nokeys DESTDIR="${D}"
214 fperms 600 /etc/ssh/sshd_config
215 dobin contrib/ssh-copy-id
216 newinitd "${FILESDIR}"/sshd.rc6.4 sshd
217 newconfd "${FILESDIR}"/sshd.confd sshd
220 # not all openssl installs support ecc, or are functional #352645
221 if ! grep -q '#define OPENSSL_HAS_ECC 1' config.h ; then
222 elog "dev-libs/openssl was built with 'bindist' - disabling ecdsa support"
223 sed -i 's:&& gen_key ecdsa::' "${ED}"/etc/init.d/sshd || die
226 newpamd "${FILESDIR}"/sshd.pam_include.2 sshd
229 -e "/^#UsePAM /s:.*:UsePAM yes:" \
230 -e "/^#PasswordAuthentication /s:.*:PasswordAuthentication no:" \
231 -e "/^#PrintMotd /s:.*:PrintMotd no:" \
232 -e "/^#PrintLastLog /s:.*:PrintLastLog no:" \
233 "${ED}"/etc/ssh/sshd_config || die "sed of configuration file failed"
236 # Gentoo tweaks to default config files
237 cat <<-EOF >> "${ED}"/etc/ssh/sshd_config
239 # Allow client to pass locale environment variables #367017
242 cat <<-EOF >> "${ED}"/etc/ssh/ssh_config
244 # Send locale environment variables #367017
248 # This instruction is from the HPN webpage,
249 # Used for the server logging functionality
250 if [[ -n ${HPN_PATCH} ]] && use hpn ; then
251 keepdir /var/empty/dev
254 if ! use X509 && [[ -n ${LDAP_PATCH} ]] && use ldap ; then
255 insinto /etc/openldap/schema/
256 newins openssh-lpk_openldap.schema openssh-lpk.schema
259 doman contrib/ssh-copy-id.1
260 dodoc ChangeLog CREDITS OVERVIEW README* TODO sshd_config
265 systemd_dounit "${FILESDIR}"/sshd.{service,socket}
266 systemd_newunit "${FILESDIR}"/sshd_at.service 'sshd@.service'
270 local t tests skipped failed passed shell
271 tests="interop-tests compat-tests"
273 shell=$(egetshell ${UID})
274 if [[ ${shell} == */nologin ]] || [[ ${shell} == */false ]] ; then
275 elog "Running the full OpenSSH testsuite"
276 elog "requires a usable shell for the 'portage'"
277 elog "user, so we will run a subset only."
278 skipped="${skipped} tests"
280 tests="${tests} tests"
282 # It will also attempt to write to the homedir .ssh
283 local sshhome=${T}/homedir
284 mkdir -p "${sshhome}"/.ssh
285 for t in ${tests} ; do
286 # Some tests read from stdin ...
287 HOMEDIR="${sshhome}" \
288 emake -k -j1 ${t} </dev/null \
289 && passed="${passed}${t} " \
290 || failed="${failed}${t} "
292 einfo "Passed tests: ${passed}"
293 ewarn "Skipped tests: ${skipped}"
294 if [[ -n ${failed} ]] ; then
295 ewarn "Failed tests: ${failed}"
296 die "Some tests failed: ${failed}"
298 einfo "Failed tests: ${failed}"
305 enewuser sshd 22 -1 /var/empty sshd
309 if has_version "<${CATEGORY}/${PN}-5.8_p1" ; then
310 elog "Starting with openssh-5.8p1, the server will default to a newer key"
311 elog "algorithm (ECDSA). You are encouraged to manually update your stored"
312 elog "keys list as servers update theirs. See ssh-keyscan(1) for more info."
314 ewarn "Remember to merge your config files in /etc/ssh/ and then"
315 ewarn "reload sshd: '/etc/init.d/sshd reload'."
316 # This instruction is from the HPN webpage,
317 # Used for the server logging functionality
318 if [[ -n ${HPN_PATCH} ]] && use hpn ; then
319 einfo "For the HPN server logging patch, you must ensure that"
320 einfo "your syslog application also listens at /var/empty/dev/log."
322 elog "Note: openssh-6.7 versions no longer support USE=tcpd as upstream has"
323 elog " dropped it. Make sure to update any configs that you might have."