File: ftp.pm

package info (click to toggle)
libwww-perl 5.36-1.1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 848 kB
  • ctags: 400
  • sloc: perl: 6,366; makefile: 51; sh: 6
file content (76 lines) | stat: -rw-r--r-- 1,441 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package URI::URL::ftp;
require URI::URL::_generic;
@ISA = qw(URI::URL::_generic);

sub default_port { 21 }

sub _parse {
    my($self, $init) = @_;
    # The ftp URLs can't have any query string
    $self->URI::URL::_generic::_parse($init, qw(netloc path params frag));
    1;
}


sub user
{
    my($self, @val) = @_;
    my $old = $self->SUPER::user(@val);
    defined $old ? $old : "anonymous";
}

BEGIN {
    $whoami = undef;
    $fqdn   = undef;
}

sub password
{
    my($self, @val) = @_;
    my $old = $self->SUPER::password(@val);
    unless (defined $old) {
	my $user = $self->user;
	if ($user eq 'anonymous' || $user eq 'ftp') {
	    # anonymous ftp login password
	    unless (defined $fqdn) {
		eval {
		    require Net::Domain;
		    $fqdn = Net::Domain::hostfqdn();
		};
		if ($@) {
		    $fqdn = '';
		}
	    }
	    unless (defined $whoami) {
		$whoami = $ENV{USER} || $ENV{LOGNAME} || $ENV{USERNAME};
		unless ($whoami) {
		    if ($^O eq 'MSWin32') { $whoami = Win32::LoginName() }
		    else {
		        $whoami = getlogin || getpwuid($<) || 'unknown';
		    }
		}
	    }
	    $old = "$whoami\@$fqdn";
	} else {
	    $old = "";
	}
    }
    $old;
}

sub crack
{
    my $self = shift;
    my @c = $self->SUPER::crack;
    if ($c[3] && !$c[1]) {
	# hostname defined, but user is undefined
	$c[1] = $self->user;
	$c[2] = $self->password;
    }
    @c;
}

*query  = \&URI::URL::bad_method;
*equery = \&URI::URL::bad_method;

1;