releasing/cbrtools/perl/Net/Netrc.pm
author lorewang
Wed, 10 Nov 2010 14:19:09 +0800
changeset 676 b5e6747818a9
parent 602 3145852acc89
permissions -rw-r--r--
add rofs image compare
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Net::Netrc.pm
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# Copyright (c) 1995-1998 Graham Barr <gbarr@pobox.com>. All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# This program is free software; you can redistribute it and/or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# modify it under the same terms as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
package Net::Netrc;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
use Carp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
use FileHandle;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
use vars qw($VERSION);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
$VERSION = "2.12"; # $Id: //depot/libnet/Net/Netrc.pm#13 $
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
my %netrc = ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
sub _readrc
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
 my $host = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
 my($home,$file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
 if($^O eq "MacOS") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
   $home = $ENV{HOME} || `pwd`;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
   chomp($home);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
   $file = ($home =~ /:$/ ? $home . "netrc" : $home . ":netrc");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
 } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
   # Some OS's don't have `getpwuid', so we default to $ENV{HOME}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
   $home = eval { (getpwuid($>))[7] } || $ENV{HOME};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
   $home ||= $ENV{HOMEDRIVE} . ($ENV{HOMEPATH}||'') if defined $ENV{HOMEDRIVE};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
   $file = $home . "/.netrc";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
 my($login,$pass,$acct) = (undef,undef,undef);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
 my $fh;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
 local $_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
 $netrc{default} = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
 # OS/2 and Win32 do not handle stat in a way compatable with this check :-(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
 unless($^O eq 'os2'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
     || $^O eq 'MSWin32'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
     || $^O eq 'MacOS'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
     || $^O =~ /^cygwin/)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
  { 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
   my @stat = stat($file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
   if(@stat)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
     if($stat[2] & 077)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
       carp "Bad permissions: $file";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
       return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
     if($stat[4] != $<)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
       carp "Not owner: $file";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
       return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
 if($fh = FileHandle->new($file,"r"))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
   my($mach,$macdef,$tok,@tok) = (0,0);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
   while(<$fh>)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
     undef $macdef if /\A\n\Z/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
     if($macdef)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
       push(@$macdef,$_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
       next;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
     s/^\s*//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
     chomp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
     while(length && s/^("((?:[^"]+|\\.)*)"|((?:[^\\\s]+|\\.)*))\s*//) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
       (my $tok = $+) =~ s/\\(.)/$1/g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
       push(@tok, $tok);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
     }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
TOKEN:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
     while(@tok)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
       if($tok[0] eq "default")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
        {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
         shift(@tok);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
         $mach = bless {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
   	 $netrc{default} = [$mach];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
         next TOKEN;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
       last TOKEN
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
            unless @tok > 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
       $tok = shift(@tok);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
       if($tok eq "machine")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
        {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
         my $host = shift @tok;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
         $mach = bless {machine => $host};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
         $netrc{$host} = []
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
            unless exists($netrc{$host});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
         push(@{$netrc{$host}}, $mach);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
       elsif($tok =~ /^(login|password|account)$/)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
        {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
         next TOKEN unless $mach;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
         my $value = shift @tok;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
         # Following line added by rmerrell to remove '/' escape char in .netrc
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
         $value =~ s/\/\\/\\/g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
         $mach->{$1} = $value;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
       elsif($tok eq "macdef")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
        {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
         next TOKEN unless $mach;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
         my $value = shift @tok;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
         $mach->{macdef} = {}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
            unless exists $mach->{macdef};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
         $macdef = $mach->{machdef}{$value} = [];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
   $fh->close();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
sub lookup
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
 my($pkg,$mach,$login) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
 _readrc()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
    unless exists $netrc{default};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
 $mach ||= 'default';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
 undef $login
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
    if $mach eq 'default';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
 if(exists $netrc{$mach})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
   if(defined $login)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
     my $m;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
     foreach $m (@{$netrc{$mach}})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
       return $m
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
            if(exists $m->{login} && $m->{login} eq $login);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
     return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
   return $netrc{$mach}->[0]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
 return $netrc{default}->[0]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
    if defined $netrc{default};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
 return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
sub login
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
 my $me = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
 exists $me->{login}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
    ? $me->{login}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
    : undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
sub account
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
 my $me = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
 exists $me->{account}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
    ? $me->{account}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
    : undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
sub password
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
 my $me = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
 exists $me->{password}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
    ? $me->{password}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
    : undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
sub lpa
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
 my $me = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
 ($me->login, $me->password, $me->account);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
Net::Netrc - OO interface to users netrc file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
    use Net::Netrc;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
    $mach = Net::Netrc->lookup('some.machine');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
    $login = $mach->login;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
    ($login, $password, $account) = $mach->lpa;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
C<Net::Netrc> is a class implementing a simple interface to the .netrc file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
used as by the ftp program.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
C<Net::Netrc> also implements security checks just like the ftp program,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
these checks are, first that the .netrc file must be owned by the user and 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
second the ownership permissions should be such that only the owner has
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
read and write access. If these conditions are not met then a warning is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
output and the .netrc file is not read.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
=head1 THE .netrc FILE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
The .netrc file contains login and initialization information used by the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
auto-login process.  It resides in the user's home directory.  The following
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
tokens are recognized; they may be separated by spaces, tabs, or new-lines:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
=item machine name
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
Identify a remote machine name. The auto-login process searches
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
the .netrc file for a machine token that matches the remote machine
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
specified.  Once a match is made, the subsequent .netrc tokens
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
are processed, stopping when the end of file is reached or an-
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
other machine or a default token is encountered.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
=item default
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
This is the same as machine name except that default matches
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
any name.  There can be only one default token, and it must be
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
after all machine tokens.  This is normally used as:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
    default login anonymous password user@site
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
thereby giving the user automatic anonymous login to machines
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
not specified in .netrc.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
=item login name
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
Identify a user on the remote machine.  If this token is present,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
the auto-login process will initiate a login using the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
specified name.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
=item password string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
Supply a password.  If this token is present, the auto-login
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
process will supply the specified string if the remote server
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
requires a password as part of the login process.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
=item account string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
Supply an additional account password.  If this token is present,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
the auto-login process will supply the specified string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
if the remote server requires an additional account password.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
=item macdef name
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
Define a macro. C<Net::Netrc> only parses this field to be compatible
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
with I<ftp>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
=head1 CONSTRUCTOR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
The constructor for a C<Net::Netrc> object is not called new as it does not
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
really create a new object. But instead is called C<lookup> as this is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
essentially what it does.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
=item lookup ( MACHINE [, LOGIN ])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
Lookup and return a reference to the entry for C<MACHINE>. If C<LOGIN> is given
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
then the entry returned will have the given login. If C<LOGIN> is not given then
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
the first entry in the .netrc file for C<MACHINE> will be returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
If a matching entry cannot be found, and a default entry exists, then a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
reference to the default entry is returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
If there is no matching entry found and there is no default defined, or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
no .netrc file is found, then C<undef> is returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
=head1 METHODS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
=item login ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
Return the login id for the netrc entry
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
=item password ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
Return the password for the netrc entry
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
=item account ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
Return the account information for the netrc entry
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
=item lpa ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
Return a list of login, password and account information fir the netrc entry
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
=head1 AUTHOR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
Graham Barr <gbarr@pobox.com>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
=head1 SEE ALSO
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
L<Net::Netrc>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
L<Net::Cmd>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
Copyright (c) 1995-1998 Graham Barr. All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
This program is free software; you can redistribute it and/or modify
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
it under the same terms as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
=for html <hr>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
$Id: //depot/libnet/Net/Netrc.pm#13 $
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
=cut