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.8p1-r5-hpnssh14v5.tar.xz"
13 LDAP_PATCH="${PN}-lpk-6.8p1-0.3.14.patch.xz"
14 X509_VER="8.3.1" 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} )}
27 http://roumenpetrov.info/openssh/x509-${X509_VER}/${X509_PATCH}
28 mirror://gentoo/${P}-x509-${X509_VER}-glue.patch.xz
34 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"
35 # Probably want to drop ssh1/ssl defaulting to on in a future version.
36 IUSE="bindist debug ${HPN_PATCH:++}hpn kerberos kernel_linux ldap ldns libedit pam +pie sctp selinux skey +ssh1 +ssl static X X509"
37 REQUIRED_USE="pie? ( !static )
39 static? ( !kerberos !pam )
42 LIB_DEPEND="sctp? ( net-misc/lksctp-tools[static-libs(+)] )
43 selinux? ( >=sys-libs/libselinux-1.28[static-libs(+)] )
44 skey? ( >=sys-auth/skey-1.1.5-r1[static-libs(+)] )
45 libedit? ( dev-libs/libedit[static-libs(+)] )
47 >=dev-libs/openssl-0.9.6d:0[bindist=]
48 dev-libs/openssl[static-libs(+)]
50 >=sys-libs/zlib-1.2.3[static-libs(+)]"
53 ${LIB_DEPEND//\[static-libs(+)]}
55 !bindist? ( net-libs/ldns[ecdsa,ssl] )
56 bindist? ( net-libs/ldns[-ecdsa,ssl] )
60 kerberos? ( virtual/krb5 )
61 ldap? ( net-nds/openldap )"
66 !bindist? ( net-libs/ldns[ecdsa,ssl,static-libs(+)] )
67 bindist? ( net-libs/ldns[-ecdsa,ssl,static-libs(+)] )
74 pam? ( >=sys-auth/pambase-20081028 )
75 userland_GNU? ( virtual/shadow )
76 X? ( x11-apps/xauth )"
81 # this sucks, but i'd rather have people unable to `emerge -u openssh`
82 # than not be able to log in to their server any more
83 maybe_fail() { [[ -z ${!2} ]] && echo "$1" ; }
85 $(use X509 && maybe_fail X509 X509_PATCH)
86 $(use ldap && maybe_fail ldap LDAP_PATCH)
87 $(use hpn && maybe_fail hpn HPN_PATCH)
90 if [[ -n ${fail} ]] ; then
91 eerror "Sorry, but this version does not yet support features"
92 eerror "that you requested: ${fail}"
93 eerror "Please mask ${PF} for now and check back later:"
94 eerror " # echo '=${CATEGORY}/${PF}' >> /etc/portage/package.mask"
98 # Make sure people who are using tcp wrappers are notified of its removal. #531156
99 if grep -qs '^ *sshd *:' "${EROOT}"/etc/hosts.{allow,deny} ; then
100 eerror "Sorry, but openssh no longer supports tcp-wrappers, and it seems like"
101 eerror "you're trying to use it. Update your ${EROOT}etc/hosts.{allow,deny} please."
102 die "USE=tcpd no longer works"
107 # version.h patch conflict avoidence
108 mv version.h version.h.$1
109 cp -f version.h.pristine version.h
114 -e "/_PATH_XAUTH/s:/usr/X11R6/bin/xauth:${EPREFIX}/usr/bin/xauth:" \
116 # keep this as we need it to avoid the conflict between LPK and HPN changing
118 cp version.h version.h.pristine
120 # don't break .ssh/authorized_keys2 for fun
121 sed -i '/^AuthorizedKeysFile/s:^:#:' sshd_config || die
123 epatch "${FILESDIR}"/${PN}-6.8_p1-sshd-gssapi-multihomed.patch #378361
126 epatch "${WORKDIR}"/${P}-x509-${X509_VER}-glue.patch
127 epatch "${FILESDIR}"/${P}-sctp-x509-glue.patch
129 epatch "${WORKDIR}"/${X509_PATCH%.*}
130 epatch "${FILESDIR}"/${PN}-6.3_p1-x509-hpn14v2-glue.patch
134 epatch "${WORKDIR}"/${LDAP_PATCH%.*}
137 epatch "${FILESDIR}"/${PN}-4.7_p1-GSSAPI-dns.patch #165444 integrated into gsskex
138 epatch "${FILESDIR}"/${PN}-6.7_p1-openssl-ignore-status.patch
139 epatch "${FILESDIR}"/${PN}-6.8_p1-ssh-keygen-no-ssh1.patch #544078
140 epatch "${FILESDIR}"/${PN}-6.8_p1-teraterm.patch #547944
141 # The X509 patchset fixes this independently.
142 use X509 || epatch "${FILESDIR}"/${PN}-6.8_p1-ssl-engine-configure.patch
143 epatch "${WORKDIR}"/${P}-sctp.patch
145 # The teraterm patch pulled in an upstream update.
146 pushd "${WORKDIR}"/${HPN_PATCH%.*.*} >/dev/null
147 epatch "${FILESDIR}"/${PN}-6.8_p1-teraterm-hpn-glue.patch
149 EPATCH_FORCE="yes" EPATCH_SUFFIX="patch" \
150 EPATCH_MULTI_MSG="Applying HPN patchset ..." \
151 epatch "${WORKDIR}"/${HPN_PATCH%.*.*}
157 -e "s:-lcrypto:$(${PKG_CONFIG} --libs openssl):"
158 # Disable PATH reset, trust what portage gives us #254615
159 -e 's:^PATH=/:#PATH=/:'
160 # Disable fortify flags ... our gcc does this for us
161 -e 's:-D_FORTIFY_SOURCE=2::'
163 # The -ftrapv flag ICEs on hppa #505182
164 use hppa && sed_args+=(
165 -e '/CFLAGS/s:-ftrapv:-fdisable-this-test:'
166 -e '/OSSH_CHECK_CFLAG_LINK.*-ftrapv/d'
168 sed -i "${sed_args[@]}" configure{.ac,} || die
172 # Now we can build a sane merged version.h
174 sed '/^#define SSH_RELEASE/d' version.h.* | sort -u
176 for p in HPN LPK X509 ; do [ -e version.h.${p} ] && macros+=( SSH_${p} ) ; done
177 printf '#define SSH_RELEASE SSH_VERSION SSH_PORTABLE %s\n' "${macros}"
185 addpredict /etc/skey/skeykeys # skey configure code triggers this
187 use debug && append-cppflags -DSANDBOX_SECCOMP_FILTER_DEBUG
188 use static && append-ldflags -static
191 --with-ldflags="${LDFLAGS}"
193 --with-pid-dir="${EPREFIX}"$(usex kernel_linux '' '/var')/run
194 --sysconfdir="${EPREFIX}"/etc/ssh
195 --libexecdir="${EPREFIX}"/usr/$(get_libdir)/misc
196 --datadir="${EPREFIX}"/usr/share/openssh
197 --with-privsep-path="${EPREFIX}"/var/empty
198 --with-privsep-user=sshd
199 $(use_with kerberos kerberos5 "${EPREFIX}"/usr)
200 # We apply the ldap patch conditionally, so can't pass --without-ldap
201 # unconditionally else we get unknown flag warnings.
202 $(use ldap && use_with ldap)
211 # The X509 patch deletes this option entirely.
212 $(use X509 || use_with ssl openssl)
213 $(use_with ssl md5-passwords)
214 $(use_with ssl ssl-engine)
217 # Special settings for Gentoo/FreeBSD 9.0 or later (see bug #391011)
218 if use elibc_FreeBSD && version_is_at_least 9.0 "$(uname -r|sed 's/\(.\..\).*/\1/')" ; then
219 myconf+=( --disable-utmp --disable-wtmp --disable-wtmpx )
220 append-ldflags -lutil
227 emake install-nokeys DESTDIR="${D}"
228 fperms 600 /etc/ssh/sshd_config
229 dobin contrib/ssh-copy-id
230 newinitd "${FILESDIR}"/sshd.rc6.4 sshd
231 newconfd "${FILESDIR}"/sshd.confd sshd
234 newpamd "${FILESDIR}"/sshd.pam_include.2 sshd
237 -e "/^#UsePAM /s:.*:UsePAM yes:" \
238 -e "/^#PasswordAuthentication /s:.*:PasswordAuthentication no:" \
239 -e "/^#PrintMotd /s:.*:PrintMotd no:" \
240 -e "/^#PrintLastLog /s:.*:PrintLastLog no:" \
241 "${ED}"/etc/ssh/sshd_config || die
244 # Gentoo tweaks to default config files
245 cat <<-EOF >> "${ED}"/etc/ssh/sshd_config
247 # Allow client to pass locale environment variables #367017
250 cat <<-EOF >> "${ED}"/etc/ssh/ssh_config
252 # Send locale environment variables #367017
256 # This instruction is from the HPN webpage,
257 # Used for the server logging functionality
258 if [[ -n ${HPN_PATCH} ]] && use hpn ; then
259 keepdir /var/empty/dev
262 if ! use X509 && [[ -n ${LDAP_PATCH} ]] && use ldap ; then
263 insinto /etc/openldap/schema/
264 newins openssh-lpk_openldap.schema openssh-lpk.schema
267 doman contrib/ssh-copy-id.1
268 dodoc ChangeLog CREDITS OVERVIEW README* TODO sshd_config
273 systemd_dounit "${FILESDIR}"/sshd.{service,socket}
274 systemd_newunit "${FILESDIR}"/sshd_at.service 'sshd@.service'
278 local t tests skipped failed passed shell
279 tests="interop-tests compat-tests"
281 shell=$(egetshell ${UID})
282 if [[ ${shell} == */nologin ]] || [[ ${shell} == */false ]] ; then
283 elog "Running the full OpenSSH testsuite"
284 elog "requires a usable shell for the 'portage'"
285 elog "user, so we will run a subset only."
286 skipped="${skipped} tests"
288 tests="${tests} tests"
290 # It will also attempt to write to the homedir .ssh
291 local sshhome=${T}/homedir
292 mkdir -p "${sshhome}"/.ssh
293 for t in ${tests} ; do
294 # Some tests read from stdin ...
295 HOMEDIR="${sshhome}" \
296 emake -k -j1 ${t} </dev/null \
297 && passed="${passed}${t} " \
298 || failed="${failed}${t} "
300 einfo "Passed tests: ${passed}"
301 ewarn "Skipped tests: ${skipped}"
302 if [[ -n ${failed} ]] ; then
303 ewarn "Failed tests: ${failed}"
304 die "Some tests failed: ${failed}"
306 einfo "Failed tests: ${failed}"
313 enewuser sshd 22 -1 /var/empty sshd
317 if has_version "<${CATEGORY}/${PN}-5.8_p1" ; then
318 elog "Starting with openssh-5.8p1, the server will default to a newer key"
319 elog "algorithm (ECDSA). You are encouraged to manually update your stored"
320 elog "keys list as servers update theirs. See ssh-keyscan(1) for more info."
322 ewarn "Remember to merge your config files in /etc/ssh/ and then"
323 ewarn "reload sshd: '/etc/init.d/sshd reload'."
324 # This instruction is from the HPN webpage,
325 # Used for the server logging functionality
326 if [[ -n ${HPN_PATCH} ]] && use hpn ; then
327 einfo "For the HPN server logging patch, you must ensure that"
328 einfo "your syslog application also listens at /var/empty/dev/log."
330 elog "Note: openssh-6.7 versions no longer support USE=tcpd as upstream has"
331 elog " dropped it. Make sure to update any configs that you might have."