openssh-7.3_p1-r8.ebuild 11 KB

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