openssh-7.5_p1-r1.ebuild 11 KB

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