princepawn has asked for the wisdom of the Perl Monks concerning the following question:

As you can see from the output of this program, when I attempt to chroot a directory other than my home directory, chroot fails. But the permissions and ownership of the two directories is exactly the same.

Thus this failure is occuring due to some variable not stated in the chroot manpgage and that is not file ownership or permissions.

So, if some kind genie/guru could tell me the appropriate magic incantation to cast over this code to get it to chroot in both cases, I would appreciate it.

This is Perl 5.6.1 by the way.

sub ls_ld { my @dir = split '/', $_[0]; my $ret_text; for (2 .. $#dir) { my $path = join '/', @dir[0..$_]; my $ls_ld = `ls -ld $path`; $ret_text .= $ls_ld; } $ret_text; } my %dir = ( home => '/home/tmbranno', other => '/home/tmbranno/src/Net/FTPServer/ARU/ftp-dir/t' ); map { chroot $dir{$_} or die sprintf "cannot chroot: $dir{$_}: $!\n all paths of this:\n%s" +, ls_ld($dir{$_}) ; } (keys %dir);

{ap555sun:tmbranno:tmbranno_1693779_arulinkftp:arudev}133> /home/tmbra +nno/src/te sts % perl chroot.pl perl chroot.pl cannot chroot: /home/tmbranno/src/Net/FTPServer/ARU/ftp-dir/t: Not own +er all paths of this: drwxr-xr-x 19 tmbranno g680 8192 May 8 15:52 /home/tmbranno drwxr-xr-x 15 tmbranno g680 8192 May 3 09:59 /home/tmbranno/s +rc drwxr-xr-x 3 tmbranno g680 96 May 3 09:59 /home/tmbranno/s +rc/Net drwxr-xr-x 3 tmbranno g680 96 May 3 09:59 /home/tmbranno/s +rc/Net/FTPServer drwxr-xr-x 7 tmbranno g680 8192 May 8 15:35 /home/tmbranno/s +rc/Net/FTPServer/ARU drwxr-xr-x 4 tmbranno g680 96 May 8 15:26 /home/tmbranno/s +rc/Net/FTPServer/ARU/ftp-dir drwxr-xr-x 2 tmbranno g680 96 May 8 17:20 /home/tmbranno/s +rc/Net/FTPServer/ARU/ftp-dir/t {ap555sun:tmbranno:tmbranno_1693779_arulinkftp:arudev}134> /home/tmbra +nno/src/te sts %

Replies are listed 'Best First'.
Re: chroot fails for no obvious reason
by knobunc (Pilgrim) on May 09, 2001 at 21:02 UTC

    You know that you have to be root to chroot right?

    -ben

Re: chroot fails for no obvious reason
by princepawn (Parson) on May 09, 2001 at 21:04 UTC
    I saw that in the manpage, but then why doesn't it fail for my HOME directory?
      Perhaps because you're doing them sequentially?

      After you've chrooted, do you have a directory with that longer path below the directory that is now slash?

      -- Randal L. Schwartz, Perl hacker

        That's a brilliant observation, but off-target. I took the "home" key-value pair out of the hash, so there was only one chroot call, and it still failed the same way.
      (rpc@marduk):(~)$ id uid=1000(rpc) gid=1000(rpc) groups=1000(rpc) (rpc@marduk):(~)$ perl -e "chroot '/home/rpc' or die" Died at -e line 1. (rpc@marduk):(~)$