openssh-7.3_p1-r7.ebuild 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI="5"
  4. inherit eutils user flag-o-matic multilib autotools pam systemd versionator
  5. # Make it more portable between straight releases
  6. # and _p? releases.
  7. PARCH=${P/_}
  8. HPN_PV="${PV}"
  9. HPN_VER="14.10"
  10. HPN_PATCH="${PN}-${HPN_PV}-hpn-14.10-r1.patch"
  11. SCTP_PATCH="${PN}-7.3_p1-sctp.patch.xz"
  12. LDAP_PATCH="${PN}-lpk-7.3p1-0.3.14.patch.xz"
  13. X509_VER="9.2" X509_PATCH="${PN}-${PV/_}+x509-${X509_VER}.diff.gz"
  14. DESCRIPTION="Port of OpenBSD's free SSH release"
  15. HOMEPAGE="http://www.openssh.org/"
  16. SRC_URI="mirror://openbsd/OpenSSH/portable/${PARCH}.tar.gz
  17. ${SCTP_PATCH:+mirror://gentoo/${SCTP_PATCH}}
  18. ${HPN_PATCH:+hpn? (
  19. mirror://gentoo/${HPN_PATCH}.xz
  20. http://dev.gentoo.org/~chutzpah/${HPN_PATCH}.xz
  21. )}
  22. ${LDAP_PATCH:+ldap? ( mirror://gentoo/${LDAP_PATCH} )}
  23. ${X509_PATCH:+X509? ( http://roumenpetrov.info/openssh/x509-${X509_VER}/${X509_PATCH} )}
  24. "
  25. LICENSE="BSD GPL-2"
  26. SLOT="0"
  27. KEYWORDS="alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 s390 sh sparc x86 ~ppc-aix ~amd64-fbsd ~sparc-fbsd ~x86-fbsd ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
  28. # Probably want to drop ssl defaulting to on in a future version.
  29. IUSE="bindist debug ${HPN_PATCH:++}hpn kerberos kernel_linux ldap ldns libedit libressl livecd pam +pie sctp selinux skey ssh1 +ssl static test X X509"
  30. REQUIRED_USE="ldns? ( ssl )
  31. pie? ( !static )
  32. ssh1? ( ssl )
  33. static? ( !kerberos !pam )
  34. X509? ( !ldap ssl )
  35. test? ( ssl )"
  36. LIB_DEPEND="
  37. ldns? (
  38. net-libs/ldns[static-libs(+)]
  39. !bindist? ( net-libs/ldns[ecdsa,ssl] )
  40. bindist? ( net-libs/ldns[-ecdsa,ssl] )
  41. )
  42. libedit? ( dev-libs/libedit[static-libs(+)] )
  43. sctp? ( net-misc/lksctp-tools[static-libs(+)] )
  44. selinux? ( >=sys-libs/libselinux-1.28[static-libs(+)] )
  45. skey? ( >=sys-auth/skey-1.1.5-r1[static-libs(+)] )
  46. ssl? (
  47. !libressl? (
  48. >=dev-libs/openssl-0.9.8f:0[bindist=]
  49. dev-libs/openssl:0[static-libs(+)]
  50. )
  51. libressl? ( dev-libs/libressl[static-libs(+)] )
  52. )
  53. >=sys-libs/zlib-1.2.3[static-libs(+)]"
  54. RDEPEND="
  55. !static? ( ${LIB_DEPEND//\[static-libs(+)]} )
  56. pam? ( virtual/pam )
  57. kerberos? ( virtual/krb5 )
  58. ldap? ( net-nds/openldap )"
  59. DEPEND="${RDEPEND}
  60. static? ( ${LIB_DEPEND} )
  61. virtual/pkgconfig
  62. virtual/os-headers
  63. sys-devel/autoconf"
  64. RDEPEND="${RDEPEND}
  65. pam? ( >=sys-auth/pambase-20081028 )
  66. userland_GNU? ( virtual/shadow )
  67. X? ( x11-apps/xauth )"
  68. S=${WORKDIR}/${PARCH}
  69. pkg_pretend() {
  70. # this sucks, but i'd rather have people unable to `emerge -u openssh`
  71. # than not be able to log in to their server any more
  72. maybe_fail() { [[ -z ${!2} ]] && echo "$1" ; }
  73. local fail="
  74. $(use X509 && maybe_fail X509 X509_PATCH)
  75. $(use ldap && maybe_fail ldap LDAP_PATCH)
  76. $(use hpn && maybe_fail hpn HPN_PATCH)
  77. "
  78. fail=$(echo ${fail})
  79. if [[ -n ${fail} ]] ; then
  80. eerror "Sorry, but this version does not yet support features"
  81. eerror "that you requested: ${fail}"
  82. eerror "Please mask ${PF} for now and check back later:"
  83. eerror " # echo '=${CATEGORY}/${PF}' >> /etc/portage/package.mask"
  84. die "booooo"
  85. fi
  86. # Make sure people who are using tcp wrappers are notified of its removal. #531156
  87. if grep -qs '^ *sshd *:' "${EROOT}"/etc/hosts.{allow,deny} ; then
  88. ewarn "Sorry, but openssh no longer supports tcp-wrappers, and it seems like"
  89. ewarn "you're trying to use it. Update your ${EROOT}etc/hosts.{allow,deny} please."
  90. fi
  91. }
  92. save_version() {
  93. # version.h patch conflict avoidence
  94. mv version.h version.h.$1
  95. cp -f version.h.pristine version.h
  96. }
  97. src_prepare() {
  98. sed -i \
  99. -e "/_PATH_XAUTH/s:/usr/X11R6/bin/xauth:${EPREFIX}/usr/bin/xauth:" \
  100. pathnames.h || die
  101. # keep this as we need it to avoid the conflict between LPK and HPN changing
  102. # this file.
  103. cp version.h version.h.pristine
  104. # don't break .ssh/authorized_keys2 for fun
  105. sed -i '/^AuthorizedKeysFile/s:^:#:' sshd_config || die
  106. if use X509 ; then
  107. pushd .. >/dev/null
  108. if use hpn ; then
  109. pushd "${WORKDIR}" >/dev/null
  110. epatch "${FILESDIR}"/${P}-hpn-x509-9.2-glue.patch
  111. popd >/dev/null
  112. fi
  113. epatch "${FILESDIR}"/${PN}-7.3_p1-sctp-x509-glue.patch
  114. sed -i 's:PKIX_VERSION:SSH_X509:g' "${WORKDIR}"/${X509_PATCH%.*} || die
  115. popd >/dev/null
  116. epatch "${WORKDIR}"/${X509_PATCH%.*}
  117. epatch "${FILESDIR}"/${P}-x509-9.2-warnings.patch
  118. save_version X509
  119. else
  120. # bug #592122, fixed by X509 patch
  121. epatch "${FILESDIR}"/${P}-fix-ssh1-with-no-ssh1-host-key.patch
  122. fi
  123. if use ldap ; then
  124. epatch "${WORKDIR}"/${LDAP_PATCH%.*}
  125. save_version LPK
  126. fi
  127. epatch "${FILESDIR}"/${PN}-7.3_p1-GSSAPI-dns.patch #165444 integrated into gsskex
  128. epatch "${FILESDIR}"/${PN}-6.7_p1-openssl-ignore-status.patch
  129. epatch "${WORKDIR}"/${SCTP_PATCH%.*}
  130. if use hpn ; then
  131. #EPATCH_FORCE="yes" EPATCH_SUFFIX="patch" \
  132. # EPATCH_MULTI_MSG="Applying HPN patchset ..." \
  133. # epatch "${WORKDIR}"/${HPN_PATCH%.*.*}
  134. epatch "${WORKDIR}"/${HPN_PATCH}
  135. epatch "${FILESDIR}"/${P}-hpn-cipher-ctr-mt-no-deadlocks.patch
  136. save_version HPN
  137. fi
  138. tc-export PKG_CONFIG
  139. local sed_args=(
  140. -e "s:-lcrypto:$(${PKG_CONFIG} --libs openssl):"
  141. # Disable PATH reset, trust what portage gives us #254615
  142. -e 's:^PATH=/:#PATH=/:'
  143. # Disable fortify flags ... our gcc does this for us
  144. -e 's:-D_FORTIFY_SOURCE=2::'
  145. )
  146. # The -ftrapv flag ICEs on hppa #505182
  147. use hppa && sed_args+=(
  148. -e '/CFLAGS/s:-ftrapv:-fdisable-this-test:'
  149. -e '/OSSH_CHECK_CFLAG_LINK.*-ftrapv/d'
  150. )
  151. sed -i "${sed_args[@]}" configure{.ac,} || die
  152. # 7.3 added seccomp support to MIPS, but failed to handled the N32
  153. # case. This patch is temporary until upstream fixes. See
  154. # Gentoo bug #591392 or upstream #2590.
  155. [[ ${CHOST} == mips64*-linux-* && ${ABI} == "n32" ]] \
  156. && epatch "${FILESDIR}"/${PN}-7.3-mips-seccomp-n32.patch
  157. epatch "${FILESDIR}"/${P}-NEWKEYS_null_deref.patch # 595342
  158. epatch "${FILESDIR}"/${P}-Unregister-the-KEXINIT-handler-after-receive.patch # 597360
  159. epatch_user #473004
  160. # Now we can build a sane merged version.h
  161. (
  162. sed '/^#define SSH_RELEASE/d' version.h.* | sort -u
  163. macros=()
  164. for p in HPN LPK X509 ; do [ -e version.h.${p} ] && macros+=( SSH_${p} ) ; done
  165. printf '#define SSH_RELEASE SSH_VERSION SSH_PORTABLE %s\n' "${macros}"
  166. ) > version.h
  167. eautoreconf
  168. }
  169. src_configure() {
  170. addwrite /dev/ptmx
  171. use debug && append-cppflags -DSANDBOX_SECCOMP_FILTER_DEBUG
  172. use static && append-ldflags -static
  173. local myconf=(
  174. --with-ldflags="${LDFLAGS}"
  175. --disable-strip
  176. --with-pid-dir="${EPREFIX}"$(usex kernel_linux '' '/var')/run
  177. --sysconfdir="${EPREFIX}"/etc/ssh
  178. --libexecdir="${EPREFIX}"/usr/$(get_libdir)/misc
  179. --datadir="${EPREFIX}"/usr/share/openssh
  180. --with-privsep-path="${EPREFIX}"/var/empty
  181. --with-privsep-user=sshd
  182. $(use_with kerberos kerberos5 "${EPREFIX}"/usr)
  183. # We apply the ldap patch conditionally, so can't pass --without-ldap
  184. # unconditionally else we get unknown flag warnings.
  185. $(use ldap && use_with ldap)
  186. $(use_with ldns)
  187. $(use_with libedit)
  188. $(use_with pam)
  189. $(use_with pie)
  190. $(use_with sctp)
  191. $(use_with selinux)
  192. $(use_with skey)
  193. $(use_with ssh1)
  194. $(use_with ssl openssl)
  195. $(use_with ssl md5-passwords)
  196. $(use_with ssl ssl-engine)
  197. )
  198. # The seccomp sandbox is broken on x32, so use the older method for now. #553748
  199. use amd64 && [[ ${ABI} == "x32" ]] && myconf+=( --with-sandbox=rlimit )
  200. econf "${myconf[@]}"
  201. }
  202. src_install() {
  203. emake install-nokeys DESTDIR="${D}"
  204. fperms 600 /etc/ssh/sshd_config
  205. dobin contrib/ssh-copy-id
  206. newinitd "${FILESDIR}"/sshd.rc6.4 sshd
  207. newconfd "${FILESDIR}"/sshd.confd sshd
  208. keepdir /var/empty
  209. newpamd "${FILESDIR}"/sshd.pam_include.2 sshd
  210. if use pam ; then
  211. sed -i \
  212. -e "/^#UsePAM /s:.*:UsePAM yes:" \
  213. -e "/^#PasswordAuthentication /s:.*:PasswordAuthentication no:" \
  214. -e "/^#PrintMotd /s:.*:PrintMotd no:" \
  215. -e "/^#PrintLastLog /s:.*:PrintLastLog no:" \
  216. "${ED}"/etc/ssh/sshd_config || die
  217. fi
  218. # Gentoo tweaks to default config files
  219. cat <<-EOF >> "${ED}"/etc/ssh/sshd_config
  220. # Allow client to pass locale environment variables #367017
  221. AcceptEnv LANG LC_*
  222. EOF
  223. cat <<-EOF >> "${ED}"/etc/ssh/ssh_config
  224. # Send locale environment variables #367017
  225. SendEnv LANG LC_*
  226. EOF
  227. if use livecd ; then
  228. sed -i \
  229. -e '/^#PermitRootLogin/c# Allow root login with password on livecds.\nPermitRootLogin Yes' \
  230. "${ED}"/etc/ssh/sshd_config || die
  231. fi
  232. if ! use X509 && [[ -n ${LDAP_PATCH} ]] && use ldap ; then
  233. insinto /etc/openldap/schema/
  234. newins openssh-lpk_openldap.schema openssh-lpk.schema
  235. fi
  236. doman contrib/ssh-copy-id.1
  237. dodoc CREDITS OVERVIEW README* TODO sshd_config
  238. use X509 || dodoc ChangeLog
  239. diropts -m 0700
  240. dodir /etc/skel/.ssh
  241. systemd_dounit "${FILESDIR}"/sshd.{service,socket}
  242. systemd_newunit "${FILESDIR}"/sshd_at.service 'sshd@.service'
  243. }
  244. src_test() {
  245. local t tests skipped failed passed shell
  246. tests="interop-tests compat-tests"
  247. skipped=""
  248. shell=$(egetshell ${UID})
  249. if [[ ${shell} == */nologin ]] || [[ ${shell} == */false ]] ; then
  250. elog "Running the full OpenSSH testsuite"
  251. elog "requires a usable shell for the 'portage'"
  252. elog "user, so we will run a subset only."
  253. skipped="${skipped} tests"
  254. else
  255. tests="${tests} tests"
  256. fi
  257. # It will also attempt to write to the homedir .ssh
  258. local sshhome=${T}/homedir
  259. mkdir -p "${sshhome}"/.ssh
  260. for t in ${tests} ; do
  261. # Some tests read from stdin ...
  262. HOMEDIR="${sshhome}" HOME="${sshhome}" \
  263. emake -k -j1 ${t} </dev/null \
  264. && passed="${passed}${t} " \
  265. || failed="${failed}${t} "
  266. done
  267. einfo "Passed tests: ${passed}"
  268. ewarn "Skipped tests: ${skipped}"
  269. if [[ -n ${failed} ]] ; then
  270. ewarn "Failed tests: ${failed}"
  271. die "Some tests failed: ${failed}"
  272. else
  273. einfo "Failed tests: ${failed}"
  274. return 0
  275. fi
  276. }
  277. pkg_preinst() {
  278. enewgroup sshd 22
  279. enewuser sshd 22 -1 /var/empty sshd
  280. }
  281. pkg_postinst() {
  282. if has_version "<${CATEGORY}/${PN}-5.8_p1" ; then
  283. elog "Starting with openssh-5.8p1, the server will default to a newer key"
  284. elog "algorithm (ECDSA). You are encouraged to manually update your stored"
  285. elog "keys list as servers update theirs. See ssh-keyscan(1) for more info."
  286. fi
  287. if has_version "<${CATEGORY}/${PN}-6.9_p1" ; then
  288. elog "Starting with openssh-6.9p1, ssh1 support is disabled by default."
  289. fi
  290. if has_version "<${CATEGORY}/${PN}-7.0_p1" ; then
  291. elog "Starting with openssh-6.7, support for USE=tcpd has been dropped by upstream."
  292. elog "Make sure to update any configs that you might have. Note that xinetd might"
  293. elog "be an alternative for you as it supports USE=tcpd."
  294. fi
  295. if has_version "<${CATEGORY}/${PN}-7.1_p1" ; then #557388 #555518
  296. elog "Starting with openssh-7.0, support for ssh-dss keys were disabled due to their"
  297. elog "weak sizes. If you rely on these key types, you can re-enable the key types by"
  298. elog "adding to your sshd_config or ~/.ssh/config files:"
  299. elog " PubkeyAcceptedKeyTypes=+ssh-dss"
  300. elog "You should however generate new keys using rsa or ed25519."
  301. elog "Starting with openssh-7.0, the default for PermitRootLogin changed from 'yes'"
  302. elog "to 'prohibit-password'. That means password auth for root users no longer works"
  303. elog "out of the box. If you need this, please update your sshd_config explicitly."
  304. fi
  305. if ! use ssl && has_version "${CATEGORY}/${PN}[ssl]" ; then
  306. elog "Be aware that by disabling openssl support in openssh, the server and clients"
  307. elog "no longer support dss/rsa/ecdsa keys. You will need to generate ed25519 keys"
  308. elog "and update all clients/servers that utilize them."
  309. fi
  310. }