openssh-7.4_p1.ebuild 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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.4p1-0.3.14.patch.xz"
  11. X509_VER="9.3" 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? ( !hpn !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-0.9.8f:0[bindist=]
  45. dev-libs/openssl:0[static-libs(+)]
  46. )
  47. libressl? ( dev-libs/libressl[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. epatch "${WORKDIR}"/${X509_PATCH%.*}
  104. # We no longer allow X509 to be used with anything else.
  105. #save_version X509
  106. fi
  107. if use ldap ; then
  108. epatch "${WORKDIR}"/${LDAP_PATCH%.*}
  109. save_version LPK
  110. fi
  111. epatch "${FILESDIR}"/${PN}-7.4_p1-GSSAPI-dns.patch #165444 integrated into gsskex
  112. epatch "${FILESDIR}"/${PN}-6.7_p1-openssl-ignore-status.patch
  113. use X509 || epatch "${WORKDIR}"/${SCTP_PATCH%.*}
  114. epatch "${FILESDIR}"/${P}-test-bashism.patch
  115. use abi_mips_n32 && epatch "${FILESDIR}"/${PN}-7.3-mips-seccomp-n32.patch
  116. if use hpn ; then
  117. EPATCH_FORCE="yes" EPATCH_SUFFIX="patch" \
  118. EPATCH_MULTI_MSG="Applying HPN patchset ..." \
  119. epatch "${WORKDIR}"/${HPN_PATCH%.*.*}
  120. save_version HPN
  121. fi
  122. tc-export PKG_CONFIG
  123. local sed_args=(
  124. -e "s:-lcrypto:$(${PKG_CONFIG} --libs openssl):"
  125. # Disable PATH reset, trust what portage gives us #254615
  126. -e 's:^PATH=/:#PATH=/:'
  127. # Disable fortify flags ... our gcc does this for us
  128. -e 's:-D_FORTIFY_SOURCE=2::'
  129. )
  130. # The -ftrapv flag ICEs on hppa #505182
  131. use hppa && sed_args+=(
  132. -e '/CFLAGS/s:-ftrapv:-fdisable-this-test:'
  133. -e '/OSSH_CHECK_CFLAG_LINK.*-ftrapv/d'
  134. )
  135. # _XOPEN_SOURCE causes header conflicts on Solaris
  136. [[ ${CHOST} == *-solaris* ]] && sed_args+=(
  137. -e 's/-D_XOPEN_SOURCE//'
  138. )
  139. sed -i "${sed_args[@]}" configure{.ac,} || die
  140. epatch_user #473004
  141. # Now we can build a sane merged version.h
  142. (
  143. sed '/^#define SSH_RELEASE/d' version.h.* | sort -u
  144. macros=()
  145. for p in HPN LPK X509 ; do [ -e version.h.${p} ] && macros+=( SSH_${p} ) ; done
  146. printf '#define SSH_RELEASE SSH_VERSION SSH_PORTABLE %s\n' "${macros}"
  147. ) > version.h
  148. eautoreconf
  149. }
  150. src_configure() {
  151. addwrite /dev/ptmx
  152. use debug && append-cppflags -DSANDBOX_SECCOMP_FILTER_DEBUG
  153. use static && append-ldflags -static
  154. local myconf=(
  155. --with-ldflags="${LDFLAGS}"
  156. --disable-strip
  157. --with-pid-dir="${EPREFIX}"$(usex kernel_linux '' '/var')/run
  158. --sysconfdir="${EPREFIX}"/etc/ssh
  159. --libexecdir="${EPREFIX}"/usr/$(get_libdir)/misc
  160. --datadir="${EPREFIX}"/usr/share/openssh
  161. --with-privsep-path="${EPREFIX}"/var/empty
  162. --with-privsep-user=sshd
  163. $(use_with audit audit linux)
  164. $(use_with kerberos kerberos5 "${EPREFIX}"/usr)
  165. # We apply the ldap patch conditionally, so can't pass --without-ldap
  166. # unconditionally else we get unknown flag warnings.
  167. $(use ldap && use_with ldap)
  168. $(use_with ldns)
  169. $(use_with libedit)
  170. $(use_with pam)
  171. $(use_with pie)
  172. $(use X509 || use_with sctp)
  173. $(use_with selinux)
  174. $(use_with skey)
  175. $(use_with ssh1)
  176. $(use_with ssl openssl)
  177. $(use_with ssl md5-passwords)
  178. $(use_with ssl ssl-engine)
  179. )
  180. # The seccomp sandbox is broken on x32, so use the older method for now. #553748
  181. use amd64 && [[ ${ABI} == "x32" ]] && myconf+=( --with-sandbox=rlimit )
  182. econf "${myconf[@]}"
  183. }
  184. src_install() {
  185. emake install-nokeys DESTDIR="${D}"
  186. fperms 600 /etc/ssh/sshd_config
  187. dobin contrib/ssh-copy-id
  188. newinitd "${FILESDIR}"/sshd.rc6.4 sshd
  189. newconfd "${FILESDIR}"/sshd.confd sshd
  190. keepdir /var/empty
  191. newpamd "${FILESDIR}"/sshd.pam_include.2 sshd
  192. if use pam ; then
  193. sed -i \
  194. -e "/^#UsePAM /s:.*:UsePAM yes:" \
  195. -e "/^#PasswordAuthentication /s:.*:PasswordAuthentication no:" \
  196. -e "/^#PrintMotd /s:.*:PrintMotd no:" \
  197. -e "/^#PrintLastLog /s:.*:PrintLastLog no:" \
  198. "${ED}"/etc/ssh/sshd_config || die
  199. fi
  200. # Gentoo tweaks to default config files
  201. cat <<-EOF >> "${ED}"/etc/ssh/sshd_config
  202. # Allow client to pass locale environment variables #367017
  203. AcceptEnv LANG LC_*
  204. EOF
  205. cat <<-EOF >> "${ED}"/etc/ssh/ssh_config
  206. # Send locale environment variables #367017
  207. SendEnv LANG LC_*
  208. EOF
  209. if use livecd ; then
  210. sed -i \
  211. -e '/^#PermitRootLogin/c# Allow root login with password on livecds.\nPermitRootLogin Yes' \
  212. "${ED}"/etc/ssh/sshd_config || die
  213. fi
  214. if ! use X509 && [[ -n ${LDAP_PATCH} ]] && use ldap ; then
  215. insinto /etc/openldap/schema/
  216. newins openssh-lpk_openldap.schema openssh-lpk.schema
  217. fi
  218. doman contrib/ssh-copy-id.1
  219. dodoc CREDITS OVERVIEW README* TODO sshd_config
  220. use X509 || dodoc ChangeLog
  221. diropts -m 0700
  222. dodir /etc/skel/.ssh
  223. systemd_dounit "${FILESDIR}"/sshd.{service,socket}
  224. systemd_newunit "${FILESDIR}"/sshd_at.service 'sshd@.service'
  225. }
  226. src_test() {
  227. local t skipped=() failed=() passed=()
  228. local tests=( interop-tests compat-tests )
  229. local shell=$(egetshell "${UID}")
  230. if [[ ${shell} == */nologin ]] || [[ ${shell} == */false ]] ; then
  231. elog "Running the full OpenSSH testsuite requires a usable shell for the 'portage'"
  232. elog "user, so we will run a subset only."
  233. skipped+=( tests )
  234. else
  235. tests+=( tests )
  236. fi
  237. # It will also attempt to write to the homedir .ssh.
  238. local sshhome=${T}/homedir
  239. mkdir -p "${sshhome}"/.ssh
  240. for t in "${tests[@]}" ; do
  241. # Some tests read from stdin ...
  242. HOMEDIR="${sshhome}" HOME="${sshhome}" \
  243. emake -k -j1 ${t} </dev/null \
  244. && passed+=( "${t}" ) \
  245. || failed+=( "${t}" )
  246. done
  247. einfo "Passed tests: ${passed[*]}"
  248. [[ ${#skipped[@]} -gt 0 ]] && ewarn "Skipped tests: ${skipped[*]}"
  249. [[ ${#failed[@]} -gt 0 ]] && die "Some tests failed: ${failed[*]}"
  250. }
  251. pkg_preinst() {
  252. enewgroup sshd 22
  253. enewuser sshd 22 -1 /var/empty sshd
  254. }
  255. pkg_postinst() {
  256. if has_version "<${CATEGORY}/${PN}-5.8_p1" ; then
  257. elog "Starting with openssh-5.8p1, the server will default to a newer key"
  258. elog "algorithm (ECDSA). You are encouraged to manually update your stored"
  259. elog "keys list as servers update theirs. See ssh-keyscan(1) for more info."
  260. fi
  261. if has_version "<${CATEGORY}/${PN}-6.9_p1" ; then
  262. elog "Starting with openssh-6.9p1, ssh1 support is disabled by default."
  263. fi
  264. if has_version "<${CATEGORY}/${PN}-7.0_p1" ; then
  265. elog "Starting with openssh-6.7, support for USE=tcpd has been dropped by upstream."
  266. elog "Make sure to update any configs that you might have. Note that xinetd might"
  267. elog "be an alternative for you as it supports USE=tcpd."
  268. fi
  269. if has_version "<${CATEGORY}/${PN}-7.1_p1" ; then #557388 #555518
  270. elog "Starting with openssh-7.0, support for ssh-dss keys were disabled due to their"
  271. elog "weak sizes. If you rely on these key types, you can re-enable the key types by"
  272. elog "adding to your sshd_config or ~/.ssh/config files:"
  273. elog " PubkeyAcceptedKeyTypes=+ssh-dss"
  274. elog "You should however generate new keys using rsa or ed25519."
  275. elog "Starting with openssh-7.0, the default for PermitRootLogin changed from 'yes'"
  276. elog "to 'prohibit-password'. That means password auth for root users no longer works"
  277. elog "out of the box. If you need this, please update your sshd_config explicitly."
  278. fi
  279. if ! use ssl && has_version "${CATEGORY}/${PN}[ssl]" ; then
  280. elog "Be aware that by disabling openssl support in openssh, the server and clients"
  281. elog "no longer support dss/rsa/ecdsa keys. You will need to generate ed25519 keys"
  282. elog "and update all clients/servers that utilize them."
  283. fi
  284. }