OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
4.8 KiB

  1. jail_lib_needed() {
  2. ### $1 dirtree to search for +x files (usually $jail)
  3. ### $2 lib list file to add needed libs to
  4. tmplib=`mktemp`
  5. cp $2 $tmplib
  6. # Using ldd is not perfect (as I learned from Clifford) but
  7. # it's simple, usually works and extra libs and bins can be
  8. # hand added in specific_postmake
  9. find $1 -perm +111 -type f -exec ldd {} \; | grep -v 'not' | \
  10. grep -v "$1" | cut -d' ' -f3 >> $tmplib
  11. # Always needed
  12. echo /lib/libnss_files.so.2 >> $tmplib
  13. echo /lib/libnss_dns.so.2 >> $tmplib
  14. # Sorting to remove duplications (very high)
  15. sort -u $tmplib > $2
  16. rm -f $tmplib
  17. unset tmplib
  18. }
  19. jail_create() {
  20. ### Pseudo 00-dirtree
  21. # Path for external binaries
  22. [ -a $root/$jail/bin ] || mkdir -p $root/$jail/bin
  23. # Path for external libraries
  24. [ -a $root/$jail/lib ] || mkdir -p $root/$jail/lib
  25. [ -a $root/$jail/etc ] || mkdir -p $root/$jail/etc
  26. [ -a $root/$jail/var ] || mkdir -p $root/$jail/var
  27. [ -a $root/$jail/tmp ] || mkdir -p $root/$jail/tmp
  28. chmod 1777 $root/$jail/tmp
  29. [ -a $root/$jail/dev ] || mkdir -p $root/$jail/dev
  30. [ -a $root/$jail/dev/null ] || mknod -m 666 $root/$jail/dev/null c 1 3
  31. [ -a $root/$jail/dev/random ] || mknod -m 444 $root/$jail/dev/random c 1 8
  32. [ -a $root/$jail/dev/urandom ] || mknod -m 444 $root/$jail/dev/urandom c 1 9
  33. [ -a $root/$docdir ] || mkdir -p $root/$docdir
  34. ### END Pseudo 00-dirtree
  35. ### Make some base etc configuration if not already present
  36. if [ ! -f $root/$jail/etc/ld.so.conf ] ; then
  37. cat <<- EOT > $root/$jail/etc/ld.so.conf
  38. /lib
  39. /usr/lib
  40. EOT
  41. fi
  42. if [ ! -f $root/$jail/etc/nsswitch.conf ] ; then
  43. cat <<- EOT > $root/$jail/etc/nsswitch.conf
  44. passwd: files
  45. group: files
  46. shadow: files
  47. hosts: files dns
  48. EOT
  49. fi
  50. ### END Make some base etc configuration
  51. }
  52. jail_copy_needed_libs() {
  53. ### Copy needed libs in $root/$jail/lib if not already present
  54. tmp=`mktemp`
  55. jail_lib_needed $root/$jail $tmp
  56. if [ "$SDECFG_JAILING_LIBSAFE" = 1 -a \
  57. "$pkg_libsafe_support" = 1 ] ; then
  58. echo "/lib/libsafe.so.2" >> $tmp
  59. grep "/lib/libsafe.so.2" $root/$jail/etc/ld.so.preload > \
  60. /dev/null 2>&1 || echo "/lib/libsafe.so.2" >> \
  61. $root/$jail/etc/ld.so.preload
  62. fi
  63. for x in `grep -v $jail $tmp` ; do
  64. [ -f $root/$jail/lib/${x##*/} ] || cp -vf $x $root/$jail/lib
  65. done
  66. rm -f $tmp
  67. unset tmp x
  68. ldconfig -r $root/$jail
  69. ### END Copy needed libs
  70. }
  71. # Ensure given users are present in jail and if not add them
  72. # needed groups are added too.
  73. jail_ensure_users() {
  74. if [ "$jail" ] ; then
  75. for user_name in "$@" ; do
  76. if ! grep "^$user_name:" $root/$jail/etc/passwd \
  77. > /dev/null 2>&1 ; then
  78. # Add group to jail
  79. grep "^$user_name:" /etc/passwd >> \
  80. $root/$jail/etc/passwd || true
  81. jail_ensure_gids `grep "^$user_name:" /etc/passwd | cut -d":" -f4`
  82. fi
  83. done
  84. fi
  85. unset user_name
  86. }
  87. # Ensure given groups gid are present in jail and if not add them.
  88. jail_ensure_groups() {
  89. if [ "$jail" ] ; then
  90. for group_name in "$@" ; do
  91. if ! grep "^$group_name:" $root/$jail/etc/group \
  92. > /dev/null 2>&1 ; then
  93. # Add group to jail
  94. grep "^$group_name:" /etc/group >> \
  95. $root/$jail/etc/group || true
  96. fi
  97. done
  98. fi
  99. unset group_name
  100. }
  101. # Ensure given groups gid are present in jail and if not add them.
  102. jail_ensure_gids() {
  103. if [ "$jail" ] ; then
  104. for gid in "$@" ; do
  105. if ! grep ":$gid:" $root/$jail/etc/group \
  106. > /dev/null 2>&1 ; then
  107. # Add group to jail
  108. grep ":$gid:" /etc/group >> \
  109. $root/$jail/etc/group || true
  110. fi
  111. done
  112. fi
  113. unset gid
  114. }
  115. # This function sets the 'confopt' and some other variables.
  116. #
  117. jail_set_confopt() {
  118. if [ "$destvar" ] ; then
  119. prefix=$root/usr
  120. sysconfdir="$root/etc"
  121. localstatedir="$root/var"
  122. else
  123. prefix="$root/$jail/usr"
  124. sysconfdir="$root/$jail/etc"
  125. localstatedir="$root/$jail/var"
  126. fi
  127. bindir="$prefix/bin"
  128. sbindir="$prefix/sbin"
  129. libdir="$prefix/lib"
  130. docdir="$prefix/doc/$pkg"
  131. datadir="$prefix/share"
  132. infodir="$prefix/info"
  133. mandir="$prefix/man"
  134. includedir="$root/include"
  135. confopt="--prefix=$prefix"
  136. confopt="$confopt --bindir=\$bindir"
  137. confopt="$confopt --sbindir=\$sbindir"
  138. confopt="$confopt --libdir=\$libdir"
  139. confopt="$confopt --datadir=\$datadir"
  140. confopt="$confopt --infodir=\$infodir"
  141. confopt="$confopt --mandir=\$mandir"
  142. confopt="$confopt --sysconfdir=\$sysconfdir"
  143. confopt="$confopt --localstatedir=\$localstatedir"
  144. confopt="$confopt --includedir=\$includedir"
  145. if [ "$SDECFG_CONFIGURE_OPTS" ] ; then
  146. confopt="$confopt $SDECFG_CONFIGURE_OPTS"
  147. fi
  148. if [ "$SDECFG_DEBUG" = 0 ] ; then
  149. confopt="$confopt --disable-debug"
  150. else
  151. confopt="$confopt --enable-debug"
  152. fi
  153. if ! atstage native || [ "$SDECFG_DISABLE_NLS" = 1 ] ; then
  154. confopt="${confopt//--enable-nls/} --disable-nls"
  155. fi
  156. confopt="$confopt \$extraconfopt"
  157. confopt="$confopt --build=\$arch_build --host=\$arch_target"
  158. }