scponly-4.8-r5.ebuild 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. # Copyright 1999-2014 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=5
  4. inherit eutils multilib readme.gentoo toolchain-funcs user
  5. DESCRIPTION="A tiny pseudoshell which only permits scp and sftp"
  6. HOMEPAGE="http://www.sublimation.org/scponly/"
  7. SRC_URI="mirror://sourceforge/scponly/${P}.tgz"
  8. LICENSE="BSD-2"
  9. SLOT="0"
  10. KEYWORDS="amd64 ppc sparc x86"
  11. IUSE="+sftp scp winscp gftp rsync unison subversion wildcards quota passwd logging"
  12. REQUIRED_USE="
  13. || ( sftp scp winscp rsync unison subversion )
  14. "
  15. RDEPEND="
  16. sys-apps/sed
  17. net-misc/openssh
  18. quota? ( sys-fs/quota )
  19. rsync? ( net-misc/rsync )
  20. subversion? ( dev-vcs/subversion )
  21. "
  22. DEPEND="${RDEPEND}"
  23. myuser="scponly"
  24. myhome="/home/${myuser}"
  25. mysubdir="/pub"
  26. DOC_CONTENTS="
  27. You might want to run\n
  28. emerge --config =${CATEGORY}/${PF}\n
  29. \nto setup the chroot. Otherwise you will have to setup chroot manually
  30. Please read the docs in /usr/share/doc/${PF} for more informations, also
  31. the SECURITY file.
  32. "
  33. src_prepare() {
  34. epatch "${FILESDIR}/${P}-rsync.patch"
  35. # bug #269242
  36. epatch "${FILESDIR}/${P}-gcc4.4.0.patch"
  37. }
  38. src_configure() {
  39. CFLAGS="${CFLAGS} ${LDFLAGS}" econf \
  40. --with-sftp-server="/usr/$(get_libdir)/misc/sftp-server" \
  41. --disable-restrictive-names \
  42. --enable-chrooted-binary \
  43. --enable-chroot-checkdir \
  44. $(use_enable winscp winscp-compat) \
  45. $(use_enable gftp gftp-compat) \
  46. $(use_enable scp scp-compat) \
  47. $(use_enable sftp sftp) \
  48. $(use_enable quota quota-compat) \
  49. $(use_enable passwd passwd-compat) \
  50. $(use_enable rsync rsync-compat) \
  51. $(use_enable unison unison-compat) \
  52. $(use_enable subversion svn-compat) \
  53. $(use_enable subversion svnserv-compat) \
  54. $(use_enable logging sftp-logging-compat) \
  55. $(use_enable wildcards wildcards)
  56. }
  57. src_compile() {
  58. emake CC=$(tc-getCC)
  59. }
  60. src_install() {
  61. emake DESTDIR="${D}" install
  62. dodoc AUTHOR BUILDING-JAILS.TXT CHANGELOG CONTRIB README SECURITY TODO
  63. # don't compress setup-script, so it is usable if necessary
  64. insinto /usr/share/doc/${PF}/chroot
  65. doins setup_chroot.sh config.h
  66. readme.gentoo_create_doc
  67. }
  68. pkg_postinst() {
  69. # two slashes ('//') are used by scponlyc to determine the chroot point.
  70. enewgroup "${myuser}"
  71. enewuser "${myuser}" -1 /usr/sbin/scponlyc "${myhome}//" "${myuser}"
  72. readme.gentoo_print_elog
  73. }
  74. pkg_config() {
  75. # pkg_postinst is based on ${S}/setup_chroot.sh.
  76. einfo "Collecting binaries and libraries..."
  77. # Binaries launched in sftp compat mode
  78. if has_version "=${CATEGORY}/${PF}[sftp]" ; then
  79. BINARIES="/usr/$(get_libdir)/misc/sftp-server"
  80. fi
  81. # Binaries launched by vanilla- and WinSCP modes
  82. if has_version "=${CATEGORY}/${PF}[scp]" || \
  83. has_version "=${CATEGORY}/${PF}[winscp]" ; then
  84. BINARIES="${BINARIES} /usr/bin/scp /bin/ls /bin/rm /bin/ln /bin/mv"
  85. BINARIES="${BINARIES} /bin/chmod /bin/chown /bin/chgrp /bin/mkdir /bin/rmdir"
  86. fi
  87. # Binaries launched in WinSCP compatibility mode
  88. if has_version "=${CATEGORY}/${PF}[winscp]" ; then
  89. BINARIES="${BINARIES} /bin/pwd /bin/groups /usr/bin/id /bin/echo"
  90. fi
  91. # Rsync compatability mode
  92. if has_version "=${CATEGORY}/${PF}[rsync]" ; then
  93. BINARIES="${BINARIES} /usr/bin/rsync"
  94. fi
  95. # Unison compatability mode
  96. if has_version "=${CATEGORY}/${PF}[unison]" ; then
  97. BINARIES="${BINARIES} /usr/bin/unison"
  98. fi
  99. # subversion cli/svnserv compatibility
  100. if has_version "=${CATEGORY}/${PF}[subversion]" ; then
  101. BINARIES="${BINARIES} /usr/bin/svn /usr/bin/svnserve"
  102. fi
  103. # passwd compatibility
  104. if has_version "=${CATEGORY}/${PF}[passwd]" ; then
  105. BINARIES="${BINARIES} /bin/passwd"
  106. fi
  107. # quota compatibility
  108. if has_version "=${CATEGORY}/${PF}[quota]" ; then
  109. BINARIES="${BINARIES} /usr/bin/quota"
  110. fi
  111. # build lib dependencies
  112. LIB_LIST=$(ldd ${BINARIES} | sed -n 's:.* => \(/[^ ]\+\).*:\1:p' | sort -u)
  113. # search and add ld*.so
  114. for LIB in /$(get_libdir)/ld.so /libexec/ld-elf.so /libexec/ld-elf.so.1 \
  115. /usr/libexec/ld.so /$(get_libdir)/ld-linux*.so.2 /usr/libexec/ld-elf.so.1; do
  116. [ -f "${LIB}" ] && LIB_LIST="${LIB_LIST} ${LIB}"
  117. done
  118. # search and add libnss_*.so
  119. for LIB in /$(get_libdir)/libnss_{compat,files}*.so.*; do
  120. [ -f "${LIB}" ] && LIB_LIST="${LIB_LIST} ${LIB}"
  121. done
  122. # create base dirs
  123. if [ ! -d "${myhome}" ]; then
  124. einfo "Creating ${myhome}"
  125. install -o0 -g0 -m0755 -d "${myhome}"
  126. else
  127. einfo "Setting owner for ${myhome}"
  128. chown 0:0 "${myhome}"
  129. fi
  130. if [ ! -d "${myhome}/etc" ]; then
  131. einfo "Creating ${myhome}/etc"
  132. install -o0 -g0 -m0755 -d "${myhome}/etc"
  133. fi
  134. if [ ! -d "${myhome}/$(get_libdir)" ]; then
  135. einfo "Creating ${myhome}/$(get_libdir)"
  136. install -o0 -g0 -m0755 -d "${myhome}/$(get_libdir)"
  137. fi
  138. if [ ! -e "${myhome}/lib" ]; then
  139. einfo "Creating ${myhome}/lib"
  140. ln -snf $(get_libdir) "${myhome}/lib"
  141. fi
  142. if [ ! -d "${myhome}/usr/$(get_libdir)" ]; then
  143. einfo "Creating ${myhome}/usr/$(get_libdir)"
  144. install -o0 -g0 -m0755 -d "${myhome}/usr/$(get_libdir)"
  145. fi
  146. if [ ! -e "${myhome}/usr/lib" ]; then
  147. einfo "Creating ${myhome}/usr/lib"
  148. ln -snf $(get_libdir) "${myhome}/usr/lib"
  149. fi
  150. if [ ! -d "${myhome}${mysubdir}" ]; then
  151. einfo "Creating ${myhome}${mysubdir} directory for uploading files"
  152. install -o${myuser} -g${myuser} -m0755 -d "${myhome}${mysubdir}"
  153. fi
  154. # create /dev/null (Bug 135505)
  155. if [ ! -e "${myhome}/dev/null" ]; then
  156. install -o0 -g0 -m0755 -d "${myhome}/dev"
  157. mknod -m0777 "${myhome}/dev/null" c 1 3
  158. fi
  159. # install binaries
  160. for BIN in ${BINARIES}; do
  161. einfo "Install ${BIN}"
  162. install -o0 -g0 -m0755 -d "${myhome}$(dirname ${BIN})"
  163. if [ "${BIN}" = "/bin/passwd" ]; then # needs suid
  164. install -p -o0 -g0 -m04711 "${BIN}" "${myhome}/${BIN}"
  165. else
  166. install -p -o0 -g0 -m0755 "${BIN}" "${myhome}/${BIN}"
  167. fi
  168. done
  169. # install libs
  170. for LIB in ${LIB_LIST}; do
  171. einfo "Install ${LIB}"
  172. install -o0 -g0 -m0755 -d "${myhome}$(dirname ${LIB})"
  173. install -p -o0 -g0 -m0755 "${LIB}" "${myhome}/${LIB}"
  174. done
  175. # create ld.so.conf
  176. einfo "Creating /etc/ld.so.conf"
  177. for LIB in ${LIB_LIST}; do
  178. dirname ${LIB}
  179. done | sort -u | while read DIR; do
  180. if ! grep 2>/dev/null -q "^${DIR}$" "${myhome}/etc/ld.so.conf"; then
  181. echo "${DIR}" >> "${myhome}/etc/ld.so.conf"
  182. fi
  183. done
  184. ldconfig -r "${myhome}"
  185. # update shells
  186. einfo "Updating /etc/shells"
  187. grep 2>/dev/null -q "^/usr/bin/scponly$" /etc/shells \
  188. || echo "/usr/bin/scponly" >> /etc/shells
  189. grep 2>/dev/null -q "^/usr/sbin/scponlyc$" /etc/shells \
  190. || echo "/usr/sbin/scponlyc" >> /etc/shells
  191. # create /etc/passwd
  192. if [ ! -e "${myhome}/etc/passwd" ]; then
  193. (
  194. echo "root:x:0:0:root:/:/bin/sh"
  195. sed -n "s|^\(${myuser}:[^:]*:[^:]*:[^:]*:[^:]*:\).*|\1${mysubdir}:/bin/sh|p" /etc/passwd
  196. ) > "${myhome}/etc/passwd"
  197. fi
  198. # create /etc/group
  199. if [ ! -e "${myhome}/etc/group" ]; then
  200. (
  201. echo "root:x:0:"
  202. sed -n "s|^\(${myuser}:[^:]*:[^:]*:\).*|\1|p" /etc/group
  203. ) > "${myhome}/etc/group"
  204. fi
  205. }