Use https by default
[gentoo.git] / net-misc / openssh / openssh-6.8_p1-r5.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI="4"
6 inherit eutils user flag-o-matic multilib autotools pam systemd versionator
7
8 # Make it more portable between straight releases
9 # and _p? releases.
10 PARCH=${P/_}
11
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"
15
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
20         ${HPN_PATCH:+hpn? (
21                 mirror://gentoo/${HPN_PATCH}
22                 https://dev.gentoo.org/~vapier/dist/${HPN_PATCH}
23                 mirror://sourceforge/hpnssh/${HPN_PATCH}
24         )}
25         ${LDAP_PATCH:+ldap? ( mirror://gentoo/${LDAP_PATCH} )}
26         ${X509_PATCH:+X509? (
27                 http://roumenpetrov.info/openssh/x509-${X509_VER}/${X509_PATCH}
28                 mirror://gentoo/${P}-x509-${X509_VER}-glue.patch.xz
29         )}
30         "
31
32 LICENSE="BSD GPL-2"
33 SLOT="0"
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 )
38         ssh1? ( ssl )
39         static? ( !kerberos !pam )
40         X509? ( !ldap ssl )"
41
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(+)] )
46         ssl? (
47                 >=dev-libs/openssl-0.9.6d:0[bindist=]
48                 dev-libs/openssl[static-libs(+)]
49         )
50         >=sys-libs/zlib-1.2.3[static-libs(+)]"
51 RDEPEND="
52         !static? (
53                 ${LIB_DEPEND//\[static-libs(+)]}
54                 ldns? (
55                         !bindist? ( net-libs/ldns[ecdsa,ssl] )
56                         bindist? ( net-libs/ldns[-ecdsa,ssl] )
57                 )
58         )
59         pam? ( virtual/pam )
60         kerberos? ( virtual/krb5 )
61         ldap? ( net-nds/openldap )"
62 DEPEND="${RDEPEND}
63         static? (
64                 ${LIB_DEPEND}
65                 ldns? (
66                         !bindist? ( net-libs/ldns[ecdsa,ssl,static-libs(+)] )
67                         bindist? ( net-libs/ldns[-ecdsa,ssl,static-libs(+)] )
68                 )
69         )
70         virtual/pkgconfig
71         virtual/os-headers
72         sys-devel/autoconf"
73 RDEPEND="${RDEPEND}
74         pam? ( >=sys-auth/pambase-20081028 )
75         userland_GNU? ( virtual/shadow )
76         X? ( x11-apps/xauth )"
77
78 S=${WORKDIR}/${PARCH}
79
80 pkg_setup() {
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" ; }
84         local fail="
85                 $(use X509 && maybe_fail X509 X509_PATCH)
86                 $(use ldap && maybe_fail ldap LDAP_PATCH)
87                 $(use hpn && maybe_fail hpn HPN_PATCH)
88         "
89         fail=$(echo ${fail})
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"
95                 die "booooo"
96         fi
97
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"
103         fi
104 }
105
106 save_version() {
107         # version.h patch conflict avoidence
108         mv version.h version.h.$1
109         cp -f version.h.pristine version.h
110 }
111
112 src_prepare() {
113         sed -i \
114                 -e "/_PATH_XAUTH/s:/usr/X11R6/bin/xauth:${EPREFIX}/usr/bin/xauth:" \
115                 pathnames.h || die
116         # keep this as we need it to avoid the conflict between LPK and HPN changing
117         # this file.
118         cp version.h version.h.pristine
119
120         # don't break .ssh/authorized_keys2 for fun
121         sed -i '/^AuthorizedKeysFile/s:^:#:' sshd_config || die
122
123         epatch "${FILESDIR}"/${PN}-6.8_p1-sshd-gssapi-multihomed.patch #378361
124         if use X509 ; then
125                 pushd .. >/dev/null
126                 epatch "${WORKDIR}"/${P}-x509-${X509_VER}-glue.patch
127                 epatch "${FILESDIR}"/${P}-sctp-x509-glue.patch
128                 popd >/dev/null
129                 epatch "${WORKDIR}"/${X509_PATCH%.*}
130                 epatch "${FILESDIR}"/${PN}-6.3_p1-x509-hpn14v2-glue.patch
131                 save_version X509
132         fi
133         if use ldap ; then
134                 epatch "${WORKDIR}"/${LDAP_PATCH%.*}
135                 save_version LPK
136         fi
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
144         if use hpn ; then
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
148                 popd >/dev/null
149                 EPATCH_FORCE="yes" EPATCH_SUFFIX="patch" \
150                         EPATCH_MULTI_MSG="Applying HPN patchset ..." \
151                         epatch "${WORKDIR}"/${HPN_PATCH%.*.*}
152                 save_version HPN
153         fi
154
155         tc-export PKG_CONFIG
156         local sed_args=(
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::'
162         )
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'
167         )
168         sed -i "${sed_args[@]}" configure{.ac,} || die
169
170         epatch_user #473004
171
172         # Now we can build a sane merged version.h
173         (
174                 sed '/^#define SSH_RELEASE/d' version.h.* | sort -u
175                 macros=()
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}"
178         ) > version.h
179
180         eautoreconf
181 }
182
183 src_configure() {
184         addwrite /dev/ptmx
185         addpredict /etc/skey/skeykeys # skey configure code triggers this
186
187         use debug && append-cppflags -DSANDBOX_SECCOMP_FILTER_DEBUG
188         use static && append-ldflags -static
189
190         local myconf=(
191                 --with-ldflags="${LDFLAGS}"
192                 --disable-strip
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)
203                 $(use_with ldns)
204                 $(use_with libedit)
205                 $(use_with pam)
206                 $(use_with pie)
207                 $(use_with sctp)
208                 $(use_with selinux)
209                 $(use_with skey)
210                 $(use_with ssh1)
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)
215         )
216
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
221         fi
222
223         econf "${myconf[@]}"
224 }
225
226 src_install() {
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
232         keepdir /var/empty
233
234         newpamd "${FILESDIR}"/sshd.pam_include.2 sshd
235         if use pam ; then
236                 sed -i \
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
242         fi
243
244         # Gentoo tweaks to default config files
245         cat <<-EOF >> "${ED}"/etc/ssh/sshd_config
246
247         # Allow client to pass locale environment variables #367017
248         AcceptEnv LANG LC_*
249         EOF
250         cat <<-EOF >> "${ED}"/etc/ssh/ssh_config
251
252         # Send locale environment variables #367017
253         SendEnv LANG LC_*
254         EOF
255
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
260         fi
261
262         if ! use X509 && [[ -n ${LDAP_PATCH} ]] && use ldap ; then
263                 insinto /etc/openldap/schema/
264                 newins openssh-lpk_openldap.schema openssh-lpk.schema
265         fi
266
267         doman contrib/ssh-copy-id.1
268         dodoc ChangeLog CREDITS OVERVIEW README* TODO sshd_config
269
270         diropts -m 0700
271         dodir /etc/skel/.ssh
272
273         systemd_dounit "${FILESDIR}"/sshd.{service,socket}
274         systemd_newunit "${FILESDIR}"/sshd_at.service 'sshd@.service'
275 }
276
277 src_test() {
278         local t tests skipped failed passed shell
279         tests="interop-tests compat-tests"
280         skipped=""
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"
287         else
288                 tests="${tests} tests"
289         fi
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} "
299         done
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}"
305         else
306                 einfo "Failed tests: ${failed}"
307                 return 0
308         fi
309 }
310
311 pkg_preinst() {
312         enewgroup sshd 22
313         enewuser sshd 22 -1 /var/empty sshd
314 }
315
316 pkg_postinst() {
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."
321         fi
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."
329         fi
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."
332 }