@@ -1031,6 +1031,61 @@ function remove_broken_symlinks($path, $recursive=false) {
10311031 }
10321032 }
10331033
1034+ function remove_recursive_symlinks ($ path , $ chroot_basedir ='' , $ recursive =false ) {
1035+ global $ app ;
1036+
1037+ if ($ path != '/ ' ) {
1038+ $ path = rtrim ($ path , '/ ' );
1039+ }
1040+ if (strlen ($ chroot_basedir ) > 0 ) {
1041+ if (!is_dir ($ chroot_basedir )) {
1042+ $ app ->log ("remove_recursive_symlink: invalid chroot basedir: $ chroot_basedir " , LOGLEVEL_DEBUG );
1043+ return false ;
1044+ }
1045+ if (!(substr ($ path , 0 , strlen ($ chroot_basedir )) === $ chroot_basedir )) {
1046+ $ app ->log ("remove_recursive_symlink: path $ path is not below chroot basedir $ chroot_basedir " , LOGLEVEL_DEBUG );
1047+ return false ;
1048+ }
1049+ if ($ chroot_basedir != '/ ' ) {
1050+ $ chroot_basedir = rtrim ($ chroot_basedir , '/ ' );
1051+ }
1052+ }
1053+ if (is_dir ($ path )) {
1054+ $ objects = array_diff (scandir ($ path ), array ('. ' , '.. ' ));
1055+ foreach ($ objects as $ object ) {
1056+ if (is_dir ("$ path/ $ object " ) && $ recursive ) {
1057+ $ this ->remove_recursive_symlinks ("$ path/ $ object " , $ chroot_basedir , $ recursive );
1058+ } elseif (is_link ("$ path/ $ object " )) {
1059+ $ realpath = realpath ("$ path/ $ object " );
1060+ if (strlen ($ chroot_basedir ) > 0 ) {
1061+ $ root_path = substr ("$ path/ $ object " , strlen ($ chroot_basedir ));
1062+ if ($ root_path && $ realpath == $ root_path ) {
1063+ $ app ->log ("removing recursive symlink $ path/ $ object " , LOGLEVEL_DEBUG );
1064+ unlink ("$ path/ $ object " );
1065+ }
1066+ }
1067+ if ($ realpath = "" || $ realpath == "$ path/ $ object " ) {
1068+ $ app ->log ("removing recursive symlink $ path/ $ object " , LOGLEVEL_DEBUG );
1069+ unlink ("$ path/ $ object " );
1070+ }
1071+ }
1072+ }
1073+ } elseif (is_link ("$ path " )) {
1074+ $ realpath = realpath ($ path );
1075+ if (strlen ($ chroot_basedir ) > 0 ) {
1076+ $ root_path = substr ($ path , strlen ($ chroot_basedir ));
1077+ if ($ root_path && $ realpath == $ root_path ) {
1078+ $ app ->log ("removing recursive symlink $ path " , LOGLEVEL_DEBUG );
1079+ unlink ($ path );
1080+ }
1081+ }
1082+ if ($ realpath = "" || $ realpath == $ path ) {
1083+ $ app ->log ("removing recursive symlink $ path " , LOGLEVEL_DEBUG );
1084+ unlink ($ path );
1085+ }
1086+ }
1087+ }
1088+
10341089 function checkpath ($ path ) {
10351090 $ path = trim ($ path );
10361091 //* We allow only absolute paths
@@ -2485,6 +2540,7 @@ public function update_jailkit_chroot($home_dir, $sections = array(), $programs
24852540 }
24862541
24872542 $ this ->remove_broken_symlinks ($ jail_dir , true );
2543+ $ this ->remove_recursive_symlinks ($ jail_dir , $ home_dir , true );
24882544
24892545 // save list of hardlinked files
24902546 if (!(in_array ('hardlink ' , $ opts ) || in_array ('allow_hardlink ' , $ options ))) {
@@ -2531,18 +2587,22 @@ public function update_jailkit_chroot($home_dir, $sections = array(), $programs
25312587 foreach ($ this ->_last_exec_out as $ line ) {
25322588 # jk_update sample output:
25332589 # skip /var/www/clients/client1/web1/opt/
2534- if (substr ( $ line , 0 , 4 ) === "skip " ) {
2590+ # removing outdated file /var/www/clients/client15/web19/usr/bin/host
2591+ # removing deprecated directory /var/www/clients/client15/web19/usr/lib/x86_64-linux-gnu/libtasn1.so.6.5.3
2592+ # Creating symlink /var/www/clients/client15/web19/lib/x86_64-linux-gnu/libicudata.so.65 to libicudata.so.65.1
2593+ # Copying /usr/bin/mysql to /var/www/clients/client15/web19/usr/bin/mysql
2594+ if (preg_match ('@^(skip|removing (outdated|deprecated)|Creating|Copying)@ ' , $ line )) {
25352595 continue ;
25362596 }
25372597
25382598 # jk_update sample output:
25392599 # ERROR: failed to remove deprecated directory /var/www/clients/client1/web10/usr/lib/x86_64-linux-gnu/libGeoIP.so.1.6.9
2540- if (preg_match ('@^(?:[^ ]+){6}(?:.+)( ' .preg_quote ($ home_dir , '@ ' ).'.+)@ ' , $ line , $ matches )) {
2600+ if (preg_match ('@^(?:[^ ]+ ){6}(?:.+)( ' .preg_quote ($ home_dir , '@ ' ).'.+)@ ' , $ line , $ matches )) {
25412601 # remove deprecated files that jk_update failed to remove
2542- if (is_file ($ matches [1 ])) {
2602+ if (is_file ($ matches [1 ]) || is_link ( $ matches [ 1 ]) ) {
25432603$ app ->log ("update_jailkit_chroot: removing deprecated file which jk_update failed to remove: " .$ matches [1 ], LOGLEVEL_DEBUG );
25442604 unlink ($ matches [1 ]);
2545- } elseif (is_dir ($ matches [1 ])) {
2605+ } elseif (is_dir ($ matches [1 ]) && ! is_link ( $ matches [ 1 ]) ) {
25462606$ app ->log ("update_jailkit_chroot: removing deprecated directory which jk_update failed to remove: " .$ matches [1 ], LOGLEVEL_DEBUG );
25472607 $ this ->rmdir ($ matches [1 ], true );
25482608 } else {
0 commit comments