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

I've got a chroot problem. It probably isn't a problem if you know FreeBSD 3.? very well at all. That's why I need help. I tracked this much down on my own, but then became completely baffled.

This whole problem is related to the fact that I didn't copy something into my fake root ... but I haven't the foggiest idea what that would be.

Arren@Anarres II on (Intermud III) suggested it might have to do with the getpeername(). Though I didn't follow it...

[code 15:35] Arren@Anarres II: I did do a fix recently where getpeerna +me() wasn't working properly on some generated symbol globs for sockets, something seems to have changed there. Probably doesn't h +elp.

This works (without being in the chroot prison):

#!/usr/bin/perl -w use strict; use Net::SMTP; use Carp qw(confess cluck); $SIG{__WARN__} = sub { cluck(@_) }; $SIG{__DIE__} = sub { confess(@_) }; my $smtp = Net::SMTP->new("localhost", Hello=>"localhost", Timeout=>20 +, Debug=>1) or die "$!";

However, when I'm in the prison, it turns up this nonsense:

No such file or directory at ./file.pl line 17. main::__ANON__('No such file or directory at ./file.pl line 17 +.^J') called at ./file.pl line 17
Using the perl debugger, I found this (this is not all of the trace):
44: if(defined $proto) { IO::Socket::INET::_sock_info(/usr/local/lib/perl5/5.6.1/IO/Socket/INET +.pm:45): 45: if (@proto = ( $proto =~ m,\D, 46: ? getprotobyname($proto) 47: : getprotobynumber($proto)) 48: ) { IO::Socket::INET::_sock_info(/usr/local/lib/perl5/5.6.1/IO/Socket/INET +.pm:52): 52: $@ = "Bad protocol '$proto'"; IO::Socket::INET::_sock_info(/usr/local/lib/perl5/5.6.1/IO/Socket/INET +.pm:53): 53: return; IO::Socket::INET::_error(/usr/local/lib/perl5/5.6.1/IO/Socket/INET.pm: +83):
So, I changed my Net::SMTP new to this:
my $sock = new IO::Socket::INET ( LocalPort => 88988, Proto => 'tcp', Reuse => 1, Listen => 1, ) or die "poopy: $!";
and got this:
poopy: No such file or directory at ./file.pl line 10. main::__ANON__('poopy: No such file or directory at ./file.pl +line 10.^J') called at ./file.pl line 10

Edit by tye to change 'pre' tags to 'code' tags

Replies are listed 'Best First'.
Re: Obscure IO::Socket poop under a chroot Help Help Help!
by jettero (Monsignor) on Jul 11, 2002 at 20:14 UTC
    Didn't realize it was this simple:
    [code 16:02] Dorn :) http://www.perlmonks.org/index.pl?node_id=181126. [code 16:03] Arren@Anarres II: Ohhhhhh. [code 16:03] Arren@Anarres II: Now I see the trace, it's obvious. [code 16:04] Arren@Anarres II: getprotobyname is a C library call whic +h reads /etc/protocols, which is not available in your chroot. [code 16:04] Arren@Anarres II hits himself with a stick. [code 16:04] CyberTiger@Anarres II slaps Arren@Anarres II. (from Cyber +Tiger@Anarres II) [code 16:04] CyberTiger@Anarres II: yoou shoulda known that :P. [code 16:04] Arren@Anarres II: Thankyou. I suck goats off for fun. But + that's the problem. [code 16:05] CyberTiger@Anarres II: don't get yourself confused with A +l. [code 16:05] Arren@Anarres II: You might be able to just use 6 instead + of 'tcp'. [code 16:06] CyberTiger@Anarres II: so turn /etc/protocols into a #def +ine, there's a #define for the protocol number for tcp anyway. [code 16:07] Arren@Anarres II hits CyberTiger. 1. This is Perl. 2. The + number for TCP isn't going to change this week. 3. What? 4.
      If you want to be extremely anal about this, you could do your own getprotobyname before you chroot(), and use the value it returns instead of hardcoding a "6" (or whatever).

      It may not make sense for your particular application, but you may also be able to open your listening socket first, and then chroot.

      Alan